aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-25 11:08:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-25 11:09:15 -0700
commit6f0decb1c5c65f7873c9afadbf04ab8fed7b83a0 (patch)
treede5122d9f95f6d08976c5ac12d0db580389d5a0b
parent7e516c8b034c1a49524eaa140a5da9b9d94e9991 (diff)
fix a_texCoord* usage, and use current program texture setup if present ; some texture rendering in cubegeom test
-rw-r--r--src/library_gl.js17
-rw-r--r--tests/cubegeom.c2
2 files changed, 10 insertions, 9 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index d2b7cd7c..1b9edd3c 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1266,14 +1266,14 @@ var LibraryGL = {
this.vertexShader = Module.ctx.createShader(Module.ctx.VERTEX_SHADER);
var zero = positionSize == 2 ? '0, ' : '';
Module.ctx.shaderSource(this.vertexShader, 'attribute vec' + positionSize + ' a_position; \n' +
- 'attribute vec2 a_texCoord; \n' +
+ 'attribute vec2 a_texCoord0; \n' +
(textureSize ? 'varying vec2 v_texCoord; \n' : '') +
'uniform mat4 u_modelView; \n' +
'uniform mat4 u_projection; \n' +
'void main() \n' +
'{ \n' +
' gl_Position = u_projection * (u_modelView * vec4(a_position, ' + zero + '1.0)); \n' +
- (textureSize ? 'v_texCoord = a_texCoord; \n' : '') +
+ (textureSize ? 'v_texCoord = a_texCoord0; \n' : '') +
'} \n');
Module.ctx.compileShader(this.vertexShader);
@@ -1295,7 +1295,7 @@ var LibraryGL = {
}
this.positionLocation = Module.ctx.getAttribLocation(this.program, 'a_position');
- this.texCoordLocation = Module.ctx.getAttribLocation(this.program, 'a_texCoord');
+ this.texCoordLocation = Module.ctx.getAttribLocation(this.program, 'a_texCoord0');
this.textureLocation = Module.ctx.getUniformLocation(this.program, 'u_texture');
this.modelViewLocation = Module.ctx.getUniformLocation(this.program, 'u_modelView');
this.projectionLocation = Module.ctx.getUniformLocation(this.program, 'u_projection');
@@ -1314,11 +1314,12 @@ var LibraryGL = {
}
Module.ctx.enableVertexAttribArray(this.positionLocation);
- // TODO: use client texture info
- var texture = Module.ctx.getParameter(Module.ctx.TEXTURE_BINDING_2D);
- Module.ctx.activeTexture(Module.ctx.TEXTURE0);
- Module.ctx.bindTexture(Module.ctx.TEXTURE_2D, texture);
- Module.ctx.uniform1i(this.textureLocation, 0);
+ if (!useCurrProgram) { // otherwise, the user program will set the sampler2D binding and uniform itself
+ var texture = Module.ctx.getParameter(Module.ctx.TEXTURE_BINDING_2D);
+ Module.ctx.activeTexture(Module.ctx.TEXTURE0);
+ Module.ctx.bindTexture(Module.ctx.TEXTURE_2D, texture);
+ Module.ctx.uniform1i(this.textureLocation, 0);
+ }
Module.ctx.uniformMatrix4fv(this.modelViewLocation, false, GL.immediate.matrix['m']);
Module.ctx.uniformMatrix4fv(this.projectionLocation, false, GL.immediate.matrix['p']);
diff --git a/tests/cubegeom.c b/tests/cubegeom.c
index d5d09435..529e1355 100644
--- a/tests/cubegeom.c
+++ b/tests/cubegeom.c
@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
// sauer vertex data is apparently 0-12: V3F, 12: N1B, 16-24: T2F, 24-28: T2S, 28-32: C4B
glVertexPointer(3, GL_FLOAT, 32, (void*)0); // all these apply to the ARRAY_BUFFER that is bound
glTexCoordPointer(2, GL_FLOAT, 32, (void*)16);
- glClientActiveTexture(GL_TEXTURE1);
+ glClientActiveTexture(GL_TEXTURE1); // XXX seems to be ignored in native build
glTexCoordPointer(2, GL_SHORT, 32, (void*)24);
glClientActiveTexture(GL_TEXTURE0); // likely not needed, it is a cleanup
glNormalPointer(GL_BYTE, 32, (void*)12);