diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index ba892bd..d8187a8 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,25 @@ return null; } + const boundTextures = this.renderer.boundTextures; + + 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; + } + } + } + + boundTextures[location] = texture; + gl.activeTexture(gl.TEXTURE0 + location); let glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; @@ -158,8 +176,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..d8187a8 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,25 @@ return null; } + const boundTextures = this.renderer.boundTextures; + + 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; + } + } + } + + boundTextures[location] = texture; + gl.activeTexture(gl.TEXTURE0 + location); let glTexture = texture._glTextures[this.renderer.CONTEXT_UID]; @@ -158,8 +176,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 5d14094..b76ae09 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -13,7 +13,6 @@ import { pluginTarget } from '../../utils'; import glCore from 'pixi-gl-core'; import { RENDERER_TYPE } from '../../const'; -import settings from '../../settings'; let CONTEXT_UID = 0; @@ -192,7 +191,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);