From 27963677652cbf19ecfd5bbd9ddf6ba919c2af0a Mon Sep 17 00:00:00 2001 From: Olli Etuaho Date: Wed, 25 Jun 2014 18:30:05 +0300 Subject: [PATCH] Simplify morph geometry handling --- src/core/display/chunks/geometryChunk.js | 138 +++++++++-------------- src/core/display/chunks/programChunk.js | 16 --- src/core/display/display.js | 5 - 3 files changed, 54 insertions(+), 105 deletions(-) diff --git a/src/core/display/chunks/geometryChunk.js b/src/core/display/chunks/geometryChunk.js index bd9d1a95..f54cbe9a 100644 --- a/src/core/display/chunks/geometryChunk.js +++ b/src/core/display/chunks/geometryChunk.js @@ -38,20 +38,7 @@ SceneJS_ChunkFactory.createChunkType({ this._uMorphFactorPick = pick.getUniformLocation("SCENEJS_uMorphFactor"); }, - morphDraw:function (ctx) { - - var targets = this.core.targets; - - if (!targets || targets.length == 0) { - ctx.vertexBuf = false; - ctx.normalBuf = false; - ctx.uvBuf = false; - ctx.uvBuf2 = false; - ctx.colorBuf = false; - return; - } - - var gl = this.program.gl; + morphDraw:function () { var target1 = this.core.targets[this.core.key1]; // Keys will update var target2 = this.core.targets[this.core.key2]; @@ -59,182 +46,165 @@ SceneJS_ChunkFactory.createChunkType({ if (this._aMorphVertexDraw) { this._aVertexDraw.bindFloatArrayBuffer(target1.vertexBuf); this._aMorphVertexDraw.bindFloatArrayBuffer(target2.vertexBuf); - ctx.vertexBuf = true; - } else { - ctx.vertexBuf = false; + } else if (this._aVertexDraw) { + this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf); } if (this._aMorphNormalDraw) { this._aNormalDraw.bindFloatArrayBuffer(target1.normalBuf); this._aMorphNormalDraw.bindFloatArrayBuffer(target2.normalBuf); - ctx.normalBuf = true; - } else { - ctx.normalBuf = false; + } else if (this._aNormalDraw) { + this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf); } if (this._aMorphUVDraw) { this._aUVDraw.bindFloatArrayBuffer(target1.uvBuf); this._aMorphUVDraw.bindFloatArrayBuffer(target2.uvBuf); - ctx.uvBuf = true; - } else { - ctx.uvBuf = false; + } else if (this._aUVDraw) { + this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf); } if (this._aMorphUV2Draw) { this._aUV2Draw.bindFloatArrayBuffer(target1.uvBuf2); this._aMorphUV2Draw.bindFloatArrayBuffer(target2.uvBuf2); - ctx.uvBuf2 = true; - } else { - ctx.uvBuf2 = false; + } else if (this._aUV2Draw) { + this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2); } if (this._aMorphColorDraw) { this._aColorDraw.bindFloatArrayBuffer(target1.colorBuf); this._aMorphColorDraw.bindFloatArrayBuffer(target2.colorBuf); - ctx.colorBuf = true; - } else { - ctx.colorBuf = false; + } else if (this._aColorDraw) { + this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf); } if (this._uMorphFactorDraw) { - gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor + this.program.gl.uniform1f(this._uMorphFactorDraw, this.core.factor); // Bind LERP factor } + }, draw:function (ctx) { - this.morphDraw(ctx); - - var gl = this.program.gl; + if (this.core.targets && this.core.targets.length) { + this.morphDraw(); + } else { if (this.core2.interleavedBuf && !this.core2.interleavedBuf.dirty) { this.core2.interleavedBuf.bind(); - if (this._aVertexDraw && !ctx.vertexBuf) { + if (this._aVertexDraw) { this._aVertexDraw.bindInterleavedFloatArrayBuffer(3, this.core2.interleavedStride, this.core2.interleavedPositionOffset); } - if (this._aNormalDraw && !ctx.normalBuf) { + if (this._aNormalDraw) { this._aNormalDraw.bindInterleavedFloatArrayBuffer(3, this.core2.interleavedStride, this.core2.interleavedNormalOffset); } - if (this._aUVDraw && !ctx.uvBuf) { + if (this._aUVDraw) { this._aUVDraw.bindInterleavedFloatArrayBuffer(2, this.core2.interleavedStride, this.core2.interleavedUVOffset); } - if (this._aUV2Draw && !ctx.uv2Buf) { + if (this._aUV2Draw) { this._aUV2Draw.bindInterleavedFloatArrayBuffer(2, this.core2.interleavedStride, this.core2.interleavedUV2Offset); } - if (this._aColorDraw && !ctx.colorBuf) { + if (this._aColorDraw) { this._aColorDraw.bindInterleavedFloatArrayBuffer(4, this.core2.interleavedStride, this.core2.interleavedColorOffset); } } else { - if (this._aVertexDraw && !ctx.vertexBuf) { + if (this._aVertexDraw) { this._aVertexDraw.bindFloatArrayBuffer(this.core2.vertexBuf); } - if (this._aNormalDraw && !ctx.normalBuf) { + if (this._aNormalDraw) { this._aNormalDraw.bindFloatArrayBuffer(this.core2.normalBuf); } - if (this._aUVDraw && !ctx.uvBuf) { + if (this._aUVDraw) { this._aUVDraw.bindFloatArrayBuffer(this.core2.uvBuf); } - if (this._aUV2Draw && !ctx.uvBuf2) { + if (this._aUV2Draw) { this._aUV2Draw.bindFloatArrayBuffer(this.core2.uvBuf2); } - if (this._aColorDraw && !ctx.colorBuf) { + if (this._aColorDraw) { this._aColorDraw.bindFloatArrayBuffer(this.core2.colorBuf); } } - this.core2.indexBuf.bind(); - - }, - - morphPick:function (ctx) { + } - var targets = this.core.targets; + this.core2.indexBuf.bind(); - if (!targets || targets.length == 0) { - ctx.vertexBuf = false; - ctx.normalBuf = false; - ctx.uvBuf = false; - ctx.uvBuf2 = false; - ctx.colorBuf = false; - return; - } + }, - var gl = this.program.gl; + morphPick:function () { - var target1 = targets[this.core.key1]; // Keys will update - var target2 = targets[this.core.key2]; + var target1 = this.core.targets[this.core.key1]; // Keys will update + var target2 = this.core.targets[this.core.key2]; if (this._aMorphVertexPick) { this._aVertexPick.bindFloatArrayBuffer(target1.vertexBuf); this._aMorphVertexPick.bindFloatArrayBuffer(target2.vertexBuf); - ctx.vertexBuf = true; - } else { - ctx.vertexBuf = false; + } else if (this._aVertexPick) { + this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf); } if (this._aMorphNormalPick) { this._aNormalPick.bindFloatArrayBuffer(target1.normalBuf); this._aMorphNormalPick.bindFloatArrayBuffer(target2.normalBuf); - ctx.normalBuf = true; - } else { - ctx.normalBuf = false; + } else if (this._aNormalPick) { + this._aNormalPick.bindFloatArrayBuffer(this.core2.normalBuf); } if (this._aMorphUVPick) { this._aUVPick.bindFloatArrayBuffer(target1.uvBuf); this._aMorphUVPick.bindFloatArrayBuffer(target2.uvBuf); - ctx.uvBuf = true; - } else { - ctx.uvBuf = false; + } else if (this._aUVPick) { + this._aUVPick.bindFloatArrayBuffer(this.core2.uvBuf); } if (this._aMorphUV2Pick) { this._aUV2Pick.bindFloatArrayBuffer(target1.uvBuf2); this._aMorphUV2Pick.bindFloatArrayBuffer(target2.uvBuf2); - ctx.uvBuf2 = true; - } else { - ctx.uvBuf2 = false; + } else if (this._aUV2Pick) { + this._aUV2Pick.bindFloatArrayBuffer(this.core2.uvBuf2); } if (this._aMorphColorPick) { this._aColorPick.bindFloatArrayBuffer(target1.colorBuf); this._aMorphColorPick.bindFloatArrayBuffer(target2.colorBuf); - ctx.colorBuf = true; - } else { - ctx.colorBuf = false; + } else if (this._aColorPick) { + this._aColorPick.bindFloatArrayBuffer(this.core2.colorBuf); } if (this._uMorphFactorPick) { - gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor + this.program.gl.uniform1f(this._uMorphFactorPick, this.core.factor); // Bind LERP factor } + }, pick:function (ctx) { - this.morphPick(ctx); - - var gl = this.program.gl; + if (this.core.targets && this.core.targets.length) { + this.morphPick(); + } else { - if (this._aVertexPick && !ctx.vertexBuf) { + if (this._aVertexPick) { this._aVertexPick.bindFloatArrayBuffer(this.core2.vertexBuf); } - if (this._aNormalPick && !ctx.normalBuf) { + if (this._aNormalPick) { this._aNormalPick.bindFloatArrayBuffer(this.core2.normalBuf); } - if (this._aUVPick && !ctx.uvBuf) { + if (this._aUVPick) { this._aUVPick.bindFloatArrayBuffer(this.core2.uvBuf); } - if (this._aUV2Pick && !ctx.uvBuf2) { + if (this._aUV2Pick) { this._aUV2Pick.bindFloatArrayBuffer(this.core2.uvBuf2); } - this.core2.indexBuf.bind(); + } + + this.core2.indexBuf.bind(); } }); diff --git a/src/core/display/chunks/programChunk.js b/src/core/display/chunks/programChunk.js index 8137a6bb..f1799749 100644 --- a/src/core/display/chunks/programChunk.js +++ b/src/core/display/chunks/programChunk.js @@ -12,14 +12,6 @@ SceneJS_ChunkFactory.createChunkType({ drawProgram.bind(); - /* - * HACK until we have distinct chunk for each VBO (maybe) - */ - frameCtx.vertexBuf = false; - frameCtx.normalBuf = false; - frameCtx.uvBuf = false; - frameCtx.uvBuf2 = false; - frameCtx.colorBuf = false; frameCtx.textureUnit = 0; var gl = this.program.gl; @@ -39,14 +31,6 @@ SceneJS_ChunkFactory.createChunkType({ gl.uniform1i(this._rayPickMode, frameCtx.rayPick); - /* - * HACK until we have distinct chunk for each VBO (maybe) - */ - frameCtx.vertexBuf = false; - frameCtx.normalBuf = false; - frameCtx.uvBuf = false; - frameCtx.uvBuf2 = false; - frameCtx.colorBuf = false; frameCtx.textureUnit = 0; for (var i = 0; i < 10; i++) { diff --git a/src/core/display/display.js b/src/core/display/display.js index 16d46d7b..1770e9fc 100644 --- a/src/core/display/display.js +++ b/src/core/display/display.js @@ -920,11 +920,6 @@ SceneJS_Display.prototype._doDrawList = function (pick, rayPick) { frameCtx.blendEnabled = false; - frameCtx.vertexBuf = false; - frameCtx.normalBuf = false; - frameCtx.uvBuf = false; - frameCtx.uvBuf2 = false; - frameCtx.colorBuf = false; frameCtx.backfaces = true; frameCtx.frontface = "ccw"; frameCtx.pick = !!pick;