From 08eb4c66edc03363634ee7db722619391b5060af Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 21 Nov 2023 15:39:41 +0000 Subject: [PATCH 1/4] set and test size correctly --- src/platform/graphics/webgl/webgl-texture.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/graphics/webgl/webgl-texture.js b/src/platform/graphics/webgl/webgl-texture.js index 809bcc2b40d..3e345843f4c 100644 --- a/src/platform/graphics/webgl/webgl-texture.js +++ b/src/platform/graphics/webgl/webgl-texture.js @@ -512,10 +512,13 @@ class WebglTexture { } } + const w = mipObject.width || mipObject.videoWidth; + const h = mipObject.height || mipObject.videoHeight; + // Upload the image, canvas or video device.setUnpackFlipY(texture._flipY); device.setUnpackPremultiplyAlpha(texture._premultiplyAlpha); - if (this._glCreated && mipObject.width === texture._width && mipObject.height === texture._height) { + if (this._glCreated && texture._width === w && texture._height === h) { gl.texSubImage2D( gl.TEXTURE_2D, mipLevel, @@ -533,6 +536,9 @@ class WebglTexture { this._glPixelType, mipObject ); + + texture._width = w; + texture._height = h; } } else { // Upload the byte array @@ -562,7 +568,7 @@ class WebglTexture { } else { device.setUnpackFlipY(false); device.setUnpackPremultiplyAlpha(texture._premultiplyAlpha); - if (this._glCreated) { + if (this._glCreated && mipObject) { gl.texSubImage2D( gl.TEXTURE_2D, mipLevel, From 8c55baeb7031b3a44a2e6cf2112807bcc35b29dc Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 21 Nov 2023 16:33:49 +0000 Subject: [PATCH 2/4] revert --- examples/src/examples/graphics/video-texture.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/src/examples/graphics/video-texture.mjs b/examples/src/examples/graphics/video-texture.mjs index 73e5efdff6a..7c16a85c698 100644 --- a/examples/src/examples/graphics/video-texture.mjs +++ b/examples/src/examples/graphics/video-texture.mjs @@ -52,6 +52,7 @@ async function example({ canvas, assetPath }) { // Create a texture to hold the video frame data const videoTexture = new pc.Texture(app.graphicsDevice, { + name: 'video', format: pc.PIXELFORMAT_RGB565, mipmaps: false, minFilter: pc.FILTER_LINEAR, From 0a60236cc52128a405d416f415abdb4284344f19 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 21 Nov 2023 16:36:26 +0000 Subject: [PATCH 3/4] revert revert --- examples/src/examples/graphics/video-texture.mjs | 1 - src/platform/graphics/webgl/webgl-texture.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/src/examples/graphics/video-texture.mjs b/examples/src/examples/graphics/video-texture.mjs index 7c16a85c698..73e5efdff6a 100644 --- a/examples/src/examples/graphics/video-texture.mjs +++ b/examples/src/examples/graphics/video-texture.mjs @@ -52,7 +52,6 @@ async function example({ canvas, assetPath }) { // Create a texture to hold the video frame data const videoTexture = new pc.Texture(app.graphicsDevice, { - name: 'video', format: pc.PIXELFORMAT_RGB565, mipmaps: false, minFilter: pc.FILTER_LINEAR, diff --git a/src/platform/graphics/webgl/webgl-texture.js b/src/platform/graphics/webgl/webgl-texture.js index 3e345843f4c..76bf15404a2 100644 --- a/src/platform/graphics/webgl/webgl-texture.js +++ b/src/platform/graphics/webgl/webgl-texture.js @@ -568,7 +568,7 @@ class WebglTexture { } else { device.setUnpackFlipY(false); device.setUnpackPremultiplyAlpha(texture._premultiplyAlpha); - if (this._glCreated && mipObject) { + if (this._glCreated) { gl.texSubImage2D( gl.TEXTURE_2D, mipLevel, From 74a4a1a40bc74bab0a1b3d3e0952df2f1b9d0163 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 21 Nov 2023 16:54:14 +0000 Subject: [PATCH 4/4] only set width and height on level 0 --- src/platform/graphics/webgl/webgl-texture.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/graphics/webgl/webgl-texture.js b/src/platform/graphics/webgl/webgl-texture.js index 76bf15404a2..52e4a4e9198 100644 --- a/src/platform/graphics/webgl/webgl-texture.js +++ b/src/platform/graphics/webgl/webgl-texture.js @@ -537,8 +537,10 @@ class WebglTexture { mipObject ); - texture._width = w; - texture._height = h; + if (mipLevel === 0) { + texture._width = w; + texture._height = h; + } } } else { // Upload the byte array