Пример #1
0
        /// <summary>
        /// Create a shader-resource view from a file.
        /// </summary>
        /// <param name="device">A reference to the device (see <see cref="SharpDX.Direct3D10.Device"/>) that will use the resource. </param>
        /// <param name="fileName">Name of the file that contains the shader-resource view.</param>
        /// <param name="loadInformation">Identifies the characteristics of a texture (see <see cref="SharpDX.Direct3D10.ImageLoadInformation"/>) when the data processor is created. </param>
        /// <returns>Returns a reference to the shader-resource view (see <see cref="SharpDX.Direct3D10.ShaderResourceView"/>). </returns>
        /// <unmanaged>HRESULT D3DX10CreateShaderResourceViewFromFileW([None] ID3D10Device* pDevice,[None] const wchar_t* pSrcFile,[In, Optional] D3DX10_IMAGE_LOAD_INFO* pLoadInfo,[None] ID3DX10ThreadPump* pPump,[None] ID3D10ShaderResourceView** ppShaderResourceView,[None] HRESULT* pHResult)</unmanaged>
        public static ShaderResourceView FromFile(Device device, string fileName, ImageLoadInformation loadInformation)
        {
            ShaderResourceView temp;
            Result             hResult;

            D3DX10.CreateShaderResourceViewFromFile(device, fileName, loadInformation, IntPtr.Zero, out temp, out hResult);
            return(temp);
        }
Пример #2
0
        /// <summary>
        ///   Saves a texture to file.
        /// </summary>
        /// <param name = "texture">The texture to save.</param>
        /// <param name = "format">The format the texture will be saved as.</param>
        /// <param name = "fileName">Name of the destination output file where the texture will be saved.</param>
        /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
        public static void ToFile <T>(T texture, ImageFileFormat format, string fileName)
            where T : Resource
        {
            System.Diagnostics.Debug.Assert(typeof(T) == typeof(Texture1D) || typeof(T) == typeof(Texture2D) ||
                                            typeof(T) == typeof(Texture3D));

            D3DX10.SaveTextureToFile(texture, format, fileName);
        }
Пример #3
0
        /// <summary>
        /// Create a shader-resource view from a file. Read the characteristics of a texture when the texture is loaded.
        /// </summary>
        /// <param name="device">A reference to the device (see <see cref="SharpDX.Direct3D10.Device"/>) that will use the resource. </param>
        /// <param name="fileName">Name of the file that contains the shader-resource view.</param>
        /// <returns>Returns a reference to the shader-resource view (see <see cref="SharpDX.Direct3D10.ShaderResourceView"/>). </returns>
        /// <unmanaged>HRESULT D3DX10CreateShaderResourceViewFromFileW([None] ID3D10Device* pDevice,[None] const wchar_t* pSrcFile,[In, Optional] D3DX10_IMAGE_LOAD_INFO* pLoadInfo,[None] ID3DX10ThreadPump* pPump,[None] ID3D10ShaderResourceView** ppShaderResourceView,[None] HRESULT* pHResult)</unmanaged>
        public static ShaderResourceView FromFile(Device device, string fileName)
        {
            ShaderResourceView temp;
            Result             hResult;

            D3DX10.CreateShaderResourceViewFromFile(device, fileName, null, IntPtr.Zero, out temp, out hResult);
            return(temp);
        }
Пример #4
0
        /// <summary>
        ///   Loads a texture from an image file.
        /// </summary>
        /// <param name = "device">The device used to load the texture.</param>
        /// <param name = "fileName">Path to the file on disk.</param>
        /// <param name = "loadInfo">Specifies information used to load the texture.</param>
        /// <returns>The loaded texture object.</returns>
        public static T FromFile <T>(Device device, string fileName, ImageLoadInformation loadInfo) where T : Resource
        {
            IntPtr temp;
            Result resultOut;

            D3DX10.CreateTextureFromFile(device, fileName, loadInfo, IntPtr.Zero, out temp, out resultOut);
            // TODO test resultOut?
            return(FromPointer <T>(temp));
        }
Пример #5
0
        /// <summary>
        ///   Loads a texture from an image file.
        /// </summary>
        /// <param name = "device">The device used to load the texture.</param>
        /// <param name = "fileName">Path to the file on disk.</param>
        /// <returns>The loaded texture object.</returns>
        public static T FromFile <T>(Device device, string fileName) where T : Resource
        {
            IntPtr temp;
            Result resultOut;

            D3DX10.CreateTextureFromFile(device, fileName, null, IntPtr.Zero, out temp, out resultOut);
            // TODO Test resultOut
            return(FromPointer <T>(temp));
        }
Пример #6
0
        /// <summary>
        ///   Loads a texture from an image file.
        /// </summary>
        /// <param name = "device">The device used to load the texture.</param>
        /// <param name = "fileName">Path to the file on disk.</param>
        /// <param name = "loadInfo">Specifies information used to load the texture.</param>
        /// <returns>The loaded texture object.</returns>
        public static T FromFile <T>(Device device, string fileName, ImageLoadInformation loadInfo) where T : Resource
        {
            System.Diagnostics.Debug.Assert(typeof(T) == typeof(Texture1D) || typeof(T) == typeof(Texture2D) ||
                                            typeof(T) == typeof(Texture3D));

            IntPtr temp;
            Result resultOut;

            D3DX10.CreateTextureFromFile(device, fileName, loadInfo, IntPtr.Zero, out temp, out resultOut);
            // TODO test resultOut?
            return(FromPointer <T>(temp));
        }
Пример #7
0
        /// <summary>
        /// Create a shader-resource view from a file in memory.
        /// </summary>
        /// <param name="device">A reference to the device (see <see cref="SharpDX.Direct3D10.Device"/>) that will use the resource. </param>
        /// <param name="memory">Pointer to a memory location that contains the shader-resource view. </param>
        /// <param name="loadInformation">Identifies the characteristics of a texture (see <see cref="SharpDX.Direct3D10.ImageLoadInformation"/>) when the data processor is created. </param>
        /// <returns>Returns a reference to the shader-resource view (see <see cref="SharpDX.Direct3D10.ShaderResourceView"/>). </returns>
        /// <unmanaged>HRESULT D3DX10CreateShaderResourceViewFromMemory([None] ID3D10Device* pDevice,[None] const void* pSrcData,[None] SIZE_T SrcDataSize,[In, Optional] D3DX10_IMAGE_LOAD_INFO* pLoadInfo,[None] ID3DX10ThreadPump* pPump,[None] ID3D10ShaderResourceView** ppShaderResourceView,[None] HRESULT* pHResult)</unmanaged>
        public static ShaderResourceView FromMemory(Device device, byte[] memory, ImageLoadInformation loadInformation)
        {
            unsafe
            {
                ShaderResourceView temp;
                Result             hResult;

                fixed(void *pMemory = &memory[0])
                D3DX10.CreateShaderResourceViewFromMemory(device, new IntPtr(pMemory), memory.Length, loadInformation, IntPtr.Zero, out temp, out hResult);

                return(temp);
            }
        }
Пример #8
0
 /// <summary>
 /// Retrieves information about a given image file.
 /// </summary>
 /// <param name="fileName">File name of image to retrieve information about.</param>
 /// <returns>If the function succeeds, returns a <see cref="SharpDX.Direct3D10.ImageInformation"/> filled with the description of the data in the source file. else returns null </returns>
 /// <unmanaged>HRESULT D3DX11GetImageInfoFromFileW([None] const wchar_t* pSrcFile,[None] ID3DX11ThreadPump* pPump,[None] D3DX11_IMAGE_INFO* pSrcInfo,[None] HRESULT* pHResult)</unmanaged>
 public static ImageInformation?FromFile(string fileName)
 {
     try
     {
         var    info = new ImageInformation();
         Result hresult;
         D3DX10.GetImageInfoFromFile(fileName, IntPtr.Zero, ref info, out hresult);
         // TODO check hresult?
         return(info);
     }
     catch (SharpDXException)
     { }
     return(null);
 }
Пример #9
0
        /// <summary>
        /// Create a shader-resource view from a file in memory.
        /// </summary>
        /// <param name="device">A reference to the device (see <see cref="SharpDX.Direct3D10.Device"/>) that will use the resource. </param>
        /// <param name="memory">Pointer to a memory location that contains the shader-resource view. </param>
        /// <returns>Returns a reference to the shader-resource view (see <see cref="SharpDX.Direct3D10.ShaderResourceView"/>). </returns>
        /// <unmanaged>HRESULT D3DX10CreateShaderResourceViewFromMemory([None] ID3D10Device* pDevice,[None] const void* pSrcData,[None] SIZE_T SrcDataSize,[In, Optional] D3DX10_IMAGE_LOAD_INFO* pLoadInfo,[None] ID3DX10ThreadPump* pPump,[None] ID3D10ShaderResourceView** ppShaderResourceView,[None] HRESULT* pHResult)</unmanaged>
        public static ShaderResourceView FromMemory(Device device, byte[] memory)
        {
            unsafe
            {
                ShaderResourceView temp;
                Result             hResult;

                fixed(void *pMemory = &memory[0])
                D3DX10.CreateShaderResourceViewFromMemory(device, new IntPtr(pMemory), memory.Length, null, IntPtr.Zero, out temp, out hResult);

                // TODO test hResult?
                return(temp);
            }
        }
Пример #10
0
        /// <summary>
        ///   Loads a texture from an image in memory.
        /// </summary>
        /// <param name = "device">The device used to load the texture.</param>
        /// <param name = "memory">Array of memory containing the image data to load.</param>
        /// <returns>The loaded texture object.</returns>
        public static T FromMemory <T>(Device device, byte[] memory) where T : Resource
        {
            unsafe
            {
                IntPtr temp;
                Result resultOut;

                fixed(void *pBuffer = &memory[0])
                D3DX10.CreateTextureFromMemory(device, (IntPtr)pBuffer, memory.Length, null, IntPtr.Zero,
                                               out temp, out resultOut);

                // TODO test resultOut
                return(FromPointer <T>(temp));
            }
        }
Пример #11
0
        /// <summary>
        ///   Saves a texture to a stream.
        /// </summary>
        /// <param name = "texture">The texture to save.</param>
        /// <param name = "format">The format the texture will be saved as.</param>
        /// <param name = "stream">Destination memory stream where the image will be saved.</param>
        /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
        public static void ToStream <T>(T texture, ImageFileFormat format, Stream stream)
            where T : Resource
        {
            Blob blob;

            D3DX10.SaveTextureToMemory(texture, format, out blob, 0);

            IntPtr bufferPtr = blob.BufferPointer;
            int    blobSize  = blob.BufferSize;

            // Write byte-by-byte to avoid allocating a managed byte[] that will wastefully persist.
            for (int byteIndex = 0; byteIndex < blobSize; ++byteIndex)
            {
                stream.WriteByte(Marshal.ReadByte(bufferPtr, byteIndex));
            }

            blob.Dispose();
        }
Пример #12
0
        /// <summary>
        ///   Loads a texture from an image in memory.
        /// </summary>
        /// <param name = "device">The device used to load the texture.</param>
        /// <param name = "memory">Array of memory containing the image data to load.</param>
        /// <returns>The loaded texture object.</returns>
        public static T FromMemory <T>(Device device, byte[] memory) where T : Resource
        {
            System.Diagnostics.Debug.Assert(typeof(T) == typeof(Texture1D) || typeof(T) == typeof(Texture2D) ||
                                            typeof(T) == typeof(Texture3D));

            unsafe
            {
                System.Diagnostics.Debug.Assert(memory != null);
                System.Diagnostics.Debug.Assert(memory.Length > 0);
                IntPtr temp;
                Result resultOut;

                fixed(void *pBuffer = &memory[0])
                D3DX10.CreateTextureFromMemory(device, (IntPtr)pBuffer, memory.Length, null, IntPtr.Zero,
                                               out temp, out resultOut);

                // TODO test resultOut
                return(FromPointer <T>(temp));
            }
        }
Пример #13
0
        /// <summary>
        /// Retrieves information about a given image file from a memory location.
        /// </summary>
        /// <param name="memory">an array to the image in memory</param>
        /// <returns>If the function succeeds, returns a <see cref="SharpDX.Direct3D10.ImageInformation"/> filled with the description of the data from the image memory. else returns null </returns>
        /// <unmanaged>HRESULT D3DX11GetImageInfoFromFileW([None] const wchar_t* pSrcFile,[None] ID3DX11ThreadPump* pPump,[None] D3DX11_IMAGE_INFO* pSrcInfo,[None] HRESULT* pHResult)</unmanaged>
        public static ImageInformation?FromMemory(byte[] memory)
        {
            unsafe
            {
                try
                {
                    var    info = new ImageInformation();
                    Result hresult;

                    fixed(void *pMemory = &memory[0])
                    D3DX10.GetImageInfoFromMemory((IntPtr)pMemory, memory.Length, IntPtr.Zero, ref info, out hresult);

                    // TODO check hresult?
                    return(info);
                }
                catch (SharpDXException)
                {
                }
                return(null);
            }
        }
Пример #14
0
 /// <summary>
 /// Generates mipmap chain using a particular texture filter.
 /// </summary>
 /// <param name="sourceLevel">The mipmap level whose data is used to generate the rest of the mipmap chain. </param>
 /// <param name="mipFilter">Flags controlling how each miplevel is filtered (or D3DX10_DEFAULT for D3DX10_FILTER_BOX). See <see cref="SharpDX.Direct3D10.FilterFlags"/>. </param>
 /// <returns>The return value is one of the values listed in {{Direct3D 10 Return Codes}}. </returns>
 /// <unmanaged>HRESULT D3DX10FilterTexture([None] ID3D10Resource* pTexture,[None] int SrcLevel,[None] int MipFilter)</unmanaged>
 public void FilterTexture(int sourceLevel, FilterFlags mipFilter)
 {
     D3DX10.FilterTexture(this, sourceLevel, (int)mipFilter);
 }
Пример #15
0
 /// <summary>
 /// Load a texture from a texture.
 /// </summary>
 /// <param name="source">Pointer to the source texture. See <see cref="SharpDX.Direct3D10.Resource"/>. </param>
 /// <param name="destination">Pointer to the destination texture. See <see cref="SharpDX.Direct3D10.Resource"/>. </param>
 /// <param name="loadInformation">Pointer to texture loading parameters. See <see cref="SharpDX.Direct3D10.TextureLoadInformation"/>. </param>
 /// <returns>The return value is one of the values listed in {{Direct3D 10 Return Codes}}. </returns>
 /// <unmanaged>HRESULT D3DX10LoadTextureFromTexture([None] ID3D10Resource* pSrcTexture,[None] D3DX10_TEXTURE_LOAD_INFO* pLoadInfo,[None] ID3D10Resource* pDstTexture)</unmanaged>
 public static void LoadTextureFromTexture(Resource source, Resource destination, TextureLoadInformation loadInformation)
 {
     D3DX10.LoadTextureFromTexture(source, loadInformation, destination);
 }
Пример #16
0
 /// <summary>
 /// Creates a mesh object using a declarator.
 /// </summary>
 /// <param name="device">Pointer to an <see cref="SharpDX.Direct3D10.Device"/>, the device object to be associated with the mesh. </param>
 /// <param name="elements">Array of <see cref="SharpDX.Direct3D10.InputElement"/> elements, describing the vertex format for the returned mesh. This parameter must map directly to a flexible vertex format (FVF). </param>
 /// <param name="positionElement">Semantic that identifies which part of the vertex declaration contains position information. </param>
 /// <param name="vertexCount">Number of vertices for the mesh. This parameter must be greater than 0. </param>
 /// <param name="faceCount">Number of faces for the mesh. The valid range for this number is greater than 0, and one less than the maximum DWORD (typically 65534), because the last index is reserved. </param>
 /// <param name="flags">Combination of one or more flags from the <see cref="MeshFlags"/>, specifying options for the mesh.  </param>
 /// <unmanaged>HRESULT D3DX10CreateMesh([None] ID3D10Device* pDevice,[In, Buffer] const D3D10_INPUT_ELEMENT_DESC* pDeclaration,[None] int DeclCount,[None] const char* pPositionSemantic,[None] int VertexCount,[None] int FaceCount,[None] int Options,[None] ID3DX10Mesh** ppMesh)</unmanaged>
 public Mesh(Device device, InputElement[] elements, string positionElement, int vertexCount, int faceCount, MeshFlags flags)
 {
     D3DX10.CreateMesh(device, elements, elements.Length, positionElement, vertexCount, faceCount, (int)flags, this);
 }
Пример #17
0
 /// <summary>
 ///   Converts a height map into a normal map. The (x,y,z) components of each normal are mapped to the (r,g,b) channels of the output texture.
 /// </summary>
 /// <param name = "source">The source height map texture.</param>
 /// <param name = "destination">The destination texture.</param>
 /// <param name = "flags">One or more flags that control generation of normal maps.</param>
 /// <param name = "channel">One or more flag specifying the source of height information.</param>
 /// <param name = "amplitude">Constant value multiplier that increases (or decreases) the values in the normal map. Higher values usually make bumps more visible, lower values usually make bumps less visible.</param>
 /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
 public static void ComputeNormalMap(Texture2D source, Texture2D destination,
                                     NormalMapFlags flags, Channel channel, float amplitude)
 {
     D3DX10.ComputeNormalMap(source, flags, channel, amplitude, destination);
 }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Font"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="height">The height.</param>
 /// <param name="width">The width.</param>
 /// <param name="weight">The weight.</param>
 /// <param name="mipLevels">The mip levels.</param>
 /// <param name="isItalic">if set to <c>true</c> [is italic].</param>
 /// <param name="characterSet">The character set.</param>
 /// <param name="precision">The precision.</param>
 /// <param name="quality">The quality.</param>
 /// <param name="pitchAndFamily">The pitch and family.</param>
 /// <param name="faceName">Name of the face.</param>
 public Font(Device device, int height, int width, FontWeight weight, int mipLevels, bool isItalic, FontCharacterSet characterSet, FontPrecision precision, FontQuality quality, FontPitchAndFamily pitchAndFamily, string faceName)
 {
     D3DX10.CreateFont(device, height, width, (int)weight, mipLevels, isItalic, (int)characterSet, (int)precision, (int)quality, (int)pitchAndFamily,
                       faceName, this);
 }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Font"/> class from a <see cref="System.Drawing.Font"/>
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="font">The font.</param>
 public Font(Device device, System.Drawing.Font font)
 {
     D3DX10.CreateFont(device, font.Height, 0, (int)(font.Bold ? FontWeight.Bold : FontWeight.Normal), 0, font.Italic, (int)FontCharacterSet.Default, (int)FontPrecision.Default, (int)FontQuality.Default, (int)FontPitchAndFamily.Default, font.Name, this);
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Font"/> class.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="fontDescription">The font description.</param>
 public Font(Device device, FontDescription fontDescription) : base(IntPtr.Zero)
 {
     D3DX10.CreateFontIndirect(device, ref fontDescription, this);
 }
Пример #21
0
 /// <summary>
 /// Create a sprite for drawing a 2D texture.
 /// </summary>
 /// <param name="device">A reference to the device (see <see cref="SharpDX.Direct3D10.Device"/>) that will draw the sprite. </param>
 /// <param name="bufferSize">The size of the vertex buffer, in number of sprites, that will be sent to the device when <see cref="SharpDX.Direct3D10.Sprite.Flush"/> or <see cref="DrawSpritesBuffered(SpriteInstance[])"/> is called. This should be a small number if you know you will be rendering a small number of sprites at a time (to save memory) and a large number if you know you will be rendering a large number of sprites at a time. The maximum value is 4096. If 0 is specified, the vertex buffer size will automatically be set to 4096. </param>
 /// <unmanaged>HRESULT D3DX10CreateSprite([None] ID3D10Device* pDevice,[None] int cDeviceBufferSize,[None] LPD3DX10SPRITE* ppSprite)</unmanaged>
 public Sprite(Device device, int bufferSize = 0)
 {
     D3DX10.CreateSprite(device, bufferSize, this);
 }
Пример #22
0
 /// <summary>
 ///   Saves a texture to file.
 /// </summary>
 /// <param name = "texture">The texture to save.</param>
 /// <param name = "format">The format the texture will be saved as.</param>
 /// <param name = "fileName">Name of the destination output file where the texture will be saved.</param>
 /// <returns>A <see cref = "T:SharpDX.Result" /> object describing the result of the operation.</returns>
 public static void ToFile <T>(T texture, ImageFileFormat format, string fileName)
     where T : Resource
 {
     D3DX10.SaveTextureToFile(texture, format, fileName);
 }