diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index ba892bd..b685c1a 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -68,7 +68,6 @@ { // assume it good! // texture = texture.baseTexture || texture; - location = location || 0; const gl = this.gl; @@ -79,6 +78,29 @@ return null; } + const boundTextures = this.renderer.boundTextures; + + // if the location is undefined then this may have been called by n event. + // this being the case the texture may already be bound to a slot. As a texture can only be bound once + // we need to find its current location if it exists. + if (location === undefined) + { + location = 0; + + // TODO maybe we can use texture bound ids later on... + // check if texture is already bound.. + for (let i = 0; i < boundTextures.length; ++i) + { + if (boundTextures[i] === texture) + { + location = i; + break; + } + } + } + + boundTextures[location] = texture; + gl.activeTexture(gl.TEXTURE0 + location); let glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; @@ -158,8 +180,6 @@ glTexture.upload(texture.source); } - this.renderer.boundTextures[location] = texture; - return glTexture; } diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index ba892bd..b685c1a 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -68,7 +68,6 @@ { // assume it good! // texture = texture.baseTexture || texture; - location = location || 0; const gl = this.gl; @@ -79,6 +78,29 @@ return null; } + const boundTextures = this.renderer.boundTextures; + + // if the location is undefined then this may have been called by n event. + // this being the case the texture may already be bound to a slot. As a texture can only be bound once + // we need to find its current location if it exists. + if (location === undefined) + { + location = 0; + + // TODO maybe we can use texture bound ids later on... + // check if texture is already bound.. + for (let i = 0; i < boundTextures.length; ++i) + { + if (boundTextures[i] === texture) + { + location = i; + break; + } + } + } + + boundTextures[location] = texture; + gl.activeTexture(gl.TEXTURE0 + location); let glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; @@ -158,8 +180,6 @@ glTexture.upload(texture.source); } - this.renderer.boundTextures[location] = texture; - return glTexture; } diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index c6e7721..026e741 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -15,7 +15,6 @@ import { pluginTarget } from '../../utils'; import glCore from 'pixi-gl-core'; import { RENDERER_TYPE } from '../../const'; -import settings from '../../settings'; let CONTEXT_UID = 0; @@ -197,7 +196,7 @@ gl.getExtension('WEBGL_lose_context').restoreContext(); } - const maxTextures = settings.SPRITE_MAX_TEXTURES; + const maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); this.boundTextures = new Array(maxTextures); this.emptyTextures = new Array(maxTextures);