示例#1
0
            /// <summary>
            /// Allocate an instance of the type.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating the instance.
            /// </param>
            /// <returns>
            /// It returns an instance of a specific type.
            /// </returns>
            public override object Allocate(GraphicsContext ctx)
            {
                ShaderInclude shaderInclude = new ShaderInclude("/Test.glsl");

                shaderInclude.LoadSource(ShaderIncludeSource);

                return(shaderInclude);
            }
示例#2
0
            /// <summary>
            /// Allocate an instance of the type mocked for spying.
            /// </summary>
            /// <param name="ctx">
            /// A <see cref="GraphicsContext"/> used for allocating the instance.
            /// </param>
            /// <returns>
            /// It returns an instance of a specific type.
            /// </returns>
            public override T AllocateSpy <T>(GraphicsContext ctx)
            {
                T             shaderIncludeSpy = (T)CreateTypeSpy(_InstanceType, "/Test.glsl");
                ShaderInclude shaderInclude    = shaderIncludeSpy as ShaderInclude;

                if (shaderInclude != null)
                {
                    shaderInclude.LoadSource(ShaderIncludeSource);
                }

                return(shaderIncludeSpy);
            }
示例#3
0
        internal Shader(Device device, string shaderFile, string[] includePaths)
        {
            var shaderContent = File.ReadAllText(shaderFile);
            var shaderData    = JsonConvert.DeserializeObject <ShaderData>(shaderContent);

            var shaderDir = Path.GetDirectoryName(shaderFile);

            var shaderInclude = new ShaderInclude(includePaths);

            var vertexMacros = new List <ShaderMacro> {
                new ShaderMacro("VERTEX_SHADER", 1)
            };
            var pixelMacros = new List <ShaderMacro> {
                new ShaderMacro("PIXEL_SHADER", 1)
            };

            ZWrite     = shaderData.ZWrite;
            WriteMask  = shaderData.WriteMask;
            Instancing = shaderData.Instancing;
            if (Instancing)
            {
                vertexMacros.Add(new ShaderMacro("INSTANCING", 1));
                pixelMacros.Add(new ShaderMacro("INSTANCING", 1));
            }

            ShaderBytecode vertexShaderByteCode = ShaderBytecode.CompileFromFile(shaderDir + "/" + shaderData.Vertex.Path, shaderData.Vertex.Entry, "vs_5_0", ShaderFlags.None, EffectFlags.None, vertexMacros.ToArray(), shaderInclude);
            ShaderBytecode pixelShaderByteCode  = ShaderBytecode.CompileFromFile(shaderDir + "/" + shaderData.Pixel.Path, shaderData.Pixel.Entry, "ps_5_0", ShaderFlags.None, EffectFlags.None, pixelMacros.ToArray(), shaderInclude);

            InputElement[] inputElements = LoadInputs(shaderData.Vertex.Input, shaderData.Instancing);
            ShaderInputLayout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), inputElements);

            VertexShader = new VertexShader(device, vertexShaderByteCode);
            PixelShader  = new PixelShader(device, pixelShaderByteCode);


            vertexShaderByteCode.Dispose();
            pixelShaderByteCode.Dispose();
            this.device = device;
        }