aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js29
-rw-r--r--src/library.js20
-rw-r--r--src/library_egl.js20
-rw-r--r--src/library_gl.js590
-rw-r--r--src/library_glut.js310
-rw-r--r--src/library_sdl.js17
-rw-r--r--src/library_xlib.js24
-rw-r--r--src/long.js1633
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js58
-rw-r--r--src/settings.js3
-rw-r--r--src/shell.html1
12 files changed, 2253 insertions, 454 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 99176fd2..8e688d8d 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -166,23 +166,27 @@ function JSify(data, functionsOnly, givenFunctions) {
ret[index++] = 0;
}
// Add current value(s)
- var currValue = flatten(values[i]);
+ var currValue = values[i];
if (USE_TYPED_ARRAYS == 2 && typeData.fields[i] == 'i64') {
// 'flatten' out the 64-bit value into two 32-bit halves
- ret[index++] = currValue>>>0;
+ var parts = parseI64Constant(currValue, true);
+ ret[index++] = parts[0];
ret[index++] = 0;
ret[index++] = 0;
ret[index++] = 0;
- ret[index++] = Math.floor(currValue/4294967296);
+ ret[index++] = parts[1];
ret[index++] = 0;
ret[index++] = 0;
ret[index++] = 0;
- } else if (typeof currValue == 'object') {
- for (var j = 0; j < currValue.length; j++) {
- ret[index++] = currValue[j];
- }
} else {
- ret[index++] = currValue;
+ currValue = flatten(currValue);
+ if (typeof currValue == 'object') {
+ for (var j = 0; j < currValue.length; j++) {
+ ret[index++] = currValue[j];
+ }
+ } else {
+ ret[index++] = currValue;
+ }
}
i += 1;
}
@@ -400,7 +404,8 @@ function JSify(data, functionsOnly, givenFunctions) {
// name the function; overwrite if it's already named
snippet = snippet.replace(/function(?:\s+([^(]+))?\s*\(/, 'function _' + ident + '(');
if (LIBRARY_DEBUG) {
- snippet = snippet.replace('{', '{ Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments) + "]"); ');
+ snippet = snippet.replace('{', '{ var ret = (function() {Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments) + "]"); ');
+ snippet = snippet.substr(0, snippet.length-1) + '}).apply(this, arguments); Module.printErr(" [ return:" + ret); return ret; }';
}
}
@@ -1195,6 +1200,12 @@ function JSify(data, functionsOnly, givenFunctions) {
// This is the main pass. Print out the generated code that we have here, together with the
// rest of the output that we started to print out earlier (see comment on the
// "Final shape that will be created").
+ if (PRECISE_I64_MATH && preciseI64MathUsed) {
+ print(read('long.js'));
+ } else {
+ print('// Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included');
+ print('var i64Math = null;');
+ }
var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet);
generated.forEach(function(item) { print(indentify(item.JS || '', 2)); });
if (RUNTIME_TYPE_INFO) {
diff --git a/src/library.js b/src/library.js
index 78dd629b..6c96bcca 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2487,6 +2487,10 @@ LibraryManager.library = {
var signed = next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0);
argSize = argSize || 4;
var currArg = getNextArg('i' + (argSize * 8));
+#if PRECISE_I64_MATH == 1
+ var origArg = currArg;
+#endif
+ var argText;
#if USE_TYPED_ARRAYS == 2
// Flatten i64-1 [low, high] into a (slightly rounded) double
if (argSize == 8) {
@@ -2500,11 +2504,16 @@ LibraryManager.library = {
}
// Format the number.
var currAbsArg = Math.abs(currArg);
- var argText;
var prefix = '';
if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) {
+#if PRECISE_I64_MATH == 1
+ if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1]); else
+#endif
argText = reSign(currArg, 8 * argSize, 1).toString(10);
} else if (next == 'u'.charCodeAt(0)) {
+#if PRECISE_I64_MATH == 1
+ if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], true); else
+#endif
argText = unSign(currArg, 8 * argSize, 1).toString(10);
currArg = Math.abs(currArg);
} else if (next == 'o'.charCodeAt(0)) {
@@ -6078,3 +6087,12 @@ LibraryManager.library = {
}
};
+function autoAddDeps(object, name) {
+ name = [name];
+ for (var item in object) {
+ if (item.substr(-6) != '__deps' && !object[item + '__deps']) {
+ object[item + '__deps'] = name;
+ }
+ }
+}
+
diff --git a/src/library_egl.js b/src/library_egl.js
new file mode 100644
index 00000000..6ad226f0
--- /dev/null
+++ b/src/library_egl.js
@@ -0,0 +1,20 @@
+
+var LibraryEGL = {
+ eglGetDisplay: function(x_display) { return 3 },
+ eglInitialize: function(display, majorVersion, minorVersion) { return 1 },
+ eglGetConfigs: function(display, hmm1, hmm2, numConfigs) { return 1 },
+ eglChooseConfig: function(display, attribList, config, hmm, numConfigs) { return 1 },
+ eglCreateWindowSurface: function(display, config, hWnd, hmm) { return 4 },
+
+ eglCreateContext__deps: ['glutCreateWindow', '$GL'],
+ eglCreateContext: function(display, config, hmm, contextAttribs) {
+ _glutCreateWindow();
+ return 1;
+ },
+
+ eglMakeCurrent: function(display, surface, surface, context) { return 1 },
+ eglSwapBuffers: function() {},
+};
+
+mergeInto(LibraryManager.library, LibraryEGL);
+
diff --git a/src/library_gl.js b/src/library_gl.js
index 4651e0d0..8a24a345 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1,54 +1,21 @@
//"use strict";
-// FIXME:
-// * glGetUniformLocation should return -1 when the value is not valid, not null
-// * glUniform1fi should be glUniform1iv
-// * glGetAttribLocation lacks return value (and should be -1 when not valid)
-// * single-underscore deps need double underscore (and, just auto-add them all)
-// * glGetProgramInfoLog and *shader* should be essentially identical
-// * glGetIntegerv set to bool etc needs fixing
-
var LibraryGL = {
$GL: {
- hashtable: function(name) {
- if (!this._hashtables) {
- this._hashtables = {};
- }
- if (!(name in this._hashtables)) {
- this._hashtables[name] = {
- table: {},
- counter: 1,
- add: function(obj) {
- var id = this.counter++;
- this.table[id] = obj;
- return id;
- },
- get: function(id) {
- if( id == 0 ) return null;
-#if ASSERTIONS
- assert(id < this.counter, "Invalid id " + id + " for the hashtable " + name);
-#endif
- return this.table[id];
- },
- id: function(obj) {
- for (var i = 1; i < this.counter; ++i) {
- if (obj == this.table[i]) {
- return i;
- }
- }
- return null;
- },
- remove: function(id) {
- if( id == 0 ) return;
-#if ASSERTIONS
- assert(id < this.counter, "Invalid id " + id + " for the hashtable " + name);
-#endif
- delete this.table[id];
- }
- };
- }
- return this._hashtables[name];
- },
+ buffers: {},
+ bufferCounter: 1,
+ programs: {},
+ programCounter: 1,
+ framebuffers: {},
+ framebufferCounter: 1,
+ renderbuffer: {},
+ renderbufferCounter: 1,
+ textures: {},
+ textureCounter: 1,
+ uniforms: {},
+ uniformCounter: 1,
+ shaders: {},
+ shaderCounter: 1
},
glGetString: function(name_) {
@@ -71,7 +38,7 @@ var LibraryGL = {
{{{ makeSetValue('p', '0', 'result', 'i32') }}};
break;
case "boolean":
- {{{ makeSetValue('p', '0', 'result ? 1 : 0', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'result ? 1 : 0', 'i8') }}};
break;
case "string":
throw 'Native code calling glGetIntegerv(' + name_ + ') on a name which returns a string!';
@@ -83,18 +50,18 @@ var LibraryGL = {
result instanceof Int32Array ||
result instanceof Array) {
for (var i = 0; i < result.length; ++i) {
- {{{ makeSetValue('p', 'i', 'result[i]', 'i32') }}};
+ {{{ makeSetValue('p', 'i*4', 'result[i]', 'i32') }}};
}
} else if (result instanceof WebGLBuffer) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("buffer").id(result)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'GL.buffers[result]', 'i32') }}};
} else if (result instanceof WebGLProgram) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("program").id(result)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'GL.programs[result]', 'i32') }}};
} else if (result instanceof WebGLFramebuffer) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("framebuffer").id(result)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'GL.framebuffers[result]', 'i32') }}};
} else if (result instanceof WebGLRenderbuffer) {
- {{{ makeSetValue('p', '0', 'gl.hashtable("renderbuffer").id(result)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'GL.renderbuffers[result]', 'i32') }}};
} else if (result instanceof WebGLTexture) {
- {{{ makeSetValue('p', '0', 'gl.hashtable("texture").id(result)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'GL.textures[result]', 'i32') }}};
} else {
throw 'Unknown object returned from WebGL getParameter';
}
@@ -125,18 +92,18 @@ var LibraryGL = {
result instanceof Int32Array ||
result instanceof Array) {
for (var i = 0; i < result.length; ++i) {
- {{{ makeSetValue('p', 'i', 'result[i]', 'float') }}};
+ {{{ makeSetValue('p', 'i*4', 'result[i]', 'float') }}};
}
} else if (result instanceof WebGLBuffer) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("buffer").id(result)', 'float') }}};
+ {{{ makeSetValue('p', '0', 'GL.buffers[result]', 'float') }}};
} else if (result instanceof WebGLProgram) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("program").id(result)', 'float') }}};
+ {{{ makeSetValue('p', '0', 'GL.programs[result]', 'float') }}};
} else if (result instanceof WebGLFramebuffer) {
- {{{ makeSetValue('p', '0', 'GL.hashtable("framebuffer").id(result)', 'float') }}};
+ {{{ makeSetValue('p', '0', 'GL.framebuffers[result]', 'float') }}};
} else if (result instanceof WebGLRenderbuffer) {
- {{{ makeSetValue('p', '0', 'gl.hashtable("renderbuffer").id(result)', 'float') }}};
+ {{{ makeSetValue('p', '0', 'gl.renderbuffers[result]', 'float') }}};
} else if (result instanceof WebGLTexture) {
- {{{ makeSetValue('p', '0', 'gl.hashtable("texture").id(result)', 'float') }}};
+ {{{ makeSetValue('p', '0', 'gl.textures[result]', 'float') }}};
} else {
throw 'Unknown object returned from WebGL getParameter';
}
@@ -186,19 +153,19 @@ var LibraryGL = {
}
},
- glGenTextures__deps: ['$GL'],
glGenTextures: function(n, textures) {
for (var i = 0; i < n; i++) {
- var id = GL.hashtable("texture").add(Module.ctx.createTexture());
- {{{ makeSetValue('textures', 'i', 'id', 'i32') }}};
+ var id = GL.textureCounter++;
+ GL.textures[id] = Module.ctx.createTexture();
+ {{{ makeSetValue('textures', 'i*4', 'id', 'i32') }}};
}
},
glDeleteTextures: function(n, textures) {
for (var i = 0; i < n; i++) {
- var id = {{{ makeGetValue('textures', 'i', 'i32') }}};
- Module.ctx.deleteTexture(GL.hashtable("texture").get(id));
- GL.hashtable("texture").remove(id);
+ var id = {{{ makeGetValue('textures', 'i*4', 'i32') }}};
+ Module.ctx.deleteTexture(GL.textures[id]);
+ GL.textures[id] = null;
}
},
@@ -299,7 +266,7 @@ var LibraryGL = {
},
glBindTexture: function(target, texture) {
- Module.ctx.bindTexture(target, GL.hashtable("texture").get(texture));
+ Module.ctx.bindTexture(target, GL.textures[texture]);
},
glGetTexParameterfv: function(target, pname, params) {
@@ -310,34 +277,32 @@ var LibraryGL = {
{{{ makeSetValue('params', '0', 'Module.getTexParameter(target, pname)', 'i32') }}};
},
- glIsTexture_deps: ['$GL'],
glIsTexture: function(texture) {
- var fb = GL.hashtable("texture").get(texture);
+ var fb = GL.textures[texture];
if (typeof(fb) == 'undefined') {
return false;
}
return Module.ctx.isTexture(fb);
},
- glGenBuffers__deps: ['$GL'],
glGenBuffers: function(n, buffers) {
for (var i = 0; i < n; i++) {
- var id = GL.hashtable("buffer").add(Module.ctx.createBuffer());
- {{{ makeSetValue('buffers', 'i', 'id', 'i32') }}};
+ var id = GL.bufferCounter++;
+ GL.buffers[id] = Module.ctx.createBuffer();
+ {{{ makeSetValue('buffers', 'i*4', 'id', 'i32') }}};
}
},
glDeleteBuffers: function(n, buffers) {
for (var i = 0; i < n; i++) {
- var id = {{{ makeGetValue('buffers', 'i', 'i32') }}};
- Module.ctx.deleteBuffer(GL.hashtable("buffer").get(id));
- GL.hashtable("buffer").remove(id);
+ var id = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
+ Module.ctx.deleteBuffer(GL.buffers[id]);
+ GL.buffers[id] = null;
}
},
glBufferData: function(target, size, data, usage) {
- var floatArray = new Float32Array(TypedArray_copy(data, size));
- Module.ctx.bufferData(target, floatArray, usage);
+ Module.ctx.bufferData(target, HEAPU8.subarray(data, data+size), usage);
},
glBufferSubData: function(target, offset, size, data) {
@@ -345,172 +310,145 @@ var LibraryGL = {
Module.ctx.bufferSubData(target, offset, floatArray);
},
- glIsBuffer_deps: ['$GL'],
glIsBuffer: function(buffer) {
- var fb = GL.hashtable("buffer").get(buffer);
+ var fb = GL.buffers[buffer];
if (typeof(fb) == 'undefined') {
return false;
}
return Module.ctx.isBuffer(fb);
},
- glGenRenderbuffers__deps: ['$GL'],
glGenRenderbuffers: function(n, renderbuffers) {
for (var i = 0; i < n; i++) {
- var id = GL.hashtable("renderbuffer").add(Module.ctx.createRenderbuffer());
- {{{ makeSetValue('renderbuffers', 'i', 'id', 'i32') }}};
+ var id = GL.renderbufferCounter++;
+ GL.renderbuffers[id] = Module.ctx.createRenderbuffer();
+ {{{ makeSetValue('renderbuffers', 'i*4', 'id', 'i32') }}};
}
},
glDeleteRenderbuffers: function(n, renderbuffers) {
for (var i = 0; i < n; i++) {
- var id = {{{ makeGetValue('renderbuffers', 'i', 'i32') }}};
- Module.ctx.deleteRenderbuffer(GL.hashtable("renderbuffer").get(id));
- GL.hashtable("renderbuffer").remove(id);
+ var id = {{{ makeGetValue('renderbuffers', 'i*4', 'i32') }}};
+ Module.ctx.deleteRenderbuffer(GL.renderbuffers[id]);
+ GL.renderbuffers[id];
}
},
glBindRenderbuffer: function(target, renderbuffer) {
- Module.ctx.bindRenderbuffer(target, GL.hashtable("renderbuffer").get(renderbuffer));
+ Module.ctx.bindRenderbuffer(target, GL.renderbuffers[renderbuffer]);
},
glGetRenderbufferParameteriv: function(target, pname, params) {
{{{ makeSetValue('params', '0', 'Module.ctx.getRenderbufferParameter(target, pname)', 'i32') }}};
},
- glIsRenderbuffer_deps: ['$GL'],
glIsRenderbuffer: function(renderbuffer) {
- var fb = GL.hashtable("renderbuffer").get(renderbuffer);
+ var fb = GL.renderbuffers[renderbuffer];
if (typeof(fb) == 'undefined') {
return false;
}
return Module.ctx.isRenderbuffer(fb);
},
- glBindAttribLocation_deps: ['$GL'],
glGetUniformLocation: function(program, name) {
name = Pointer_stringify(name);
- return GL.hashtable("uniform").add(
- Module.ctx.getUniformLocation(GL.hashtable("program").get(program), name));
+ var loc = Module.ctx.getUniformLocation(GL.programs[program], name);
+ if (!loc) return -1;
+ var id = GL.uniformCounter++;
+ GL.uniforms[id] = loc;
+ return id;
},
- glUniform1f: function(Location, v0) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform1f(Location, v0);
+ glUniform1f: function(location, v0) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform1f(location, v0);
},
- glUniform2f: function(Location, v0, v1) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform2f(Location, v0, v1);
+ glUniform2f: function(location, v0, v1) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform2f(location, v0, v1);
},
- glUniform3f: function(Location, v0, v1, v2) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform3f(Location, v0, v1, v2);
+ glUniform3f: function(location, v0, v1, v2) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform3f(location, v0, v1, v2);
},
- glUniform4f: function(Location, v0, v1, v2, v3) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform4f(Location, v0, v1, v2, v3);
+ glUniform4f: function(location, v0, v1, v2, v3) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform4f(location, v0, v1, v2, v3);
},
- glUniform1i: function(Location, v0) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform1i(Location, v0);
+ glUniform1i: function(location, v0) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform1i(location, v0);
},
- glUniform2i: function(Location, v0, v1) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform2i(Location, v0, v1);
+ glUniform2i: function(location, v0, v1) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform2i(location, v0, v1);
},
- glUniform3i: function(Location, v0, v1, v2) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform3i(Location, v0, v1, v2);
+ glUniform3i: function(location, v0, v1, v2) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform3i(location, v0, v1, v2);
},
- glUniform4i: function(Location, v0, v1, v2, v3) {
- Location = GL.hashtable("uniform").get(Location);
- Module.ctx.uniform4i(Location, v0, v1, v2, v3);
+ glUniform4i: function(location, v0, v1, v2, v3) {
+ location = GL.uniforms[location];
+ Module.ctx.uniform4i(location, v0, v1, v2, v3);
},
- glUniform1fv: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniform1fv: function(location, count, value) {
+ location = GL.uniforms[location];
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform1fv(Location, value);
+ Module.ctx.uniform1fv(location, value);
},
- glUniform2fv: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniform2fv: function(location, count, value) {
+ location = GL.uniforms[location];
count *= 2;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform2fv(Location, value);
+ Module.ctx.uniform2fv(location, value);
},
- glUniform3fv: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniform3fv: function(location, count, value) {
+ location = GL.uniforms[location];
count *= 3;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform3fv(Location, value);
+ Module.ctx.uniform3fv(location, value);
},
- glUniform4fv: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniform4fv: function(location, count, value) {
+ location = GL.uniforms[location];
count *= 4;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform4fv(Location, value);
- },
-
- glUniform1fi: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
- value = new Uint32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform1fi(Location, value);
- },
-
- glUniform2fi: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
- count *= 2;
- value = new Uint32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform2fi(Location, value);
- },
-
- glUniform3fi: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
- count *= 3;
- value = new Uint32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform3fi(Location, value);
+ Module.ctx.uniform4fv(location, value);
},
- glUniform4fi: function(Location, count, value) {
- Location = GL.hashtable("uniform").get(Location);
- count *= 4;
- value = new Uint32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniform4fi(Location, value);
- },
-
- glUniformMatrix2fv: function(Location, count, transpose, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniformMatrix2fv: function(location, count, transpose, value) {
+ location = GL.uniforms[location];
count *= 4;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniformMatrix2fv(Location, transpose, value);
+ Module.ctx.uniformMatrix2fv(location, transpose, value);
},
- glUniformMatrix3fv: function(Location, count, transpose, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniformMatrix3fv: function(location, count, transpose, value) {
+ location = GL.uniforms[location];
count *= 9;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniformMatrix3fv(Location, transpose, value);
+ Module.ctx.uniformMatrix3fv(location, transpose, value);
},
- glUniformMatrix4fv: function(Location, count, transpose, value) {
- Location = GL.hashtable("uniform").get(Location);
+ glUniformMatrix4fv: function(location, count, transpose, value) {
+ location = GL.uniforms[location];
count *= 16;
value = new Float32Array(TypedArray_copy(value, count*4)); // TODO: optimize
- Module.ctx.uniformMatrix4fv(Location, transpose, value);
+ Module.ctx.uniformMatrix4fv(location, transpose, value);
},
glBindBuffer: function(target, buffer) {
- Module.ctx.bindBuffer(target, GL.hashtable("buffer").get(buffer));
+ Module.ctx.bindBuffer(target, GL.buffers[buffer]);
},
glVertexAttrib1fv: function(index, v) {
@@ -534,63 +472,60 @@ var LibraryGL = {
},
glGetAttribLocation: function(program, name) {
- program = GL.hashtable("program").get(program);
+ program = GL.programs[program];
name = Pointer_stringify(name);
- Module.ctx.getAttribLocation(program, name);
+ return Module.ctx.getAttribLocation(program, name);
},
- glCreateShader_deps: ['$GL'],
glCreateShader: function(shaderType) {
- var shader = Module.ctx.createShader(shaderType);
- return GL.hashtable("shader").add(shader);
+ var id = GL.shaderCounter++;
+ GL.shaders[id] = Module.ctx.createShader(shaderType);
+ return id;
},
glDeleteShader: function(shader) {
- Module.ctx.deleteShader(GL.hashtable("shader").get(shader));
+ Module.ctx.deleteShader(GL.shaders[shader]);
+ GL.shaders[shader] = null;
},
glDetachShader: function(program, shader) {
- Module.ctx.detachShader(GL.hashtable("program").get(program),
- GL.hashtable("shader").get(shader));
+ Module.ctx.detachShader(GL.programs[program],
+ GL.shaders[shader]);
},
glGetAttachedShaders: function(program, maxCount, count, shaders) {
- var result = Module.ctx.getAttachedShaders(GL.hashtable("program").get(program));
+ var result = Module.ctx.getAttachedShaders(GL.programs[program]);
var len = result.length;
if (len > maxCount) {
len = maxCount;
}
{{{ makeSetValue('count', '0', 'len', 'i32') }}};
for (var i = 0; i < len; ++i) {
- {{{ makeSetValue('shaders', 'i', 'GL.hashtable("shader").get(result[i])', 'i32') }}};
+ {{{ makeSetValue('shaders', 'i*4', 'GL.shaders[result[i]]', 'i32') }}};
}
},
- glShaderSource_deps: ['$GL'],
glShaderSource: function(shader, count, string, length) {
var source = "";
for (var i = 0; i < count; ++i) {
- var frag = string[i];
+ var frag;
if (length) {
- var len = {{{ makeGetValue('length', 'i', 'i32') }}};
+ var len = {{{ makeGetValue('length', 'i*4', 'i32') }}};
if (len < 0) {
- frag = Pointer_stringify({{{ makeGetValue('string', 'i', 'i32') }}});
+ frag = Pointer_stringify({{{ makeGetValue('string', 'i*4', 'i32') }}});
} else {
- frag = Pointer_stringify({{{ makeGetValue('string', 'i', 'i32') }}}, len);
+ frag = Pointer_stringify({{{ makeGetValue('string', 'i*4', 'i32') }}}, len);
}
} else {
- frag = Pointer_stringify({{{ makeGetValue('string', 'i', 'i32') }}});
- }
- if (source.length) {
- source += "\n";
+ frag = Pointer_stringify({{{ makeGetValue('string', 'i*4', 'i32') }}});
}
source += frag;
}
- Module.ctx.shaderSource(GL.hashtable("shader").get(shader), source);
+ Module.ctx.shaderSource(GL.shaders[shader], source);
},
glGetShaderSource: function(shader, bufsize, length, source) {
- var result = Module.ctx.getShaderSource(GL.hashtable("shader").get(shader));
+ var result = Module.ctx.getShaderSource(GL.shaders[shader]);
result.slice(0, bufsize - 1);
writeStringToMemory(result, source);
if (length) {
@@ -598,70 +533,68 @@ var LibraryGL = {
}
},
- glCompileShader_deps: ['$GL'],
glCompileShader: function(shader) {
- Module.ctx.compileShader(GL.hashtable("shader").get(shader));
+ Module.ctx.compileShader(GL.shaders[shader]);
},
- glGetShaderInfoLog_deps: ['$GL'],
glGetShaderInfoLog: function(shader, maxLength, length, infoLog) {
- var log = Module.ctx.getShaderInfoLog(GL.hashtable("shader").get(shader));
- log.slice(0, maxLength - 1);
+ var log = Module.ctx.getShaderInfoLog(GL.shaders[shader]);
+ // Work around a bug in Chromium which causes getShaderInfoLog to return null
+ if (!log) {
+ log = "";
+ }
+ log = log.substr(0, maxLength - 1);
writeStringToMemory(log, infoLog);
if (length) {
{{{ makeSetValue('length', '0', 'log.length', 'i32') }}}
}
},
- glGetShaderiv_deps: ['$GL'],
glGetShaderiv : function(shader, pname, p) {
- {{{ makeSetValue('p', '0', 'Module.ctx.getShaderParameter(GL.hashtable("shader").get(shader), pname)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'Module.ctx.getShaderParameter(GL.shaders[shader], pname)', 'i32') }}};
},
- glGetProgramiv_deps: ['$GL'],
glGetProgramiv : function(program, pname, p) {
- {{{ makeSetValue('p', '0', 'Module.ctx.getProgramParameter(GL.hashtable("program").get(program), pname)', 'i32') }}};
+ {{{ makeSetValue('p', '0', 'Module.ctx.getProgramParameter(GL.programs[program], pname)', 'i32') }}};
},
- glIsShader_deps: ['$GL'],
glIsShader: function(shader) {
- var fb = GL.hashtable("shader").get(shader);
+ var fb = GL.shaders[shader];
if (typeof(fb) == 'undefined') {
return false;
}
return Module.ctx.isShader(fb);
},
- glCreateProgram_deps: ['$GL'],
glCreateProgram: function() {
- return GL.hashtable("program").add(Module.ctx.createProgram());
+ var id = GL.programCounter++;
+ GL.programs[id] = Module.ctx.createProgram();
+ return id;
},
glDeleteProgram: function(program) {
- Module.ctx.deleteProgram(GL.hashtable("program").get(program));
+ Module.ctx.deleteProgram(GL.programs[program]);
+ GL.programs[program] = null;
},
- glAttachShader_deps: ['$GL'],
glAttachShader: function(program, shader) {
- Module.ctx.attachShader(GL.hashtable("program").get(program),
- GL.hashtable("shader").get(shader));
+ Module.ctx.attachShader(GL.programs[program],
+ GL.shaders[shader]);
},
glGetShaderPrecisionFormat: function(shaderType, precisionType, range, precision) {
var result = Module.ctx.getShaderPrecisionFormat(shaderType, precisionType);
{{{ makeSetValue('range', '0', 'result.rangeMin', 'i32') }}};
- {{{ makeSetValue('range', '1', 'result.rangeMax', 'i32') }}};
+ {{{ makeSetValue('range', '4', 'result.rangeMax', 'i32') }}};
{{{ makeSetValue('precision', '0', 'result.precision', 'i32') }}};
},
- glLinkProgram_deps: ['$GL'],
glLinkProgram: function(program) {
- Module.ctx.linkProgram(GL.hashtable("program").get(program));
+ Module.ctx.linkProgram(GL.programs[program]);
},
- glGetProgramInfoLog_deps: ['$GL'],
glGetProgramInfoLog: function(program, maxLength, length, infoLog) {
- var log = Module.ctx.getProgramInfoLog(GL.hashtable("program").get(program));
+ var log = Module.ctx.getProgramInfoLog(GL.programs[program]);
// Work around a bug in Chromium which causes getProgramInfoLog to return null
if (!log) {
log = "";
@@ -673,73 +606,64 @@ var LibraryGL = {
}
},
- glUseProgram_deps: ['$Gl'],
glUseProgram: function(program) {
- Module.ctx.useProgram(GL.hashtable("program").get(program));
+ Module.ctx.useProgram(GL.programs[program]);
},
- glValidateProgram_deps: ['$Gl'],
glValidateProgram: function(program) {
- Module.ctx.validateProgram(GL.hashtable("program").get(program));
+ Module.ctx.validateProgram(GL.programs[program]);
},
- glIsProgram_deps: ['$GL'],
glIsProgram: function(program) {
- var fb = GL.hashtable("program").get(program);
+ var fb = GL.programs[program];
if (typeof(fb) == 'undefined') {
return false;
}
return Module.ctx.isProgram(fb);
},
- glBindAttribLocation_deps: ['$GL'],
glBindAttribLocation: function(program, index, name) {
name = Pointer_stringify(name);
- Module.ctx.bindAttribLocation(GL.hashtable("program").get(program), index, name);
+ Module.ctx.bindAttribLocation(GL.programs[program], index, name);
},
- glBindFramebuffer_deps: ['$GL'],
glBindFramebuffer: function(target, framebuffer) {
- Module.ctx.bindFramebuffer(target, GL.hashtable("framebuffer").get(framebuffer));
+ Module.ctx.bindFramebuffer(target, GL.framebuffers[framebuffer]);
},
- glGenFramebuffers_deps: ['$GL'],
glGenFramebuffers: function(n, ids) {
for (var i = 0; i < n; ++i) {
- var fb = GL.hashtable("framebuffer").add(Module.ctx.createFramebuffer());
- {{{ makeSetValue('ids', 'i', 'fb', 'i32') }}};
+ var id = GL.framebufferCounter++;
+ GL.framebuffers[id] = Module.ctx.createFramebuffer();
+ {{{ makeSetValue('ids', 'i*4', 'id', 'i32') }}};
}
},
- glDeleteFramebuffers_deps: ['$GL'],
glDeleteFramebuffers: function(n, framebuffers) {
for (var i = 0; i < n; ++i) {
- var fb = GL.hashtable("framebuffer").get({{{ makeGetValue('framebuffers', 'i', 'i32' ) }}});
- Module.ctx.deleteFramebuffer(fb);
+ var id = {{{ makeGetValue('framebuffers', 'i*4', 'i32') }}};
+ Module.ctx.deleteFramebuffer(GL.framebuffers[id]);
+ GL.framebuffers[id] = null;
}
},
- glFramebufferRenderbuffer_deps: ['$GL'],
glFramebufferRenderbuffer: function(target, attachment, renderbuffertarget, renderbuffer) {
Module.ctx.framebufferRenderbuffer(target, attachment, renderbuffertarget,
- GL.hashtable("renderbuffer").get(renderbuffer));
+ GL.renderbuffers[renderbuffer]);
},
- glFramebufferTexture2D_deps: ['$GL'],
glFramebufferTexture2D: function(target, attachment, textarget, texture, level) {
Module.ctx.framebufferTexture2D(target, attachment, textarget,
- GL.hashtable("texture").get(texture), level);
+ GL.textures[texture], level);
},
- glGetFramebufferAttachmentParameteriv_deps: ['$GL'],
glGetFramebufferAttachmentParameteriv: function(target, attachment, pname, params) {
var result = Module.ctx.getFramebufferAttachmentParameter(target, attachment, pname);
{{{ makeSetValue('params', '0', 'params', 'i32') }}};
},
- glIsFramebuffer_deps: ['$GL'],
glIsFramebuffer: function(framebuffer) {
- var fb = GL.hashtable("framebuffer").get(framebuffer);
+ var fb = GL.framebuffers[framebuffer];
if (typeof(fb) == 'undefined') {
return false;
}
@@ -748,10 +672,10 @@ var LibraryGL = {
};
-
// Simple pass-through functions
[[0, 'shadeModel fogi fogfv getError finish flush'],
[1, 'clearDepth depthFunc enable disable frontFace cullFace clear enableVertexAttribArray disableVertexAttribArray lineWidth clearStencil depthMask stencilMask stencilMaskSeparate checkFramebufferStatus generateMipmap activeTexture'],
+ [2, 'pixelStorei'],
[3, 'texParameteri texParameterf drawArrays vertexAttrib2f'],
[4, 'viewport clearColor scissor vertexAttrib3f colorMask drawElements renderbufferStorage'],
[5, 'vertexAttrib4f'],
@@ -763,213 +687,11 @@ var LibraryGL = {
var stub = '(function(' + args + ') { ' + (num > 0 ? 'Module.ctx.NAME(' + args + ')' : '') + ' })';
names.split(' ').forEach(function(name_) {
var cName = 'gl' + name_[0].toUpperCase() + name_.substr(1);
-#if ASSERTIONS
assert(!(cName in LibraryGL), "Cannot reimplement the existing function " + cName);
-#endif
LibraryGL[cName] = eval(stub.replace('NAME', name_));
- //print(cName + ': ' + LibraryGL[cName]);
});
});
-var LibraryGLUT = {
- $GLUT: {
- initTime: null,
- idleFunc: null,
- keyboardFunc: null,
- keyboardUpFunc: null,
- specialFunc: null,
- specialUpFunc: null,
- reshapeFunc: null,
- passiveMotionFunc: null,
- mouseFunc: null,
- lastX: 0,
- lastY: 0,
-
- onMousemove: function(event) {
- GLUT.lastX = event['clientX'];
- GLUT.lastY = event['clientY'];
- if (GLUT.passiveMotionFunc) {
- FUNCTION_TABLE[GLUT.passiveMotionFunc](GLUT.lastX, GLUT.lastY);
- }
- },
-
- getSpecialKey: function(keycode) {
- var key = null;
- switch (keycode) {
- case 0x70 /*DOM_VK_F1*/: key = 1 /* GLUT_KEY_F1 */; break;
- case 0x71 /*DOM_VK_F2*/: key = 2 /* GLUT_KEY_