Skip to content

Commit 7ba1b13

Browse files
committed
Added rebind function, to reset the shader attributes.
1 parent 6e115e4 commit 7ba1b13

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,34 @@ var WebGLPipeline = new Class({
743743
return this;
744744
},
745745

746+
/**
747+
* This method is called every time the Pipeline Manager rebinds this pipeline.
748+
*
749+
* It resets all shaders this pipeline uses, setting their attributes again.
750+
*
751+
* @method Phaser.Renderer.WebGL.WebGLPipeline#rebind
752+
* @since 3.0.0
753+
*
754+
* @return {this} This WebGLPipeline instance.
755+
*/
756+
rebind: function ()
757+
{
758+
this.renderer.setVertexBuffer(this.vertexBuffer);
759+
760+
var shaders = this.shaders;
761+
762+
for (var i = 0; i < shaders.length; i++)
763+
{
764+
shaders[i].rebind();
765+
}
766+
767+
this.currentShader = shaders[0];
768+
769+
this.onRebind();
770+
771+
return this;
772+
},
773+
746774
/**
747775
* TODO
748776
*
@@ -875,6 +903,20 @@ var WebGLPipeline = new Class({
875903
{
876904
},
877905

906+
/**
907+
* By default this is an empty method hook that you can override and use in your own custom pipelines.
908+
*
909+
* This method is called when the Pipeline Manager needs to rebind this pipeline. This happens after a
910+
* pipeline has been cleared, usually when passing control over to a 3rd party WebGL library, like Spine,
911+
* and then returing to Phaser again.
912+
*
913+
* @method Phaser.Renderer.WebGL.WebGLPipeline#onRebind
914+
* @since 3.50.0
915+
*/
916+
onRebind: function ()
917+
{
918+
},
919+
878920
/**
879921
* By default this is an empty method hook that you can override and use in your own custom pipelines.
880922
*

src/renderer/webgl/WebGLShader.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ var WebGLShader = new Class({
235235
return this;
236236
},
237237

238+
/**
239+
* Sets the program this shader uses as being the active shader in the WebGL Renderer.
240+
*
241+
* Then resets all of the attribute pointers.
242+
*
243+
* @method Phaser.Renderer.WebGL.WebGLShader#rebind
244+
* @since 3.50.0
245+
*
246+
* @return {this} This WebGLShader instance.
247+
*/
248+
rebind: function ()
249+
{
250+
this.renderer.setProgram(this.program);
251+
252+
this.setAttribPointers(true);
253+
254+
return this;
255+
},
256+
238257
/**
239258
* Sets the vertex attribute pointers.
240259
*

0 commit comments

Comments
 (0)