[canvas/surface cleanup]
- properly destroy gl canvas backend - properly destroy gl surface
This commit is contained in:
parent
af7cbae1fa
commit
08d3521b61
|
@ -238,6 +238,8 @@ int main()
|
|||
frameTime = mp_get_time(MP_CLOCK_MONOTONIC) - startTime;
|
||||
}
|
||||
|
||||
mg_canvas_destroy(canvas);
|
||||
mg_surface_destroy(surface);
|
||||
mp_terminate();
|
||||
|
||||
return(0);
|
||||
|
|
|
@ -17,19 +17,20 @@ typedef struct mg_gl_canvas_backend
|
|||
mg_canvas_backend interface;
|
||||
mg_surface surface;
|
||||
|
||||
GLint dummyVertexBuffer;
|
||||
GLint vertexBuffer;
|
||||
GLint shapeBuffer;
|
||||
GLint indexBuffer;
|
||||
GLint tileCounterBuffer;
|
||||
GLint tileArrayBuffer;
|
||||
GLint clearCounterProgram;
|
||||
GLint tileProgram;
|
||||
GLint sortProgram;
|
||||
GLint drawProgram;
|
||||
GLint blitProgram;
|
||||
GLuint vao;
|
||||
GLuint dummyVertexBuffer;
|
||||
GLuint vertexBuffer;
|
||||
GLuint shapeBuffer;
|
||||
GLuint indexBuffer;
|
||||
GLuint tileCounterBuffer;
|
||||
GLuint tileArrayBuffer;
|
||||
GLuint clearCounterProgram;
|
||||
GLuint tileProgram;
|
||||
GLuint sortProgram;
|
||||
GLuint drawProgram;
|
||||
GLuint blitProgram;
|
||||
|
||||
GLint outTexture;
|
||||
GLuint outTexture;
|
||||
|
||||
char* indexMapping;
|
||||
char* vertexMapping;
|
||||
|
@ -255,7 +256,21 @@ void mg_gl_canvas_destroy(mg_canvas_backend* interface)
|
|||
{
|
||||
mg_gl_canvas_backend* backend = (mg_gl_canvas_backend*)interface;
|
||||
|
||||
//TODO
|
||||
glDeleteTextures(1, &backend->outTexture);
|
||||
|
||||
glDeleteBuffers(1, &backend->dummyVertexBuffer);
|
||||
glDeleteBuffers(1, &backend->vertexBuffer);
|
||||
glDeleteBuffers(1, &backend->shapeBuffer);
|
||||
glDeleteBuffers(1, &backend->indexBuffer);
|
||||
glDeleteBuffers(1, &backend->tileCounterBuffer);
|
||||
glDeleteBuffers(1, &backend->tileArrayBuffer);
|
||||
|
||||
glDeleteVertexArrays(1, &backend->vao);
|
||||
|
||||
free(backend->shapeMapping);
|
||||
free(backend->vertexMapping);
|
||||
free(backend->indexMapping);
|
||||
free(backend);
|
||||
}
|
||||
|
||||
void mg_gl_canvas_atlas_upload(mg_canvas_backend* interface, mp_rect rect, u8* bytes)
|
||||
|
@ -391,9 +406,8 @@ mg_canvas_backend* mg_gl_canvas_create(mg_surface surface)
|
|||
|
||||
mg_surface_prepare(surface);
|
||||
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glGenVertexArrays(1, &backend->vao);
|
||||
glBindVertexArray(backend->vao);
|
||||
|
||||
glGenBuffers(1, &backend->dummyVertexBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, backend->dummyVertexBuffer);
|
||||
|
@ -444,10 +458,7 @@ mg_canvas_backend* mg_gl_canvas_create(mg_surface surface)
|
|||
|
||||
if(err)
|
||||
{
|
||||
free(backend->shapeMapping);
|
||||
free(backend->vertexMapping);
|
||||
free(backend->indexMapping);
|
||||
free(backend);
|
||||
mg_gl_canvas_destroy((mg_canvas_backend*)backend);
|
||||
backend = 0;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
GL_PROC(GLBINDBUFFER, glBindBuffer) \
|
||||
GL_PROC(GLBUFFERDATA, glBufferData) \
|
||||
GL_PROC(GLBUFFERSUBDATA, glBufferSubData) \
|
||||
GL_PROC(GLDELETEVERTEXARRAYS, glDeleteVertexArrays) \
|
||||
GL_PROC(GLDELETEBUFFERS, glDeleteBuffers) \
|
||||
GL_PROC(GLUNIFORMMATRIX4FV, glUniformMatrix4fv) \
|
||||
GL_PROC(GLVERTEXATTRIBPOINTER, glVertexAttribPointer) \
|
||||
GL_PROC(GLENABLEVERTEXATTRIBARRAY, glEnableVertexAttribArray) \
|
||||
|
|
|
@ -26,7 +26,13 @@ typedef struct mg_gl_surface
|
|||
void mg_gl_surface_destroy(mg_surface_data* interface)
|
||||
{
|
||||
mg_gl_surface* surface = (mg_gl_surface*)interface;
|
||||
//TODO
|
||||
|
||||
if(surface->glContext == wglGetCurrentContext())
|
||||
{
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
}
|
||||
wglDeleteContext(surface->glContext);
|
||||
free(surface);
|
||||
}
|
||||
|
||||
void mg_gl_surface_prepare(mg_surface_data* interface)
|
||||
|
|
12
todo.txt
12
todo.txt
|
@ -3,7 +3,8 @@ Overview
|
|||
--------
|
||||
[x] Pan/Zoom on text example
|
||||
[.] Clean+Fixes of canvas code and examples
|
||||
[ ] Make backend selection easier
|
||||
|
||||
[>] Make backend selection easier
|
||||
|
||||
[ ] Image API and backend
|
||||
[ ] Build image atlas on top
|
||||
|
@ -12,14 +13,15 @@ Overview
|
|||
[ ] Allow different versions of GL to co-exist
|
||||
[?] Backport canvas to GLES
|
||||
|
||||
[ ] Back surface by child windows and implement moving frame/hiding/overlay
|
||||
|
||||
[ ] Delegated drawing API+Impl
|
||||
|
||||
Clean+Fixes
|
||||
-----------
|
||||
|
||||
[x] Rename MG_GL_CANVAS_TILE_ARRAY_SIZE/LENGTH unambiguously and make it consistent between C and glsl code
|
||||
|
||||
[.] Clean shaders (folder/filenames, version string, debug flags, ...)
|
||||
[x] Clean shaders (folder/filenames, version string, debug flags, ...)
|
||||
[x] Simplify shader names, prefix embedded strings by "glsl_"
|
||||
[x] Extract shader compilation in a function
|
||||
[x] Add version strings/common structs in canvas code (maybe revisit later when we have multiple versions, but ok for now)
|
||||
|
@ -28,6 +30,10 @@ Clean+Fixes
|
|||
[x] Clean-up context on error and return nil handle
|
||||
[/] Could return non-nil "invalid" handle and set error flags in handle
|
||||
|
||||
[x] Destroy canvas backend properly
|
||||
[x] Destroy surface properly
|
||||
[ ] Destroy window properly
|
||||
|
||||
[>] Make surface backend and canvas backend compile-time and run-time selections easier
|
||||
|
||||
[ ] GL loader: allow using different GL versions (eg using a desktop GL surface and a GLES surface in the same app).
|
||||
|
|
Loading…
Reference in New Issue