Added rebind function, to reset the shader attributes.

This commit is contained in:
Richard Davey 2020-11-10 15:50:51 +00:00
parent 6e115e4e04
commit 7ba1b132ab
2 changed files with 61 additions and 0 deletions

View file

@ -743,6 +743,34 @@ var WebGLPipeline = new Class({
return this;
},
/**
* This method is called every time the Pipeline Manager rebinds this pipeline.
*
* It resets all shaders this pipeline uses, setting their attributes again.
*
* @method Phaser.Renderer.WebGL.WebGLPipeline#rebind
* @since 3.0.0
*
* @return {this} This WebGLPipeline instance.
*/
rebind: function ()
{
this.renderer.setVertexBuffer(this.vertexBuffer);
var shaders = this.shaders;
for (var i = 0; i < shaders.length; i++)
{
shaders[i].rebind();
}
this.currentShader = shaders[0];
this.onRebind();
return this;
},
/**
* TODO
*
@ -875,6 +903,20 @@ var WebGLPipeline = new Class({
{
},
/**
* By default this is an empty method hook that you can override and use in your own custom pipelines.
*
* This method is called when the Pipeline Manager needs to rebind this pipeline. This happens after a
* pipeline has been cleared, usually when passing control over to a 3rd party WebGL library, like Spine,
* and then returing to Phaser again.
*
* @method Phaser.Renderer.WebGL.WebGLPipeline#onRebind
* @since 3.50.0
*/
onRebind: function ()
{
},
/**
* By default this is an empty method hook that you can override and use in your own custom pipelines.
*

View file

@ -235,6 +235,25 @@ var WebGLShader = new Class({
return this;
},
/**
* Sets the program this shader uses as being the active shader in the WebGL Renderer.
*
* Then resets all of the attribute pointers.
*
* @method Phaser.Renderer.WebGL.WebGLShader#rebind
* @since 3.50.0
*
* @return {this} This WebGLShader instance.
*/
rebind: function ()
{
this.renderer.setProgram(this.program);
this.setAttribPointers(true);
return this;
},
/**
* Sets the vertex attribute pointers.
*