// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.IO; using System.Runtime.InteropServices; using SharpDX.Mathematics.Interop; namespace SharpDX.Direct3D9 { public partial class VolumeTexture { /// /// Initializes a new instance of the class. /// /// The device. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// HRESULT IDirect3DDevice9::CreateVolumeTexture([In] unsigned int Width,[In] unsigned int Height,[In] unsigned int Levels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out, Fast] IDirect3DVolumeTexture9** ppVolumeTexture,[In] void** pSharedHandle) public VolumeTexture(Device device, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool) : base(IntPtr.Zero) { device.CreateVolumeTexture(width, height, depth, levelCount, (int)usage, format, pool, this, IntPtr.Zero); } /// /// Initializes a new instance of the class. /// /// The device. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The shared handle. /// HRESULT IDirect3DDevice9::CreateVolumeTexture([In] unsigned int Width,[In] unsigned int Height,[In] unsigned int Levels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[Out, Fast] IDirect3DVolumeTexture9** ppVolumeTexture,[In] void** pSharedHandle) public VolumeTexture(Device device, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, ref IntPtr sharedHandle) : base(IntPtr.Zero) { unsafe { fixed (void* pSharedHandle = &sharedHandle) device.CreateVolumeTexture(width, height, depth, levelCount, (int)usage, format, pool, this, new IntPtr(pSharedHandle)); } } /// /// Checks texture-creation parameters. /// /// Device associated with the texture. /// The width. /// The height. /// The depth. /// Requested number of mipmap levels for the texture. /// The requested usage for the texture. /// Requested format for the texture. /// Memory class where the resource will be placed. /// /// A value type containing the proposed values to pass to the texture creation functions. /// /// HRESULT D3DXCheckVolumeTextureRequirements([In] IDirect3DDevice9* pDevice,[InOut] unsigned int* pWidth,[InOut] unsigned int* pHeight,[InOut] unsigned int* pDepth,[InOut] unsigned int* pNumMipLevels,[In] unsigned int Usage,[InOut] D3DFORMAT* pFormat,[In] D3DPOOL Pool) public static VolumeTextureRequirements CheckRequirements(Device device, int width, int height, int depth, int mipLevelCount, Usage usage, Format format, Pool pool) { var result = new VolumeTextureRequirements(); D3DX9.CheckVolumeTextureRequirements(device, ref result.Width, ref result.Height, ref result.Depth, ref result.MipLevelCount, (int)usage, ref result.Format, pool); return result; } /// /// Uses a user-provided function to fill each texel of each mip level of a given texture. /// /// A function that is used to fill the texture. /// A object describing the result of the operation. /// HRESULT D3DXFillVolumeTexture([In] IDirect3DVolumeTexture9* pVolumeTexture,[In] __function__stdcall* pFunction,[In] void* pData) public void Fill(Fill3DCallback callback) { var handle = GCHandle.Alloc(callback); try { D3DX9.FillVolumeTexture(this, FillCallbackHelper.Native2DCallbackPtr, GCHandle.ToIntPtr(handle)); } finally { handle.Free(); } } /// /// Uses a compiled high-level shader language (HLSL) function to fill each texel of each mipmap level of a texture. /// /// A texture shader object that is used to fill the texture. /// A object describing the result of the operation. /// HRESULT D3DXFillVolumeTextureTX([In] IDirect3DVolumeTexture9* pVolumeTexture,[In] ID3DXVolumeTextureShader* pVolumeTextureShader) public void Fill(TextureShader shader) { D3DX9.FillVolumeTextureTX(this, shader); } /// /// Locks a box on a volume texture resource. /// /// The level. /// The flags. /// /// A describing the region locked. /// /// HRESULT IDirect3DVolumeTexture9::LockBox([In] unsigned int Level,[Out] D3DLOCKED_BOX* pLockedVolume,[In] const void* pBox,[In] D3DLOCK Flags) public DataBox LockBox(int level, SharpDX.Direct3D9.LockFlags flags) { LockedBox lockedRect; LockBox(level, out lockedRect, IntPtr.Zero, flags); return new DataBox(lockedRect.PBits, lockedRect.RowPitch, lockedRect.SlicePitch); } /// /// Locks a box on a volume texture resource. /// /// The level. /// The box. /// The flags. /// /// A describing the region locked. /// /// HRESULT IDirect3DVolumeTexture9::LockBox([In] unsigned int Level,[Out] D3DLOCKED_BOX* pLockedVolume,[In] const void* pBox,[In] D3DLOCK Flags) public DataBox LockBox(int level, Box box, SharpDX.Direct3D9.LockFlags flags) { unsafe { LockedBox lockedRect; LockBox(level, out lockedRect, new IntPtr(&box), flags); return new DataBox(lockedRect.PBits, lockedRect.RowPitch, lockedRect.SlicePitch); } } /// /// Adds a dirty region to a texture resource. /// /// /// A object describing the result of the operation. /// /// HRESULT IDirect3DVolumeTexture9::AddDirtyBox([In] const void* pDirtyBox) public void AddDirtyBox() { AddDirtyBox(IntPtr.Zero); } /// /// Adds a dirty region to a texture resource. /// /// The direct box ref. /// /// A object describing the result of the operation. /// /// HRESULT IDirect3DVolumeTexture9::AddDirtyBox([In] const void* pDirtyBox) public void AddDirtyBox(Box directBoxRef) { unsafe { AddDirtyBox(new IntPtr(&directBoxRef)); } } /// /// Creates a from a file /// /// The device. /// The filename. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromFile(Device device, string filename) { VolumeTexture cubeVolumeTexture; D3DX9.CreateVolumeTextureFromFileW(device, filename, out cubeVolumeTexture); return cubeVolumeTexture; } /// /// Creates a from a file /// /// The device. /// The filename. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromFile(Device device, string filename, Usage usage, Pool pool) { return FromFile(device, filename, -1, -1, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a file /// /// The device. /// The filename. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromFile(Device device, string filename, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromFile(device, filename, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a file /// /// The device. /// The filename. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromFile(Device device, string filename, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation) { fixed (void* pImageInfo = &imageInformation) return CreateFromFile(device, filename, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a file /// /// The device. /// The filename. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileExW([In] IDirect3DDevice9* pDevice,[In] const wchar_t* pSrcFile,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[In] void* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromFile(Device device, string filename, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette) { palette = new PaletteEntry[256]; fixed (void* pImageInfo = &imageInformation) return CreateFromFile(device, filename, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemory([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromMemory(Device device, byte[] buffer) { VolumeTexture cubeVolumeTexture; unsafe { fixed (void* pData = buffer) D3DX9.CreateVolumeTextureFromFileInMemory(device, (IntPtr)pData, buffer.Length, out cubeVolumeTexture); } return cubeVolumeTexture; } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromMemory(Device device, byte[] buffer, Usage usage, Pool pool) { return FromMemory(device, buffer, -1, -1, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromMemory(device, buffer, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation) { fixed (void* pImageInfo = &imageInformation) return CreateFromMemory(device, buffer, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette) { palette = new PaletteEntry[256]; fixed (void* pImageInfo = &imageInformation) return CreateFromMemory(device, buffer, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// A /// HRESULT D3DXCreateVolumeTextureFromFileInMemory([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromStream(Device device, Stream stream) { VolumeTexture cubeVolumeTexture; if (stream is DataStream) { D3DX9.CreateVolumeTextureFromFileInMemory(device, ((DataStream)stream).PositionPointer, (int)(stream.Length - stream.Position), out cubeVolumeTexture); } else { unsafe { var data = Utilities.ReadStream(stream); fixed (void* pData = data) D3DX9.CreateVolumeTextureFromFileInMemory(device, (IntPtr)pData, data.Length, out cubeVolumeTexture); } } return cubeVolumeTexture; } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromStream(Device device, Stream stream, Usage usage, Pool pool) { return FromStream(device, stream, 0, -1, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromStream(Device device, Stream stream, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return FromStream(device, stream, 0, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static VolumeTexture FromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromStream(device, stream, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation) { fixed (void* pImageInfo = &imageInformation) return CreateFromStream(device, stream, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) public static unsafe VolumeTexture FromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, out ImageInformation imageInformation, out PaletteEntry[] palette) { palette = new PaletteEntry[256]; fixed (void* pImageInfo = &imageInformation) return CreateFromStream(device, stream, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a stream. /// /// The device. /// The buffer. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) private static unsafe VolumeTexture CreateFromMemory(Device device, byte[] buffer, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { VolumeTexture cubeVolumeTexture; fixed (void* pBuffer = buffer) cubeVolumeTexture = CreateFromPointer( device, (IntPtr)pBuffer, buffer.Length, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); return cubeVolumeTexture; } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// A /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) private static unsafe VolumeTexture CreateFromStream(Device device, Stream stream, int sizeBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { VolumeTexture cubeVolumeTexture; sizeBytes = sizeBytes == 0 ? (int)(stream.Length - stream.Position): sizeBytes; if (stream is DataStream) { cubeVolumeTexture = CreateFromPointer( device, ((DataStream)stream).PositionPointer, sizeBytes, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); } else { var data = Utilities.ReadStream(stream); fixed (void* pData = data) cubeVolumeTexture = CreateFromPointer( device, (IntPtr)pData, data.Length, width, height, depth, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); } stream.Position = sizeBytes; return cubeVolumeTexture; } /// /// Creates a from a stream. /// /// The device. /// The pointer. /// The size in bytes. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) private static unsafe VolumeTexture CreateFromPointer(Device device, IntPtr pointer, int sizeInBytes, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { VolumeTexture cubeVolumeTexture; D3DX9.CreateVolumeTextureFromFileInMemoryEx( device, pointer, sizeInBytes, width, height, depth, levelCount, (int)usage, format, pool, (int)filter, (int)mipFilter, *(RawColorBGRA*)&colorKey, imageInformation, palette, out cubeVolumeTexture); return cubeVolumeTexture; } /// /// Creates a from a stream. /// /// The device. /// Name of the file. /// The width. /// The height. /// The depth. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateVolumeTextureFromFileInMemoryEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] unsigned int Size,[In] unsigned int MipLevels,[In] unsigned int Usage,[In] D3DFORMAT Format,[In] D3DPOOL Pool,[In] unsigned int Filter,[In] unsigned int MipFilter,[In] D3DCOLOR ColorKey,[Out] D3DXIMAGE_INFO* pSrcInfo,[Out, Buffer] PALETTEENTRY* pPalette,[In] IDirect3DVolumeTexture9** ppVolumeTexture) private unsafe static VolumeTexture CreateFromFile(Device device, string fileName, int width, int height, int depth, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { VolumeTexture cubeVolumeTexture; D3DX9.CreateVolumeTextureFromFileExW( device, fileName, width, height, depth, levelCount, (int)usage, format, pool, (int)filter, (int)mipFilter, *(RawColorBGRA*)&colorKey, imageInformation, palette, out cubeVolumeTexture); return cubeVolumeTexture; } } }