--- a/src/glcontext.c Sun Jun 01 14:59:40 2025 +0200 +++ b/src/glcontext.c Sun Jun 01 16:35:23 2025 +0200 @@ -28,6 +28,8 @@ #include "ascension/glcontext.h" #include "ascension/error.h" +#include "ascension/2d/sprite.h" + #include <GL/glew.h> #include <cx/array_list.h> @@ -46,40 +48,17 @@ } static int asc_shader_initialize_predefined(AscGLContext *ctx) { + // TODO: check if we can replace that by lazy loading shaders just like fonts int ret = 0; - ret |= asc_shader_sprite_init(&ctx->shader.sprite); + ret |= asc_shader_sprite_init(&ctx->shader.sprite_uv, false); + ret |= asc_shader_sprite_init(&ctx->shader.sprite_rect, true); ret |= asc_error_catch_all_gl(); return ret; } static void asc_shader_destroy_predefined(AscGLContext *ctx) { - asc_shader_program_destroy(&ctx->shader.sprite.program); -} - -static int asc_texture_initialize_predefined(AscGLContext *ctx) { - asc_texture_init_rectangle(ctx->textures_rect, ASC_TEXTURE_RECT_COUNT); - asc_texture_init_2d(ctx->textures_2d, ASC_TEXTURE_2D_COUNT); - - // Create a 1x1 surface with 32-bit RGBA format - SDL_Surface* white1x1 = SDL_CreateRGBSurface( - 0, 1, 1, 32, - 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); - if (white1x1 == NULL) { - asc_error("Failed to create surface: %s", SDL_GetError()); - return 1; - } - SDL_FillRect(white1x1, NULL, 0xFFFFFFFF); - - // Initialize the empty textures with the white surface - asc_texture_from_surface(&ctx->textures_rect[ASC_TEXTURE_RECT_EMPTY_1X1_IDX], white1x1); - asc_texture_from_surface(&ctx->textures_2d[ASC_TEXTURE_2D_EMPTY_1X1_IDX], white1x1); - - return asc_error_catch_all_gl(); -} - -static void asc_texture_destroy_predefined(AscGLContext *ctx) { - asc_texture_destroy(ctx->textures_rect, ASC_TEXTURE_RECT_COUNT); - asc_texture_destroy(ctx->textures_2d, ASC_TEXTURE_2D_COUNT); + asc_shader_program_destroy(&ctx->shader.sprite_uv.program); + asc_shader_program_destroy(&ctx->shader.sprite_rect.program); } struct asc_gl_context_cleanup_data { @@ -136,11 +115,6 @@ return false; } - if (asc_texture_initialize_predefined(ctx)) { - asc_error("Initializing predefined textures failed"); - return false; - } - ctx->cleanup_funcs = cxArrayListCreateSimple(sizeof(struct asc_gl_context_cleanup_data), 8); cxDefineDestructor(ctx->cleanup_funcs, asc_gl_context_cleanup); @@ -157,7 +131,6 @@ SDL_GL_MakeCurrent(ctx->window, ctx->glctx); cxListFree(ctx->cleanup_funcs); - asc_texture_destroy_predefined(ctx); asc_shader_destroy_predefined(ctx); // destroy the GL context and the window