Skip to content

NanoVG rend bug when draw a rectangle #10191

@Lander112233

Description

@Lander112233

LVGL version

Master

Platform

Linux, with Wayland EGL

What happened?

When I use NanoVG to draw a rectangle, thera is a rend bug, causing by rectangle boarder. For example, I draw a blue rectangle with orange boarder, here is the rend result:

Image

If I doesn't draw the boarder, the rectangle is rended very well.

And, I found the reason.

When using NanoVG, Stencil buffer will be cleared only once in function on_layer_changed.
When draw rectangle, NanoVG will:
1.Draw a FILL task first, with NVGwinding NVG_CCW;
2.Then draw the BOARDER task, outher rect, and inner rect, with NVGwinding NVG_CW;
3.The Stencil buffer will not be cleared after the Step 1. Somehow it affect the NVG_CW rend, causing the bug.
(AI said, Stencil buffer should be cleared before rening every frame. I really not familiar with OpenGL, I don't know if it is proper...)

The solution is sample, add glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); in function draw_execute in /lvgl/src/draw/nanovg/lv_draw_nanovg.c.

I need someone to make sure, that am I doing it right? Is it the right way to fix like this?

How to reproduce?

void show_rectangle(void) {
lv_obj_t *rect = lv_obj_create(lv_scr_act());
lv_obj_align(rect, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_size(rect, 200, 200);
lv_obj_set_style_bg_color(rect, lv_palette_main(LV_PALETTE_BLUE), 0);
lv_obj_set_style_border_width(rect, 20, 0);
lv_obj_set_style_border_color(rect, lv_palette_main(LV_PALETTE_ORANGE), 0);
}
int main(void) {
lv_init();
lv_drv_hal_init();
show_rectangle();
while (1) {
lv_timer_handler();
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions