aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-06-06 18:08:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-06-06 18:08:36 -0700
commitf5fc497c1be48e4718cb4a0259c127223840bb74 (patch)
treea09bc81d200e1ce76604f7aebd0b4112e0f9746b /src
parent2f61063528d19a3e612bd1b90b0ec66ae1148cf1 (diff)
refactor array buffer and program setting into renderer in preparation for further optimizations
Diffstat (limited to 'src')
-rw-r--r--src/library_gl.js38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/library_gl.js b/src/library_gl.js
index 1f1f4aea..2a70503a 100644
--- a/src/library_gl.js
+++ b/src/library_gl.js
@@ -1535,6 +1535,18 @@ var LibraryGL = {
},
prepare: function() {
+ if (!GL.currArrayBuffer) {
+ var start = GL.immediate.firstVertex*GL.immediate.stride;
+ var end = GL.immediate.lastVertex*GL.immediate.stride;
+ assert(end <= GL.immediate.MAX_TEMP_BUFFER_SIZE, 'too much vertex data');
+ var vertexBuffer = GL.immediate.tempVertexBuffers[GL.immediate.tempBufferIndexLookup[end]];
+ Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, vertexBuffer);
+ Module.ctx.bufferSubData(Module.ctx.ARRAY_BUFFER, start, GL.immediate.vertexData.subarray(start >> 2, end >> 2));
+ }
+ 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']);
@@ -1592,6 +1604,12 @@ var LibraryGL = {
if (this.hasNormal) {
Module.ctx.disableVertexAttribArray(this.normalLocation);
}
+ if (!GL.currProgram) {
+ Module.ctx.useProgram(null);
+ }
+ if (!GL.currArrayBuffer) {
+ Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, null);
+ }
}
};
ret.init();
@@ -1781,20 +1799,6 @@ var LibraryGL = {
emulatedElementArrayBuffer = true;
}
- if (!GL.currArrayBuffer) {
- var start = GL.immediate.firstVertex*GL.immediate.stride;
- var end = GL.immediate.lastVertex*GL.immediate.stride;
- assert(end <= GL.immediate.MAX_TEMP_BUFFER_SIZE, 'too much vertex data');
- var vertexBuffer = GL.immediate.tempVertexBuffers[GL.immediate.tempBufferIndexLookup[end]];
- Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, vertexBuffer);
- Module.ctx.bufferSubData(Module.ctx.ARRAY_BUFFER, start, this.vertexData.subarray(start >> 2, end >> 2));
- }
-
- // Render
- if (!GL.currProgram) {
- Module.ctx.useProgram(renderer.program);
- }
-
renderer.prepare();
if (numIndexes) {
@@ -1805,15 +1809,9 @@ var LibraryGL = {
renderer.cleanup();
- if (!GL.currArrayBuffer) {
- Module.ctx.bindBuffer(Module.ctx.ARRAY_BUFFER, null);
- }
if (emulatedElementArrayBuffer) {
Module.ctx.bindBuffer(Module.ctx.ELEMENT_ARRAY_BUFFER, GL.buffers[GL.currElementArrayBuffer] || null);
}
- if (!GL.currProgram) {
- Module.ctx.useProgram(null);
- }
}
},