summaryrefslogtreecommitdiff
path: root/libs/hwui/Program.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-09-26 16:39:40 -0700
committerRomain Guy <romainguy@google.com>2012-09-26 16:39:40 -0700
commit39284b763a09688468ed3799ebd2ebb76ea5dfd5 (patch)
treeb67c139bf0552ff066a4eafb9e29deae62924075 /libs/hwui/Program.cpp
parentbd43152bda835c5a9a619a5869344a6a3af11917 (diff)
Make gradients beautiful again
Bug #7239634 This change passes two matrices to the vertex shader instead of one. We used to compute the final MVP matrix on the CPU to minimize the number of operations in the vertex shaders. Shader compilers are however smart enough to perform this optimization for us. Since we need the MV matrix to properly compute gradients dithering, this change splits the MVP matrix into two. This has the advantage of removing one matrix multiplication per drawing operation on the CPU. The SGX 540 shader compiler produces the same number of instructions in both cases. There is no penalty hit with having two matrices instead of one. We also send so few vertices per frame that it does not matter very much. Change-Id: I17d47ac4772615418e0e1885b97493d31435a936
Diffstat (limited to 'libs/hwui/Program.cpp')
-rw-r--r--libs/hwui/Program.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libs/hwui/Program.cpp b/libs/hwui/Program.cpp
index 5b1b57d3a664..f0b5553a79a7 100644
--- a/libs/hwui/Program.cpp
+++ b/libs/hwui/Program.cpp
@@ -81,6 +81,7 @@ Program::Program(const ProgramDescription& description, const char* vertex, cons
if (mInitialized) {
transform = addUniform("transform");
+ projection = addUniform("projection");
}
}
@@ -152,18 +153,20 @@ GLuint Program::buildShader(const char* source, GLenum type) {
void Program::set(const mat4& projectionMatrix, const mat4& modelViewMatrix,
const mat4& transformMatrix, bool offset) {
- mat4 t(projectionMatrix);
+ mat4 p(projectionMatrix);
if (offset) {
// offset screenspace xy by an amount that compensates for typical precision
// issues in GPU hardware that tends to paint hor/vert lines in pixels shifted
// up and to the left.
// This offset value is based on an assumption that some hardware may use as
// little as 12.4 precision, so we offset by slightly more than 1/16.
- t.translate(.375, .375, 0);
+ p.translate(.375, .375, 0);
}
- t.multiply(transformMatrix);
+
+ mat4 t(transformMatrix);
t.multiply(modelViewMatrix);
+ glUniformMatrix4fv(projection, 1, GL_FALSE, &p.data[0]);
glUniformMatrix4fv(transform, 1, GL_FALSE, &t.data[0]);
}