diff -r 9f7bfc0a1dc3 -r 84a546e282b7 src/glcontext.c --- a/src/glcontext.c Fri Apr 18 19:34:31 2025 +0200 +++ b/src/glcontext.c Fri Apr 18 20:13:01 2025 +0200 @@ -48,9 +48,25 @@ cx_strfree(&buf); } +static int asc_primitives_init(AscGLContext *context) { + asc_dprintf("Create primitives for the GL context of active window."); + asc_mesh_allocate_buffers((AscMesh*)&context->primitives, sizeof(context->primitives) / sizeof(AscMesh)); + + asc_primitives_init_plane(&context->primitives.plane); + // TODO: more primitives + + return asc_error_catch_all_gl(); +} + +static void asc_primitives_destroy(AscGLContext *context) { + asc_dprintf("Destroy primitives in GL context of active window."); + asc_mesh_free_buffers((AscMesh*)&context->primitives, sizeof(context->primitives) / sizeof(AscMesh)); +} + static int asc_shader_initialize_predefined(AscGLContext *ctx) { int ret = 0; ret |= asc_shader_sprite_init(&ctx->shader.sprite); + ret |= asc_error_catch_all_gl(); return ret; } @@ -81,13 +97,14 @@ glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(asc_gl_debug_callback, NULL); - if (!asc_primitives_init(&ctx->primitives)) { + if (asc_primitives_init(ctx)) { asc_error("Creating primitive meshes failed"); SDL_GL_DeleteContext(ctx->glctx); return false; } if (asc_shader_initialize_predefined(ctx)) { + asc_error("Initializing predefined shaders failed"); SDL_GL_DeleteContext(ctx->glctx); return false; } @@ -105,7 +122,7 @@ SDL_GL_MakeCurrent(ctx->window, ctx->glctx); asc_shader_destroy_predefined(ctx); - asc_primitives_destroy(&ctx->primitives); + asc_primitives_destroy(ctx); // destroy the GL context and the window SDL_GL_DeleteContext(ctx->glctx);