131 lines
4.5 KiB
Diff
131 lines
4.5 KiB
Diff
From dff07a38021ccfbbcbe14bd0b409565b53acbc9a Mon Sep 17 00:00:00 2001
|
|
From: Mathias-Boulay <mathiasboulay@free.fr>
|
|
Date: Thu, 27 Apr 2023 11:51:01 +0200
|
|
Subject: [PATCH 241/249] Feat[buffers]: Erase buffers from cache upon deletion
|
|
|
|
---
|
|
src/gl/buffers.c | 17 ++++++++++++-----
|
|
src/gl/buffers.h | 2 ++
|
|
src/gl/gl4es.c | 3 ++-
|
|
src/gl/list.c | 6 +++---
|
|
4 files changed, 19 insertions(+), 9 deletions(-)
|
|
|
|
diff --git a/src/gl/buffers.c b/src/gl/buffers.c
|
|
index eaf881f0..eb539da6 100644
|
|
--- a/src/gl/buffers.c
|
|
+++ b/src/gl/buffers.c
|
|
@@ -184,8 +184,8 @@ void APIENTRY_GL4ES gl4es_glBufferData(GLenum target, GLsizeiptr size, const GLv
|
|
|
|
if(buff->real_buffer && !go_real) {
|
|
rebind_real_buff_arrays(buff->real_buffer, 0);
|
|
- LOAD_GLES(glDeleteBuffers);
|
|
- gles_glDeleteBuffers(1, &buff->real_buffer);
|
|
+
|
|
+ deleteSingleBuffer(buff->real_buffer);
|
|
// what about VA already pointing there?
|
|
buff->real_buffer = 0;
|
|
}
|
|
@@ -242,8 +242,7 @@ void APIENTRY_GL4ES gl4es_glNamedBufferData(GLuint buffer, GLsizeiptr size, cons
|
|
go_real = 1;
|
|
|
|
if(buff->real_buffer && !go_real) {
|
|
- LOAD_GLES(glDeleteBuffers);
|
|
- gles_glDeleteBuffers(1, &buff->real_buffer);
|
|
+ deleteSingleBuffer(buff->real_buffer);
|
|
// what about VA already pointing there?
|
|
buff->real_buffer = 0;
|
|
}
|
|
@@ -349,7 +348,7 @@ void APIENTRY_GL4ES gl4es_glDeleteBuffers(GLsizei n, const GLuint * buffers) {
|
|
if(buff->real_buffer) {
|
|
rebind_real_buff_arrays(buff->real_buffer, 0); // unbind
|
|
LOAD_GLES(glDeleteBuffers);
|
|
- gles_glDeleteBuffers(1, &buff->real_buffer);
|
|
+ deleteSingleBuffer(buff->real_buffer);
|
|
}
|
|
if (glstate->vao->vertex == buff)
|
|
glstate->vao->vertex = NULL;
|
|
@@ -736,6 +735,14 @@ void realize_bufferIndex()
|
|
}
|
|
}
|
|
|
|
+void deleteSingleBuffer(GLuint buffer) {
|
|
+ LOAD_GLES(glDeleteBuffers);
|
|
+ if(glstate->bind_buffer.index == buffer) glstate->bind_buffer.index = 0;
|
|
+ else if(glstate->bind_buffer.want_index == buffer) glstate->bind_buffer.want_index = 0;
|
|
+ else if(glstate->bind_buffer.array == buffer) glstate->bind_buffer.array = 0;
|
|
+ gles_glDeleteBuffers(1, &buffer);
|
|
+}
|
|
+
|
|
void unboundBuffers()
|
|
{
|
|
if(!glstate->bind_buffer.used)
|
|
diff --git a/src/gl/buffers.h b/src/gl/buffers.h
|
|
index 1a7c3a31..f23d288f 100644
|
|
--- a/src/gl/buffers.h
|
|
+++ b/src/gl/buffers.h
|
|
@@ -69,6 +69,8 @@ void APIENTRY_GL4ES glGetBufferPointervARB(GLenum target, GLenum pname, GLvoid *
|
|
|
|
// internal actual BindBuffer with cache
|
|
void bindBuffer(GLenum target, GLuint buffer);
|
|
+// delete a single buffer (and erase it from the cache)
|
|
+void deleteSingleBuffer(GLuint buffer);
|
|
// unbound all buffer
|
|
void unboundBuffers();
|
|
// update wanted Index Buffer
|
|
diff --git a/src/gl/gl4es.c b/src/gl/gl4es.c
|
|
index 06fee21b..86cdf96c 100644
|
|
--- a/src/gl/gl4es.c
|
|
+++ b/src/gl/gl4es.c
|
|
@@ -16,6 +16,7 @@
|
|
#include "init.h"
|
|
#include "loader.h"
|
|
#include "matrix.h"
|
|
+#include "buffers.h"
|
|
#ifdef _WIN32
|
|
#ifdef _WINBASE_
|
|
#define GSM_CAST(c) ((LPFILETIME)c)
|
|
@@ -1179,7 +1180,7 @@ void gl4es_scratch_vertex(int alloc) {
|
|
LOAD_GLES(glDeleteBuffers);
|
|
GLuint old_buffer = glstate->scratch_vertex;
|
|
gles_glGenBuffers(1, &glstate->scratch_vertex);
|
|
- gles_glDeleteBuffers(1, &old_buffer);
|
|
+ deleteSingleBuffer(old_buffer);
|
|
#endif
|
|
bindBuffer(GL_ARRAY_BUFFER, glstate->scratch_vertex);
|
|
gles_glBufferData(GL_ARRAY_BUFFER, alloc, NULL, GL_STREAM_DRAW);
|
|
diff --git a/src/gl/list.c b/src/gl/list.c
|
|
index 64f9d857..591a79ee 100644
|
|
--- a/src/gl/list.c
|
|
+++ b/src/gl/list.c
|
|
@@ -6,6 +6,7 @@
|
|
#include "glstate.h"
|
|
#include "init.h"
|
|
#include "loader.h"
|
|
+#include "buffers.h"
|
|
|
|
// KH Map implementation
|
|
KHASH_MAP_IMPL_INT(material, rendermaterial_t *);
|
|
@@ -670,7 +671,6 @@ renderlist_t* append_calllist(renderlist_t *list, renderlist_t *a)
|
|
}
|
|
|
|
void free_renderlist(renderlist_t *list) {
|
|
- LOAD_GLES2(glDeleteBuffers);
|
|
// test if list is NULL
|
|
if (list == NULL)
|
|
return;
|
|
@@ -761,9 +761,9 @@ void free_renderlist(renderlist_t *list) {
|
|
if(list->final_colors)
|
|
free(list->final_colors);
|
|
if(list->vbo_array)
|
|
- gles_glDeleteBuffers(1, &list->vbo_array);
|
|
+ deleteSingleBuffer(list->vbo_array);
|
|
if(list->vbo_indices)
|
|
- gles_glDeleteBuffers(1, &list->vbo_indices);
|
|
+ deleteSingleBuffer(list->vbo_array);
|
|
|
|
next = list->next;
|
|
free(list);
|
|
--
|
|
2.30.2
|
|
|