create, track, and clean up texture ids responsibly

This commit is contained in:
Chris Sarbora 2024-08-01 04:00:22 -05:00
parent a5081982f6
commit 0dd203e2c0
No known key found for this signature in database
2 changed files with 7 additions and 15 deletions

View File

@ -154,7 +154,7 @@ static int OpenGL_verts_processed = 0;
static int OpenGL_uploads = 0;
static int OpenGL_sets_this_frame[10];
static int OpenGL_packed_pixels = 0;
static int Cur_texture_object_num = 1;
static std::vector<GLuint> textures_;
static int OpenGL_cache_initted = 0;
static int OpenGL_last_bound[2];
@ -225,9 +225,9 @@ void opengl_GetInformation() {
}
int opengl_MakeTextureObject(int tn) {
int num = Cur_texture_object_num;
Cur_texture_object_num++;
GLuint num;
dglGenTextures(1, &num);
textures_.push_back(num);
dglActiveTextureARB(GL_TEXTURE0_ARB + tn);
@ -259,8 +259,6 @@ int opengl_InitCache(void) {
OpenGL_lightmap_states = (uint8_t *)mem_malloc(MAX_LIGHTMAPS);
ASSERT(OpenGL_lightmap_states);
Cur_texture_object_num = 1;
// Setup textures and cacheing
int i;
for (i = 0; i < MAX_BITMAPS; i++) {
@ -711,15 +709,8 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) {
void opengl_Close(const bool just_resizing) {
CHECK_ERROR(5)
uint32_t *delete_list = (uint32_t *)mem_malloc(Cur_texture_object_num * sizeof(int));
ASSERT(delete_list);
for (int i = 1; i < Cur_texture_object_num; i++)
delete_list[i] = i;
if (Cur_texture_object_num > 1)
dglDeleteTextures(Cur_texture_object_num, (const uint32_t *)delete_list);
mem_free(delete_list);
dglDeleteTextures(textures_.size(), textures_.data());
textures_.clear();
gRenderer.reset();

View File

@ -165,6 +165,7 @@ DYNAEXTERN(glFogf);
DYNAEXTERN(glFogfv);
DYNAEXTERN(glFogi);
DYNAEXTERN(glGenBuffers);
DYNAEXTERN(glGenTextures);
DYNAEXTERN(glGenVertexArrays);
DYNAEXTERN(glGetError);
DYNAEXTERN(glGetIntegerv);