From ac670c0433d19397d4e36ced2110475b6f54fe26 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 27 Jul 2010 17:39:27 -0700 Subject: Generate shaders to cover all possible cases. With this change, all the vertex and fragment shaders used by the GL renderer are now generated based on a program description supplied by the caller. This allows the renderer to generate a large number of shaders without having to write all the possible combinations by hand. The generated shaders are stored in a program cache. Change-Id: If54d286e77ae021c724d42090da476df12a18ebb --- libs/hwui/Program.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'libs/hwui/Program.cpp') diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp index 6e608084f5bb..86fc154bb9c2 100644 --- a/libs/hwui/Program.cpp +++ b/libs/hwui/Program.cpp @@ -27,7 +27,6 @@ namespace uirenderer { #define SHADER_SOURCE(name, source) const char* name = #source -#include "shaders/drawColor.vert" #include "shaders/drawColor.frag" #include "shaders/drawTexture.vert" @@ -127,7 +126,7 @@ GLuint Program::buildShader(const char* source, GLenum type) { /////////////////////////////////////////////////////////////////////////////// DrawColorProgram::DrawColorProgram(): - Program(gDrawColorVertexShader, gDrawColorFragmentShader) { + Program(gDrawTextureVertexShader, gDrawColorFragmentShader) { getAttribsAndUniforms(); } @@ -138,6 +137,7 @@ DrawColorProgram::DrawColorProgram(const char* vertex, const char* fragment): void DrawColorProgram::getAttribsAndUniforms() { position = addAttrib("position"); + texCoords = addAttrib("texCoords"); color = addUniform("color"); transform = addUniform("transform"); } @@ -154,11 +154,13 @@ void DrawColorProgram::set(const mat4& projectionMatrix, const mat4& modelViewMa void DrawColorProgram::use() { Program::use(); glEnableVertexAttribArray(position); + glEnableVertexAttribArray(texCoords); } void DrawColorProgram::remove() { Program::remove(); glDisableVertexAttribArray(position); + glDisableVertexAttribArray(texCoords); } /////////////////////////////////////////////////////////////////////////////// @@ -167,26 +169,21 @@ void DrawColorProgram::remove() { DrawTextureProgram::DrawTextureProgram(): DrawColorProgram(gDrawTextureVertexShader, gDrawTextureFragmentShader) { - texCoords = addAttrib("texCoords"); sampler = addUniform("sampler"); } DrawTextureProgram::DrawTextureProgram(const char* vertex, const char* fragment): DrawColorProgram(vertex, fragment) { - texCoords = addAttrib("texCoords"); sampler = addUniform("sampler"); } void DrawTextureProgram::use() { DrawColorProgram::use(); - glActiveTexture(GL_TEXTURE0); glUniform1i(sampler, 0); - glEnableVertexAttribArray(texCoords); } void DrawTextureProgram::remove() { DrawColorProgram::remove(); - glDisableVertexAttribArray(texCoords); } /////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3-59-g8ed1b