Create app's canvas surface on demand, like the gles one

This commit is contained in:
Martin Fouilleul 2023-08-03 13:42:47 +02:00
parent 754dfc2f0e
commit a33a978415
2 changed files with 14 additions and 26 deletions

View File

@ -170,11 +170,6 @@ void orca_log(log_level level,
msg); msg);
} }
mg_surface orca_surface_canvas(void)
{
return(__orcaApp.surface);
}
typedef struct orca_surface_create_data typedef struct orca_surface_create_data
{ {
mp_window window; mp_window window;
@ -183,13 +178,25 @@ typedef struct orca_surface_create_data
} orca_surface_create_data; } orca_surface_create_data;
i32 orca_surface_gles_callback(void* user) i32 orca_surface_callback(void* user)
{ {
orca_surface_create_data* data = (orca_surface_create_data*)user; orca_surface_create_data* data = (orca_surface_create_data*)user;
data->surface = mg_surface_create_for_window(data->window, data->api); data->surface = mg_surface_create_for_window(data->window, data->api);
return(0); return(0);
} }
mg_surface orca_surface_canvas(void)
{
orca_surface_create_data data = {
.surface = mg_surface_nil(),
.window = __orcaApp.window,
.api = MG_CANVAS
};
mp_dispatch_on_main_thread_sync(orca_surface_callback, (void*)&data);
return(data.surface);
}
mg_surface orca_surface_gles(void) mg_surface orca_surface_gles(void)
{ {
orca_surface_create_data data = { orca_surface_create_data data = {
@ -198,7 +205,7 @@ mg_surface orca_surface_gles(void)
.api = MG_GLES .api = MG_GLES
}; };
mp_dispatch_on_main_thread_sync(orca_surface_gles_callback, (void*)&data); mp_dispatch_on_main_thread_sync(orca_surface_callback, (void*)&data);
return(data.surface); return(data.surface);
} }
@ -478,9 +485,6 @@ i32 orca_runloop(void* user)
app->rootDir = cmp.handle; app->rootDir = cmp.handle;
} }
//NOTE: prepare GL surface
mg_surface_prepare(app->surface);
IM3Function* exports = app->runtime.exports; IM3Function* exports = app->runtime.exports;
//NOTE: call init handler //NOTE: call init handler
@ -759,7 +763,6 @@ i32 orca_runloop(void* user)
if(exports[G_EXPORT_FRAME_REFRESH]) if(exports[G_EXPORT_FRAME_REFRESH])
{ {
mg_surface_prepare(app->surface);
m3_Call(exports[G_EXPORT_FRAME_REFRESH], 0, 0); m3_Call(exports[G_EXPORT_FRAME_REFRESH], 0, 0);
} }
@ -788,11 +791,6 @@ int main(int argc, char** argv)
mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610}; mp_rect windowRect = {.x = 100, .y = 100, .w = 810, .h = 610};
app->window = mp_window_create(windowRect, "orca", 0); app->window = mp_window_create(windowRect, "orca", 0);
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.show = false;
app->debugOverlay.surface = mg_surface_create_for_window(app->window, MG_CANVAS); app->debugOverlay.surface = mg_surface_create_for_window(app->window, MG_CANVAS);
app->debugOverlay.canvas = mg_canvas_create(); app->debugOverlay.canvas = mg_canvas_create();
@ -812,11 +810,6 @@ int main(int argc, char** argv)
for(int i=0; i<3; i++) for(int i=0; i<3; i++)
{ {
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(app->debugOverlay.surface); mg_surface_prepare(app->debugOverlay.surface);
mg_canvas_set_current(app->debugOverlay.canvas); mg_canvas_set_current(app->debugOverlay.canvas);
mg_render(app->debugOverlay.surface, app->debugOverlay.canvas); mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
@ -840,9 +833,6 @@ int main(int argc, char** argv)
mp_thread_join(runloopThread, NULL); mp_thread_join(runloopThread, NULL);
mg_canvas_destroy(app->canvas);
mg_surface_destroy(app->surface);
mg_canvas_destroy(app->debugOverlay.canvas); mg_canvas_destroy(app->debugOverlay.canvas);
mg_surface_destroy(app->debugOverlay.surface); mg_surface_destroy(app->debugOverlay.surface);

View File

@ -112,8 +112,6 @@ typedef struct orca_debug_overlay
typedef struct orca_app typedef struct orca_app
{ {
mp_window window; mp_window window;
mg_surface surface;
mg_canvas canvas;
file_table fileTable; file_table fileTable;
file_handle rootDir; file_handle rootDir;