Skip to content

Commit

Permalink
clear out texture on first batch. This fixes aliasing artifacts due t…
Browse files Browse the repository at this point in the history
…o incorrect blending of old texture
  • Loading branch information
martinfouilleul committed May 1, 2024
1 parent 05d9c23 commit 2160c7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
10 changes: 5 additions & 5 deletions samples/clock/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,35 @@ 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();

// 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();

// 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);
Expand Down
27 changes: 26 additions & 1 deletion src/graphics/wgpu_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/perf/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/

0 comments on commit 2160c7f

Please sign in to comment.