Skip to content

Commit

Permalink
Added "clearEachPass" option to SceneJS.Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Aug 26, 2016
1 parent a464cf3 commit 5204f92
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/core/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ var SceneJS_Engine = function (json, options) {

/**
* Number of times the scene is drawn each time it's rendered.
* <p>This is useful for when we need to do things like render for left and right eyes.
* <p>This is useful for when we need to do things like render for left and right eyes.</p>
* @type {*|number}
*/
this._numPasses = json.numPasses || 1;

/**
* When doing multiple passes per frame, specifies whether to clear the
* canvas before each pass (true) or just before the first pass (false, default).
* @type Boolean
*/
this._clearEachPass = !!json.clearEachPass;

/**
* Canvas and GL context for this engine
*/
Expand Down Expand Up @@ -193,7 +200,7 @@ var SceneJS_Engine = function (json, options) {

/**
* Sets the number of times the scene is drawn on each render.
* <p>This is useful for when we need to do things like render for left and right eyes.
* <p>This is useful for when we need to do things like render for left and right eyes.</p>
* @param {Number} numPasses The number of times the scene is drawn on each frame.
* @see #getTagMask
* @see SceneJS.Tag
Expand All @@ -202,6 +209,20 @@ SceneJS_Engine.prototype.setNumPasses = function (numPasses) {
this._numPasses = numPasses;
};

/**
* When doing multiple passes per frame, specifies whether to clear the
* canvas before each pass (true) or just before the first pass (false).
*
* <p>This is useful for when we need to do things like render a separate pass to a stereo framebuffer for left and right eyes,
* where we want to clear the buffer before each pass.</p>
*
* @param {Boolean} clearEachPass True to clear before each pass (default is false).
* @see SceneJS.Tag
*/
SceneJS_Engine.prototype.setClearEachPass = function (clearEachPass) {
this._clearEachPass = clearEachPass;
};

/**
* Simulate a lost WebGL context.
* Only works if the simulateWebGLContextLost was given as an option to the engine's constructor.
Expand Down Expand Up @@ -393,7 +414,7 @@ SceneJS_Engine.prototype.renderFrame = function (params) {
// Render display graph
// Clear buffers only on first frame
this.display.render({
clear: i == 0,
clear: this._clearEachPass || i == 0,
force: force,
opaqueOnly: params && params.opaqueOnly
});
Expand Down
20 changes: 18 additions & 2 deletions src/core/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,31 @@ SceneJS.Scene.prototype.getTagMask = function () {

/**
* Sets the number of times this scene is drawn on each render.
* <p>This is useful for when we need to do things like render for left and right eyes.
*
* <p>This is useful for when we need to do things like render for left and right eyes.</p>
*
* @param {Number} numPasses The number of times the scene is drawn on each frame.
* @see #getTagMask
* @see SceneJS.Tag
*/
SceneJS.Scene.prototype.setNumPasses = function (numPasses) {
this._engine.setNumPasses(numPasses);
};

/**
* When doing multiple passes per frame, specifies whether to clear the
* canvas before each pass (true) or just before the first pass (false).
*
* <p>This is useful for when we need to do things like render a separate pass to a stereo framebuffer for left and right eyes,
* where we want to clear the buffer before each pass.</p>
*
* @param {Boolean} clearEachPass Tryu to clear before each pass (default is false).
* @see SceneJS.Tag
*/
SceneJS.Scene.prototype.setClearEachPass = function (clearEachPass) {
this._engine.setClearEachPass(clearEachPass);
};


/**
* Render a single frame if new frame pending, or force a new frame
* Returns true if frame rendered
Expand Down
3 changes: 3 additions & 0 deletions src/core/scenejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ var SceneJS = new (function () {
* @param {String} json JSON scene description
* @param {*} options Optional options
* @param {Boolean} options.simulateWebGLContextLost Set true to enable simulation of lost WebGL context (has performance impact)
* @param {Number} options.passes The number of times this Scene renders per frame.
* @param {Boolean} options.clearEachPass When doing multiple passes per frame, specifies whether to clear the
* canvas before each pass (true) or just before the first pass (false).
* @returns {SceneJS.Scene} New scene
*/
this.createScene = function (json, options) {
Expand Down

0 comments on commit 5204f92

Please sign in to comment.