Exemplo n.º 1
0
        /// <summary>
        /// Saves a volume to a <see cref="DataStream"/>.
        /// </summary>
        /// <param name="volume">The volume.</param>
        /// <param name="format">The format.</param>
        /// <returns>
        /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
        /// </returns>
        /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged>
        public static DataStream ToStream(Volume volume, ImageFileFormat format)
        {
            Blob blob;

            D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, null, IntPtr.Zero);
            return(new DataStream(blob));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Loads a volume from a source volume.
 /// </summary>
 /// <param name="destinationVolume">The destination volume.</param>
 /// <param name="sourceVolume">The source volume.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="destinationPalette">The destination palette.</param>
 /// <param name="sourcePalette">The source palette.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromVolume([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] IDirect3DVolume9* pSrcVolume,[In] const PALETTEENTRY* pSrcPalette,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey)</unmanaged>
 public static void FromVolume(Volume destinationVolume, Volume sourceVolume, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] destinationPalette, PaletteEntry[] sourcePalette)
 {
     unsafe
     {
         D3DX9.LoadVolumeFromVolume(destinationVolume, destinationPalette, new IntPtr(&destinationBox), sourceVolume, sourcePalette, new IntPtr(&sourceBox), filter, colorKey);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves information about a given image file from a stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="keepPosition">if set to <c>true</c> preserve the stream position; <c>false</c> will move the stream pointer.</param>
        /// <returns>A <see cref="ImageInformation"/> structure</returns>
        /// <unmanaged>HRESULT D3DXGetImageInfoFromFileInMemory([In] const void* pSrcData,[In] unsigned int SrcDataSize,[Out] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
        public static ImageInformation FromStream(Stream stream, bool keepPosition)
        {
            long savedPosition = 0;

            if (keepPosition)
            {
                savedPosition = stream.Position;
            }

            ImageInformation result;

            if (stream is DataStream)
            {
                var dataStream = ((DataStream)stream);
                result = D3DX9.GetImageInfoFromFileInMemory(dataStream.PositionPointer, (int)(dataStream.Length - dataStream.Position));
                dataStream.Position = dataStream.Length;
            }
            else
            {
                var buffer = Utilities.ReadStream(stream);
                result = FromMemory(buffer);
            }
            if (keepPosition)
            {
                stream.Position = savedPosition;
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks texture-creation parameters.
        /// </summary>
        /// <param name="device">Device associated with the texture.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="mipLevelCount">Requested number of mipmap levels for the texture.</param>
        /// <param name="usage">The requested usage for the texture.</param>
        /// <param name="format">Requested format for the texture.</param>
        /// <param name="pool">Memory class where the resource will be placed.</param>
        /// <returns>
        /// A value type containing the proposed values to pass to the texture creation functions.
        /// </returns>
        /// <unmanaged>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)</unmanaged>
        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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Compiles an effect from a string.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="sourceData">The source data.</param>
        /// <param name="preprocessorDefines">The preprocessor defines.</param>
        /// <param name="includeFile">The include file.</param>
        /// <param name="skipConstants">The skip constants.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="pool">The pool.</param>
        /// <returns>
        /// An <see cref="Effect"/>
        /// </returns>
        /// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
        public static Effect FromString(Device device, string sourceData, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
        {
            Effect effect        = null;
            Blob   blobForErrors = null;

            var buffer = Marshal.StringToHGlobalAnsi(sourceData);

            try
            {
                D3DX9.CreateEffectEx(
                    device,
                    buffer,
                    sourceData.Length,
                    PrepareMacros(preprocessorDefines),
                    IncludeShadow.ToIntPtr(includeFile),
                    skipConstants,
                    (int)flags,
                    pool,
                    out effect,
                    out blobForErrors);
            }
            catch (SharpDXException ex)
            {
                if (blobForErrors != null)
                {
                    throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                }
                throw;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
            return(effect);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks texture-creation parameters.
        /// </summary>
        /// <param name="device">Device associated with the texture.</param>
        /// <param name="size">Requested size of the texture. Null if </param>
        /// <param name="mipLevelCount">Requested number of mipmap levels for the texture.</param>
        /// <param name="usage">The requested usage for the texture.</param>
        /// <param name="format">Requested format for the texture.</param>
        /// <param name="pool">Memory class where the resource will be placed.</param>
        /// <returns>A value type containing the proposed values to pass to the texture creation functions.</returns>
        /// <unmanaged>HRESULT D3DXCheckCubeTextureRequirements([In] IDirect3DDevice9* pDevice,[InOut] unsigned int* pSize,[InOut] unsigned int* pNumMipLevels,[In] unsigned int Usage,[InOut] D3DFORMAT* pFormat,[In] D3DPOOL Pool)</unmanaged>
        public static CubeTextureRequirements CheckRequirements(Device device, int size, int mipLevelCount, Usage usage, Format format, Pool pool)
        {
            var result = new CubeTextureRequirements();

            D3DX9.CheckCubeTextureRequirements(device, ref result.Size, ref result.MipLevelCount, (int)usage, ref result.Format, pool);
            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Compiles an effect from a memory buffer.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="memory">The buffer.</param>
        /// <param name="preprocessorDefines">The preprocessor defines.</param>
        /// <param name="includeFile">The include file.</param>
        /// <param name="skipConstants">The skip constants.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="pool">The pool.</param>
        /// <returns>An <see cref="Effect"/></returns>
        /// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
        public static Effect FromMemory(Device device, byte[] memory, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
        {
            unsafe
            {
                Effect effect        = null;
                Blob   blobForErrors = null;

                try
                {
                    fixed(void *pData = memory)
                    D3DX9.CreateEffectEx(
                        device,
                        (IntPtr)pData,
                        memory.Length,
                        PrepareMacros(preprocessorDefines),
                        IncludeShadow.ToIntPtr(includeFile),
                        skipConstants,
                        (int)flags,
                        pool,
                        out effect,
                        out blobForErrors);
                }
                catch (SharpDXException ex)
                {
                    if (blobForErrors != null)
                    {
                        throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                    }
                    throw;
                }
                return(effect);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a <see cref="CubeTexture"/> from a file
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="filename">The filename.</param>
        /// <returns>
        /// A <see cref="CubeTexture"/>
        /// </returns>
        /// <unmanaged>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)</unmanaged>
        public static CubeTexture FromFile(Device device, string filename)
        {
            CubeTexture cubeTexture;

            D3DX9.CreateCubeTextureFromFileW(device, filename, out cubeTexture);
            return(cubeTexture);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Saves a volume to a file on disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="format">The format.</param>
 /// <param name="box">The box.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXSaveVolumeToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In] const PALETTEENTRY* pSrcPalette,[In] const D3DBOX* pSrcBox)</unmanaged>
 public static void ToFile(Volume volume, string fileName, ImageFileFormat format, Box box, PaletteEntry[] palette)
 {
     unsafe
     {
         D3DX9.SaveVolumeToFileW(fileName, format, volume, palette, new IntPtr(&box));
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Disassembles compiled HLSL code back into textual source.
        /// </summary>
        /// <param name="enableColorCode">if set to <c>true</c> [enable color code].</param>
        /// <param name="comments">Commenting information to embed in the disassembly.</param>
        /// <returns>
        /// The textual source of the shader or effect.
        /// </returns>
        /// <unmanaged>HRESULT D3DXDisassembleShader([In] const void* pShader,[In] BOOL EnableColorCode,[In] const char* pComments,[In] ID3DXBuffer** ppDisassembly)</unmanaged>
        public string Disassemble(bool enableColorCode, string comments)
        {
            Blob output;

            D3DX9.DisassembleShader(BufferPointer, enableColorCode, comments, out output);
            return(Utilities.BlobToString(output));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Loads a volume from a file on the disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox)
 {
     unsafe
     {
         D3DX9.LoadVolumeFromFileW(volume, null, new IntPtr(&destinationBox), fileName, new IntPtr(&sourceBox), filter, colorKey, IntPtr.Zero);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Retrieves information about a given image file in memory.
 /// </summary>
 /// <param name="memory">The memory.</param>
 /// <returns>A <see cref="ImageInformation"/> structure</returns>
 /// <unmanaged>HRESULT D3DXGetImageInfoFromFileInMemory([In] const void* pSrcData,[In] unsigned int SrcDataSize,[Out] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static ImageInformation FromMemory(byte[] memory)
 {
     unsafe
     {
         fixed(void *pMemory = memory)
         return(D3DX9.GetImageInfoFromFileInMemory((IntPtr)pMemory, memory.Length));
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey)
 {
     unsafe
     {
         fixed(void *pMemory = memory)
         D3DX9.LoadVolumeFromFileInMemory(volume, null, IntPtr.Zero, (IntPtr)pMemory, memory.Length, IntPtr.Zero, filter, colorKey, IntPtr.Zero);
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox)
 {
     unsafe
     {
         fixed(void *pMemory = memory)
         D3DX9.LoadVolumeFromFileInMemory(volume, null, new IntPtr(&destinationBox), (IntPtr)pMemory, memory.Length, new IntPtr(&sourceBox), filter, colorKey, IntPtr.Zero);
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Loads a volume from a file on the disk.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileW([In] IDirect3DVolume9* pDestVolume,[In] const PALETTEENTRY* pDestPalette,[In] const D3DBOX* pDestBox,[In] const wchar_t* pSrcFile,[In] const D3DBOX* pSrcBox,[In] unsigned int Filter,[In] D3DCOLOR ColorKey,[In] D3DXIMAGE_INFO* pSrcInfo)</unmanaged>
 public static void FromFile(Volume volume, string fileName, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed(void *pImageInformation = &imageInformation)
         D3DX9.LoadVolumeFromFileW(volume, palette, new IntPtr(&destinationBox), fileName, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Loads a volume from a file in memory.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="memory">The memory.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="colorKey">The color key.</param>
 /// <param name="sourceBox">The source box.</param>
 /// <param name="destinationBox">The destination box.</param>
 /// <param name="palette">The palette.</param>
 /// <param name="imageInformation">The image information.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXLoadVolumeFromFileInMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey,[In] void* pSrcInfo)</unmanaged>
 public static void FromFileInMemory(Volume volume, byte[] memory, Filter filter, int colorKey, Box sourceBox, Box destinationBox, PaletteEntry[] palette, out ImageInformation imageInformation)
 {
     unsafe
     {
         fixed(void *pMemory = memory)
         fixed(void *pImageInformation = &imageInformation)
         D3DX9.LoadVolumeFromFileInMemory(volume, palette, new IntPtr(&destinationBox), (IntPtr)pMemory, memory.Length, new IntPtr(&sourceBox), filter, colorKey, (IntPtr)pImageInformation);
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Searches through the shader for the specified comment.
        /// </summary>
        /// <param name="fourCC">A FOURCC code used to identify the comment.</param>
        /// <returns>The comment data.</returns>
        /// <unmanaged>HRESULT D3DXFindShaderComment([In] const void* pFunction,[In] unsigned int FourCC,[Out] const void** ppData,[Out] unsigned int* pSizeInBytes)</unmanaged>
        public DataStream FindComment(Format fourCC)
        {
            IntPtr buffer;
            int    size;

            D3DX9.FindShaderComment(BufferPointer, (int)fourCC, out buffer, out size);

            return(new DataStream(buffer, size, true, true));
        }
Exemplo n.º 18
0
 /// <summary>
 /// Saves a volume to a <see cref="DataStream"/>.
 /// </summary>
 /// <param name="volume">The volume.</param>
 /// <param name="format">The format.</param>
 /// <param name="box">The box.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXSaveVolumeToFileInMemory([In] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DVolume9* pSrcVolume,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox)</unmanaged>
 public static DataStream ToStream(Volume volume, ImageFileFormat format, Box box, PaletteEntry[] palette)
 {
     unsafe
     {
         Blob blob;
         D3DX9.SaveVolumeToFileInMemory(out blob, format, volume, palette, new IntPtr(&box));
         return(new DataStream(blob));
     }
 }
Exemplo n.º 19
0
 public void LoadResources(Direct3DDevice9 device)
 {
     if (device == null || Texture != null)
     {
         return;
     }
     using (var stream = m_iconDesc.GetImageStream())
     {
         Texture = D3DX9.CreateTextureFromStream(device, stream);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Creates a <see cref="CubeTexture"/> from a memory buffer.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="buffer">The buffer.</param>
        /// <returns>
        /// A <see cref="CubeTexture"/>
        /// </returns>
        /// <unmanaged>HRESULT D3DXCreateCubeTextureFromFileInMemory([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataSize,[In] IDirect3DCubeTexture9** ppCubeTexture)</unmanaged>
        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);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Compiles an effect from a stream.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="preprocessorDefines">The preprocessor defines.</param>
        /// <param name="includeFile">The include file.</param>
        /// <param name="skipConstants">The skip constants.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="pool">The pool.</param>
        /// <returns>An <see cref="Effect"/></returns>
        /// <unmanaged>HRESULT D3DXCreateEffectEx([In] IDirect3DDevice9* pDevice,[In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pSkipConstants,[In] unsigned int Flags,[In] ID3DXEffectPool* pPool,[In] ID3DXEffect** ppEffect,[In] ID3DXBuffer** ppCompilationErrors)</unmanaged>
        public static Effect FromStream(Device device, Stream stream, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags, EffectPool pool)
        {
            unsafe
            {
                Effect effect        = null;
                Blob   blobForErrors = null;

                try
                {
                    if (stream is DataStream)
                    {
                        D3DX9.CreateEffectEx(
                            device,
                            ((DataStream)stream).PositionPointer,
                            (int)(stream.Length - stream.Position),
                            PrepareMacros(preprocessorDefines),
                            IncludeShadow.ToIntPtr(includeFile),
                            skipConstants,
                            (int)flags,
                            pool,
                            out effect,
                            out blobForErrors);
                    }
                    else
                    {
                        var data = Utilities.ReadStream(stream);

                        fixed(void *pData = data)
                        D3DX9.CreateEffectEx(
                            device,
                            (IntPtr)pData,
                            data.Length,
                            PrepareMacros(preprocessorDefines),
                            IncludeShadow.ToIntPtr(includeFile),
                            skipConstants,
                            (int)flags,
                            pool,
                            out effect,
                            out blobForErrors);
                    }
                    stream.Position = stream.Length;
                }
                catch (SharpDXException ex)
                {
                    if (blobForErrors != null)
                    {
                        throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                    }
                    throw;
                }
                return(effect);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Loads a volume from memory.
        /// </summary>
        /// <param name="destPaletteRef"><para>Pointer to a  <see cref="SharpDX.Direct3D9.PaletteEntry"/> structure, the destination palette of 256 colors or <c>null</c>.</para></param>
        /// <param name="destBox"><para>Pointer to a <see cref="SharpDX.Direct3D9.Box"/> structure. Specifies the destination box. Set this parameter to <c>null</c> to specify the entire volume.</para></param>
        /// <param name="srcMemoryPointer"><para>Pointer to the top-left corner of the source volume in memory.</para></param>
        /// <param name="srcFormat"><para>Member of the <see cref="SharpDX.Direct3D9.Format"/> enumerated type, the pixel format of the source volume.</para></param>
        /// <param name="srcRowPitch"><para>Pitch of source image, in bytes. For DXT formats (compressed texture formats), this number should represent the size of one row of cells, in bytes.</para></param>
        /// <param name="srcSlicePitch"><para>Pitch of source image, in bytes. For DXT formats (compressed texture formats), this number should represent the size of one slice of cells, in bytes.</para></param>
        /// <param name="srcPaletteRef"><para>Pointer to a <see cref="SharpDX.Direct3D9.PaletteEntry"/> structure, the source palette of 256 colors or <c>null</c>.</para></param>
        /// <param name="srcBox"><para>Pointer to a <see cref="SharpDX.Direct3D9.Box"/> structure. Specifies the source box. <c>null</c> is not a valid value for this parameter.</para></param>
        /// <param name="filter"><para>A combination of one or more <see cref="SharpDX.Direct3D9.Filter"/> controlling how the image is filtered. Specifying D3DX_DEFAULT for this parameter is the equivalent of specifying <see cref="SharpDX.Direct3D9.Filter.Triangle"/> | <see cref="SharpDX.Direct3D9.Filter.Dither"/>.</para></param>
        /// <param name="colorKey"><para> <see cref="RawColor4"/> value to replace with transparent black, or 0 to disable the color key. This is always a 32-bit ARGB color, independent of the source image format. Alpha is significant and should usually be set to FF for opaque color keys. Thus, for opaque black, the value would be equal to 0xFF000000.</para></param>
        /// <returns>If the function succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the function fails, the return value can be one of the following values: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns>
        /// <remarks>
        /// Writing to a non-level-zero surface of the volume texture will not cause the dirty rectangle to be updated. If <see cref="SharpDX.Direct3D9.D3DX9.LoadVolumeFromMemory"/> is called and the texture was not already dirty (this is unlikely under normal usage scenarios), the application needs to explicitly call <see cref="SharpDX.Direct3D9.VolumeTexture.AddDirtyBox"/> on the volume texture.
        /// </remarks>
        /// <unmanaged>HRESULT D3DXLoadVolumeFromMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcRowPitch,[In] unsigned int SrcSlicePitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey)</unmanaged>
        public unsafe void LoadFromMemory(SharpDX.Direct3D9.PaletteEntry[] destPaletteRef, Box?destBox, System.IntPtr srcMemoryPointer, SharpDX.Direct3D9.Format srcFormat, int srcRowPitch, int srcSlicePitch, SharpDX.Direct3D9.PaletteEntry[] srcPaletteRef, Box srcBox, SharpDX.Direct3D9.Filter filter, RawColorBGRA colorKey)
        {
            Box localDestBox;

            if (destBox.HasValue)
            {
                localDestBox = destBox.Value;
            }

            D3DX9.LoadVolumeFromMemory(
                this, destPaletteRef, new IntPtr(&localDestBox), srcMemoryPointer, srcFormat, srcRowPitch, srcSlicePitch, srcPaletteRef, new IntPtr(&srcBox), filter, *(int *)&colorKey);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Uses a user-provided function to fill each texel of each mip level of a given cube texture.
        /// </summary>
        /// <param name="callback">A function that is used to fill the texture.</param>
        /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
        public void Fill(Fill3DCallback callback)
        {
            var handle = GCHandle.Alloc(callback);

            try
            {
                D3DX9.FillCubeTexture(this, FillCallbackHelper.Native3DCallbackPtr, GCHandle.ToIntPtr(handle));
            }
            finally
            {
                handle.Free();
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Compiles the provided shader or effect source.
        /// </summary>
        /// <param name="shaderSource">An array of bytes containing the raw source of the shader or effect to compile.</param>
        /// <param name="entryPoint">The name of the shader entry-point function, or <c>null</c> for an effect file.</param>
        /// <param name="profile">The shader target or set of shader features to compile against.</param>
        /// <param name="shaderFlags">Shader compilation options.</param>
        /// <param name="defines">A set of macros to define during compilation.</param>
        /// <param name="include">An interface for handling include files.</param>
        /// <returns>
        /// The compiled shader bytecode, or <c>null</c> if the method fails.
        /// </returns>
        /// <unmanaged>HRESULT D3DXCompileShader([In] const char* pSrcData,[In] unsigned int SrcDataLen,[In] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] const char* pFunctionName,[In] const char* pProfile,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs,[In] ID3DXConstantTable** ppConstantTable)</unmanaged>
        public static CompilationResult Compile(byte[] shaderSource, string entryPoint, string profile, ShaderFlags shaderFlags, Macro[] defines, Include include)
        {
            unsafe
            {
                var resultCode = Result.Ok;

                Blob          blobForCode   = null;
                Blob          blobForErrors = null;
                ConstantTable constantTable = null;

                try
                {
                    fixed(void *pData = &shaderSource[0])
                    D3DX9.CompileShader(
                        (IntPtr)pData,
                        shaderSource.Length,
                        PrepareMacros(defines),
                        IncludeShadow.ToIntPtr(include),
                        entryPoint,
                        profile,
                        (int)shaderFlags,
                        out blobForCode,
                        out blobForErrors,
                        out constantTable);
                }
                catch (SharpDXException ex)
                {
                    if (blobForErrors != null)
                    {
                        resultCode = ex.ResultCode;
                        if (Configuration.ThrowOnShaderCompileError)
                        {
                            throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if (constantTable != null)
                    {
                        constantTable.Dispose();
                    }
                }

                return(new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors)));
            }
        }
Exemplo n.º 25
0
        private static void CreateFromFileInStream(Volume volume, Stream stream, Filter filter, int colorKey, IntPtr sourceBox, IntPtr destinationBox, PaletteEntry[] palette, IntPtr imageInformation)
        {
            unsafe
            {
                if (stream is DataStream)
                {
                    D3DX9.LoadVolumeFromFileInMemory(volume, palette, destinationBox, ((DataStream)stream).PositionPointer, (int)(stream.Length - stream.Position), sourceBox, filter, colorKey, (IntPtr)imageInformation);
                }
                var data = Utilities.ReadStream(stream);

                fixed(void *pData = data)
                D3DX9.LoadVolumeFromFileInMemory(volume, palette, destinationBox, (IntPtr)pData, data.Length, sourceBox, filter, colorKey, (IntPtr)imageInformation);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets the set of semantics for shader outputs.
        /// </summary>
        /// <returns>The set of semantics for shader outputs.</returns>
        /// <unmanaged>HRESULT D3DXGetShaderOutputSemantics([In] const void* pFunction,[In, Out, Buffer] D3DXSEMANTIC* pSemantics,[InOut] unsigned int* pCount)</unmanaged>
        public ShaderSemantic[] GetOutputSemantics()
        {
            int count = 0;

            D3DX9.GetShaderOutputSemantics(BufferPointer, null, ref count);
            if (count == 0)
            {
                return(null);
            }

            var buffer = new ShaderSemantic[count];

            D3DX9.GetShaderOutputSemantics(BufferPointer, buffer, ref count);

            return(buffer);
        }
Exemplo n.º 27
0
        private static void CreateEffectCompiler(IntPtr data, int length, Macro[] defines, Include includeFile, ShaderFlags flags, EffectCompiler instance)
        {
            Blob blobForErrors = null;

            try
            {
                D3DX9.CreateEffectCompiler(data, length, defines, IncludeShadow.ToIntPtr(includeFile), (int)flags, instance, out blobForErrors);
            }
            catch (SharpDXException ex)
            {
                if (blobForErrors != null)
                {
                    throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                }
                throw;
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Generates an output vertex declaration from the input declaration. The output declaration is intended for use by the mesh tessellation functions.
        /// </summary>
        /// <param name="declaration">The input declaration.</param>
        /// <returns>The output declaration</returns>
        /// <unmanaged>HRESULT D3DXGenerateOutputDecl([In, Buffer] D3DVERTEXELEMENT9* pOutput,[In, Buffer] const D3DVERTEXELEMENT9* pInput)</unmanaged>
        public static VertexElement[] GenerateOutputDeclaration(VertexElement[] declaration)
        {
            var vertices = new VertexElement[(int)VertexFormatDeclaratorCount.Max];

            var result = D3DX9.GenerateOutputDecl(vertices, declaration);

            if (result.Failure)
            {
                return(null);
            }

            var copy = new VertexElement[D3DX9.GetDeclLength(vertices) + 1];

            Array.Copy(vertices, copy, copy.Length);
            copy[copy.Length - 1] = VertexElement.VertexDeclarationEnd;
            return(copy);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Generates an optimized vertex remapping for a triangle list. This function is commonly used after applying the face remapping generated by <see cref="OptimizeFaces(int[],int,int)"/>.
        /// </summary>
        /// <param name="indices">The indices.</param>
        /// <param name="faceCount">The face count.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <returns>A buffer that will contain the new index for each vertex. The value stored in pVertexRemap for a given element is the source vertex location in the new vertex ordering.</returns>
        /// <unmanaged>HRESULT D3DXOptimizeVertices([In] const void* pbIndices,[In] unsigned int cFaces,[In] unsigned int cVertices,[In] BOOL b32BitIndices,[In, Buffer] int* pVertexRemap)</unmanaged>
        public static int[] OptimizeVertices(int[] indices, int faceCount, int vertexCount)
        {
            unsafe
            {
                var    faces = new int[faceCount];
                Result result;

                fixed(void *pIndices = indices)
                result = D3DX9.OptimizeVertices((IntPtr)pIndices, faceCount, indices.Length, true, faces);

                if (result.Failure)
                {
                    return(null);
                }
                return(faces);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Converts a declarator from a flexible vertex format (FVF) code.
        /// </summary>
        /// <param name="fvf">Combination of <see cref="VertexFormat"/> that describes the FVF from which to generate the returned declarator array..</param>
        /// <returns>
        /// A declarator from a flexible vertex format (FVF) code.
        /// </returns>
        /// <unmanaged>HRESULT D3DXDeclaratorFromFVF([In] D3DFVF FVF,[In, Buffer] D3DVERTEXELEMENT9* pDeclarator)</unmanaged>
        public static VertexElement[] DeclaratorFromFVF(VertexFormat fvf)
        {
            var vertices = new VertexElement[(int)VertexFormatDeclaratorCount.Max];

            var result = D3DX9.DeclaratorFromFVF(fvf, vertices);

            if (result.Failure)
            {
                return(null);
            }

            var copy = new VertexElement[D3DX9.GetDeclLength(vertices) + 1];

            Array.Copy(vertices, copy, copy.Length);
            copy[copy.Length - 1] = VertexElement.VertexDeclarationEnd;
            return(copy);
        }