diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-16 16:47:14 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-16 16:47:14 -0700 |
commit | 860a97627d61a4783e60b9d90c9fdf5c043414e8 (patch) | |
tree | 1bf6861e53a66294e0244765a7e6dba17cebdccd | |
parent | 8d338b4ac241974a3fedb3b8977e8cbe569dd1e2 (diff) |
more glsl workarounds
-rw-r--r-- | src/library_gl.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 5f720842..b3919412 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -912,8 +912,27 @@ var LibraryGL = { source = 'attribute vec3 a_position; \n\ uniform mat4 u_modelView; \n\ uniform mat4 u_projection; \n' + - source.replace('ftransform()', 'u_projection * u_modelView * vec4(a.position, 1.0)'); + source.replace(/ftransform\(\)/g, 'u_projection * u_modelView * vec4(a_position, 1.0)'); } + if (source.indexOf('gl_TexCoord[0]') >= 0) { + // XXX To handle both regular texture mapping and cube mapping, we use vec3 for tex coordinates. + source = 'attribute vec3 a_texCoord; \n\ + varying vec3 v_texCoord; \n' + + source.replace(/gl_TexCoord\[0\]/g, 'v_texCoord').replace(/gl_MultiTexCoord0/g, 'a_texCoord'); + } + if (source.indexOf('gl_Color') >= 0) { + source = 'attribute vec4 a_color; \n\ + varying vec4 v_color; \n' + + source.replace(/gl_Color/g, 'a_color').replace(/gl_FrontColor/g, 'v_color'); + } + } else { // Fragment shader + if (source.indexOf('gl_TexCoord[0]') >= 0) { + source = 'varying vec3 v_texCoord; \n' + source.replace(/gl_TexCoord\[0\]/g, 'v_texCoord'); + } + if (source.indexOf('gl_Color') >= 0) { + source = 'varying vec4 v_color; \n' + source.replace(/gl_Color/g, 'v_color'); + } + source = 'precision mediump float;\n' + source; } GL.shaderSources[shader] = source; Module.ctx.shaderSource(GL.shaders[shader], source); |