// 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 CubeTexture { /// /// Initializes a new instance of the class. /// /// The device. /// Length of the edge. /// The level count. /// The usage. /// The format. /// The pool. public CubeTexture(Device device, int edgeLength, int levelCount, Usage usage, Format format, Pool pool = Pool.Managed) : base(IntPtr.Zero) { device.CreateCubeTexture(edgeLength, levelCount, (int)usage, format, pool, this, IntPtr.Zero); } /// /// Initializes a new instance of the class. /// /// The device. /// Length of the edge. /// The level count. /// The usage. /// The format. /// The pool. /// The shared handle. public CubeTexture(Device device, int edgeLength, int levelCount, Usage usage, Format format, Pool pool, ref IntPtr sharedHandle) : base(IntPtr.Zero) { unsafe { fixed (void* pSharedHandle = &sharedHandle) device.CreateCubeTexture(edgeLength, levelCount, (int)usage, format, pool, this, (IntPtr)pSharedHandle); } } /// /// Checks texture-creation parameters. /// /// Device associated with the texture. /// Requested size of the texture. Null if /// 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 D3DXCheckCubeTextureRequirements([In] IDirect3DDevice9* pDevice,[InOut] unsigned int* pSize,[InOut] unsigned int* pNumMipLevels,[In] unsigned int Usage,[InOut] D3DFORMAT* pFormat,[In] D3DPOOL Pool) public static CubeTextureRequirements CheckRequirements(Device device, int size, int mipLevelCount, Usage usage, Format format, Pool pool) { var result = new CubeTextureRequirements { Size = size, MipLevelCount = mipLevelCount, Format = format }; D3DX9.CheckCubeTextureRequirements(device, ref result.Size, 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 cube texture. /// /// A function that is used to fill the texture. /// A object describing the result of the operation. public void Fill(Fill3DCallback callback) { var handle = GCHandle.Alloc(callback); try { D3DX9.FillCubeTexture(this, FillCallbackHelper.Native3DCallbackPtr, 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. public void Fill(TextureShader shader) { D3DX9.FillCubeTextureTX(this, shader); } /// /// Locks a rectangle on a cube texture resource. /// /// Type of the face. /// The level. /// The flags. /// /// A describing the region locked. /// /// HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags) public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, SharpDX.Direct3D9.LockFlags flags) { LockedRectangle lockedRect; LockRectangle(faceType, level, out lockedRect, IntPtr.Zero, flags); return new DataRectangle(lockedRect.PBits, lockedRect.Pitch); } /// /// Locks a rectangle on a cube texture resource. /// /// Type of the face. /// The level. /// The flags. /// The stream pointing to the locked region. /// /// A describing the region locked. /// /// HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags) public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, SharpDX.Direct3D9.LockFlags flags, out DataStream stream) { LockedRectangle lockedRect; LockRectangle(faceType, level, out lockedRect, IntPtr.Zero, flags); stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * GetLevelDescription(level).Height, true, (flags & LockFlags.ReadOnly) == 0); return new DataRectangle(lockedRect.PBits, lockedRect.Pitch); } /// /// Locks a rectangle on a cube texture resource. /// /// Type of the face. /// The level. /// The rectangle. /// The flags. /// /// A describing the region locked. /// /// HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags) public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags) { unsafe { LockedRectangle lockedRect; LockRectangle(faceType, level, out lockedRect, new IntPtr(&rectangle), flags); return new DataRectangle(lockedRect.PBits, lockedRect.Pitch); } } /// /// Locks a rectangle on a cube texture resource. /// /// Type of the face. /// The level. /// The rectangle. /// The flags. /// The stream pointing to the locked region. /// /// A describing the region locked. /// /// HRESULT IDirect3DCubeTexture9::LockRect([In] D3DCUBEMAP_FACES FaceType,[In] unsigned int Level,[In] D3DLOCKED_RECT* pLockedRect,[In] const void* pRect,[In] D3DLOCK Flags) public DataRectangle LockRectangle(SharpDX.Direct3D9.CubeMapFace faceType, int level, RawRectangle rectangle, SharpDX.Direct3D9.LockFlags flags, out DataStream stream) { unsafe { LockedRectangle lockedRect; LockRectangle(faceType, level, out lockedRect, new IntPtr(&rectangle), flags); stream = new DataStream(lockedRect.PBits, lockedRect.Pitch * GetLevelDescription(level).Height, true, (flags & LockFlags.ReadOnly) == 0); return new DataRectangle(lockedRect.PBits, lockedRect.Pitch); } } /// /// Adds a dirty region to a cube texture resource. /// /// Type of the face. /// A object describing the result of the operation. /// HRESULT IDirect3DCubeTexture9::AddDirtyRect([In] D3DCUBEMAP_FACES FaceType,[In] const void* pDirtyRect) public void AddDirtyRectangle(SharpDX.Direct3D9.CubeMapFace faceType) { AddDirtyRectangle(faceType, IntPtr.Zero); } /// /// Adds a dirty region to a cube texture resource. /// /// Type of the face. /// The dirty rect ref. /// A object describing the result of the operation. /// HRESULT IDirect3DCubeTexture9::AddDirtyRect([In] D3DCUBEMAP_FACES FaceType,[In] const void* pDirtyRect) public void AddDirtyRectangle(SharpDX.Direct3D9.CubeMapFace faceType, RawRectangle dirtyRectRef) { unsafe { AddDirtyRectangle(faceType, new IntPtr(&dirtyRectRef)); } } /// /// Creates a from a file /// /// The device. /// The filename. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileExW([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromFile(Device device, string filename) { CubeTexture cubeTexture; D3DX9.CreateCubeTextureFromFileW(device, filename, out cubeTexture); return cubeTexture; } /// /// Creates a from a file /// /// The device. /// The filename. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileExW([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromFile(Device device, string filename, Usage usage, Pool pool) { return FromFile(device, filename, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a file /// /// The device. /// The filename. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileExW([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromFile(Device device, string filename, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromFile(device, filename, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a file /// /// The device. /// The filename. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileExW([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromFile(Device device, string filename, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a file /// /// The device. /// The filename. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileExW([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromFile(Device device, string filename, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemory([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromMemory(Device device, byte[] buffer) { CubeTexture cubeTexture; unsafe { fixed (void* pData = buffer) D3DX9.CreateCubeTextureFromFileInMemory(device, (IntPtr)pData, buffer.Length, out cubeTexture); } return cubeTexture; } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromMemory(Device device, byte[] buffer, Usage usage, Pool pool) { return FromMemory(device, buffer, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromMemory(Device device, byte[] buffer, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromMemory(device, buffer, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromMemory(Device device, byte[] buffer, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a memory buffer. /// /// The device. /// The buffer. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromMemory(Device device, byte[] buffer, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// A /// HRESULT D3DXCreateCubeTextureFromFileInMemory([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromStream(Device device, Stream stream) { CubeTexture cubeTexture; if (stream is DataStream) { D3DX9.CreateCubeTextureFromFileInMemory(device, ((DataStream)stream).PositionPointer, (int)(stream.Length - stream.Position), out cubeTexture); } else { unsafe { var data = Utilities.ReadStream(stream); fixed (void* pData = data) D3DX9.CreateCubeTextureFromFileInMemory(device, (IntPtr)pData, data.Length, out cubeTexture); } } return cubeTexture; } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The usage. /// The pool. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromStream(Device device, Stream stream, Usage usage, Pool pool) { return FromStream(device, stream, 0, -1, -1, usage, Format.Unknown, pool, Filter.Default, Filter.Default, 0); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromStream(Device device, Stream stream, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return FromStream(device, stream, 0, size, levelCount, usage, format, pool, filter, mipFilter, colorKey); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static CubeTexture FromStream(Device device, Stream stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey) { return CreateFromStream(device, stream, sizeBytes, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, IntPtr.Zero, null); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromStream(Device device, Stream stream, int sizeBytes, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, null); } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) public static unsafe CubeTexture FromStream(Device device, Stream stream, int sizeBytes, int size, 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, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, (IntPtr)pImageInfo, palette); } /// /// Creates a from a stream. /// /// The device. /// The buffer. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) private static unsafe CubeTexture CreateFromMemory(Device device, byte[] buffer, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { CubeTexture cubeTexture; fixed (void* pBuffer = buffer) cubeTexture = CreateFromPointer( device, (IntPtr)pBuffer, buffer.Length, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); return cubeTexture; } /// /// Creates a from a stream. /// /// The device. /// The stream. /// The size bytes. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// A /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) private static unsafe CubeTexture CreateFromStream(Device device, Stream stream, int sizeBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { CubeTexture cubeTexture; sizeBytes = sizeBytes == 0 ? (int)(stream.Length - stream.Position) : sizeBytes; if (stream is DataStream) { cubeTexture = CreateFromPointer( device, ((DataStream)stream).PositionPointer, sizeBytes, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); } else { var data = Utilities.ReadStream(stream); fixed (void* pData = data) cubeTexture = CreateFromPointer( device, (IntPtr)pData, data.Length, size, levelCount, usage, format, pool, filter, mipFilter, colorKey, imageInformation, palette ); } stream.Position = sizeBytes; return cubeTexture; } /// /// Creates a from a stream. /// /// The device. /// The pointer. /// The size in bytes. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) private static unsafe CubeTexture CreateFromPointer(Device device, IntPtr pointer, int sizeInBytes, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { CubeTexture cubeTexture; D3DX9.CreateCubeTextureFromFileInMemoryEx( device, pointer, sizeInBytes, size, levelCount, (int)usage, format, pool, (int)filter, (int)mipFilter, *(RawColorBGRA*)&colorKey, imageInformation, palette, out cubeTexture); return cubeTexture; } /// /// Creates a from a stream. /// /// The device. /// Name of the file. /// The size. /// The level count. /// The usage. /// The format. /// The pool. /// The filter. /// The mip filter. /// The color key. /// The image information. /// The palette. /// /// A /// /// HRESULT D3DXCreateCubeTextureFromFileInMemoryEx([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] IDirect3DCubeTexture9** ppCubeTexture) private unsafe static CubeTexture CreateFromFile(Device device, string fileName, int size, int levelCount, Usage usage, Format format, Pool pool, Filter filter, Filter mipFilter, int colorKey, IntPtr imageInformation, PaletteEntry[] palette) { CubeTexture cubeTexture; D3DX9.CreateCubeTextureFromFileExW( device, fileName, size, levelCount, (int)usage, format, pool, (int)filter, (int)mipFilter, *(RawColorBGRA*)&colorKey, imageInformation, palette, out cubeTexture); return cubeTexture; } } }