Added clearPipeline and rebindPipeline and force argument.

This commit is contained in:
Richard Davey 2018-10-25 14:13:40 +01:00
parent 7441ff90ae
commit bed1141d9a
2 changed files with 48 additions and 2 deletions

View file

@ -5,6 +5,8 @@
### New Features
* The data object being sent to the Dynamic Bitmap Text callback now has a new property `parent`, which is a reference to the Bitmap Text instance that owns the data object (thanks ornyth)
* The WebGL Renderer has a new method `clearPipeline`, which will clear down the current pipeline and reset the blend mode, ready for the context to be passed to a 3rd party library.
* The WebGL Renderer has a new method `rebindPipeline`, which will rebind the given pipeline instance, reset the blank texture and reset the blend mode. Which is useful for recovering from 3rd party libs that have modified the gl context.
### Updates
@ -19,6 +21,7 @@
* `PluginFile` will now install the plugin into the _current_ Scene as long as the `start` or `mapping` arguments are provided.
* MATH_CONST no longer requires or sets the Random Data Generator, this is now done in the Game Config, allowing you to require the math constants without pulling in a whole copy of the RNG with it.
* The Dynamic Bitmap Text Canvas Renderer was creating a new data object every frame for the callback. It now uses the `callbackData` object instead, like the WebGL renderer does.
* `WebGLRenderer.setBlendMode` has a new optional argument `force`, which will force the given blend mode to be set, regardless of the current settings.
### Bug Fixes

View file

@ -926,6 +926,46 @@ var WebGLRenderer = new Class({
return this.currentPipeline;
},
/**
* Rebinds the given pipeline instance to the renderer and then sets the blank texture as default.
* Doesn't flush the old pipeline first.
*
* @method Phaser.Renderer.WebGL.WebGLRenderer#rebindPipeline
* @since 3.16.0
*
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - The pipeline instance to be activated.
*/
rebindPipeline: function (pipelineInstance)
{
this.currentPipeline = pipelineInstance;
this.currentPipeline.bind();
this.currentPipeline.onBind();
this.setBlankTexture(true);
this.setBlendMode(0, true);
},
/**
* Flushes the current WebGLPipeline being used and then clears it, along with the
* the current shader program and vertex buffer. Then resets the blend mode to NORMAL.
*
* @method Phaser.Renderer.WebGL.WebGLRenderer#clearPipeline
* @since 3.16.0
*/
clearPipeline: function ()
{
this.flush();
this.currentPipeline = null;
this.currentProgram = null;
this.currentVertexBuffer = null;
this.setBlendMode(0, true);
},
/**
* Sets the blend mode to the value given.
*
@ -936,15 +976,18 @@ var WebGLRenderer = new Class({
* @since 3.0.0
*
* @param {integer} blendModeId - The blend mode to be set. Can be a `BlendModes` const or an integer value.
* @param {boolean} [force=false] - Force the blend mode to be set, regardless of the currently set blend mode.
*
* @return {boolean} `true` if the blend mode was changed as a result of this call, forcing a flush, otherwise `false`.
*/
setBlendMode: function (blendModeId)
setBlendMode: function (blendModeId, force)
{
if (force === undefined) { force = false; }
var gl = this.gl;
var blendMode = this.blendModes[blendModeId];
if (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId)
if (force || (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId))
{
this.flush();