diff --git a/packages/core/src/renderers/systems/textures/GLTexture.js b/packages/core/src/renderers/systems/textures/GLTexture.js index 3f5bf44..c3fb8dc 100644 --- a/packages/core/src/renderers/systems/textures/GLTexture.js +++ b/packages/core/src/renderers/systems/textures/GLTexture.js @@ -23,5 +23,11 @@ * @type {number} */ this.dirtyStyleId = -1; + + /** + * Whether mip levels has to be generated + * @type {boolean} + */ + this.mipmap = false; } } diff --git a/packages/core/src/renderers/systems/textures/GLTexture.js b/packages/core/src/renderers/systems/textures/GLTexture.js index 3f5bf44..c3fb8dc 100644 --- a/packages/core/src/renderers/systems/textures/GLTexture.js +++ b/packages/core/src/renderers/systems/textures/GLTexture.js @@ -23,5 +23,11 @@ * @type {number} */ this.dirtyStyleId = -1; + + /** + * Whether mip levels has to be generated + * @type {boolean} + */ + this.mipmap = false; } } diff --git a/packages/core/src/renderers/systems/textures/TextureSystem.js b/packages/core/src/renderers/systems/textures/TextureSystem.js index 5c159e2..5e5a7d6 100644 --- a/packages/core/src/renderers/systems/textures/TextureSystem.js +++ b/packages/core/src/renderers/systems/textures/TextureSystem.js @@ -157,17 +157,35 @@ updateTexture(texture) { const glTexture = texture._glTextures[this.CONTEXT_UID]; + const renderer = this.renderer; - if (texture.resource && texture.resource.upload(this.renderer, texture, glTexture)) + if (texture.resource && texture.resource.upload(renderer, texture, glTexture)) { // texture is uploaded, dont do anything! } - else if (glTexture.width !== texture.realWidth - || glTexture.height !== texture.realHeight - || glTexture.dirtyId < 0) + else { // default, renderTexture-like logic - glTexture.uploadData(null, texture.realWidth, texture.realHeight); + const width = texture.realWidth; + const height = texture.realHeight; + const gl = renderer.gl; + + if (glTexture.width !== width + || glTexture.height !== height + || glTexture.dirtyId < 0) + { + glTexture.width = width; + glTexture.height = height; + + gl.texImage2D(texture.target, 0, + texture.format, + width, + height, + 0, + texture.format, + texture.type, + null); + } } // lets only update what changes.. @@ -213,6 +231,7 @@ { const glTexture = texture._glTextures[this.CONTEXT_UID]; + glTexture.mipmap = texture.mipmap && texture.isPowerOfTwo; if (!glTexture) { return; @@ -230,11 +249,11 @@ glTexture.dirtyStyleId = texture.dirtyStyleId; } - setStyle(texture) + setStyle(texture, glTexture) { const gl = this.gl; - if (texture.mipmap && texture.isPowerOfTwo) + if (glTexture.mipmap) { gl.generateMipmap(texture.target); } @@ -242,7 +261,7 @@ gl.texParameteri(texture.target, gl.TEXTURE_WRAP_S, texture.wrapMode); gl.texParameteri(texture.target, gl.TEXTURE_WRAP_T, texture.wrapMode); - if (texture.mipmap) + if (glTexture.mipmap) { /* eslint-disable max-len */ gl.texParameteri(texture.target, gl.TEXTURE_MIN_FILTER, texture.scaleMode ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); diff --git a/packages/core/src/renderers/systems/textures/GLTexture.js b/packages/core/src/renderers/systems/textures/GLTexture.js index 3f5bf44..c3fb8dc 100644 --- a/packages/core/src/renderers/systems/textures/GLTexture.js +++ b/packages/core/src/renderers/systems/textures/GLTexture.js @@ -23,5 +23,11 @@ * @type {number} */ this.dirtyStyleId = -1; + + /** + * Whether mip levels has to be generated + * @type {boolean} + */ + this.mipmap = false; } } diff --git a/packages/core/src/renderers/systems/textures/TextureSystem.js b/packages/core/src/renderers/systems/textures/TextureSystem.js index 5c159e2..5e5a7d6 100644 --- a/packages/core/src/renderers/systems/textures/TextureSystem.js +++ b/packages/core/src/renderers/systems/textures/TextureSystem.js @@ -157,17 +157,35 @@ updateTexture(texture) { const glTexture = texture._glTextures[this.CONTEXT_UID]; + const renderer = this.renderer; - if (texture.resource && texture.resource.upload(this.renderer, texture, glTexture)) + if (texture.resource && texture.resource.upload(renderer, texture, glTexture)) { // texture is uploaded, dont do anything! } - else if (glTexture.width !== texture.realWidth - || glTexture.height !== texture.realHeight - || glTexture.dirtyId < 0) + else { // default, renderTexture-like logic - glTexture.uploadData(null, texture.realWidth, texture.realHeight); + const width = texture.realWidth; + const height = texture.realHeight; + const gl = renderer.gl; + + if (glTexture.width !== width + || glTexture.height !== height + || glTexture.dirtyId < 0) + { + glTexture.width = width; + glTexture.height = height; + + gl.texImage2D(texture.target, 0, + texture.format, + width, + height, + 0, + texture.format, + texture.type, + null); + } } // lets only update what changes.. @@ -213,6 +231,7 @@ { const glTexture = texture._glTextures[this.CONTEXT_UID]; + glTexture.mipmap = texture.mipmap && texture.isPowerOfTwo; if (!glTexture) { return; @@ -230,11 +249,11 @@ glTexture.dirtyStyleId = texture.dirtyStyleId; } - setStyle(texture) + setStyle(texture, glTexture) { const gl = this.gl; - if (texture.mipmap && texture.isPowerOfTwo) + if (glTexture.mipmap) { gl.generateMipmap(texture.target); } @@ -242,7 +261,7 @@ gl.texParameteri(texture.target, gl.TEXTURE_WRAP_S, texture.wrapMode); gl.texParameteri(texture.target, gl.TEXTURE_WRAP_T, texture.wrapMode); - if (texture.mipmap) + if (glTexture.mipmap) { /* eslint-disable max-len */ gl.texParameteri(texture.target, gl.TEXTURE_MIN_FILTER, texture.scaleMode ? gl.LINEAR_MIPMAP_LINEAR : gl.NEAREST_MIPMAP_NEAREST); diff --git a/packages/core/src/textures/resources/BaseImageResource.js b/packages/core/src/textures/resources/BaseImageResource.js index c3012b9..c5470ec 100644 --- a/packages/core/src/textures/resources/BaseImageResource.js +++ b/packages/core/src/textures/resources/BaseImageResource.js @@ -53,19 +53,21 @@ upload(renderer, baseTexture, glTexture, source) { const gl = renderer.gl; + const width = baseTexture.realWidth; + const height = baseTexture.realHeight; source = source || this.source; gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.premultiplyAlpha); - if (glTexture.width === baseTexture.width && glTexture.height === baseTexture.height) + if (glTexture.width === width && glTexture.height === height) { gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, baseTexture.type, source); } else { - glTexture.width = baseTexture.width; - glTexture.height = baseTexture.height; + glTexture.width = width; + glTexture.height = height; gl.texImage2D(gl.TEXTURE_2D, 0, baseTexture.format, baseTexture.format, baseTexture.type, source); }