示例#1
0
        protected override void UnloadHighLevelImpl()
        {
            MicroCode.SafeDispose();
            MicroCode = null;

            this.constTable.SafeDispose();
            this.constTable = null;
        }
示例#2
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)));
            }
        }
示例#3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (blob != null)
                {
                    blob.Dispose();
                    blob = null;
                }

                if (constantTable != null)
                {
                    constantTable.Dispose();
                    constantTable = null;
                }
            }
            if (isOwner && BufferPointer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(BufferPointer);
                BufferPointer = IntPtr.Zero;
                BufferSize    = 0;
            }
        }
示例#4
0
 /// <summary>
 /// Compiles a shader from an effect that contains one or more functions.
 /// </summary>
 /// <param name="functionHandle">The function handle.</param>
 /// <param name="target">The target.</param>
 /// <param name="flags">The flags.</param>
 /// <param name="constantTable">The constant table.</param>
 /// <exception cref="CompilationException">If a compilation errors occurs</exception>
 /// <returns>The bytecode of the effect.</returns>
 /// <unmanaged>HRESULT ID3DXEffectCompiler::CompileShader([In] D3DXHANDLE hFunction,[In] const char* pTarget,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs,[In] ID3DXConstantTable** ppConstantTable)</unmanaged>
 public ShaderBytecode CompileShader(EffectHandle functionHandle, string target, ShaderFlags flags, out ConstantTable constantTable)
 {
     Blob shaderBytecode;
     Blob blobForErrors = null;
     try
     {
         CompileShader(functionHandle, target, (int)flags, out shaderBytecode, out blobForErrors, out constantTable);
     }
     catch (SharpDXException ex)
     {
         if (blobForErrors != null)
             throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
         throw;
     }
     return new ShaderBytecode(shaderBytecode);
 }
示例#5
0
		protected override void UnloadHighLevelImpl()
		{
			MicroCode.SafeDispose();
			MicroCode = null;

			this.constTable.SafeDispose();
			this.constTable = null;
		}
示例#6
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (blob != null)
                {
                    blob.Dispose();
                    blob = null;
                }

                if (constantTable != null)
                {
                    constantTable.Dispose();
                    constantTable = null;
                }
            }
            if (isOwner && BufferPointer != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(BufferPointer);
                BufferPointer = IntPtr.Zero;
                BufferSize = 0;
            }
        }
示例#7
0
        /// <summary>
        /// Compiles a shader from an effect that contains one or more functions.
        /// </summary>
        /// <param name="functionHandle">The function handle.</param>
        /// <param name="target">The target.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="constantTable">The constant table.</param>
        /// <exception cref="CompilationException">If a compilation errors occurs</exception>
        /// <returns>The bytecode of the effect.</returns>
        /// <unmanaged>HRESULT ID3DXEffectCompiler::CompileShader([In] D3DXHANDLE hFunction,[In] const char* pTarget,[In] unsigned int Flags,[In] ID3DXBuffer** ppShader,[In] ID3DXBuffer** ppErrorMsgs,[In] ID3DXConstantTable** ppConstantTable)</unmanaged>
        public ShaderBytecode CompileShader(EffectHandle functionHandle, string target, ShaderFlags flags, out ConstantTable constantTable)
        {
            Blob shaderBytecode;
            Blob blobForErrors = null;

            try
            {
                CompileShader(functionHandle, target, (int)flags, out shaderBytecode, out blobForErrors, out constantTable);
            }
            catch (SharpDXException ex)
            {
                if (blobForErrors != null)
                {
                    throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                }
                throw;
            }
            return(new ShaderBytecode(shaderBytecode));
        }