# HG changeset patch # User Mike Becker # Date 1745445574 -7200 # Node ID 52611a99e574e69903c382fcc5297a748240ff0a # Parent 78ce93fb46e5fa5c476f7cca0db4b6bd3c45bf58 add memory pool to gl context diff -r 78ce93fb46e5 -r 52611a99e574 src/ascension/glcontext.h --- a/src/ascension/glcontext.h Wed Apr 23 23:43:45 2025 +0200 +++ b/src/ascension/glcontext.h Wed Apr 23 23:59:34 2025 +0200 @@ -34,6 +34,8 @@ #include "shader.h" #include "texture.h" +#include + typedef struct AscGLContextSettings { int gl_major_version; int gl_minor_version; @@ -58,6 +60,7 @@ typedef struct AscGLContext { SDL_Window *window; + CxMempool *mpool; SDL_GLContext glctx; AscMesh primitives[ASC_PRIMITIVE_COUNT]; AscTexture textures_2d[ASC_TEXTURE_2D_COUNT]; @@ -68,6 +71,7 @@ } AscGLContext; #define asc_active_glctx (&asc_active_window->glctx) +#define asc_active_glctx_mpool asc_active_window->glctx.mpool #define ASC_PRIMITIVE_PLANE (&asc_active_glctx->primitives[ASC_PRIMITIVE_PLANE_IDX]) #define ASC_TEXTURE_2D_EMPTY_1X1 (&asc_active_glctx->textures_2d[ASC_TEXTURE_2D_EMPTY_1X1_IDX]) #define ASC_TEXTURE_RECT_EMPTY_1X1 (&asc_active_glctx->textures_rect[ASC_TEXTURE_RECT_EMPTY_1X1_IDX]) diff -r 78ce93fb46e5 -r 52611a99e574 src/glcontext.c --- a/src/glcontext.c Wed Apr 23 23:43:45 2025 +0200 +++ b/src/glcontext.c Wed Apr 23 23:59:34 2025 +0200 @@ -138,6 +138,8 @@ return false; } + ctx->mpool = cxMempoolCreateSimple(128); + return true; } else { asc_error("glewInit failed: %s", glewGetErrorString(err)); @@ -150,6 +152,8 @@ if (ctx->glctx == NULL) return; SDL_GL_MakeCurrent(ctx->window, ctx->glctx); + cxMempoolFree(ctx->mpool); + ctx->mpool = NULL; asc_texture_destroy_predefined(ctx); asc_shader_destroy_predefined(ctx); asc_primitives_destroy(ctx); diff -r 78ce93fb46e5 -r 52611a99e574 test/snake/snake.c --- a/test/snake/snake.c Wed Apr 23 23:43:45 2025 +0200 +++ b/test/snake/snake.c Wed Apr 23 23:59:34 2025 +0200 @@ -37,13 +37,14 @@ static AscTexture tex2d[TEX2D_COUNT]; #define TEXTURE_SHIP &tex2d[TEX_SHIP] +static void destroy_textures(void *dummy) { + asc_texture_destroy(tex2d, TEX2D_COUNT); +} + static void init_textures(void) { asc_texture_init_2d(tex2d, TEX2D_COUNT); asc_texture_from_file(TEXTURE_SHIP, "ship.png"); -} - -static void destroy_textures(void) { - asc_texture_destroy(tex2d, TEX2D_COUNT); + cxMempoolRegister(asc_active_glctx_mpool, tex2d, destroy_textures); } static void update_fps_counter(AscSceneNode *node) { @@ -155,7 +156,6 @@ } while (asc_loop_next()); // cleanup - destroy_textures(); asc_context_destroy(); return 0; }