summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-16 17:37:04 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-16 17:37:04 -0700
commit6368908ccf220c7ba55dbdab99eab683356515a6 (patch)
tree30cf614cded6696700935a9585f4c9c65e8c9535
parent860a97627d61a4783e60b9d90c9fdf5c043414e8 (diff)
yet more glsl workarounds
-rw-r--r--src/library_gl.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index b3919412..826eb904 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -897,6 +897,7 @@ var LibraryGL = {
// Note that we need to remember shader types for this rewriting, saving sources makes it easier to debug.
GL.shaderTypes = {};
GL.shaderSources = {};
+ GL.shaderOriginalSources = {};
var glCreateShader = _glCreateShader;
_glCreateShader = function(shaderType) {
var id = glCreateShader(shaderType);
@@ -906,13 +907,16 @@ var LibraryGL = {
var glShaderSource = _glShaderSource;
_glShaderSource = function(shader, count, string, length) {
var source = GL.getSource(shader, count, string, length);
+ GL.shaderOriginalSources[shader] = source;
if (GL.shaderTypes[shader] == Module.ctx.VERTEX_SHADER) {
if (source.indexOf('ftransform()') >= 0) {
// Replace ftransform() with explicit project/modelview transforms, and add position and matrix info.
source = 'attribute vec3 a_position; \n\
uniform mat4 u_modelView; \n\
uniform mat4 u_projection; \n' +
- source.replace(/ftransform\(\)/g, 'u_projection * u_modelView * vec4(a_position, 1.0)');
+ source.replace(/ftransform\(\)/g, 'u_projection * u_modelView * vec4(a_position, 1.0)')
+ .replace(/gl_Vertex/g, 'a_position')
+ .replace(/gl_ModelViewMatrixTranspose\[2\]/g, 'vec3(u_modelView[0][0], u_modelView[1][0], u_modelView[2][0])'); // XXX extremely inefficient
}
if (source.indexOf('gl_TexCoord[0]') >= 0) {
// XXX To handle both regular texture mapping and cube mapping, we use vec3 for tex coordinates.
@@ -925,6 +929,10 @@ var LibraryGL = {
varying vec4 v_color; \n' +
source.replace(/gl_Color/g, 'a_color').replace(/gl_FrontColor/g, 'v_color');
}
+ if (source.indexOf('gl_FogFragCoord') >= 0) {
+ source = 'varying float v_fogCoord; \n' +
+ source.replace(/gl_FogFragCoord/g, 'v_fogCoord');
+ }
} else { // Fragment shader
if (source.indexOf('gl_TexCoord[0]') >= 0) {
source = 'varying vec3 v_texCoord; \n' + source.replace(/gl_TexCoord\[0\]/g, 'v_texCoord');
@@ -943,6 +951,7 @@ var LibraryGL = {
if (!Module.ctx.getShaderParameter(GL.shaders[shader], Module.ctx.COMPILE_STATUS)) {
console.log('Failed to compile shader: ' + Module.ctx.getShaderInfoLog(GL.shaders[shader]));
console.log('Type: ' + GL.shaderTypes[shader]);
+ console.log('Original source: ' + GL.shaderOriginalSources[shader]);
console.log('Source: ' + GL.shaderSources[shader]);
throw 'Shader compilation halt';
}