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; }