Skip to content

Commit

Permalink
V4.0
Browse files Browse the repository at this point in the history
Depth targets
Color targets
Multipass
  • Loading branch information
xeolabs committed Aug 4, 2014
1 parent 1129a7e commit fda9187
Show file tree
Hide file tree
Showing 37 changed files with 688 additions and 524 deletions.
2 changes: 1 addition & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var SceneJS_configsModule = new (function () {
for (var i = 0; cfg && i < parts.length; i++) {
cfg = cfg[parts[i]];
}
return cfg || {};
return (cfg != undefined) ? cfg : {};
}
};

Expand Down
20 changes: 15 additions & 5 deletions src/core/display/chunks/cameraChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ SceneJS_ChunkFactory.createChunkType({
build : function() {

this._uPMatrixDraw = this.program.draw.getUniformLocation("SCENEJS_uPMatrix");
this._uZNearDraw = this.program.draw.getUniformLocation("SCENEJS_uZNear");
this._uZFarDraw = this.program.draw.getUniformLocation("SCENEJS_uZFar");

this._uPMatrixPick = this.program.pick.getUniformLocation("SCENEJS_uPMatrix");
this._uZNearPick = this.program.pick.getUniformLocation("SCENEJS_uZNear");
this._uZFarPick = this.program.pick.getUniformLocation("SCENEJS_uZFar");
},

draw : function(ctx) {
draw : function(frameCtx) {

if (this.core.dirty) {
this.core.rebuild();
Expand All @@ -23,19 +25,27 @@ SceneJS_ChunkFactory.createChunkType({
gl.uniformMatrix4fv(this._uPMatrixDraw, gl.FALSE, this.core.mat);
}

ctx.cameraMat = this.core.mat; // Query only in draw pass
if (this._uZNearDraw) {
gl.uniform1f(this._uZNearDraw, this.core.optics.near);
}

if (this._uZFarDraw) {
gl.uniform1f(this._uZFarDraw, this.core.optics.far);
}

frameCtx.cameraMat = this.core.mat; // Query only in draw pass
},


pick : function(ctx) {
pick : function(frameCtx) {

var gl = this.program.gl;

if (this._uPMatrixPick) {
gl.uniformMatrix4fv(this._uPMatrixPick, gl.FALSE, this.core.mat);
}

if (ctx.rayPick) { // Z-pick pass: feed near and far clip planes into shader
if (frameCtx.rayPick) { // Z-pick pass: feed near and far clip planes into shader

if (this._uZNearPick) {
gl.uniform1f(this._uZNearPick, this.core.optics.near);
Expand All @@ -46,6 +56,6 @@ SceneJS_ChunkFactory.createChunkType({
}
}

ctx.cameraMat = this.core.mat; // Query only in draw pass
frameCtx.cameraMat = this.core.mat; // Query only in draw pass
}
});
6 changes: 3 additions & 3 deletions src/core/display/chunks/clipsChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ SceneJS_ChunkFactory.createChunkType({
}
},

drawAndPick: function(ctx) {
drawAndPick: function(frameCtx) {

var vars = (ctx.pick) ? this._pick : this._draw;
var vars = (frameCtx.pick) ? this._pick : this._draw;

var mode;
var normalAndDist;
Expand All @@ -42,7 +42,7 @@ SceneJS_ChunkFactory.createChunkType({

for (var i = 0, len = clips.length; i < len; i++) {

if (ctx.pick) {
if (frameCtx.pick) {
mode = vars[i].uClipMode;
normalAndDist = vars[i].uClipNormalAndDist;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/core/display/chunks/colorbufChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ SceneJS_ChunkFactory.createChunkType({
build:function () {
},

drawAndPick:function (ctx) {
drawAndPick:function (frameCtx) {

if (!ctx.transparencyPass) { // Blending forced when rendering transparent bin
if (!frameCtx.transparent) { // Blending forced when rendering transparent bin

var blendEnabled = this.core.blendEnabled;

if (ctx.blendEnabled != blendEnabled) {
if (frameCtx.blendEnabled != blendEnabled) {
var gl = this.program.gl;
if (blendEnabled) {
gl.enable(gl.BLEND);
} else {
gl.disable(gl.BLEND);
}
ctx.blendEnabled = blendEnabled;
frameCtx.blendEnabled = blendEnabled;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/display/chunks/cubemapChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ SceneJS_ChunkFactory.createChunkType({
}
},

draw: function (ctx) {
draw: function (frameCtx) {
var layers = this.core.layers;
if (layers) {
var layer;
var draw = this.program.draw;
for (var i = 0, len = layers.length; i < len; i++) {
layer = layers[i];
if (this._uCubeMapSampler[i] && layer.texture) {
draw.bindTexture(this._uCubeMapSampler[i], layer.texture, ctx.textureUnit++);
draw.bindTexture(this._uCubeMapSampler[i], layer.texture, frameCtx.textureUnit++);
if (this._uCubeMapIntensity[i]) {
this._uCubeMapIntensity[i].setValue(layer.intensity);
}
}
}
}

if (ctx.textureUnit > 10) { // TODO: Find how many textures allowed
ctx.textureUnit = 0;
if (frameCtx.textureUnit > 10) { // TODO: Find how many textures allowed
frameCtx.textureUnit = 0;
}
}
});
35 changes: 35 additions & 0 deletions src/core/display/chunks/depthTargetChunk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Create display state chunk type for draw and pick render of depthTarget
*/
SceneJS_ChunkFactory.createChunkType({

type: "depthTarget",

// Avoid reapplication of this chunk type after a program switch.
programGlobal: true,

build: function () {
},

drawAndPick: function (frameCtx) {

// Flush and unbind last render buffer
if (frameCtx.depthRenderBuf) {
var gl = this.program.gl;
gl.finish();
frameCtx.depthRenderBuf.unbind();
frameCtx.depthRenderBuf = null;
frameCtx.depthPass = false;
}

// Bind this chunk's render buffer, if any
var renderBuf = this.core.renderBuf;
if (renderBuf) {
renderBuf.bind();
var gl = this.program.gl;
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
frameCtx.depthRenderBuf = renderBuf;
frameCtx.depthPass = true;
}
}
});
14 changes: 7 additions & 7 deletions src/core/display/chunks/depthbufChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@ SceneJS_ChunkFactory.createChunkType({
// Avoid reapplication of a chunk after a program switch.
programGlobal:true,

drawAndPick:function (ctx) {
drawAndPick:function (frameCtx) {

var enabled = this.core.enabled;

if (ctx.depthbufEnabled != enabled) {
if (frameCtx.depthbufEnabled != enabled) {
var gl = this.program.gl;
if (enabled) {
gl.enable(gl.DEPTH_TEST);
} else {
gl.disable(gl.DEPTH_TEST);
}
ctx.depthbufEnabled = enabled;
frameCtx.depthbufEnabled = enabled;
}

var clearDepth = this.core.clearDepth;

if (ctx.clearDepth != clearDepth) {
if (frameCtx.clearDepth != clearDepth) {
gl.clearDepth(clearDepth);
ctx.clearDepth = clearDepth;
frameCtx.clearDepth = clearDepth;
}

var depthFunc = this.core.depthFunc;

if (ctx.depthFunc != depthFunc) {
if (frameCtx.depthFunc != depthFunc) {
gl.depthFunc(depthFunc);
ctx.depthFunc = depthFunc;
frameCtx.depthFunc = depthFunc;
}
}
});
2 changes: 1 addition & 1 deletion src/core/display/chunks/drawChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SceneJS_ChunkFactory.createChunkType({

build:function () {},

drawAndPick:function (ctx) {
drawAndPick:function (frameCtx) {

var gl = this.program.gl;

Expand Down
49 changes: 35 additions & 14 deletions src/core/display/chunks/flagsChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
SceneJS_ChunkFactory.createChunkType({

type:"flags",
type: "flags",

build:function () {
build: function () {

var draw = this.program.draw;

Expand All @@ -22,43 +22,64 @@ SceneJS_ChunkFactory.createChunkType({
this._uClippingPick = pick.getUniformLocation("SCENEJS_uClipping");
},

drawAndPick:function (ctx) {
drawAndPick: function (frameCtx) {

var gl = this.program.gl;

var backfaces = this.core.backfaces;

if (ctx.backfaces != backfaces) {
if (frameCtx.backfaces != backfaces) {
if (backfaces) {
gl.disable(gl.CULL_FACE);
} else {
gl.enable(gl.CULL_FACE);
}
ctx.backfaces = backfaces;
frameCtx.backfaces = backfaces;
}

var frontface = this.core.frontface;

if (ctx.frontface != frontface) {
if (frameCtx.frontface != frontface) {
if (frontface == "ccw") {
gl.frontFace(gl.CCW);
} else {
gl.frontFace(gl.CW);
}
ctx.frontface = frontface;
frameCtx.frontface = frontface;
}

if (ctx.pick) {
var transparent = this.core.transparent;

if (frameCtx.transparent != transparent) {
if (transparent) {

// Entering a transparency bin

gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
frameCtx.blendEnabled = true;

} else {

// Leaving a transparency bin

gl.disable(gl.BLEND);
frameCtx.blendEnabled = false;
}
frameCtx.transparent = transparent;
}

if (frameCtx.pick) {
gl.uniform1i(this._uClippingPick, this.core.clipping);

} else {
var drawUniforms = (this.core.backfaceTexturing ? 1 : 0) +
(this.core.backfaceLighting ? 2 : 0) +
(this.core.specular ? 4 : 0) +
(this.core.clipping ? 8 : 0) +
(this.core.ambient ? 16 : 0) +
(this.core.diffuse ? 32 : 0) +
(this.core.reflection ? 64 : 0);
(this.core.backfaceLighting ? 2 : 0) +
(this.core.specular ? 4 : 0) +
(this.core.clipping ? 8 : 0) +
(this.core.ambient ? 16 : 0) +
(this.core.diffuse ? 32 : 0) +
(this.core.reflection ? 64 : 0);
if (this.program.drawUniformFlags != drawUniforms) {
gl.uniform1i(this._uBackfaceTexturingDraw, this.core.backfaceTexturing);
gl.uniform1i(this._uBackfaceLightingDraw, this.core.backfaceLighting);
Expand Down
38 changes: 0 additions & 38 deletions src/core/display/chunks/framebufChunk.js

This file was deleted.

14 changes: 7 additions & 7 deletions src/core/display/chunks/geometryChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ SceneJS_ChunkFactory.createChunkType({

},

draw:function (ctx) {
draw:function (frameCtx) {
var doMorph = this.core.targets && this.core.targets.length;
var cleanInterleavedBuf = this.core2.interleavedBuf && !this.core2.interleavedBuf.dirty;

if (this.VAO) {
ctx.VAO.bindVertexArrayOES(this.VAO);
frameCtx.VAO.bindVertexArrayOES(this.VAO);
if (doMorph) {
if (this.VAOMorphKey1 == this.core.key1 && this.VAOMorphKey2 == this.core.key2) {
this.setDrawMorphFactor();
Expand All @@ -103,11 +103,11 @@ SceneJS_ChunkFactory.createChunkType({
} else if (cleanInterleavedBuf || !this.VAOHasInterleavedBuf) {
return;
}
} else if (ctx.VAO) {
} else if (frameCtx.VAO) {
// Start creating a new VAO by switching to the default VAO, which doesn't have attribs enabled.
ctx.VAO.bindVertexArrayOES(null);
this.VAO = ctx.VAO.createVertexArrayOES();
ctx.VAO.bindVertexArrayOES(this.VAO);
frameCtx.VAO.bindVertexArrayOES(null);
this.VAO = frameCtx.VAO.createVertexArrayOES();
frameCtx.VAO.bindVertexArrayOES(this.VAO);
var gl = this.program.gl;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ SceneJS_ChunkFactory.createChunkType({

},

pick:function (ctx) {
pick:function (frameCtx) {

if (this.core.targets && this.core.targets.length) {
this.morphPick();
Expand Down
Loading

0 comments on commit fda9187

Please sign in to comment.