Skip to content

Commit a76f61a

Browse files
committed
WebGL _uploadDirtyTextures
1 parent 507621a commit a76f61a

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/platform/graphics/webgl/webgl-graphics-device.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,22 @@ class WebglGraphicsDevice extends GraphicsDevice {
11451145
this.gpuProfiler.request();
11461146
}
11471147

1148+
_uploadDirtyTextures() {
1149+
1150+
this.textures.forEach((texture) => {
1151+
if (texture._needsUpload || texture._needsMipmapsUpload) {
1152+
if (!texture.impl._glTexture) {
1153+
texture.impl.initialize(this, texture);
1154+
}
1155+
1156+
this.bindTexture(texture);
1157+
texture.impl.upload(this, texture);
1158+
texture._needsUpload = false;
1159+
texture._needsMipmapsUpload = false;
1160+
}
1161+
});
1162+
}
1163+
11481164
/**
11491165
* Start a render pass.
11501166
*
@@ -1153,6 +1169,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
11531169
*/
11541170
startRenderPass(renderPass) {
11551171

1172+
this._uploadDirtyTextures();
1173+
11561174
// set up render target
11571175
const rt = renderPass.renderTarget ?? this.backBuffer;
11581176
this.renderTarget = rt;
@@ -1526,7 +1544,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
15261544
impl.initialize(this, texture);
15271545
}
15281546

1529-
if (impl.dirtyParameterFlags > 0 || texture._needsUpload || texture._needsMipmapsUpload) {
1547+
if (impl.dirtyParameterFlags > 0) {
15301548

15311549
// Ensure the specified texture unit is active
15321550
this.activeTexture(textureUnit);
@@ -1538,12 +1556,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
15381556
this.setTextureParameters(texture);
15391557
impl.dirtyParameterFlags = 0;
15401558
}
1541-
1542-
if (texture._needsUpload || texture._needsMipmapsUpload) {
1543-
impl.upload(this, texture);
1544-
texture._needsUpload = false;
1545-
texture._needsMipmapsUpload = false;
1546-
}
15471559
} else {
15481560
// Ensure the texture is currently bound to the correct target on the specified texture unit.
15491561
// If the texture is already bound to the correct target on the specified unit, there's no need

src/platform/graphics/webgl/webgl-render-target.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class WebglRenderTarget {
165165
colorBuffer._width = Math.min(colorBuffer.width, device.maxRenderBufferSize);
166166
colorBuffer._height = Math.min(colorBuffer.height, device.maxRenderBufferSize);
167167
device.setTexture(colorBuffer, 0);
168+
colorBuffer.upload(true);
168169
}
169170
// Attach the color buffer
170171
gl.framebufferTexture2D(
@@ -193,6 +194,7 @@ class WebglRenderTarget {
193194
depthBuffer._width = Math.min(depthBuffer.width, device.maxRenderBufferSize);
194195
depthBuffer._height = Math.min(depthBuffer.height, device.maxRenderBufferSize);
195196
device.setTexture(depthBuffer, 0);
197+
depthBuffer.upload(true);
196198
}
197199

198200
// Attach

src/platform/graphics/webgpu/webgpu-graphics-device.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ class WebgpuGraphicsDevice extends GraphicsDevice {
658658
_uploadDirtyTextures() {
659659

660660
this.textures.forEach((texture) => {
661-
if (texture._needsUpload || texture._needsMipmaps) {
661+
if (texture._needsUpload || texture._needsMipmapsUpload) {
662662
texture.upload();
663663
}
664664
});

0 commit comments

Comments
 (0)