Skip to content

Commit

Permalink
Use draw chunk for drawElements instead of geometry chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli Etuaho committed Jun 30, 2014
1 parent 559ec47 commit f16f442
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/core/display/chunks/drawChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ SceneJS_ChunkFactory.createChunkType({

gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, gl.UNSIGNED_SHORT, 0);
}
});
});
22 changes: 0 additions & 22 deletions src/core/display/chunks/geometryChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ SceneJS_ChunkFactory.createChunkType({

type:"geometry",

/**
* As we apply a list of state chunks in a {@link SceneJS_Display}, we track the ID of each chunk
* in order to avoid redundantly re-applying the same chunk.
*
* We don't want that for draw chunks however, because they contain GL drawElements calls,
* which we need to do for each object.
*/
unique:true,

build:function () {

var draw = this.program.draw;
Expand All @@ -37,8 +28,6 @@ SceneJS_ChunkFactory.createChunkType({

var gl = this.program.gl;

if (ctx.geoChunkId != this.id) { // HACK until we have distinct state chunks for VBOs and draw call

if (this.core.interleavedBuf && !this.core.interleavedBuf.dirty) {
this.core.interleavedBuf.bind();
if (this._aVertexDraw && !ctx.vertexBuf) {
Expand Down Expand Up @@ -80,18 +69,12 @@ SceneJS_ChunkFactory.createChunkType({

this.core.indexBuf.bind();

ctx.geoChunkId = this.id;
}

gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, gl.UNSIGNED_SHORT, 0);
},

pick:function (ctx) {

var gl = this.program.gl;

if (ctx.geoChunkId != this.id) { // HACK until we have distinct state chunks for VBOs and draw call

if (this._aVertexPick && !ctx.vertexBuf) {
this._aVertexPick.bindFloatArrayBuffer(this.core.vertexBuf);
}
Expand All @@ -109,10 +92,5 @@ SceneJS_ChunkFactory.createChunkType({
}

this.core.indexBuf.bind();

ctx.geoChunkId = this.id;
}

gl.drawElements(this.core.primitive, this.core.indexBuf.numItems, gl.UNSIGNED_SHORT, 0);
}
});
4 changes: 0 additions & 4 deletions src/core/display/chunks/programChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ SceneJS_ChunkFactory.createChunkType({
frameCtx.colorBuf = false;
frameCtx.textureUnit = 0;

frameCtx.geoChunkId = null; // HACK until we have distinct state chunks for VBOs and draw call

var gl = this.program.gl;

for (var i = 0; i < 10; i++) {
Expand Down Expand Up @@ -51,8 +49,6 @@ SceneJS_ChunkFactory.createChunkType({
frameCtx.colorBuf = false;
frameCtx.textureUnit = 0;

frameCtx.geoChunkId = null; // HACK until we have distinct state chunks for VBOs and draw call

for (var i = 0; i < 10; i++) {
gl.disableVertexAttribArray(i);
}
Expand Down
9 changes: 7 additions & 2 deletions src/core/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ SceneJS_Display.prototype.buildObject = function (objectId) {
this._setChunk(object, 17, "clips", this.clips);
this._setChunk(object, 18, "morphGeometry", this.morphGeometry);
this._setChunk(object, 19, "listeners", this.renderListeners); // Must be after the above chunks
this._setChunk(object, 20, "geometry", this.geometry); // Must be last
this._setChunk(object, 20, "geometry", this.geometry);
this._setChunk(object, 21, "draw", this.geometry); // Must be last
};

SceneJS_Display.prototype._setChunk = function (object, order, chunkType, core, unique) {
Expand Down Expand Up @@ -468,6 +469,10 @@ SceneJS_Display.prototype._setChunk = function (object, order, chunkType, core,
chunkId = 'p' + object.program.id;
}

// This is needed so that chunkFactory can distinguish between draw and geometry
// chunks with the same core.
chunkId = order + '__' + chunkId;

var oldChunk = object.chunks[order];

if (oldChunk) {
Expand Down Expand Up @@ -718,7 +723,7 @@ SceneJS_Display.prototype._buildDrawList = function () {

// As we apply the state chunk lists we track the ID of most types of chunk in order
// to cull redundant re-applications of runs of the same chunk - except for those chunks with a
// 'unique' flag. We don't want to cull runs of geometry chunks because they contain the GL
// 'unique' flag. We don't want to cull runs of draw chunks because they contain the GL
// drawElements calls which render the objects.

// Chunk IDs are only considered unique within the same program. Therefore, whenever we do a
Expand Down

0 comments on commit f16f442

Please sign in to comment.