WebGLRenderer.unbindTextures is a new method that will activate and then null bind all WebGL textures.

This commit is contained in:
Richard Davey 2020-07-23 16:24:44 +01:00
parent 556b5b05be
commit c31a9ad4e5

View file

@ -1520,6 +1520,34 @@ var WebGLRenderer = new Class({
this.textureFlush++;
},
/**
* Activates each texture, in turn, then binds them all to `null`.
*
* @method Phaser.Renderer.WebGL.WebGLRenderer#unbindTextures
* @since 3.25.0
*
* @param {boolean} [all=false] - Reset all textures, or just the first two?
*/
unbindTextures: function ()
{
var gl = this.gl;
var temp = this.tempTextures;
for (var i = 0; i < temp.length; i++)
{
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, null);
}
this.normalTexture = null;
this.textureZero = null;
this.currentActiveTexture = 1;
this.startActiveTexture++;
this.textureFlush++;
},
/**
* Flushes the current pipeline, then resets the first two textures
* back to the default temporary textures, resets the start active
@ -1527,19 +1555,31 @@ var WebGLRenderer = new Class({
*
* @method Phaser.Renderer.WebGL.WebGLRenderer#resetTextures
* @since 3.25.0
*
* @param {boolean} [all=false] - Reset all textures, or just the first two?
*/
resetTextures: function ()
resetTextures: function (all)
{
if (all === undefined) { all = false; }
this.flush();
var gl = this.gl;
var temp = this.tempTextures;
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, temp[0]);
var total = (all) ? temp.length : 2;
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, temp[1]);
for (var i = 0; i < total; i++)
{
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, temp[i]);
}
if (all)
{
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, temp[1]);
}
this.normalTexture = null;
this.textureZero = null;
@ -1921,6 +1961,8 @@ var WebGLRenderer = new Class({
this.setFramebuffer(null);
this.resetTextures(true);
return framebuffer;
},
@ -2039,6 +2081,8 @@ var WebGLRenderer = new Class({
this.gl.deleteTexture(texture);
this.resetTextures();
/*
if (!this.game.pendingDestroy)
{