Added the ability for a pipeline to be locked or unlocked

This commit is contained in:
Richard Davey 2020-10-29 17:22:29 +00:00
parent bf7e7f352a
commit 6353496751

View file

@ -124,6 +124,29 @@ var PipelineManager = new Class({
* @since 3.50.0
*/
this.BITMAPMASK_PIPELINE = null;
/**
* A stack of pipeline instances that is used to manage when the pipelines
* are locked and unlocked.
*
* Treat this array as read-only.
*
* @name Phaser.Renderer.WebGL.PipelineManager#stack
* @type {array}
* @since 3.50.0
*/
this.stack = [];
/**
* Is the Pipeline Manager currently locked from setting a new pipeline?
*
* Treat this property as read-only.
*
* @name Phaser.Renderer.WebGL.PipelineManager#locked
* @type {boolean}
* @since 3.50.0
*/
this.locked = false;
},
/**
@ -378,8 +401,7 @@ var PipelineManager = new Class({
*
* This method accepts a pipeline instance as its parameter, not the name.
*
* If the pipeline isn't already the current one, it will also call `resetTextures` on
* the `WebGLRenderer`. After this, `WebGLPipeline.bind` and then `onBind` are called.
* If the pipeline isn't already the current one it will call `WebGLPipeline.bind` and then `onBind`.
*
* @method Phaser.Renderer.WebGL.PipelineManager#set
* @since 3.50.0
@ -395,23 +417,96 @@ var PipelineManager = new Class({
var current = this.current;
if (
current !== pipeline ||
!this.locked &&
(current !== pipeline ||
current.vertexBuffer !== renderer.currentVertexBuffer ||
current.currentShader.program !== renderer.currentProgram
current.currentShader.program !== renderer.currentProgram)
)
{
renderer.resetTextures();
this.current = pipeline;
pipeline.bind();
}
if (!this.locked)
{
pipeline.onBind(gameObject);
}
return pipeline;
},
/**
* Sets the current pipeline to be used by the `WebGLRenderer` and then locks it.
*
* Once a pipeline is locked, further calls to `PipelineManager.set` are ignored.
*
* However, another pipeline may also be locked. If this happens, the previous pipeline
* is flushed and the new one is locked in place.
*
* Make sure to call `PipelineManager.unlock` when you're done.
*
* This method accepts a pipeline instance as its parameter, not the name.
*
* If the pipeline isn't already the current one it will call `WebGLPipeline.bind` and then `onBind`.
*
* @method Phaser.Renderer.WebGL.PipelineManager#lock
* @since 3.50.0
*
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipeline - The pipeline instance to be set as current.
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object that invoked this pipeline, if any.
*
* @return {this} This Pipeline Manager.
*/
lock: function (pipeline, gameObject)
{
this.flush();
this.stack.push({ pipeline: pipeline, gameObject: gameObject });
this.locked = false;
this.set(pipeline, gameObject);
this.locked = true;
return this;
},
/**
* Flushes the current pipeline, pops the previous one from the locked stack (if any)
* and then sets that, locking it in turn. If there aren't any other pipelines on
* the stack, the Pipeline Manager is fully unlocked.
*
* @method Phaser.Renderer.WebGL.PipelineManager#unlock
* @since 3.50.0
*
* @return {this} This Pipeline Manager.
*/
unlock: function ()
{
this.flush();
this.stack.pop();
if (this.stack.length > 0)
{
var previous = this.stack[this.stack.length - 1];
this.locked = false;
this.set(previous.pipeline, previous.gameObject);
this.locked = true;
}
else
{
this.locked = false;
}
return this;
},
/**
* Sets the Multi Pipeline to be the currently bound pipeline.
*
@ -535,6 +630,7 @@ var PipelineManager = new Class({
this.renderer = null;
this.game = null;
this.pipelines = null;
this.stack = null;
this.current = null;
this.previous = null;
}