Skip to content

Instantly share code, notes, and snippets.

@kripken
Created March 20, 2013 18:33
Show Gist options
  • Save kripken/5207229 to your computer and use it in GitHub Desktop.
Save kripken/5207229 to your computer and use it in GitHub Desktop.
diff --git a/src/library_gl.js b/src/library_gl.js
index 297a36c..fdd138b 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1857,42 +1857,40 @@ var LibraryGL = {
for (var i = 0; i < this.NUM_ATTRIBUTES; i++) {
if (this.rendererComponents[i]) this.enabledClientAttributes[i] = false;
}
},
getRenderer: function() {
// return a renderer object given the liveClientAttributes
// we maintain a cache of renderers, optimized to not generate garbage
var attributes = GL.immediate.liveClientAttributes;
var cacheItem = GL.immediate.rendererCache;
var temp;
for (var i = 0; i < attributes.length; i++) {
var attribute = attributes[i];
temp = cacheItem[attribute.name];
cacheItem = temp ? temp : (cacheItem[attribute.name] = GL.immediate.rendererCacheItemTemplate.slice());
temp = cacheItem[attribute.size];
cacheItem = temp ? temp : (cacheItem[attribute.size] = GL.immediate.rendererCacheItemTemplate.slice());
var typeIndex = attribute.type - GL.byteSizeByTypeRoot; // ensure it starts at 0 to keep the cache items dense
temp = cacheItem[typeIndex];
cacheItem = temp ? temp : (cacheItem[typeIndex] = GL.immediate.rendererCacheItemTemplate.slice());
- temp = cacheItem[attribute.stride];
- cacheItem = temp ? temp : (cacheItem[attribute.stride] = GL.immediate.rendererCacheItemTemplate.slice());
}
var fogParam;
if (GLEmulation.fogEnabled) {
switch (GLEmulation.fogMode) {
case 0x0801: // GL_EXP2
fogParam = 1;
break;
case 0x2601: // GL_LINEAR
fogParam = 2;
break;
default: // default to GL_EXP
fogParam = 3;
break;
}
} else {
fogParam = 0;
}
temp = cacheItem[fogParam];
cacheItem = temp ? temp : (cacheItem[fogParam] = GL.immediate.rendererCacheItemTemplate.slice());
if (GL.currProgram) { // Note the order here; this one is last, and optional. Note that we cannot ensure it is dense, sadly
@@ -1902,41 +1900,40 @@ var LibraryGL = {
if (!cacheItem.renderer) {
#if GL_DEBUG
Module.printErr('generating renderer for ' + JSON.stringify(attributes));
#endif
cacheItem.renderer = this.createRenderer();
}
return cacheItem.renderer;
},
createRenderer: function(renderer) {
var useCurrProgram = !!GL.currProgram;
var hasTextures = false, textureSizes = [], textureTypes = [], textureOffsets = [];
for (var i = 0; i < GL.immediate.NUM_TEXTURES; i++) {
if (GL.immediate.enabledClientAttributes[GL.immediate.TEXTURE0 + i]) {
textureSizes[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].size;
textureTypes[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].type;
textureOffsets[i] = GL.immediate.clientAttributes[GL.immediate.TEXTURE0 + i].offset;
hasTextures = true;
}
}
- var stride = GL.immediate.stride;
var positionSize = GL.immediate.clientAttributes[GL.immediate.VERTEX].size;
var positionType = GL.immediate.clientAttributes[GL.immediate.VERTEX].type;
var positionOffset = GL.immediate.clientAttributes[GL.immediate.VERTEX].offset;
var colorSize = 0, colorType, colorOffset;
if (GL.immediate.enabledClientAttributes[GL.immediate.COLOR]) {
colorSize = GL.immediate.clientAttributes[GL.immediate.COLOR].size;
colorType = GL.immediate.clientAttributes[GL.immediate.COLOR].type;
colorOffset = GL.immediate.clientAttributes[GL.immediate.COLOR].offset;
}
var normalSize = 0, normalType, normalOffset;
if (GL.immediate.enabledClientAttributes[GL.immediate.NORMAL]) {
normalSize = GL.immediate.clientAttributes[GL.immediate.NORMAL].size;
normalType = GL.immediate.clientAttributes[GL.immediate.NORMAL].type;
normalOffset = GL.immediate.clientAttributes[GL.immediate.NORMAL].offset;
}
var ret = {
init: function() {
if (useCurrProgram) {
if (GL.shaderInfos[GL.programShaders[GL.currProgram][0]].type == Module.ctx.VERTEX_SHADER) {
this.vertexShader = GL.shaders[GL.programShaders[GL.currProgram][0]];
@@ -2089,68 +2086,68 @@ var LibraryGL = {
}
#endif
Module.ctx.bufferSubData(Module.ctx.ARRAY_BUFFER, start, GL.immediate.vertexData.subarray(start >> 2, end >> 2));
}
#if GL_UNSAFE_OPTS
if (canSkip) return;
GL.immediate.lastRenderer = this;
GL.immediate.lastArrayBuffer = arrayBuffer;
GL.immediate.lastProgram = GL.currProgram || this.program;
GL.immediate.matricesModified = false;
#endif
if (!GL.currProgram) {
Module.ctx.useProgram(this.program);
}
if (this.modelViewLocation) Module.ctx.uniformMatrix4fv(this.modelViewLocation, false, GL.immediate.matrix['m']);
if (this.projectionLocation) Module.ctx.uniformMatrix4fv(this.projectionLocation, false, GL.immediate.matrix['p']);
Module.ctx.vertexAttribPointer(this.positionLocation, positionSize, positionType, false,
- stride, positionOffset);
+ GL.immediate.stride, positionOffset);
Module.ctx.enableVertexAttribArray(this.positionLocation);
if (this.hasTextures) {
for (var i = 0; i < textureSizes.length; i++) {
if (textureSizes[i] && this.texCoordLocations[i] >= 0) {
Module.ctx.vertexAttribPointer(this.texCoordLocations[i], textureSizes[i], textureTypes[i], false,
- stride, textureOffsets[i]);
+ GL.immediate.stride, textureOffsets[i]);
Module.ctx.enableVertexAttribArray(this.texCoordLocations[i]);
}
}
for (var i = 0; i < GL.immediate.MAX_TEXTURES; i++) {
if (this.textureMatrixLocations[i]) { // XXX might we need this even without the condition we are currently in?
Module.ctx.uniformMatrix4fv(this.textureMatrixLocations[i], false, GL.immediate.matrix['t' + i]);
}
}
}
if (this.hasColorAttrib) {
Module.ctx.vertexAttribPointer(this.colorLocation, colorSize, colorType, true,
- stride, colorOffset);
+ GL.immediate.stride, colorOffset);
Module.ctx.enableVertexAttribArray(this.colorLocation);
Module.ctx.uniform1i(this.hasColorAttribLocation, 1);
} else if (this.hasColorUniform) {
Module.ctx.uniform1i(this.hasColorAttribLocation, 0);
Module.ctx.uniform4fv(this.colorUniformLocation, GL.immediate.clientColor);
}
if (this.hasNormal) {
Module.ctx.vertexAttribPointer(this.normalLocation, normalSize, normalType, true,
- stride, normalOffset);
+ GL.immediate.stride, normalOffset);
Module.ctx.enableVertexAttribArray(this.normalLocation);
}
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);
}
if (this.hasFog) {
if (this.fogColorLocation) Module.ctx.uniform4fv(this.fogColorLocation, GLEmulation.fogColor);
if (this.fogEndLocation) Module.ctx.uniform1f(this.fogEndLocation, GLEmulation.fogEnd);
if (this.fogScaleLocation) Module.ctx.uniform1f(this.fogScaleLocation, 1/(GLEmulation.fogEnd - GLEmulation.fogStart));
if (this.fogDensityLocation) Module.ctx.uniform1f(this.fogDensityLocation, GLEmulation.fogDensity);
}
},
cleanup: function() {
Module.ctx.disableVertexAttribArray(this.positionLocation);
if (this.hasTextures) {
for (var i = 0; i < textureSizes.length; i++) {
diff --git a/src/settings.js b/src/settings.js
index 97963ac..dc4131f 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -152,41 +152,41 @@ var LABEL_DEBUG = 0; // 1: Print out functions as we enter them
var LABEL_FUNCTION_FILTERS = []; // Filters for function label debug.
// The items for this array will be used
// as filters for function names. Only the
// labels of functions that is equaled to
// one of the filters are printed out
// When the array is empty, the filter is disabled.
var EXCEPTION_DEBUG = 0; // Print out exceptions in emscriptened code
var LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js). You can also unset
// Runtime.debug at runtime for logging to cease, and can set it when you
// want it back. A simple way to set it in C++ is
// emscripten_run_script("Runtime.debug = ...;");
var SOCKET_DEBUG = 0; // Log out socket/network data transfer.
var OPENAL_DEBUG = 0; // Print out debugging information from our OpenAL implementation.
var GL_DEBUG = 0; // Print out all calls into WebGL. As with LIBRARY_DEBUG, you can set a runtime
// option, in this case GL.debug.
var GL_TESTING = 0; // When enabled, sets preserveDrawingBuffer in the context, to allow tests to work (but adds overhead)
var GL_MAX_TEMP_BUFFER_SIZE = 2097152; // How large GL emulation temp buffers are
-var GL_UNSAFE_OPTS = 1; // Enables some potentially-unsafe optimizations in GL emulation code
+var GL_UNSAFE_OPTS = 0; // Enables some potentially-unsafe optimizations in GL emulation code
var FULL_ES2 = 0; // Forces support for all GLES2 features, not just the WebGL-friendly subset.
var FORCE_GL_EMULATION = 0; // Forces inclusion of full GL emulation code.
var DISABLE_EXCEPTION_CATCHING = 0; // Disables generating code to actually catch exceptions. If the code you
// are compiling does not actually rely on catching exceptions (but the
// compiler generates code for it, maybe because of stdlibc++ stuff),
// then this can make it much faster. If an exception actually happens,
// it will not be caught and the program will halt (so this will not
// introduce silent failures, which is good).
// DISABLE_EXCEPTION_CATCHING = 0 - generate code to actually catch exceptions
// DISABLE_EXCEPTION_CATCHING = 1 - disable exception catching at all
// DISABLE_EXCEPTION_CATCHING = 2 - disable exception catching, but enables
// catching in whitelist
// TODO: Make this also remove cxa_begin_catch etc., optimize relooper
// for it, etc. (perhaps do all of this as preprocessing on .ll?)
var EXCEPTION_CATCHING_WHITELIST = []; // Enables catching exception in listed functions if
// DISABLE_EXCEPTION_CATCHING = 2 set
var EXECUTION_TIMEOUT = -1; // Throw an exception after X seconds - useful to debug infinite loops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment