예제 #1
0
        public static byte[] GetByteCode(this string fileName, string entryPoint, string profile,
                                         ShaderFlags shaderFlags = ShaderFlags.None)
        {
            var compiledShader = ShaderBytecode.CompileFromFile(fileName, entryPoint, profile, shaderFlags);

            return(compiledShader.Bytecode.Data);
        }
예제 #2
0
        private static DX11Effect Compile(string content, bool isfile, Include include, ShaderMacro[] defines)
        {
            DX11Effect shader = new DX11Effect();

            string errors;

            try
            {
                ShaderFlags flags = ShaderFlags.OptimizationLevel1;

                if (isfile)
                {
                    shader.ByteCode = ShaderBytecode.CompileFromFile(content, "fx_5_0", flags, EffectFlags.None, defines, include, out errors);
                }
                else
                {
                    shader.ByteCode = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, defines, include, out errors);
                }

                //Compilation worked, but we can still have warning
                shader.IsCompiled   = true;
                shader.ErrorMessage = errors;

                shader.Preprocess();
            }
            catch (Exception ex)
            {
                shader.IsCompiled    = false;
                shader.ErrorMessage  = ex.Message;
                shader.DefaultEffect = null;
            }
            return(shader);
        }
        public static async Task <ShaderBytecode> CompileFromFileAsync(string hlslFile, string entryPoint, string profile, ShaderMacro[] defines = null)
        {
            if (!Path.IsPathRooted(hlslFile))
            {
                hlslFile = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, hlslFile);
            }

            CompilationResult result = null;

            await Task.Run(() =>
            {
                var shaderSource = SharpDX.IO.NativeFile.ReadAllText(hlslFile);

                // Compile the shader file
                ShaderFlags flags = ShaderFlags.None;
#if DEBUG
                flags |= ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
                var includeHandler = new HLSLFileIncludeHandler(Path.GetDirectoryName(hlslFile));
                result             = ShaderBytecode.Compile(shaderSource, entryPoint, profile, flags, EffectFlags.None, defines, includeHandler, Path.GetFileName(hlslFile));

                if (!String.IsNullOrEmpty(result.Message))
                {
                    throw new CompilationException(result.ResultCode, result.Message);
                }
            });

            return(result);
        }
예제 #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ShaderInfo" /> class.
 /// </summary>
 /// <param name="type">       The type. </param>
 /// <param name="entryPoint"> The entry point. </param>
 /// <param name="profile">    The profile. </param>
 /// <param name="flags">      The flags. </param>
 public ShaderInfo(string type, string entryPoint, string profile, ShaderFlags flags)
 {
     Type       = type;
     EntryPoint = entryPoint;
     Profile    = profile;
     Flags      = flags;
 }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("PacksOptimize starting ...");
            foreach (string param in args)
            {
                Console.WriteLine("Arguments received : {0}", param);
            }

            //First agument = Pack Root Path
            if (args.Length == 0)
            {
                Console.WriteLine("Utopia Pack Optimizer");
                Console.WriteLine("Syntax : PackOptimize action=Compilation path=\"rootPath\" includePath=\"includePath\" debugcompil=0");
                Console.WriteLine("Syntax : PackOptimize action=CreateTextureArray path=\"rootPath\" ");
                return;
            }
            else
            {
                foreach (string param in args)
                {
                    string p;
                    p = param.Replace("\"", "");
                    p = p.Replace("\'", "");
                    string[] paramData = p.Split('=');
                    if (paramData.Length != 2)
                    {
                        return;
                    }
                    switch (paramData[0])
                    {
                    case "action":
                        action = paramData[1];
                        break;

                    case "path":
                        rootPath = paramData[1].Replace("\"", "");
                        break;

                    case "includePath":
                        includeHandlerPath = paramData[1].Replace("\"", "");
                        break;

                    case "debugcompil":
                        if (paramData[1] == "1")
                        {
                            compilationFlag = ShaderFlags.Debug | ShaderFlags.SkipOptimization;
                        }
                        else
                        {
                            compilationFlag = ShaderFlags.OptimizationLevel3;
                        }
                        break;

                    default:
                        break;
                    }
                }
                StartPackOptimazing();
            }
        }
예제 #6
0
        public string Recompile()
        {
            try
            {
                EffectIncludeHelper h = new EffectIncludeHelper();
                ShaderFlags         f = ShaderFlags.Debug | ShaderFlags.EnableBackwardsCompatibility;
                if (BaseObjectId == "rain.fx" || BaseObjectId == "halo.fx" || BaseObjectId == "snow.fx" || BaseObjectId == "debugger.fx")
                {
                    f = ShaderFlags.Debug;
                }

                effect = Effect.FromString(Game.Device, shaderString, "fx_4_0", f, EffectFlags.None, null, h, null);
                vars   = new Dictionary <string, EffectVariable>(effect.Description.GlobalVariableCount);

                for (int i = 0; i < effect.Description.GlobalVariableCount; i++)
                {
                    EffectVariable v = effect.GetVariableByIndex(i);
                    vars.Add(v.Description.Name, v);
                }
                return("");
            }
            catch (Exception e)
            {
                effect = null;
                return(e.Message);
            }
        }
예제 #7
0
        protected void InitDrawer(string shadersFile,
                                  InputElement[] inputElements,
                                  string texture,
                                  SamplerStateDescription description,
                                  DepthStencilStateDescription DStateDescripshion,
                                  RasterizerStateDescription rasterizerStateDescription,
                                  BlendStateDescription blendDescription)
        {
            //Загружаем шейдеры из файлов
            ShaderFlags shaderFlags = ShaderFlags.None;

#if DEBUG
            shaderFlags = ShaderFlags.Debug;
#endif

            using (var vertexShaderByteCode = ShaderBytecode.CompileFromFile(shadersFile, "VS", "vs_5_0", shaderFlags))
            {
                //Синатура храянящая сведения о том какие входные переменные есть у шейдера
                _inputSignature = ShaderSignature.GetInputSignature(vertexShaderByteCode);
                _vertexShader   = new VertexShader(_dx11DeviceContext.Device, vertexShaderByteCode);
            }
            using (var pixelShaderByteCode = ShaderBytecode.CompileFromFile(shadersFile, "PS", "ps_5_0", shaderFlags))
            {
                _pixelShader = new PixelShader(_dx11DeviceContext.Device, pixelShaderByteCode);
            }
            //Создаем шаблон ввода данных для шейдера
            _inputLayout = new InputLayout(_dx11DeviceContext.Device, _inputSignature, inputElements);
            //Загружаем текстуру
            _textureResourse = _dx11DeviceContext.LoadTextureFromFile(texture);
            //Создание самплера для текстуры
            _samplerState    = new SamplerState(_dx11DeviceContext.Device, description);
            _DState          = new DepthStencilState(_dx11DeviceContext.Device, DStateDescripshion);
            _rasterizerState = new RasterizerState(_dx11DeviceContext.Device, rasterizerStateDescription);
            _blendState      = new BlendState(_dx11DeviceContext.Device, blendDescription);
        }
예제 #8
0
        public static Result Compile(
            byte[] shaderSource,
            ShaderMacro[] defines,
            Include include,
            string entryPoint,
            string sourceName,
            string profile,
            ShaderFlags shaderFlags,
            out Blob blob,
            out Blob errorBlob)
        {
            if (shaderSource == null || shaderSource.Length == 0)
            {
                throw new ArgumentNullException(nameof(shaderSource));
            }

            unsafe
            {
                fixed(void *pData = &shaderSource[0])
                {
                    return(Compile(
                               (IntPtr)pData,
                               shaderSource.Length,
                               sourceName,
                               defines,
                               include,
                               entryPoint,
                               profile,
                               shaderFlags,
                               EffectFlags.None,
                               out blob,
                               out errorBlob));
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Compile the HLSL file using the provided <paramref name="entryPoint"/>, shader <paramref name="profile"/> and optionally conditional <paramref name="defines"/>
        /// </summary>
        /// <param name="hlslFile">Absolute path to HLSL file, or path relative to application installation location</param>
        /// <param name="entryPoint">Shader function name e.g. VSMain</param>
        /// <param name="profile">Shader profile, e.g. vs_5_0</param>
        /// <param name="defines">An optional list of conditional defines.</param>
        /// <returns>The compiled ShaderBytecode</returns>
        /// <exception cref="CompilationException">Thrown if the compilation failed</exception>
        public static ShaderBytecode CompileFromFile(string hlslFile, string entryPoint, string profile, ShaderMacro[] defines = null)
        {
            if (!Path.IsPathRooted(hlslFile))
            {
                hlslFile = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), hlslFile);
            }
            var shaderSource         = SharpDX.IO.NativeFile.ReadAllText(hlslFile);
            CompilationResult result = null;

            // Compile the shader file
            ShaderFlags flags = ShaderFlags.None;

#if DEBUG
            flags |= ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
            var includeHandler = new HLSLFileIncludeHandler(Path.GetDirectoryName(hlslFile));
            result = ShaderBytecode.Compile(shaderSource, entryPoint, profile, flags, EffectFlags.None, defines, includeHandler, Path.GetFileName(hlslFile));

            if (result.ResultCode.Failure)
            {
                throw new CompilationException(result.ResultCode, result.Message);
            }

            return(result);
        }
예제 #10
0
    public void Init()
    {
        if (DXEffect != null)
        {
            DXEffect.Dispose();
        }

        CompilationResult cr = null;

        EffectFlags EFFECT_FLAGS = EffectFlags.None;

#if DEBUG
        ShaderFlags SHADER_FLAGS = ShaderFlags.Debug;
#else
        ShaderFlags SHADER_FLAGS = ShaderFlags.OptimizationLevel3;
#endif
        try
        {
            _isValid = true;
            cr       = ShaderBytecode.CompileFromFile(ShaderFullFilename, "fx_5_0", SHADER_FLAGS, EFFECT_FLAGS, null, new IncludeFX(Program.DXConfig.ShadersIncludePath));
            DXEffect = new Effect(Program.Renderer.DXDevice, cr.Bytecode);
            cr.Bytecode.Dispose();
            Dirty = false;
        }
        catch (Exception e)
        {
            _isValid = false;
            string text = "Compilation failed for shader: " + ShaderFullFilename + "\n" + e.Message;
            if (MessageBox.Show(text, "Shader compiler", MessageBoxButtons.RetryCancel) == DialogResult.Retry)
            {
                Init();
            }
        }
    }
예제 #11
0
    public static Blob CompileFromFile(
        string fileName,
        ShaderMacro[] macros,
        Include include,
        string entryPoint,
        string profile,
        ShaderFlags shaderFlags = ShaderFlags.None,
        EffectFlags effectFlags = EffectFlags.None)
    {
        Result result = CompileFromFile(
            fileName,
            macros,
            include,
            entryPoint,
            profile,
            shaderFlags,
            effectFlags,
            out Blob blob,
            out Blob? errorBlob);

        if (result.Failure)
        {
            if (errorBlob != null)
            {
                throw new SharpGenException(result, errorBlob.AsString());
            }
            else
            {
                throw new SharpGenException(result);
            }
        }

        errorBlob?.Dispose();
        return(blob);
    }
예제 #12
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>
 /// <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)
 {
     ConstantTable constantTable;
     var result = CompileShader(functionHandle, target, flags, out constantTable);
     constantTable.Dispose();
     return result;
 }
예제 #13
0
        private static DX11Effect Compile(string content, bool isfile, Include include, ShaderMacro[] defines)
        {
            DX11Effect  shader = new DX11Effect();
            ShaderFlags flags  = ShaderFlags.OptimizationLevel1;// | ShaderFlags.PackMatrixRowMajor;

            try
            {
                if (isfile)
                {
                    shader.CompilationResult = ShaderBytecode.CompileFromFile(content, "fx_5_0", flags, EffectFlags.None, defines, include);
                }
                else
                {
                    shader.CompilationResult = ShaderBytecode.Compile(content, "fx_5_0", flags, EffectFlags.None, defines, include);
                }

                if (shader.IsCompiled)
                {
                    shader.DefaultEffect = new Effect(NullDevice.Device, shader.CompilationResult.Bytecode);
                }
            }
            catch (Exception ex)
            {
                shader.CompilationResult = new CompilationResult(null, Result.Fail, ex.Message);
            }
            return(shader);
        }
예제 #14
0
        /// <summary>Create an effect from a file</summary>
        public Effect CreateEffectFromFile(Device device, string filename, Macro[] defines, Include includeFile,
                                           ShaderFlags flags, EffectPool effectPool, int instanceId, out string errors)
        {
            // No errors at first!
            errors = string.Empty;
            // Search the cache first
            foreach (CachedEffect ce in effectCache.Keys)
            {
                if ((string.Compare(ce.Source, filename, true) == 0) &&
                    (ce.Flags == flags) && (ce.InstanceId == instanceId))
                {
                    // A match was found, return that
                    return(effectCache[ce] as Effect);
                }
            }

            // Nothing found in the cache
            Effect e = Effect.FromFile(device, filename, defines, includeFile, null, flags, effectPool, out errors);
            // Add this to the cache
            CachedEffect entry = new CachedEffect();

            entry.Flags      = flags;
            entry.Source     = filename;
            entry.InstanceId = instanceId;
            effectCache.Add(entry, e);

            //if (!string.IsNullOrEmpty(errors))
            //    System.Windows.Forms.MessageBox.Show(errors);

            // Return the new effect
            return(e);
        }
예제 #15
0
            private byte[] CompileShaderDef(string definition, string source, string fileName = null)
            {
#if DEBUG
                const ShaderFlags shaderFlags = ShaderFlags.Debug;
#else
                const ShaderFlags shaderFlags = ShaderFlags.OptimizationLevel3;
#endif

                var macroArray = Defines.Select(x => new ShaderMacro(x.Text, 1)).ToArray();

                using (var includer = new Includer())
                {
                    var split  = definition.Split(' ');
                    var result = ShaderBytecode.Compile(source, split[0], split[1], shaderFlags, EffectFlags.None,
                                                        macroArray, includer, fileName);

                    /*
                     * foreach (var msg in result.Message.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                     * {
                     *  Renderer.Logger.Info(msg);
                     *  Debug.WriteLine(msg);
                     * }
                     */

                    if (result.Bytecode == null)
                    {
                        throw new Exception($"Could not compile shader \"{Name}\". \n\n{result.Message}");
                    }

                    return(result.Bytecode);
                }
            }
        private void SetComboboxes()
        {
            var newMaterial = ContentLoader.Load <Material>(materialName);

            selectedBlendMode  = newMaterial.DiffuseMap.BlendMode.ToString();
            selectedRenderSize = newMaterial.RenderSizeMode.ToString();
            if (newMaterial.Animation != null)
            {
                selectedImage = newMaterial.Animation.Name;                 //ncrunch: no coverage
            }
            else if (newMaterial.SpriteSheet != null)
            {
                selectedImage = newMaterial.SpriteSheet.Name;
            }
            else
            {
                selectedImage = newMaterial.DiffuseMap.Name;                 //ncrunch: no coverage
            }
            foreach (var colorWithString in colorList)
            {
                if (newMaterial.DefaultColor == colorWithString.Value)
                {
                    selectedColor = colorWithString.Key;
                }
            }
            selectedShader = newMaterial.Shader.Flags;
            RaiseAllPropertyChanged();
        }
예제 #17
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Initialize the stats font
            statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
                                                                     Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
                                                                     , "Arial");

            // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the
            // shader debugger. Debugging vertex shaders requires either REF or software vertex
            // processing, and debugging pixel shaders requires REF.  The
            // ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the
            // shader debugger.  It enables source level debugging, prevents instruction
            // reordering, prevents dead code elimination, and forces the compiler to compile
            // against the next higher available software target, which ensures that the
            // unoptimized shaders do not exceed the shader model limitations.  Setting these
            // flags will cause slower rendering since the shaders will be unoptimized and
            // forced into software.  See the DirectX documentation for more information about
            // using the shader debugger.
            ShaderFlags shaderFlags = ShaderFlags.NotCloneable;

#if (DEBUG_VS)
            shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
#endif
#if (DEBUG_PS)
            shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
#endif
            // Read the D3DX effect file
            string path = Utility.FindMediaFile("EmptyProject.fx");
            effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device,
                                                                            path, null, null, shaderFlags, null);

            // Setup the camera's view parameters
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, -5.0f), Vector3.Empty);
        }
 public ShaderCompilationCache(ShaderFlags flags)
 {
     ShaderFlags     = flags;
     TimeStamps      = new Dictionary <string, long>();
     CompiledShaders = new Dictionary <SourceShader, ShaderBytecode>();
     Dependencies    = new Dictionary <string, HashSet <string> >();
 }
예제 #19
0
 public FullscreenQuad(ShaderType_BL type, ShaderFlags flags)
 {
     VertexBufferObject  = GL.GenBuffer();
     VertexArrayObject   = GL.GenVertexArray();
     ElementBufferObject = GL.GenBuffer();
     Initialise(type, flags);
 }
예제 #20
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Initialize the font
            drawingFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
                                                                       Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
                                                                       , "Arial");

            // Create the vertex shader and declaration
            VertexElement[] elements = new VertexElement[]
            {
                new VertexElement(0, 0, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                VertexElement.VertexDeclarationEnd
            };

            vertexDecl = new VertexDeclaration(e.Device, elements);

            // Find the shader file
            string path = Utility.FindMediaFile("HLSLwithoutEffects.Fx");

            // Define DEBUG_VS and/or DEBUG_PS to debug vertex and/or pixel shaders with the
            // shader debugger. Debugging vertex shaders requires either REF or software vertex
            // processing, and debugging pixel shaders requires REF.  The
            // ShaderFlags.Force*SoftwareNoOptimizations flag improves the debug experience in the
            // shader debugger.  It enables source level debugging, prevents instruction
            // reordering, prevents dead code elimination, and forces the compiler to compile
            // against the next higher available software target, which ensures that the
            // unoptimized shaders do not exceed the shader model limitations.  Setting these
            // flags will cause slower rendering since the shaders will be unoptimized and
            // forced into software.  See the DirectX documentation for more information about
            // using the shader debugger.
            ShaderFlags shaderFlags = ShaderFlags.None;

#if (DEBUG_VS)
            shaderFlags |= ShaderFlags.ForceVertexShaderSoftwareNoOptimizations;
#endif
#if (DEBUG_PS)
            shaderFlags |= ShaderFlags.ForcePixelShaderSoftwareNoOptimizations;
#endif

            string errors;

            using (GraphicsStream code = ShaderLoader.CompileShaderFromFile(path, "Ripple", null, null,
                                                                            "vs_1_1", shaderFlags, out errors, out constantTable))
            {
                // We will store these constants in an effect handle here for performance reasons.
                // You could simply use the string value (i.e., "worldViewProj") in the SetValue call
                // and it would work just as well, but that actually requires an allocation to be made
                // and can actually slow your performance down.  It's much more efficient to simply
                // cache these handles for use later
                worldViewHandle = constantTable.GetConstant(null, "worldViewProj");
                timeHandle      = constantTable.GetConstant(null, "appTime");

                // Create the shader
                shader = new VertexShader(e.Device, code);
            }

            // Setup the camera's view parameters
            camera.SetViewQuat(new Quaternion(-0.275f, 0.3f, 0.0f, 0.7f));
        }
예제 #21
0
 public Material(Color nonUvColor, ShaderFlags nonUvShaderFlags)
     : base("<GeneratedCustomMaterial:" + nonUvColor + ":" + nonUvShaderFlags + ">")
 {
     Shader              = ContentLoader.Create <Shader>(new ShaderCreationData(nonUvShaderFlags));
     DefaultColor        = nonUvColor;
     MetaData            = new ContentMetaData();
     RenderingCalculator = new RenderingCalculator();
 }
예제 #22
0
        public EComputeShader(GraphicsDevice graphicsDevice)
        {
            this.graphicsDevice = graphicsDevice;
            flags = ShaderFlags.None;
#if DEBUG
            flags = ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
        }
예제 #23
0
 /// <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="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(string shaderSource, string profile, ShaderFlags shaderFlags, Macro[] defines, Include include)
 {
     if (string.IsNullOrEmpty(shaderSource))
     {
         throw new ArgumentNullException("shaderSource");
     }
     return(Compile(Encoding.ASCII.GetBytes(shaderSource), null, profile, shaderFlags, defines, include));
 }
예제 #24
0
        ShaderBytecode LoadShader(string name, ShaderFlags flags)
        {
            Assembly     assembly     = Assembly.GetExecutingAssembly();
            StreamReader reader       = new StreamReader(assembly.GetManifestResourceStream("DemoFramework.SharpDX11." + name));
            string       shaderSource = reader.ReadToEnd();

            return(ShaderBytecode.Compile(shaderSource, "fx_5_0", flags, EffectFlags.None));
        }
예제 #25
0
 public static byte[] CompileShader(
     string fileName, string entryPoint, string profile,
     ShaderFlags shaderFlags = ShaderFlags.None)
 {
     var compiledShader = ShaderBytecode.CompileFromFile(
         fileName, entryPoint, profile, shaderFlags);
     return compiledShader.Bytecode.Data;
 }
예제 #26
0
 public ShaderDesc()
 {
     _EntryPoint = new List<string>();
     _EntryPoint.Add("main");
     _BuildLevel = FeatureLevel.Level_11_0;
     _Flags = ShaderFlags.OptimizationLevel3 | ShaderFlags.Debug;
     _IncludePath = null;
 }
        static ShaderBytecode LoadShader(string name, ShaderFlags flags)
        {
            Assembly     assembly     = Assembly.GetExecutingAssembly();
            StreamReader reader       = new StreamReader(assembly.GetManifestResourceStream(string.Format("{0}.{1}", assembly.GetName().Name, name)));
            string       shaderSource = reader.ReadToEnd();

            return(ShaderBytecode.Compile(shaderSource, "fx_4_0", flags, EffectFlags.None));
        }
예제 #28
0
        internal ShaderBytecode GetShaderByteCodeFromResource(string shaderBlob, string entryPoint, string profile)
        {
            ShaderFlags flags = ShaderFlags.None;

#if DEBUG
            flags = ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
            return(ShaderBytecode.Compile(shaderBlob, entryPoint, profile, flags));
        }
예제 #29
0
 /// <summary>
 /// As opposed to loading a material from content it can also be created with this constructor.
 /// If imageOrAnimationName is used you need to provide either a DiffuseMap or an Animation.
 /// </summary>
 public Material(ShaderFlags shaderFlags, string imageOrAnimationName)
     : base("<GeneratedMaterial:" + shaderFlags + ":" + imageOrAnimationName + ">")
 {
     Initialize(shaderFlags, imageOrAnimationName, Color.White);
     if (MetaData == null)
     {
         MetaData = new ContentMetaData();
     }
 }
예제 #30
0
 /// <summary>
 /// Creates a new image with the specified size to be filled dynamically (via .DiffuseMap.Fill).
 /// </summary>
 public Material(Size customPixelSize, ShaderFlags shaderFlags = ShaderFlags.Position2DTextured)
     : base("<GeneratedCustomMaterial:" + shaderFlags + ":" + customPixelSize + ">")
 {
     Shader              = ContentLoader.Create <Shader>(new ShaderCreationData(shaderFlags));
     DiffuseMap          = ContentLoader.Create <Image>(new ImageCreationData(customPixelSize));
     pixelSize           = customPixelSize;
     DefaultColor        = Color.White;
     MetaData            = new ContentMetaData();
     RenderingCalculator = new RenderingCalculator();
 }
예제 #31
0
 public ShaderWithFormatCreationData(ShaderFlags flags, string glVertexCode,
                                     string glFragmentCode, string dx11Code, string dx9Code, VertexFormat format)
     : base(flags)
 {
     VertexCode   = glVertexCode;
     FragmentCode = glFragmentCode;
     DX11Code     = dx11Code;
     DX9Code      = dx9Code;
     Format       = format;
 }
예제 #32
0
 private void Initialize(ShaderFlags flags, string imageOrAnimationName, Color defaultColor)
 {
     Shader              = ContentLoader.Create <Shader>(new ShaderCreationData(flags));
     DefaultColor        = defaultColor;
     RenderingCalculator = new RenderingCalculator();
     if (!String.IsNullOrEmpty(imageOrAnimationName))
     {
         DetermineUseCaseData(imageOrAnimationName);
     }
 }
 public void ResetOnProjectChange()
 {
     RefreshOnContentChange();
     materialName   = "";
     selectedImage  = "";
     selectedShader = ShaderFlags.None;
     RaisePropertyChanged("MaterialName");
     RaisePropertyChanged("SelectedImage");
     RaisePropertyChanged("SelectedShader");
 }
		public ShaderWithFormatCreationData(ShaderFlags flags, string glVertexCode,
			string glFragmentCode, string dx11Code, string dx9Code, VertexFormat format)
			: base(flags)
		{
			VertexCode = glVertexCode;
			FragmentCode = glFragmentCode;
			DX11Code = dx11Code;
			DX9Code = dx9Code;
			Format = format;
		}
예제 #35
0
        public ShaderBytecode LoadByteCodeFromFile(ShaderType shaderType, string fileName, string entryPoint = null, ShaderFlags shaderFlags = ShaderFlags.None, EffectFlags effectFlags = EffectFlags.None)
        {
            #if DEBUG
            shaderFlags |= ShaderFlags.Debug;
            #endif

            var profile = GetProfileFromDevice(shaderType);
            var compilationResult = ShaderBytecode.CompileFromFile(fileName, entryPoint, profile, shaderFlags, effectFlags, include: new IncludeFromDisk());

            return compilationResult.Bytecode;
        }
예제 #36
0
 public PixelShader10(Device device,
              string shaderSource,
              string entryPoint,
              ShaderVersion shaderVersion,
              ShaderFlags shaderFlags = ShaderFlags.None,
              EffectFlags effectFlags = EffectFlags.None) :
     base(shaderSource, entryPoint, shaderVersion, shaderFlags, effectFlags)
 {
     m_device = device;
     CreatePixelShader();
 }
예제 #37
0
 protected ShaderBase(string shaderSource,
                      string entryPoint,
                      ShaderVersion shaderVersion,
                      ShaderFlags shaderFlags = ShaderFlags.None,
                      EffectFlags effectFlags = EffectFlags.None)
 {
     m_shaderByteCode = ShaderBytecode.Compile(shaderSource,
                                               entryPoint,
                                               shaderVersion.ToShaderVersionString(),
                                               shaderFlags,
                                               effectFlags);
 }
예제 #38
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, ShaderFlags flags )
		{
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.Empty;
			ps.BlendState			=	BlendState.Opaque;
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.DepthStencilState	=	DepthStencilState.None;

			if (flags==ShaderFlags.SSAO) {
				ps.BlendState = BlendState.Opaque;
			}
		}
예제 #39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EffectCompiler"/> class.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="defines">The defines.</param>
        /// <param name="includeFile">The include file.</param>
        /// <param name="flags">The flags.</param>
        /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const char* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[In] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
        public EffectCompiler(string data, Macro[] defines, Include includeFile, ShaderFlags flags) : base(IntPtr.Zero)
        {
            IntPtr dataPtr = Marshal.StringToHGlobalAnsi(data);
            try
            {

                CreateEffectCompiler(dataPtr, data.Length, defines, includeFile, flags, this);
            }
            finally
            {
                Marshal.FreeHGlobal(dataPtr);
            }
        }
예제 #40
0
 public static ShaderBytecode FromResource(Assembly assembly, string[] sourceNames, ShaderFlags flags)
 {
     string assemblyName = assembly.GetName().Name;
     string shaderSource = "";
     foreach (string source in sourceNames)
     {
         using (var stream = assembly.GetManifestResourceStream(string.Format("{0}.{1}", assemblyName, source)))
         {
             StreamReader reader = new StreamReader(stream);
             shaderSource += reader.ReadToEnd();
         }
     }
     return ShaderBytecode.Compile(shaderSource, "fx_5_0", flags, EffectFlags.None);
 }
예제 #41
0
        protected ShaderBase(string embeddedSourceResourceName,
                             Assembly resourceAssembly,
                             string entryPoint,
                             ShaderVersion shaderVersion,
                             ShaderFlags shaderFlags = ShaderFlags.None,
                             EffectFlags effectFlags = EffectFlags.None)
        {
            string shaderSource = GetResourceString(embeddedSourceResourceName, resourceAssembly);

            m_shaderByteCode = ShaderBytecode.Compile(shaderSource,
                                                      entryPoint,
                                                      shaderVersion.ToShaderVersionString(),
                                                      shaderFlags,
                                                      effectFlags);
        }
예제 #42
0
 public VertexShader10(Device device,
                      string embeddedSourceResourceName,
                      string entryPoint,
                      ShaderVersion shaderVersion,
                      ShaderFlags shaderFlags = ShaderFlags.None,
                      EffectFlags effectFlags = EffectFlags.None) :
     base(embeddedSourceResourceName,
          entryPoint,
          shaderVersion,
          shaderFlags,
          effectFlags)
 {
     m_device = device;
     CreatePixelShader();
 }
예제 #43
0
 /// <summary>
 /// Compile an effect.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <exception cref="CompilationException">If a compilation errors occurs</exception>
 /// <returns>Buffer containing the compiled effect.</returns>
 /// <unmanaged>HRESULT ID3DXEffectCompiler::CompileEffect([In] unsigned int Flags,[In] ID3DXBuffer** ppEffect,[In] ID3DXBuffer** ppErrorMsgs)</unmanaged>
 public DataStream CompileEffect(ShaderFlags flags)
 {
     Blob effect;
     Blob blobForErrors = null;
     try
     {
         CompileEffect((int)flags, out effect, out blobForErrors);
     }
     catch (SharpDXException ex)
     {
         if (blobForErrors != null)
             throw new CompilationException(ex.ResultCode, Utilities.BlobToString(blobForErrors));
         throw;
     }
     return new DataStream(effect);
 }
예제 #44
0
        public static ShaderBytecode PrecompileOrLoad(string fileName, string entryPoint, string profile, ShaderFlags shaderFlags, EffectFlags effectFlags)
        {
            FileInfo sourceFile = new FileInfo(fileName);

            if (!sourceFile.Exists)
                throw new FileNotFoundException();

            FileInfo compiledFile = new FileInfo(@"Precompiled\" + Path.GetFileNameWithoutExtension(sourceFile.Name) + "_" + entryPoint + "_" + profile + ".bin");

            if (compiledFile.Exists && sourceFile.LastWriteTime > compiledFile.LastWriteTime)
            {
                compiledFile.Delete();
                compiledFile.Refresh();
            }

            ShaderBytecode shaderBytecode = null;

            if (compiledFile.Exists)
            {
                byte[] compiledBytes = File.ReadAllBytes(compiledFile.FullName);
                DataStream compiledDataStream = new DataStream(compiledBytes, true, false);

                shaderBytecode = new ShaderBytecode(compiledDataStream);
            }
            else
            {
                shaderBytecode = ShaderBytecode.CompileFromFile(fileName, entryPoint, profile, shaderFlags, effectFlags);

                byte[] compiledBytes = shaderBytecode.Data.ReadRange<byte>((int)shaderBytecode.Data.Length);

                Directory.CreateDirectory(Path.GetDirectoryName(compiledFile.FullName));
                File.WriteAllBytes(compiledFile.FullName, compiledBytes);
            }

            if (shaderBytecode == null)
                throw new D3DCompilerException();

            return shaderBytecode;
        }
예제 #45
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>
 /// <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)
 {
     return FromString(device, sourceData, preprocessorDefines, includeFile, skipConstants, flags, null);
 }
예제 #46
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;
     }
 }
예제 #47
0
 /// <summary>
 /// Creates an effect compiler from a stream containing an ASCII effect description .
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="defines">The defines.</param>
 /// <param name="includeFile">The include file.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>An instance of <see cref="EffectCompiler"/></returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromStream(Stream stream, Macro[] defines, Include includeFile, ShaderFlags flags)
 {
     if (stream is DataStream)
     {
         var compiler = new EffectCompiler(IntPtr.Zero);
         CreateEffectCompiler(((DataStream)stream).PositionPointer, (int)(stream.Length - stream.Position), defines, includeFile, flags, compiler);
         return compiler;
     } 
     return FromMemory(Utilities.ReadStream(stream), defines, includeFile, flags);
 }
예제 #48
0
 /// <summary>
 /// Creates an effect compiler from a stream containing an ASCII effect description .
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// An instance of <see cref="EffectCompiler"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromStream(Stream stream, ShaderFlags flags)
 {
     return FromStream(stream, null, null, flags);
 }
예제 #49
0
 /// <summary>
 /// Creates an effect compiler from a memory buffer containing an ASCII effect description .
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="defines">The defines.</param>
 /// <param name="includeFile">The include file.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// An instance of <see cref="EffectCompiler"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromMemory(byte[] data, Macro[] defines, Include includeFile, ShaderFlags flags)
 {
     unsafe
     {
         var compiler = new EffectCompiler(IntPtr.Zero);
         fixed (void* pData = data)
             CreateEffectCompiler((IntPtr)pData, data.Length, defines, includeFile, flags, compiler);
         return compiler;
     }
 }
예제 #50
0
 /// <summary>
 /// Creates an effect compiler from a memory buffer containing an ASCII effect description .
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// An instance of <see cref="EffectCompiler"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromMemory(byte[] data, ShaderFlags flags)
 {
     return FromMemory(data, null, null, flags);
 }
예제 #51
0
 /// <summary>
 /// Compiles an effect from a file.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="fileName">Name of the file.</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>
 /// <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 FromFile(Device device, string fileName, Macro[] preprocessorDefines, Include includeFile, string skipConstants, ShaderFlags flags)
 {
     return FromFile(device, fileName, preprocessorDefines, includeFile, skipConstants, flags, null);
 }
예제 #52
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;
        }
예제 #53
0
		private void SetComboboxes()
		{
			var newMaterial = ContentLoader.Load<Material>(materialName);
			selectedBlendMode = newMaterial.DiffuseMap.BlendMode.ToString();
			selectedRenderSize = newMaterial.RenderSizeMode.ToString();
			if (newMaterial.Animation != null)
				selectedImage = newMaterial.Animation.Name; //ncrunch: no coverage
			else if (newMaterial.SpriteSheet != null)
				selectedImage = newMaterial.SpriteSheet.Name;
			else
				selectedImage = newMaterial.DiffuseMap.Name; //ncrunch: no coverage 
			foreach (var colorWithString in colorList)
				if (newMaterial.DefaultColor == colorWithString.Value)
					selectedColor = colorWithString.Key;
			selectedShader = newMaterial.Shader.Flags;
			RaiseAllPropertyChanged();
		}
예제 #54
0
		public void ResetOnProjectChange()
		{
			RefreshOnContentChange();
			materialName = "";
			selectedImage = "";
			selectedShader = ShaderFlags.None;
			RaisePropertyChanged("MaterialName");
			RaisePropertyChanged("SelectedImage");
			RaisePropertyChanged("SelectedShader");
		}
예제 #55
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ps"></param>
		/// <param name="flags"></param>
		void Enum ( PipelineState ps, ShaderFlags flags )
		{
			ps.Primitive			=	Primitive.TriangleList;
			ps.VertexInputElements	=	VertexInputElement.Empty;
			ps.BlendState			=	BlendState.Opaque;
			ps.RasterizerState		=	RasterizerState.CullNone;
			ps.DepthStencilState	=	DepthStencilState.None;

			if (flags==ShaderFlags.OVERLAY_ADDITIVE) {
				ps.BlendState = BlendState.Additive;
			}

			if (flags==ShaderFlags.FILL_ALPHA_ONE) {
				ps.BlendState = BlendState.AlphaMaskWrite;
			}
		}
예제 #56
0
 private static string GetShaderFlagsString(ShaderFlags shaderFlags)
 {
     var text = shaderFlags.ToString();
     return text;
 }
예제 #57
0
 /// <summary>
 /// Creates an effect compiler from a file on disk containing an ASCII effect description .
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// An instance of <see cref="EffectCompiler"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromFile(string fileName, ShaderFlags flags)
 {
     return new EffectCompiler(File.ReadAllText(fileName), null, null, flags);
 }
예제 #58
0
 /// <summary>
 /// Creates an effect compiler from a file on disk containing an ASCII effect description .
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="defines">The defines.</param>
 /// <param name="includeFile">The include file.</param>
 /// <param name="flags">The flags.</param>
 /// <returns>
 /// An instance of <see cref="EffectCompiler"/>
 /// </returns>
 /// <unmanaged>HRESULT D3DXCreateEffectCompiler([In] const void* pSrcData,[In] unsigned int SrcDataLen,[In, Buffer] const D3DXMACRO* pDefines,[In] ID3DXInclude* pInclude,[In] unsigned int Flags,[Out, Fast] ID3DXEffectCompiler** ppCompiler,[In] ID3DXBuffer** ppParseErrors)</unmanaged>
 public static EffectCompiler FromFile(string fileName, Macro[] defines, Include includeFile, ShaderFlags flags)
 {
     return new EffectCompiler(File.ReadAllText(fileName), defines, includeFile, flags);
 }
예제 #59
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);
 }
예제 #60
0
 /// <summary>
 /// Compiles an effect from a file.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="flags">The flags.</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 FromFile(Device device, string fileName, ShaderFlags flags)
 {
     return FromFile(device, fileName, null, null, null, flags, null);
 }