From 2160c7f6d890c4f329124ea68434452ca14e74b1 Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Wed, 1 May 2024 14:58:23 +0200 Subject: [PATCH] clear out texture on first batch. This fixes aliasing artifacts due to incorrect blending of old texture --- samples/clock/src/main.c | 10 +++++----- src/graphics/wgpu_renderer.c | 27 ++++++++++++++++++++++++++- tests/perf/build.sh | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/samples/clock/src/main.c b/samples/clock/src/main.c index d2358c30..59091693 100644 --- a/samples/clock/src/main.c +++ b/samples/clock/src/main.c @@ -112,14 +112,14 @@ ORCA_EXPORT void oc_on_frame_refresh(void) oc_vec2 pos = oc_mat2x3_mul(transform, (oc_vec2){ clockRadius * 0.8f, 0 }); - oc_set_color_rgba(0.2, 0.2, 0.2, 1); + oc_set_color_srgba(0.2, 0.2, 0.2, 1); oc_text_fill(pos.x, pos.y, clockNumberStrings[i]); } // hours hand oc_matrix_multiply_push(mat_transform(centerX, centerY, hoursRotation)); { - oc_set_color_rgba(.2, 0.2, 0.2, 1); + oc_set_color_srgba(.2, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -7.5 * uiScale, clockRadius * 0.5f, 15 * uiScale, 5 * uiScale); } oc_matrix_pop(); @@ -127,7 +127,7 @@ ORCA_EXPORT void oc_on_frame_refresh(void) // minutes hand oc_matrix_multiply_push(mat_transform(centerX, centerY, minutesRotation)); { - oc_set_color_rgba(.2, 0.2, 0.2, 1); + oc_set_color_srgba(.2, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -5 * uiScale, clockRadius * 0.7f, 10 * uiScale, 5 * uiScale); } oc_matrix_pop(); @@ -135,12 +135,12 @@ ORCA_EXPORT void oc_on_frame_refresh(void) // seconds hand oc_matrix_multiply_push(mat_transform(centerX, centerY, secondsRotation)); { - oc_set_color_rgba(1, 0.2, 0.2, 1); + oc_set_color_srgba(1, 0.2, 0.2, 1); oc_rounded_rectangle_fill(0, -2.5 * uiScale, clockRadius * 0.8f, 5 * uiScale, 5 * uiScale); } oc_matrix_pop(); - oc_set_color_rgba(.2, 0.2, 0.2, 1); + oc_set_color_srgba(.2, 0.2, 0.2, 1); oc_circle_fill(centerX, centerY, 10 * uiScale); oc_canvas_render(renderer, context, surface); diff --git a/src/graphics/wgpu_renderer.c b/src/graphics/wgpu_renderer.c index 7189d530..6da79410 100644 --- a/src/graphics/wgpu_renderer.c +++ b/src/graphics/wgpu_renderer.c @@ -3327,7 +3327,32 @@ void oc_wgpu_canvas_submit(oc_canvas_renderer_base* rendererBase, } //---------------------------------------------------------------------------------------- - //NOTE: clear texture + //NOTE: clear out texture if this is the first batch + if(batchCount == 0) + { + //clear out texture + WGPURenderPassDescriptor desc = { + .colorAttachmentCount = 1, + .colorAttachments = (WGPURenderPassColorAttachment[]){ + { + .view = renderer->outTextureView, + .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED, + .loadOp = WGPULoadOp_Clear, + .storeOp = WGPUStoreOp_Store, + .clearValue = { 0, 0, 0, 0 }, + }, + }, + }; + + WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &desc); + { + wgpuRenderPassEncoderSetViewport(pass, 0.f, 0.f, screenSize.x, screenSize.y, 0.f, 1.f); + } + wgpuRenderPassEncoderEnd(pass); + } + + //---------------------------------------------------------------------------------------- + //NOTE: clear batch texture { WGPURenderPassDescriptor desc = { .colorAttachmentCount = 1, diff --git a/tests/perf/build.sh b/tests/perf/build.sh index 487a3baf..ddedc8f4 100755 --- a/tests/perf/build.sh +++ b/tests/perf/build.sh @@ -15,4 +15,4 @@ install_name_tool -add_rpath "@executable_path" $BINDIR/driver cp Info.plist $BINDIR/ cp $LIBDIR/liborca.dylib $BINDIR/ -cp $SRCDIR/ext/dawn/bin/libwebgpu.dylib $BINDIR/ +cp $LIBDIR/libwebgpu.dylib $BINDIR/