summaryrefslogtreecommitdiff
path: root/rsProgramVertex.cpp
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-08-27 16:10:55 -0700
committerAlex Sakhartchouk <alexst@google.com>2010-08-27 16:10:55 -0700
commitaf83e79895d05ba45c2f8e340f2222dc19e2fffa (patch)
tree27fb59084082a707cc4b18d46be5535ce0734e86 /rsProgramVertex.cpp
parent39cd317d983410055d780d00666f724c5faeaba9 (diff)
downloadrs-af83e79895d05ba45c2f8e340f2222dc19e2fffa.tar.gz
Fixing renderscript uniform binding bugs.
Working on custom shaders. Change-Id: I0d51e879e1c2b46ef5ab696b35162898f4196fc8
Diffstat (limited to 'rsProgramVertex.cpp')
-rw-r--r--rsProgramVertex.cpp90
1 files changed, 57 insertions, 33 deletions
diff --git a/rsProgramVertex.cpp b/rsProgramVertex.cpp
index aee41333..8468e260 100644
--- a/rsProgramVertex.cpp
+++ b/rsProgramVertex.cpp
@@ -146,13 +146,24 @@ void ProgramVertex::createShader()
// Cannot be complex
rsAssert(!f->getFieldCount());
- switch(f->getComponent().getVectorSize()) {
- case 1: mShader.append("uniform float UNI_"); break;
- case 2: mShader.append("uniform vec2 UNI_"); break;
- case 3: mShader.append("uniform vec3 UNI_"); break;
- case 4: mShader.append("uniform vec4 UNI_"); break;
- default:
- rsAssert(0);
+ if(f->getType() == RS_TYPE_MATRIX_4X4) {
+ mShader.append("uniform mat4 UNI_");
+ }
+ else if(f->getType() == RS_TYPE_MATRIX_3X3) {
+ mShader.append("uniform mat3 UNI_");
+ }
+ else if(f->getType() == RS_TYPE_MATRIX_2X2) {
+ mShader.append("uniform mat2 UNI_");
+ }
+ else {
+ switch(f->getComponent().getVectorSize()) {
+ case 1: mShader.append("uniform float UNI_"); break;
+ case 2: mShader.append("uniform vec2 UNI_"); break;
+ case 3: mShader.append("uniform vec3 UNI_"); break;
+ case 4: mShader.append("uniform vec4 UNI_"); break;
+ default:
+ rsAssert(0);
+ }
}
mShader.append(fn);
@@ -250,41 +261,53 @@ void ProgramVertex::setupGL2(const Context *rsc, ProgramVertexState *state, Shad
const Element *f = e->getField(field);
uint32_t offset = e->getFieldOffsetBytes(field);
int32_t slot = sc->vtxUniformSlot(uidx);
+ const char *fieldName = e->getFieldName(field);
const float *fd = reinterpret_cast<const float *>(&data[offset]);
- //LOGE("Uniform slot=%i, offset=%i, constant=%i, field=%i, uidx=%i", slot, offset, ct, field, uidx);
+ // If this field is padding, skip it
+ if(fieldName[0] == '#') {
+ continue;
+ }
+
+ //LOGE("Uniform slot=%i, offset=%i, constant=%i, field=%i, uidx=%i, name=%s", slot, offset, ct, field, uidx, fieldName);
if (slot >= 0) {
- switch(f->getComponent().getVectorSize()) {
- case 1:
- //LOGE("Uniform 1 = %f", fd[0]);
- glUniform1fv(slot, 1, fd);
- break;
- case 2:
- //LOGE("Uniform 2 = %f %f", fd[0], fd[1]);
- glUniform2fv(slot, 1, fd);
- break;
- case 3:
- //LOGE("Uniform 3 = %f %f %f", fd[0], fd[1], fd[2]);
- glUniform3fv(slot, 1, fd);
- break;
- case 4:
- //LOGE("Uniform 4 = %f %f %f %f", fd[0], fd[1], fd[2], fd[3]);
- glUniform4fv(slot, 1, fd);
- break;
- default:
- rsAssert(0);
+ if(f->getType() == RS_TYPE_MATRIX_4X4) {
+ glUniformMatrix4fv(slot, 1, GL_FALSE, fd);
+ }
+ else if(f->getType() == RS_TYPE_MATRIX_3X3) {
+ glUniformMatrix3fv(slot, 1, GL_FALSE, fd);
+ }
+ else if(f->getType() == RS_TYPE_MATRIX_2X2) {
+ glUniformMatrix2fv(slot, 1, GL_FALSE, fd);
+ }
+ else {
+ switch(f->getComponent().getVectorSize()) {
+ case 1:
+ //LOGE("Uniform 1 = %f", fd[0]);
+ glUniform1fv(slot, 1, fd);
+ break;
+ case 2:
+ //LOGE("Uniform 2 = %f %f", fd[0], fd[1]);
+ glUniform2fv(slot, 1, fd);
+ break;
+ case 3:
+ //LOGE("Uniform 3 = %f %f %f", fd[0], fd[1], fd[2]);
+ glUniform3fv(slot, 1, fd);
+ break;
+ case 4:
+ //LOGE("Uniform 4 = %f %f %f %f", fd[0], fd[1], fd[2], fd[3]);
+ glUniform4fv(slot, 1, fd);
+ break;
+ default:
+ rsAssert(0);
+ }
}
}
uidx ++;
}
}
- for (uint32_t ct=0; ct < mConstantCount; ct++) {
- uint32_t glSlot = sc->vtxUniformSlot(ct + 1);
-
- }
-
state->mLast.set(this);
rsc->checkError("ProgramVertex::setupGL2");
}
@@ -340,7 +363,8 @@ void ProgramVertex::initAddUserElement(const Element *e, String8 *names, uint32_
const Element *ce = e->getField(ct);
if (ce->getFieldCount()) {
initAddUserElement(ce, names, count, prefix);
- } else {
+ }
+ else if(e->getFieldName(ct)[0] != '#') {
String8 tmp(prefix);
tmp.append(e->getFieldName(ct));
names[*count].setTo(tmp.string());