コード例 #1
0
ファイル: ShaderBytecode.cs プロジェクト: pH200/SharpDX
        /// <summary>
        /// Compiles the provided shader or effect source.
        /// </summary>
        /// <param name="textSource">The shader data.</param>
        /// <param name="textSize">Size of the shader.</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="effectFlags">Effect 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>
        /// <param name="sourceFileName">Name of the source file used for reporting errors. Default is "unknown"</param>
        /// <param name="secondaryDataFlags">The secondary data flags.</param>
        /// <param name="secondaryData">The secondary data.</param>
        /// <returns>
        /// The compiled shader bytecode, or <c>null</c> if the method fails.
        /// </returns>
        public static CompilationResult Compile(IntPtr textSource, int textSize, string entryPoint, string profile,
                                             ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                             Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
        {
            unsafe
            {
                var resultCode = Result.Ok;

                Blob blobForCode = null;
                Blob blobForErrors = null;

                try
                {
                    D3D.Compile2(
                        (IntPtr)textSource,
                        textSize,
                        sourceFileName,
                        PrepareMacros(defines),
                        IncludeShadow.ToIntPtr(include),
                        entryPoint,
                        profile,
                        shaderFlags,
                        effectFlags,
                        secondaryDataFlags,
                        secondaryData != null ? secondaryData.DataPointer : IntPtr.Zero,
                        secondaryData != null ? (int)secondaryData.Length : 0,
                        out blobForCode,
                        out blobForErrors);
                }
                catch (SharpDXException ex)
                {
                    if (blobForErrors != null)
                    {
                        resultCode = ex.ResultCode;
                        if (Configuration.ThrowOnShaderCompileError)
                            throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
                    }
                    else
                    {
                        throw;
                    }
                }

                return new CompilationResult(blobForCode != null ? new ShaderBytecode(blobForCode) : null, resultCode, Utilities.BlobToString(blobForErrors));
            }
        }
コード例 #2
0
ファイル: ShaderBytecode.cs プロジェクト: pH200/SharpDX
 /// <summary>
 /// Compiles the provided shader or effect source.
 /// </summary>
 /// <param name="shaderSource">A string containing the 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="effectFlags">Effect 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>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="secondaryDataFlags">The secondary data flags.</param>
 /// <param name="secondaryData">The secondary data.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(string shaderSource, string entryPoint, string profile,
                                      ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                      Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     if (string.IsNullOrEmpty(shaderSource))
     {
         throw new ArgumentNullException("shaderSource");
     }
     var shaderSourcePtr = Marshal.StringToHGlobalAnsi(shaderSource);
     try
     {
         return Compile(shaderSourcePtr, shaderSource.Length, entryPoint, profile, shaderFlags, effectFlags, defines,
                        include, sourceFileName, secondaryDataFlags, secondaryData);
     }
     finally
     {
         if (shaderSourcePtr != IntPtr.Zero) Marshal.FreeHGlobal(shaderSourcePtr);
     }
 }
コード例 #3
0
ファイル: ShaderBytecode.cs プロジェクト: pH200/SharpDX
 /// <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="effectFlags">Effect 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>
 /// <param name="sourceFileName">Name of the source file used for reporting errors. Default is "unknown"</param>
 /// <param name="secondaryDataFlags">The secondary data flags.</param>
 /// <param name="secondaryData">The secondary data.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(byte[] shaderSource, string entryPoint, string profile,
                                      ShaderFlags shaderFlags, EffectFlags effectFlags, ShaderMacro[] defines,
                                      Include include, string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     unsafe
     {
         fixed (void* pData = &shaderSource[0])
             return Compile(
                 (IntPtr)pData,
                 shaderSource.Length,
                 entryPoint,
                 profile,
                 shaderFlags,
                 effectFlags,
                 defines,
                 include,
                 sourceFileName,
                 secondaryDataFlags,
                 secondaryData);
     }
 }
コード例 #4
0
ファイル: ShaderBytecode.cs プロジェクト: pH200/SharpDX
 /// <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="profile">The shader target or set of shader features to compile against.</param>
 /// <param name="shaderFlags">Shader compilation options.</param>
 /// <param name="effectFlags">Effect 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>
 /// <param name="sourceFileName">Name of the source file.</param>
 /// <param name="secondaryDataFlags">The secondary data flags.</param>
 /// <param name="secondaryData">The secondary data.</param>
 /// <returns>
 /// The compiled shader bytecode, or <c>null</c> if the method fails.
 /// </returns>
 public static CompilationResult Compile(byte[] shaderSource, string profile, ShaderFlags shaderFlags,
                                      EffectFlags effectFlags, ShaderMacro[] defines, Include include,
                                      string sourceFileName = "unknown", SecondaryDataFlags secondaryDataFlags = SecondaryDataFlags.None, DataStream secondaryData = null)
 {
     return Compile(shaderSource, null, profile, shaderFlags, effectFlags, defines, include,
                    sourceFileName, secondaryDataFlags, secondaryData);
 }