Skip to content

Commit 0713f64

Browse files
committed
WebGL _uploadDirtyTextures
1 parent ccf2af7 commit 0713f64

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

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

+19-7
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,22 @@ class WebglGraphicsDevice extends GraphicsDevice {
11411141
this.gpuProfiler.request();
11421142
}
11431143

1144+
_uploadDirtyTextures() {
1145+
1146+
this.textures.forEach((texture) => {
1147+
if (texture._needsUpload || texture._needsMipmapsUpload) {
1148+
if (!texture.impl._glTexture) {
1149+
texture.impl.initialize(this, texture);
1150+
}
1151+
1152+
this.bindTexture(texture);
1153+
texture.impl.upload(this, texture);
1154+
texture._needsUpload = false;
1155+
texture._needsMipmapsUpload = false;
1156+
}
1157+
});
1158+
}
1159+
11441160
/**
11451161
* Start a render pass.
11461162
*
@@ -1152,6 +1168,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
11521168
DebugGraphics.pushGpuMarker(this, `Pass:${renderPass.name}`);
11531169
DebugGraphics.pushGpuMarker(this, 'START-PASS');
11541170

1171+
this._uploadDirtyTextures();
1172+
11551173
// set up render target
11561174
const rt = renderPass.renderTarget ?? this.backBuffer;
11571175
this.renderTarget = rt;
@@ -1515,7 +1533,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
15151533
impl.initialize(this, texture);
15161534
}
15171535

1518-
if (impl.dirtyParameterFlags > 0 || texture._needsUpload || texture._needsMipmapsUpload) {
1536+
if (impl.dirtyParameterFlags > 0) {
15191537

15201538
// Ensure the specified texture unit is active
15211539
this.activeTexture(textureUnit);
@@ -1527,12 +1545,6 @@ class WebglGraphicsDevice extends GraphicsDevice {
15271545
this.setTextureParameters(texture);
15281546
impl.dirtyParameterFlags = 0;
15291547
}
1530-
1531-
if (texture._needsUpload || texture._needsMipmapsUpload) {
1532-
impl.upload(this, texture);
1533-
texture._needsUpload = false;
1534-
texture._needsMipmapsUpload = false;
1535-
}
15361548
} else {
15371549
// Ensure the texture is currently bound to the correct target on the specified texture unit.
15381550
// 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

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class WebglRenderTarget {
152152
colorBuffer._width = Math.min(colorBuffer.width, device.maxRenderBufferSize);
153153
colorBuffer._height = Math.min(colorBuffer.height, device.maxRenderBufferSize);
154154
device.setTexture(colorBuffer, 0);
155+
colorBuffer.upload(true);
155156
}
156157
// Attach the color buffer
157158
gl.framebufferTexture2D(
@@ -176,6 +177,7 @@ class WebglRenderTarget {
176177
depthBuffer._width = Math.min(depthBuffer.width, device.maxRenderBufferSize);
177178
depthBuffer._height = Math.min(depthBuffer.height, device.maxRenderBufferSize);
178179
device.setTexture(depthBuffer, 0);
180+
depthBuffer.upload(true);
179181
}
180182
// Attach
181183
if (target._stencil) {

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

+1-1
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)