internal static void InitGL(this EffectPass pass) { EffectPassProperties props = PropertyTable.GetValue(pass, x => { return(new EffectPassProperties(x)); }); //EffectPassProperties props = new EffectPassProperties(pass); //if () //PropertyTable.Add(pass, props); }
private static void SetShaderSamplers(this EffectPass pass, EffectPassProperties props, Shader shader, TextureCollection textures, SamplerStateCollection samplerStates) { foreach (var sampler in shader.Samplers) { var param = props.Effect.Parameters[sampler.parameter]; var texture = param.Data as Texture; textures[sampler.textureSlot] = texture; // If there is a sampler state set it. if (sampler.state != null) samplerStates[sampler.samplerSlot] = sampler.state; } }
private static void SetShaderSamplers(this EffectPass pass, EffectPassProperties props, Shader shader, TextureCollection textures, SamplerStateCollection samplerStates) { foreach (var sampler in shader.Samplers) { var param = props.Effect.Parameters[sampler.parameter]; var texture = param.Data as Texture; textures[sampler.textureSlot] = texture; // If there is a sampler state set it. if (sampler.state != null) { samplerStates[sampler.samplerSlot] = sampler.state; } } }
public static void ApplyGL(this EffectPass pass) { // Set/get the correct shader handle/cleanups. // // TODO: This "reapply" if the shader index changes // trick is sort of ugly. We should probably rework // this to use some sort of "technique/pass redirect". // EffectPassProperties props = PropertyTable.GetValue(pass, x => { return(new EffectPassProperties(pass)); }); if (props.Effect.OnApply()) { props.Effect.CurrentTechnique.Passes[0].ApplyGL(); return; } var device = props.GraphicsDevice; ShaderProgram program = props.ShaderCache.GetProgram(props.VertexShader, props.PixelShader); GL.UseProgram(program.Program); if (props.VertexShader != null) { device.VertexShader = props.VertexShader; // Update the texture parameters. pass.SetShaderSamplers(props, props.VertexShader, device.VertexTextures, device.VertexSamplerStates); foreach (int paramIndex in props.VertexShaderParams) { EffectParameter param = props.Effect.Parameters[paramIndex]; SetEffectParameter(program, param); } // Update the constant buffers. foreach (int c in props.VertexShader.CBuffers) { device.SetConstantBuffer(ShaderStage.Vertex, c, null); } } if (props.PixelShader != null) { device.PixelShader = props.PixelShader; // Update the texture parameters. pass.SetShaderSamplers(props, props.PixelShader, device.Textures, device.SamplerStates); foreach (int paramIndex in props.PixelShaderParams) { EffectParameter param = props.Effect.Parameters[paramIndex]; SetEffectParameter(program, param); } // Update the constant buffers. foreach (int c in props.PixelShader.CBuffers) { device.SetConstantBuffer(ShaderStage.Pixel, c, null); } } // Set the render states if we have some. if (props.RasterizerState != null) { device.RasterizerState = props.RasterizerState; } if (props.BlendState != null) { device.BlendState = props.BlendState; } if (props.DepthStencilState != null) { device.DepthStencilState = props.DepthStencilState; } }