override protected void CreatePrograms() { if (_program == null) { string programName = BlurProgram.GetProgramName(false); _program = (BlurProgram)SparrowSharpApp.GetProgram(programName); if (_program == null) { _program = new BlurProgram(false); SparrowSharpApp.RegisterProgram(programName, _program); } } if (_tintedProgram == null) { string programName = BlurProgram.GetProgramName(true); _tintedProgram = (BlurProgram)SparrowSharpApp.GetProgram(programName); if (_tintedProgram == null) { _tintedProgram = new BlurProgram(true); SparrowSharpApp.RegisterProgram(programName, _tintedProgram); } } VertexPosID = _program.APosition; TexCoordsID = _program.ATexCoords; }
override protected void CreatePrograms() { if (_program == null) { string programName = "_test_emptyFilterProgram"; _program = SparrowSharpApp.GetProgram(programName); if (_program == null) { _program = new Program(FragmentFilter.StandardVertexShader(), FragmentFilter.StandardFragmentShader()); SparrowSharpApp.RegisterProgram(programName, _program); } } VertexPosID = _program.Attributes["aPosition"]; TexCoordsID = _program.Attributes["aTexCoords"]; }
override protected void CreatePrograms() { if (_shaderProgram == null) { _shaderProgram = SparrowSharpApp.GetProgram(ColorMatrixProgram); if (_shaderProgram == null) { _shaderProgram = new Program(FragmentFilter.StandardVertexShader(), GetFragmentShader()); SparrowSharpApp.RegisterProgram(ColorMatrixProgram, _shaderProgram); } VertexPosID = _shaderProgram.Attributes["aPosition"]; TexCoordsID = _shaderProgram.Attributes["aTexCoords"]; _uColorMatrix = _shaderProgram.Uniforms["uColorMatrix"]; _uColorOffset = _shaderProgram.Uniforms["uColorOffset"]; _uMvpMatrix = _shaderProgram.Uniforms["uMvpMatrix"]; } }
/// <summary> /// Activates the optimal shader program for the current settings; alpha and matrix uniforms are /// passed to the program right away, and the texture (if available) is bound. /// Parameters: /// mvpMatrix: The modelview-projection matrix used for rendering. Any vertex will be multiplied with this matrix. /// premultipliedAlpha: Indicates if the color values of texture and vertices use premultiplied alpha. /// alpha: The alpha value with which every vertex color will be multiplied. /// useTinting: Set to true if you dont use textures or want to use alpha. /// texture: The texture that's projected onto the quad, or 'null' if there is none. /// </summary> public void PrepareToDraw(Matrix mvpMatrix, bool premultipliedAlpha, float alpha, bool useTinting, Texture texture = null) { bool hasTexture = texture != null; string programName; if (hasTexture) { programName = useTinting ? "SparrowAlphaTextureProgram" : "SparrowTextureProgram"; } else { programName = "SparrowQuadProgram"; } if (_currentProgram == null || _currentProgram != SparrowSharpApp.GetProgram(programName)) { if (SparrowSharpApp.Programs.ContainsKey(programName)) { _currentProgram = SparrowSharpApp.GetProgram(programName); } else { string vertexShader = VertexShaderString(hasTexture, useTinting); string fragmentShader = FragmentShaderString(hasTexture, useTinting); _currentProgram = new Program(vertexShader, fragmentShader); SparrowSharpApp.RegisterProgram(programName, _currentProgram); } _aPosition = _currentProgram.Attributes["aPosition"]; if (_currentProgram.Attributes.ContainsKey("aColor")) { _aColor = _currentProgram.Attributes["aColor"]; } if (_currentProgram.Attributes.ContainsKey("aTexCoords")) { _aTexCoords = _currentProgram.Attributes["aTexCoords"]; } _uMvpMatrix = _currentProgram.Uniforms["uMvpMatrix"]; if (_currentProgram.Uniforms.ContainsKey("uAlpha")) { _uAlpha = _currentProgram.Uniforms["uAlpha"]; } } Matrix4 glkMvpMatrix = mvpMatrix.ConvertToMatrix4(); GL.UseProgram(_currentProgram.Name); GL.UniformMatrix4(_uMvpMatrix, false, ref glkMvpMatrix); // TODO check; was glUniformMatrix4fv(_uMvpMatrix, 1, NO, glkMvpMatrix.m); if (useTinting) { if (premultipliedAlpha) { GL.Uniform4(_uAlpha, alpha, alpha, alpha, alpha); } else { GL.Uniform4(_uAlpha, 1.0f, 1.0f, 1.0f, alpha); } } if (hasTexture) { GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texture.Name); } }