override protected void ActivateWithPass(int pass, Texture texture, Matrix mvpMatrix) { UpdateParamaters(pass, (int)texture.NativeWidth, (int)texture.NativeHeight); bool isColorPass = _enableColorUniform && pass == NumPasses - 1; BlurProgram program = isColorPass ? _tintedProgram : _program; GL.UseProgram(program.Name); Matrix4 mvp = mvpMatrix.ConvertToMatrix4(); GL.UniformMatrix4(program.UMvpMatrix, false, ref mvp); GL.Uniform4(program.UOffsets, 1, _offsets); GL.Uniform4(program.UWeights, 1, _weights); if (isColorPass) { GL.Uniform4(program.UColor, 1, _color); } }
/// <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); } }
override protected void ActivateWithPass(int pass, Texture texture, Matrix mvpMatrix) { GL.UseProgram(_program.Name); Matrix4 mvp = mvpMatrix.ConvertToMatrix4(); GL.UniformMatrix4(_program.Uniforms["uMvpMatrix"], false, ref mvp); }