Remove math from the vertex shader.

Change-Id: I02847a60a8734bf8b3d29ec12e76297795095e38
This commit is contained in:
Romain Guy
2010-07-09 18:53:25 -07:00
parent 8445ca6c3b
commit 0b9db91c3d
5 changed files with 24 additions and 27 deletions

View File

@@ -511,7 +511,7 @@ void OpenGLRenderer::drawColorRect(float left, float top, float right, float bot
mModelView.loadTranslate(left, top, 0.0f);
mModelView.scale(right - left, bottom - top, 1.0f);
mDrawColorShader->use(&mOrthoMatrix[0], &mModelView.data[0], &mSnapshot->transform.data[0]);
mDrawColorShader->use(&mOrthoMatrix[0], mModelView, mSnapshot->transform);
const GLvoid* p = &gDrawColorVertices[0].position[0];
@@ -548,7 +548,7 @@ void OpenGLRenderer::drawTextureMesh(float left, float top, float right, float b
mModelView.loadTranslate(left, top, 0.0f);
mModelView.scale(right - left, bottom - top, 1.0f);
mDrawTextureShader->use(&mOrthoMatrix[0], &mModelView.data[0], &mSnapshot->transform.data[0]);
mDrawTextureShader->use(&mOrthoMatrix[0], mModelView, mSnapshot->transform);
chooseBlending(blend || alpha < 1.0f, mode, isPremultiplied);

View File

@@ -127,17 +127,17 @@ DrawColorProgram::DrawColorProgram(const char* vertex, const char* fragment):
void DrawColorProgram::getAttribsAndUniforms() {
position = addAttrib("position");
color = addUniform("color");
projection = addUniform("projection");
modelView = addUniform("modelView");
transform = addUniform("transform");
}
void DrawColorProgram::use(const GLfloat* projectionMatrix, const GLfloat* modelViewMatrix,
const GLfloat* transformMatrix) {
void DrawColorProgram::use(const float* projectionMatrix, const mat4& modelViewMatrix,
const mat4& transformMatrix) {
mat4 t(projectionMatrix);
t.multiply(transformMatrix);
t.multiply(modelViewMatrix);
Program::use();
glUniformMatrix4fv(projection, 1, GL_FALSE, projectionMatrix);
glUniformMatrix4fv(modelView, 1, GL_FALSE, modelViewMatrix);
glUniformMatrix4fv(transform, 1, GL_FALSE, transformMatrix);
glUniformMatrix4fv(transform, 1, GL_FALSE, &t.data[0]);
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -23,6 +23,8 @@
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include "Matrix.h"
namespace android {
namespace uirenderer {
@@ -107,26 +109,18 @@ public:
* Binds the program with the specified projection, modelView and
* transform matrices.
*/
void use(const GLfloat* projectionMatrix, const GLfloat* modelViewMatrix,
const GLfloat* transformMatrix);
void use(const float* projectionMatrix, const mat4& modelViewMatrix,
const mat4& transformMatrix);
/**
* Name of the position attribute.
*/
int position;
/**
* Name of the color attribute.
*/
int color;
/**
* Name of the projection uniform.
* Name of the color uniform.
*/
int projection;
/**
* Name of the modelView uniform.
*/
int modelView;
int color;
/**
* Name of the transform uniform.
*/
@@ -146,7 +140,14 @@ class DrawTextureProgram: public DrawColorProgram {
public:
DrawTextureProgram();
/**
* Name of the texture sampler uniform.
*/
int sampler;
/**
* Name of the texture coordinates attribute.
*/
int texCoords;
};

View File

@@ -2,12 +2,10 @@ SHADER_SOURCE(gDrawColorVertexShader,
attribute vec4 position;
uniform mat4 projection;
uniform mat4 modelView;
uniform mat4 transform;
void main(void) {
gl_Position = projection * transform * modelView * position;
gl_Position = transform * position;
}
);

View File

@@ -3,15 +3,13 @@ SHADER_SOURCE(gDrawTextureVertexShader,
attribute vec4 position;
attribute vec2 texCoords;
uniform mat4 projection;
uniform mat4 modelView;
uniform mat4 transform;
varying vec2 outTexCoords;
void main(void) {
outTexCoords = texCoords;
gl_Position = projection * transform * modelView * position;
gl_Position = transform * position;
}
);