Skip to content

Commit bed1141

Browse files
committed
Added clearPipeline and rebindPipeline and force argument.
1 parent 7441ff9 commit bed1141

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### New Features
66

77
* 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)
8+
* 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.
9+
* 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.
810

911
### Updates
1012

@@ -19,6 +21,7 @@
1921
* `PluginFile` will now install the plugin into the _current_ Scene as long as the `start` or `mapping` arguments are provided.
2022
* 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.
2123
* 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.
24+
* `WebGLRenderer.setBlendMode` has a new optional argument `force`, which will force the given blend mode to be set, regardless of the current settings.
2225

2326
### Bug Fixes
2427

src/renderer/webgl/WebGLRenderer.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,46 @@ var WebGLRenderer = new Class({
926926
return this.currentPipeline;
927927
},
928928

929+
/**
930+
* Rebinds the given pipeline instance to the renderer and then sets the blank texture as default.
931+
* Doesn't flush the old pipeline first.
932+
*
933+
* @method Phaser.Renderer.WebGL.WebGLRenderer#rebindPipeline
934+
* @since 3.16.0
935+
*
936+
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - The pipeline instance to be activated.
937+
*/
938+
rebindPipeline: function (pipelineInstance)
939+
{
940+
this.currentPipeline = pipelineInstance;
941+
942+
this.currentPipeline.bind();
943+
944+
this.currentPipeline.onBind();
945+
946+
this.setBlankTexture(true);
947+
948+
this.setBlendMode(0, true);
949+
},
950+
951+
/**
952+
* Flushes the current WebGLPipeline being used and then clears it, along with the
953+
* the current shader program and vertex buffer. Then resets the blend mode to NORMAL.
954+
*
955+
* @method Phaser.Renderer.WebGL.WebGLRenderer#clearPipeline
956+
* @since 3.16.0
957+
*/
958+
clearPipeline: function ()
959+
{
960+
this.flush();
961+
962+
this.currentPipeline = null;
963+
this.currentProgram = null;
964+
this.currentVertexBuffer = null;
965+
966+
this.setBlendMode(0, true);
967+
},
968+
929969
/**
930970
* Sets the blend mode to the value given.
931971
*
@@ -936,15 +976,18 @@ var WebGLRenderer = new Class({
936976
* @since 3.0.0
937977
*
938978
* @param {integer} blendModeId - The blend mode to be set. Can be a `BlendModes` const or an integer value.
979+
* @param {boolean} [force=false] - Force the blend mode to be set, regardless of the currently set blend mode.
939980
*
940981
* @return {boolean} `true` if the blend mode was changed as a result of this call, forcing a flush, otherwise `false`.
941982
*/
942-
setBlendMode: function (blendModeId)
983+
setBlendMode: function (blendModeId, force)
943984
{
985+
if (force === undefined) { force = false; }
986+
944987
var gl = this.gl;
945988
var blendMode = this.blendModes[blendModeId];
946989

947-
if (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId)
990+
if (force || (blendModeId !== CONST.BlendModes.SKIP_CHECK && this.currentBlendMode !== blendModeId))
948991
{
949992
this.flush();
950993

0 commit comments

Comments
 (0)