[wip, win32] got debug overlay ~working, with a couple hacks: use top-level transparent windows as child windows (see milepost), and create a dummy surface just to deselect normal and debug surface before using them in render thread. TODO: make an API for deselecting those surfaces. Investigate multisurface options more...

This commit is contained in:
martinfouilleul 2023-06-21 19:27:15 +02:00
parent a09b10714c
commit 238963df0b
2 changed files with 38 additions and 95 deletions

@ -1 +1 @@
Subproject commit 0366e3d724ec4a305b69857f1aecd1d65281c3bc
Subproject commit 83f128fb55c6eec7c8ac3e17e9926d6c740fe9e8

View File

@ -475,6 +475,7 @@ void* orca_runloop(void* user)
mp_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0)
{
if(app->debugOverlay.show)
{
ui_process_event(event);
@ -568,30 +569,9 @@ void* orca_runloop(void* user)
if(eventHandlers[G_EVENT_FRAME_REFRESH])
{
// m3_Call(eventHandlers[G_EVENT_FRAME_REFRESH], 0, 0);
m3_Call(eventHandlers[G_EVENT_FRAME_REFRESH], 0, 0);
}
mg_canvas_set_current(app->canvas);
mg_surface_prepare(app->surface);
mg_set_color_rgba(0, 0, 0, 0);
mg_clear();
mg_render(app->surface, app->canvas);
mg_surface_present(app->surface);
mg_canvas_set_current(app->debugOverlay.canvas);
mg_surface_prepare(app->debugOverlay.surface);
mg_set_color_rgba(1, 0, 0, 0);
mg_clear();
// mg_set_color_rgba(1, 0, 0, 1);
// mg_rectangle_fill(10, 10, 300, 200);
mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
mg_surface_present(app->debugOverlay.surface);
/*
if(app->debugOverlay.show)
{
ui_style debugUIDefaultStyle = {.bgColor = {0},
@ -724,17 +704,12 @@ void* orca_runloop(void* user)
mg_surface_prepare(app->debugOverlay.surface);
mg_canvas_set_current(app->debugOverlay.canvas);
// ui_draw();
mg_set_color_rgba(0, 0, 0, 0);
mg_clear();
mg_set_color_rgba(1, 0, 0, 1);
mg_rectangle_fill(10, 10, 300, 200);
ui_draw();
mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
mg_surface_present(app->debugOverlay.surface);
}
*/
mem_arena_clear(mem_scratch());
}
@ -748,100 +723,68 @@ int main(int argc, char** argv)
mp_init();
mp_clock_init();
orca_app* orca = &__orcaApp;
orca_app* app = &__orcaApp;
//NOTE: create window and surfaces
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
orca->window = mp_window_create(windowRect, "orca", 0);
app->window = mp_window_create(windowRect, "orca", 0);
orca->surface = mg_surface_create_for_window(orca->window, MG_CANVAS);
orca->canvas = mg_canvas_create();
mg_surface_swap_interval(orca->surface, 1);
app->surface = mg_surface_create_for_window(app->window, MG_CANVAS);
app->canvas = mg_canvas_create();
mg_surface_swap_interval(app->surface, 1);
app->debugOverlay.show = false;
app->debugOverlay.surface = mg_surface_create_for_window(app->window, MG_CANVAS);
app->debugOverlay.canvas = mg_canvas_create();
app->debugOverlay.fontReg = orca_font_create("../resources/Menlo.ttf");
app->debugOverlay.fontBold = orca_font_create("../resources/Menlo Bold.ttf");
app->debugOverlay.maxEntries = 200;
mem_arena_init(&app->debugOverlay.logArena);
orca->debugOverlay.show = true;
orca->debugOverlay.surface = mg_surface_create_for_window(orca->window, MG_CANVAS);
orca->debugOverlay.canvas = mg_canvas_create();
// orca->debugOverlay.fontReg = orca_font_create("../resources/Menlo.ttf");
// orca->debugOverlay.fontBold = orca_font_create("../resources/Menlo Bold.ttf");
orca->debugOverlay.maxEntries = 200;
mem_arena_init(&orca->debugOverlay.logArena);
mg_surface_swap_interval(app->debugOverlay.surface, 0);
mg_surface_swap_interval(orca->debugOverlay.surface, 1);
mg_surface_set_hidden(app->debugOverlay.surface, true);
// mg_surface_set_hidden(orca->debugOverlay.surface, true);
mg_surface dummy = mg_surface_create_for_window(app->window, MG_CANVAS);
//WARN: this is a workaround to avoid stalling the first few times we acquire drawables from
// the surfaces... This should probably be fixed in the implementation of mtl_surface!
/*
for(int i=0; i<4; i++)
{
mg_surface_prepare(orca->surface);
mg_canvas_set_current(orca->canvas);
mg_render(orca->surface, orca->canvas);
mg_surface_present(orca->surface);
mg_surface_prepare(app->surface);
mg_canvas_set_current(app->canvas);
mg_render(app->surface, app->canvas);
mg_surface_present(app->surface);
mg_surface_prepare(orca->debugOverlay.surface);
mg_canvas_set_current(orca->debugOverlay.canvas);
mg_render(orca->debugOverlay.surface, orca->debugOverlay.canvas);
mg_surface_present(orca->debugOverlay.surface);
mg_surface_prepare(app->debugOverlay.surface);
mg_canvas_set_current(app->debugOverlay.canvas);
mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
mg_surface_present(app->debugOverlay.surface);
}
//*/
// ui_init(&orca->debugOverlay.ui);
ui_init(&app->debugOverlay.ui);
//NOTE: show window and start runloop
mp_window_bring_to_front(orca->window);
mp_window_focus(orca->window);
mp_window_center(orca->window);
mp_window_bring_to_front(app->window);
mp_window_focus(app->window);
mp_window_center(app->window);
// pthread_t runloopThread;
// pthread_create(&runloopThread, 0, orca_runloop, 0);
pthread_t runloopThread;
pthread_create(&runloopThread, 0, orca_runloop, 0);
while(!mp_should_quit())
{
mp_pump_events(0);
//TODO: what to do with mem scratch here?
mp_event* event = 0;
while((event = mp_next_event(mem_scratch())) != 0)
{
switch(event->type)
{
case MP_EVENT_WINDOW_CLOSE:
{
mp_request_quit();
} break;
default:
break;
}
}
mg_surface_prepare(orca->surface);
mg_canvas_set_current(orca->canvas);
mg_set_color_rgba(0, 1, 0, 1);
mg_clear();
mg_render(orca->surface, orca->canvas);
mg_surface_present(orca->surface);
mg_surface_prepare(orca->debugOverlay.surface);
mg_canvas_set_current(orca->debugOverlay.canvas);
mg_set_color_rgba(0, 0, 0, 0);
mg_clear();
mg_set_color_rgba(1, 0, 0, 1);
mg_rectangle_fill(100, 100, 200, 100);
mg_render(orca->debugOverlay.surface, orca->debugOverlay.canvas);
mg_surface_present(orca->debugOverlay.surface);
}
void* res;
// pthread_join(runloopThread, &res);
pthread_join(runloopThread, &res);
// mg_canvas_destroy(orca->canvas);
// mg_surface_destroy(orca->surface);
mp_window_destroy(orca->window);
// mg_canvas_destroy(app->canvas);
// mg_surface_destroy(app->surface);
mp_window_destroy(app->window);
mp_terminate();
return(0);