Skip to content

Commit 789713b

Browse files
committed
Updated the clear and rebind pipeline methods
1 parent 32a2214 commit 789713b

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,6 @@ var WebGLRenderer = new Class({
546546
gl.disable(gl.DEPTH_TEST);
547547
gl.disable(gl.CULL_FACE);
548548

549-
// gl.disable(gl.SCISSOR_TEST);
550-
551549
gl.enable(gl.BLEND);
552550
gl.clearColor(clearColor.redGL, clearColor.greenGL, clearColor.blueGL, 1.0);
553551

@@ -927,8 +925,18 @@ var WebGLRenderer = new Class({
927925
},
928926

929927
/**
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.
928+
* Use this to reset the gl context to the state that Phaser requires to continue rendering.
929+
* Calling this will:
930+
*
931+
* * Disable `DEPTH_TEST`, `CULL_FACE` and `STENCIL_TEST`.
932+
* * Clear the depth buffer and stencil buffers.
933+
* * Reset the viewport size.
934+
* * Reset the blend mode.
935+
* * Bind a blank texture as the active texture on texture unit zero.
936+
* * Rebinds the given pipeline instance.
937+
*
938+
* You should call this having previously called `clearPipeline` and then wishing to return
939+
* control to Phaser again.
932940
*
933941
* @method Phaser.Renderer.WebGL.WebGLRenderer#rebindPipeline
934942
* @since 3.16.0
@@ -937,20 +945,34 @@ var WebGLRenderer = new Class({
937945
*/
938946
rebindPipeline: function (pipelineInstance)
939947
{
940-
this.currentPipeline = pipelineInstance;
941-
942-
this.currentPipeline.bind();
948+
var gl = this.gl;
943949

944-
this.currentPipeline.onBind();
950+
gl.disable(gl.DEPTH_TEST);
951+
gl.disable(gl.CULL_FACE);
952+
gl.disable(gl.STENCIL_TEST);
953+
954+
gl.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
945955

946-
this.setBlankTexture(true);
956+
gl.viewport(0, 0, this.width, this.height);
947957

948958
this.setBlendMode(0, true);
959+
960+
gl.activeTexture(gl.TEXTURE0);
961+
gl.bindTexture(gl.TEXTURE_2D, this.blankTexture.glTexture);
962+
963+
this.currentActiveTextureUnit = 0;
964+
this.currentTextures[0] = this.blankTexture.glTexture;
965+
966+
this.currentPipeline = pipelineInstance;
967+
this.currentPipeline.bind();
968+
this.currentPipeline.onBind();
949969
},
950970

951971
/**
952972
* Flushes the current WebGLPipeline being used and then clears it, along with the
953973
* the current shader program and vertex buffer. Then resets the blend mode to NORMAL.
974+
* Call this before jumping to your own gl context handler, and then call `rebindPipeline` when
975+
* you wish to return control to Phaser again.
954976
*
955977
* @method Phaser.Renderer.WebGL.WebGLRenderer#clearPipeline
956978
* @since 3.16.0
@@ -962,6 +984,7 @@ var WebGLRenderer = new Class({
962984
this.currentPipeline = null;
963985
this.currentProgram = null;
964986
this.currentVertexBuffer = null;
987+
this.currentIndexBuffer = null;
965988

966989
this.setBlendMode(0, true);
967990
},

0 commit comments

Comments
 (0)