Skip to content

Commit 42a9abf

Browse files
committed
WebGL _uploadDirtyTextures
1 parent 7f72c3f commit 42a9abf

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

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

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

1173+
_uploadDirtyTextures() {
1174+
1175+
this.textures.forEach((texture) => {
1176+
if (texture._needsUpload || texture._needsMipmapsUpload) {
1177+
if (!texture.impl._glTexture) {
1178+
texture.impl.initialize(this, texture);
1179+
}
1180+
1181+
this.bindTexture(texture);
1182+
texture.impl.upload(this, texture);
1183+
texture._needsUpload = false;
1184+
texture._needsMipmapsUpload = false;
1185+
}
1186+
});
1187+
}
1188+
11731189
/**
11741190
* Start a render pass.
11751191
*
@@ -1181,6 +1197,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
11811197
DebugGraphics.pushGpuMarker(this, `Pass:${renderPass.name}`);
11821198
DebugGraphics.pushGpuMarker(this, `START-PASS`);
11831199

1200+
this._uploadDirtyTextures();
1201+
11841202
// set up render target
11851203
const rt = renderPass.renderTarget ?? this.backBuffer;
11861204
this.renderTarget = rt;
@@ -1543,7 +1561,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
15431561
if (!impl._glTexture)
15441562
impl.initialize(this, texture);
15451563

1546-
if (impl.dirtyParameterFlags > 0 || texture._needsUpload || texture._needsMipmapsUpload) {
1564+
if (impl.dirtyParameterFlags > 0) {
15471565

15481566
// Ensure the specified texture unit is active
15491567
this.activeTexture(textureUnit);
@@ -1555,12 +1573,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
15551573
this.setTextureParameters(texture);
15561574
impl.dirtyParameterFlags = 0;
15571575
}
1558-
1559-
if (texture._needsUpload || texture._needsMipmapsUpload) {
1560-
impl.upload(this, texture);
1561-
texture._needsUpload = false;
1562-
texture._needsMipmapsUpload = false;
1563-
}
15641576
} else {
15651577
// Ensure the texture is currently bound to the correct target on the specified texture unit.
15661578
// 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
@@ -150,6 +150,7 @@ class WebglRenderTarget {
150150
colorBuffer._width = Math.min(colorBuffer.width, device.maxRenderBufferSize);
151151
colorBuffer._height = Math.min(colorBuffer.height, device.maxRenderBufferSize);
152152
device.setTexture(colorBuffer, 0);
153+
colorBuffer.upload(true);
153154
}
154155
// Attach the color buffer
155156
gl.framebufferTexture2D(
@@ -174,6 +175,7 @@ class WebglRenderTarget {
174175
depthBuffer._width = Math.min(depthBuffer.width, device.maxRenderBufferSize);
175176
depthBuffer._height = Math.min(depthBuffer.height, device.maxRenderBufferSize);
176177
device.setTexture(depthBuffer, 0);
178+
depthBuffer.upload(true);
177179
}
178180
// Attach
179181
if (target._stencil) {

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

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

621621
this.textures.forEach((texture) => {
622-
if (texture._needsUpload || texture._needsMipmaps) {
622+
if (texture._needsUpload || texture._needsMipmapsUpload) {
623623
texture.upload();
624624
}
625625
});

0 commit comments

Comments
 (0)