Skip to content

Commit e7c1d6b

Browse files
committed
Fix usage of textures in setup
1 parent 397c1d8 commit e7c1d6b

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/webgpu/p5.RendererWebGPU.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class RendererWebGPU extends Renderer3D {
3636
// TODO disablable stencil
3737
this.depthFormat = 'depth24plus-stencil8';
3838
this._updateSize();
39+
this._update();
3940
}
4041

4142
_updateSize() {
@@ -662,6 +663,15 @@ class RendererWebGPU extends Renderer3D {
662663
this.queue.submit([commandEncoder.finish()]);
663664
}
664665

666+
async ensureTexture(source) {
667+
await this.queue.onSubmittedWorkDone();
668+
await new Promise((res) => requestAnimationFrame(res));
669+
const tex = this.getTexture(source);
670+
tex.update();
671+
await this.queue.onSubmittedWorkDone();
672+
await new Promise((res) => requestAnimationFrame(res));
673+
}
674+
665675
//////////////////////////////////////////////
666676
// SHADER
667677
//////////////////////////////////////////////
@@ -885,7 +895,6 @@ class RendererWebGPU extends Renderer3D {
885895
}
886896

887897
uploadTextureFromSource({ gpuTexture }, source) {
888-
this.uploadedTexture = true;
889898
this.queue.copyExternalImageToTexture(
890899
{ source },
891900
{ texture: gpuTexture },
@@ -894,7 +903,6 @@ class RendererWebGPU extends Renderer3D {
894903
}
895904

896905
uploadTextureFromData({ gpuTexture }, data, width, height) {
897-
this.uploadedTexture = true;
898906
this.queue.writeTexture(
899907
{ texture: gpuTexture },
900908
data,
@@ -1118,6 +1126,9 @@ function rendererWebGPU(p5, fn) {
11181126
p5.RendererWebGPU = RendererWebGPU;
11191127

11201128
p5.renderers[constants.WEBGPU] = p5.RendererWebGPU;
1129+
fn.ensureTexture = function(source) {
1130+
return this._renderer.ensureTexture(source);
1131+
}
11211132
}
11221133

11231134
export default rendererWebGPU;

test/unit/visual/cases/webgpu.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ visualSuite('WebGPU', function() {
8383
screenshot();
8484
});
8585

86-
// TODO: turns out textures are only available in the next animation frame!
87-
// need to figure out a workaround before uncommenting this test.
88-
/*visualTest('Textures in the material shader work', async function(p5, screenshot) {
86+
visualTest('Textures in the material shader work', async function(p5, screenshot) {
8987
await p5.createCanvas(50, 50, p5.WEBGPU);
9088
const tex = p5.createImage(50, 50);
9189
tex.loadPixels();
@@ -103,6 +101,6 @@ visualSuite('WebGPU', function() {
103101
p5.plane(p5.width, p5.height);
104102

105103
screenshot();
106-
});*/
104+
});
107105
});
108106
});
275 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)