aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library_gl.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index dbde945c..322711d9 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -14,6 +14,20 @@ var LibraryGL = {
uniforms: {},
shaders: {},
+ matrix: {
+ 'm': null, // modelview
+ 'p': null // projection
+ },
+ matrixStack: {
+ 'm': [], // modelview
+ 'p': [] // projection
+ },
+ currentMatrix: null,
+ initMatrixLibrary: function() {
+ GL.matrix['m'] = GL.matrix.lib.mat4.create();
+ GL.matrix['p'] = GL.matrix.lib.mat4.create();
+ },
+
// Linear lookup in one of the tables (buffers, programs, etc.). TODO: consider using a weakmap to make this faster, if it matters
scan: function(table, object) {
for (var item in table) {
@@ -782,6 +796,22 @@ var LibraryGL = {
return Module.ctx.isFramebuffer(fb);
},
+ // OpenGL matrix routines.
+ // Note that in the future we might make these available only in certain modes.
+ glMatrixMode: function(mode) {
+ if (mode == 0x1700 /* GL_MODELVIEW */) {
+ GL.currentMatrix = 'm';
+ } else if (mode == 0x1701 /* GL_PROJECTION */) {
+ GL.currentMatrix = 'p';
+ } else {
+ throw "Wrong mode " + mode + " passed to glMatrixMode";
+ }
+ },
+
+ glLoadIdentity: function() {
+ GL.matrix.lib.mat4.identity(GL.matrix[GL.currentMatrix]);
+ },
+
// GL emulation: provides misc. functionality not present in OpenGL ES 2.0 or WebGL
$GLEmulation__deps: ['glCreateShader', 'glShaderSource', 'glCompileShader', 'glCreateProgram', 'glDeleteShader', 'glDeleteProgram', 'glAttachShader', 'glActiveTexture', 'glGetShaderiv', 'glGetProgramiv', 'glLinkProgram'],