aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-11-25 15:53:00 +0200
committerJukka Jylänki <jujjyl@gmail.com>2013-11-26 23:26:15 +0200
commitfc5dd62fc359397245aca85b1cc847393ba5858f (patch)
treecb1f67631aaaa0bcb04cd6784315ee462a5d3eba /src
parente47ce4d71c52b9f9dba5a07d1cd639091706af42 (diff)
Cache the currently active FFP emulation renderer object. If renderer-related GL state does not change, the renderer can then be looked up very quickly, instead of having to recompute the key every time.
Diffstat (limited to 'src')
-rw-r--r--src/library_gl.js109
1 files changed, 76 insertions, 33 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index 3bd28da8..d12fba49 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -2149,7 +2149,10 @@ var LibraryGL = {
}
}
#endif
- GL.currProgram = program;
+ if (GL.currProgram != program) {
+ GL.currentRenderer = null; // This changes the FFP emulation shader program, need to recompute that.
+ GL.currProgram = program;
+ }
glUseProgram(program);
}
@@ -2757,7 +2760,10 @@ var LibraryGL = {
this.key1 = this.computeKey1();
this.key2 = this.computeKey2();
}
-
+ this.invalidateKey = function() {
+ this.key0 = -1; // The key of this texture unit must be recomputed when rendering the next time.
+ GL.immediate.currentRenderer = null; // The currently used renderer must be re-evaluated at next render.
+ }
this.traverseState = function(keyView) {
if (this.key0 == -1) {
this.recomputeKey();
@@ -3126,16 +3132,28 @@ var LibraryGL = {
var cur = getCurTexUnit();
switch (cap) {
case GL_TEXTURE_1D:
- cur.enabled_tex1D = true;
+ if (!cur.enabled_tex1D) {
+ GL.immediate.currentRenderer = null; // Renderer state changed, and must be recreated or looked up again.
+ cur.enabled_tex1D = true;
+ }
break;
case GL_TEXTURE_2D:
- cur.enabled_tex2D = true;
+ if (!cur.enabled_tex2D) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_tex2D = true;
+ }
break;
case GL_TEXTURE_3D:
- cur.enabled_tex3D = true;
+ if (!cur.enabled_tex3D) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_tex3D = true;
+ }
break;
case GL_TEXTURE_CUBE_MAP:
- cur.enabled_texCube = true;
+ if (!cur.enabled_texCube) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_texCube = true;
+ }
break;
}
},
@@ -3144,16 +3162,28 @@ var LibraryGL = {
var cur = getCurTexUnit();
switch (cap) {
case GL_TEXTURE_1D:
- cur.enabled_tex1D = false;
+ if (cur.enabled_tex1D) {
+ GL.immediate.currentRenderer = null; // Renderer state changed, and must be recreated or looked up again.
+ cur.enabled_tex1D = false;
+ }
break;
case GL_TEXTURE_2D:
- cur.enabled_tex2D = false;
+ if (cur.enabled_tex2D) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_tex2D = false;
+ }
break;
case GL_TEXTURE_3D:
- cur.enabled_tex3D = false;
+ if (cur.enabled_tex3D) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_tex3D = false;
+ }
break;
case GL_TEXTURE_CUBE_MAP:
- cur.enabled_texCube = false;
+ if (cur.enabled_texCube) {
+ GL.immediate.currentRenderer = null;
+ cur.enabled_texCube = false;
+ }
break;
}
},
@@ -3166,13 +3196,13 @@ var LibraryGL = {
switch (pname) {
case GL_RGB_SCALE:
if (env.colorScale != param) {
- env.key0 = -1; // Invalidate the cached key for this texture unit.
+ env.invalidateKey(); // We changed FFP emulation renderer state.
env.colorScale = param;
}
break;
case GL_ALPHA_SCALE:
if (env.alphaScale != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaScale = param;
}
break;
@@ -3190,109 +3220,109 @@ var LibraryGL = {
switch (pname) {
case GL_TEXTURE_ENV_MODE:
if (env.mode != param) {
- env.key0 = -1; // Invalidate the cached key for this texture unit.
+ env.invalidateKey(); // We changed FFP emulation renderer state.
env.mode = param;
}
break;
case GL_COMBINE_RGB:
if (env.colorCombiner != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorCombiner = param;
}
break;
case GL_COMBINE_ALPHA:
if (env.alphaCombiner != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaCombiner = param;
}
break;
case GL_SRC0_RGB:
if (env.colorSrc[0] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorSrc[0] = param;
}
break;
case GL_SRC1_RGB:
if (env.colorSrc[1] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorSrc[1] = param;
}
break;
case GL_SRC2_RGB:
if (env.colorSrc[2] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorSrc[2] = param;
}
break;
case GL_SRC0_ALPHA:
if (env.alphaSrc[0] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaSrc[0] = param;
}
break;
case GL_SRC1_ALPHA:
if (env.alphaSrc[1] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaSrc[1] = param;
}
break;
case GL_SRC2_ALPHA:
if (env.alphaSrc[2] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaSrc[2] = param;
}
break;
case GL_OPERAND0_RGB:
if (env.colorOp[0] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorOp[0] = param;
}
break;
case GL_OPERAND1_RGB:
if (env.colorOp[1] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorOp[1] = param;
}
break;
case GL_OPERAND2_RGB:
if (env.colorOp[2] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorOp[2] = param;
}
break;
case GL_OPERAND0_ALPHA:
if (env.alphaOp[0] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaOp[0] = param;
}
break;
case GL_OPERAND1_ALPHA:
if (env.alphaOp[1] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaOp[1] = param;
}
break;
case GL_OPERAND2_ALPHA:
if (env.alphaOp[2] != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaOp[2] = param;
}
break;
case GL_RGB_SCALE:
if (env.colorScale != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.colorScale = param;
}
break;
case GL_ALPHA_SCALE:
if (env.alphaScale != param) {
- env.key0 = -1;
+ env.invalidateKey();
env.alphaScale = param;
}
break;
@@ -3311,7 +3341,7 @@ var LibraryGL = {
for (var i = 0; i < 4; i++) {
var param = {{{ makeGetValue('params', 'i*4', 'float') }}};
if (env.envColor[i] != param) {
- env.key0 = -1; // Invalidate the cached key for this texture unit.
+ env.invalidateKey(); // We changed FFP emulation renderer state.
env.envColor[i] = param;
}
}
@@ -3360,6 +3390,7 @@ var LibraryGL = {
enabledClientAttributes: [0, 0],
clientAttributes: [], // raw data, including possible unneeded ones
liveClientAttributes: [], // the ones actually alive in the current computation, sorted
+ currentRenderer: null, // Caches the currently active FFP emulation renderer, so that it does not have to be re-looked up unless relevant state changes.
modifiedClientAttributes: false,
clientActiveTexture: 0,
clientColor: null,
@@ -3416,6 +3447,11 @@ var LibraryGL = {
},
getRenderer: function() {
+ // If no FFP state has changed that would have forced to re-evaluate which FFP emulation shader to use,
+ // we have the currently used renderer in cache, and can immediately return that.
+ if (this.currentRenderer) {
+ return this.currentRenderer;
+ }
// return a renderer object given the liveClientAttributes
// we maintain a cache of renderers, optimized to not generate garbage
var attributes = GL.immediate.liveClientAttributes;
@@ -3454,13 +3490,18 @@ var LibraryGL = {
}
// If we don't already have it, create it.
- if (!keyView.get()) {
+ var renderer = keyView.get();
+ if (!renderer) {
#if GL_DEBUG
Module.printErr('generating renderer for ' + JSON.stringify(attributes));
#endif
- keyView.set(this.createRenderer());
+ renderer = this.createRenderer();
+ this.currentRenderer = renderer;
+ keyView.set(renderer);
+ return renderer;
}
- return keyView.get();
+ this.currentRenderer = renderer; // Cache the currently used renderer, so later lookups without state changes can get this fast.
+ return renderer;
},
createRenderer: function(renderer) {
@@ -4412,10 +4453,12 @@ var LibraryGL = {
if (disable && GL.immediate.enabledClientAttributes[attrib]) {
GL.immediate.enabledClientAttributes[attrib] = false;
GL.immediate.totalEnabledClientAttributes--;
+ this.currentRenderer = null; // Will need to change current renderer, since the set of active vertex pointers changed.
if (GLEmulation.currentVao) delete GLEmulation.currentVao.enabledClientStates[cap];
} else if (!disable && !GL.immediate.enabledClientAttributes[attrib]) {
GL.immediate.enabledClientAttributes[attrib] = true;
GL.immediate.totalEnabledClientAttributes++;
+ this.currentRenderer = null; // Will need to change current renderer, since the set of active vertex pointers changed.
if (GLEmulation.currentVao) GLEmulation.currentVao.enabledClientStates[cap] = 1;
}
GL.immediate.modifiedClientAttributes = true;