diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-04-11 16:37:19 -0400 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2012-04-11 16:37:19 -0400 |
commit | 4949d7b694a2c73ee8ba6ce61319ccdf41742a71 (patch) | |
tree | 3521748a6242b4d496bdda4c9eefa1784de74a9e | |
parent | c5b8395899bdd763a51f0385178e45a29eda711c (diff) |
Initial GL matrix infrastructure
-rw-r--r-- | src/library_gl.js | 30 |
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'], |