aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_gl.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index d99d59ec..1bb94253 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -24,6 +24,31 @@ var LibraryGL = {
}
return 0;
},
+
+ // Find a token in a shader source string
+ findToken: function(source, token) {
+ function isIdentChar(ch) {
+ if (ch >= 48 && ch <= 57) // 0-9
+ return true;
+ if (ch >= 65 && ch <= 90) // A-Z
+ return true;
+ if (ch >= 97 && ch <= 122) // a-z
+ return true;
+ return false;
+ }
+ var i = source.indexOf(token);
+ if (i < 0) {
+ return false;
+ }
+ if (i > 0 && isIdentChar(source[i - 1])) {
+ return false;
+ }
+ i += token.length;
+ if (i < source.length - 1 && isIdentChar(source[i + 1])) {
+ return false;
+ }
+ return true;
+ },
},
glGetString: function(name_) {
@@ -529,6 +554,21 @@ var LibraryGL = {
}
source += frag;
}
+ // Let's see if we need to enable the standard derivatives extension
+ type = Module.ctx.getShaderParameter(GL.shaders[shader], 0x8B4F /* GL_SHADER_TYPE */);
+ if (type == 0x8B30 /* GL_FRAGMENT_SHADER */) {
+ if (GL.findToken(source, "dFdx") ||
+ GL.findToken(source, "dFdy") ||
+ GL.findToken(source, "fwidth")) {
+ source = "#extension GL_OES_standard_derivatives : enable\n" + source;
+ var extension = Module.ctx.getExtension("OES_standard_derivatives");
+#if GL_DEBUG
+ if (!extension) {
+ Module.printErr("Shader attempts to use the standard derivatives extension which is not available.");
+ }
+#endif
+ }
+ }
Module.ctx.shaderSource(GL.shaders[shader], source);
},