aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Liot <anthony.liot@gmail.com>2014-02-17 21:51:53 +0100
committerJukka Jylänki <jujjyl@gmail.com>2014-02-19 17:42:54 +0200
commit940543a71ccd5bd5638f58fa8d316e19c008514a (patch)
tree32143fe13633fd0d532badebe9f246eb3388fb1e
parentc405f9975858e4ad7da41a116c899999fd811fd9 (diff)
VAO Extension
-rw-r--r--src/library_gl.js68
1 files changed, 56 insertions, 12 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index e3442a8a..c1ecfdf8 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -19,6 +19,7 @@ var LibraryGL = {
textures: [],
uniforms: [],
shaders: [],
+ vaos: [],
#if FULL_ES2
clientBuffers: [],
@@ -633,6 +634,9 @@ var LibraryGL = {
// Extension available from Firefox 26 and Google Chrome 30
GL.instancedArraysExt = GLctx.getExtension('ANGLE_instanced_arrays');
+
+ // Extension available from Firefox 25 and WebKit
+ GL.vaoExt = Module.ctx.getExtension('OES_vertex_array_object');
// These are the 'safe' feature-enabling extensions that don't add any performance impact related to e.g. debugging, and
// should be enabled by default so that client GLES2/GL code will not need to go through extra hoops to get its stuff working.
@@ -1796,6 +1800,50 @@ var LibraryGL = {
return GLctx.isFramebuffer(fb);
},
+ glGenVertexArrays__sig: 'vii',
+ glGenVertexArrays: function (n , arrays) {
+#if ASSERTIONS
+ assert(GL.vaoExt, 'Must have OES_vertex_array_object to use vao');
+#endif
+ for (var i = 0; i < n ; i++) {
+ var id = GL.getNewId(GL.vaos);
+ var vao = GL.vaoExt.createVertexArrayOES();
+ vao.name = id;
+ GL.vaos[id] = vao;
+ {{{ makeSetValue('arrays', 'i*4', 'id', 'i32') }}};
+ }
+ },
+
+ glDeleteVertexArrays__sig: 'vii',
+ glDeleteVertexArrays: function(n, vaos) {
+#if ASSERTIONS
+ assert(GL.vaoExt, 'Must have OES_vertex_array_object to use vao');
+#endif
+ for (var i = 0; i < n; i++) {
+ var id = {{{ makeGetValue('vaos', 'i*4', 'i32') }}};
+ GL.vaoExt.deleteVertexArrayOES(GL.vaos[id]);
+ GL.vaos[id] = null;
+ }
+ },
+
+ glBindVertexArray__sig: 'vi',
+ glBindVertexArray: function(vao) {
+#if ASSERTIONS
+ assert(GL.vaoExt, 'Must have OES_vertex_array_object to use vao');
+#endif
+ GL.vaoExt.bindVertexArrayOES(GL.vaos[vao]);
+ },
+
+ glIsVertexArray__sig: 'ii',
+ glIsVertexArray: function(array) {
+#if ASSERTIONS
+ assert(GL.vaoExt, 'Must have OES_vertex_array_object to use vao');
+#endif
+ var vao = GL.vaos[array];
+ if (!vao) return 0;
+ return GL.vaoExt.isVertexArrayOES(vao);
+ },
+
#if LEGACY_GL_EMULATION
// GL emulation: provides misc. functionality not present in OpenGL ES 2.0 or WebGL
@@ -4809,9 +4857,9 @@ var LibraryGL = {
},
// Vertex array object (VAO) support. TODO: when the WebGL extension is popular, use that and remove this code and GL.vaos
- glGenVertexArrays__deps: ['$GLEmulation'],
- glGenVertexArrays__sig: 'vii',
- glGenVertexArrays: function(n, vaos) {
+ emulGlGenVertexArrays__deps: ['$GLEmulation'],
+ emulGlGenVertexArrays__sig: 'vii',
+ emulGlGenVertexArrays: function(n, vaos) {
for (var i = 0; i < n; i++) {
var id = GL.getNewId(GLEmulation.vaos);
GLEmulation.vaos[id] = {
@@ -4825,17 +4873,17 @@ var LibraryGL = {
{{{ makeSetValue('vaos', 'i*4', 'id', 'i32') }}};
}
},
- glDeleteVertexArrays__sig: 'vii',
- glDeleteVertexArrays: function(n, vaos) {
+ emulGlDeleteVertexArrays__sig: 'vii',
+ emulGlDeleteVertexArrays: function(n, vaos) {
for (var i = 0; i < n; i++) {
var id = {{{ makeGetValue('vaos', 'i*4', 'i32') }}};
GLEmulation.vaos[id] = null;
if (GLEmulation.currentVao && GLEmulation.currentVao.id == id) GLEmulation.currentVao = null;
}
},
- glBindVertexArray__deps: ['glBindBuffer', 'glEnableVertexAttribArray', 'glVertexAttribPointer', 'glEnableClientState'],
- glBindVertexArray__sig: 'vi',
- glBindVertexArray: function(vao) {
+ emulGlBindVertexArray__deps: ['glBindBuffer', 'glEnableVertexAttribArray', 'glVertexAttribPointer', 'glEnableClientState'],
+ emulGlBindVertexArray__sig: 'vi',
+ emulGlBindVertexArray: function(vao) {
// undo vao-related things, wipe the slate clean, both for vao of 0 or an actual vao
GLEmulation.currentVao = null; // make sure the commands we run here are not recorded
if (GLImmediate.lastRenderer) GLImmediate.lastRenderer.cleanup();
@@ -5034,15 +5082,11 @@ var LibraryGL = {
glCheckFramebufferStatusOES : 'glCheckFramebufferStatus',
glDeleteFramebuffersOES : 'glDeleteFramebuffers',
glDeleteRenderbuffersOES : 'glDeleteRenderbuffers',
- glGenVertexArraysOES: 'glGenVertexArrays',
- glDeleteVertexArraysOES: 'glDeleteVertexArrays',
- glBindVertexArrayOES: 'glBindVertexArray',
glFramebufferTexture2DOES: 'glFramebufferTexture2D',
#else // LEGACY_GL_EMULATION
glVertexPointer: function(){ throw 'Legacy GL function (glVertexPointer) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
- glGenVertexArrays: function(){ throw 'Legacy GL function (glGenVertexArrays) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
glMatrixMode: function(){ throw 'Legacy GL function (glMatrixMode) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
glBegin: function(){ throw 'Legacy GL function (glBegin) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },
glLoadIdentity: function(){ throw 'Legacy GL function (glLoadIdentity) called. If you want legacy GL emulation, you need to compile with -s LEGACY_GL_EMULATION=1 to enable legacy GL emulation.'; },