wip move gltextures allocating all to 1 place instead of copy paste

This commit is contained in:
Shpuld Shpuldson 2023-09-22 23:13:29 +03:00
parent a2b869e2a7
commit 4109dd2bdb
2 changed files with 50 additions and 167 deletions

View file

@ -2464,7 +2464,6 @@ GL_UnloadTexture
*/ */
void GL_UnloadTexture(int texture_index) void GL_UnloadTexture(int texture_index)
{ {
if (gltextures_used[texture_index] == true) if (gltextures_used[texture_index] == true)
{ {
gltexture_t& texture = gltextures[texture_index]; gltexture_t& texture = gltextures[texture_index];
@ -2522,23 +2521,12 @@ void GL_UnloadTexture(int texture_index)
texture.vram = NULL; texture.vram = NULL;
} }
gltextures_used[texture_index] = false;
numgltextures--;
} }
gltextures_used[texture_index] = false;
numgltextures--;
} }
/* int GL_TextureForName(const char * identifier) {
================
GL_LoadTexture
================
*/
int GL_LoadTexture (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level)
{
int texture_index = -1;
tex_scale_down = r_tex_scale_down.value == qtrue;
// See if the texture is already present. // See if the texture is already present.
if (identifier[0]) if (identifier[0])
{ {
@ -2554,27 +2542,54 @@ int GL_LoadTexture (const char *identifier, int width, int height, const byte *d
} }
} }
} }
return -1;
}
int GL_GetTextureIndex() {
// Out of textures? // Out of textures?
if (numgltextures == MAX_GLTEXTURES) if (numgltextures == MAX_GLTEXTURES)
{ {
Sys_Error("Out of OpenGL textures"); Sys_Error("Out of gl textures");
} }
// Use the next available texture.
numgltextures++; numgltextures++;
texture_index = numgltextures; int texture_index = -1;
for (int i = 0; i < MAX_GLTEXTURES; ++i) for (int i = 0; i < MAX_GLTEXTURES; ++i)
{ {
if (gltextures_used[i] == false) { if (gltextures_used[i] == false)
{
texture_index = i; texture_index = i;
break; break;
} }
} }
gltexture_t& texture = gltextures[texture_index];
if (texture_index < 0) {
Sys_Error("Could not find a free gl texture!\n");
}
Con_Printf("gltextures used %d\n", numgltextures);
gltextures_used[texture_index] = true; gltextures_used[texture_index] = true;
return texture_index;
}
/*
================
GL_LoadTexture
================
*/
int GL_LoadTexture (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level)
{
int texture_index = GL_TextureForName(identifier);
if (texture_index >= 0) return texture_index;
tex_scale_down = r_tex_scale_down.value == qtrue;
texture_index = GL_GetTextureIndex();
gltexture_t& texture = gltextures[texture_index];
// Fill in the source data. // Fill in the source data.
strcpy(texture.identifier, identifier); strcpy(texture.identifier, identifier);
texture.original_width = width; texture.original_width = width;
@ -2660,46 +2675,14 @@ GL_LoadPalTex
*/ */
int GL_LoadPalTex (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level, byte *palette, int paltype) int GL_LoadPalTex (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level, byte *palette, int paltype)
{ {
int texture_index = GL_TextureForName(identifier);
int texture_index = -1; if (texture_index >= 0) return texture_index;
tex_scale_down = r_tex_scale_down.value == qtrue; tex_scale_down = r_tex_scale_down.value == qtrue;
// See if the texture is already present.
if (identifier[0]) texture_index = GL_GetTextureIndex();
{
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == true)
{
const gltexture_t& texture = gltextures[i];
if (!strcmp (identifier, texture.identifier))
{
return i;
}
}
}
}
// Out of textures?
if (numgltextures == MAX_GLTEXTURES)
{
Sys_Error("Out of OpenGL textures");
}
// Use the next available texture.
numgltextures++;
texture_index = numgltextures;
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == false)
{
texture_index = i;
break;
}
}
gltexture_t& texture = gltextures[texture_index]; gltexture_t& texture = gltextures[texture_index];
gltextures_used[texture_index] = true;
// Fill in the source data. // Fill in the source data.
strcpy(texture.identifier, identifier); strcpy(texture.identifier, identifier);
@ -2845,51 +2828,14 @@ GL_LoadTextureLM
int GL_LoadTextureLM (const char *identifier, int width, int height, const byte *data, int bpp, int filter, qboolean update, int forcopy) int GL_LoadTextureLM (const char *identifier, int width, int height, const byte *data, int bpp, int filter, qboolean update, int forcopy)
{ {
tex_scale_down = r_tex_scale_down.value == qtrue; tex_scale_down = r_tex_scale_down.value == qtrue;
int texture_index = -1; int texture_index = GL_TextureForName(identifier);
// See if the texture is already present. if (texture_index >= 0 && update == qfalse) {
if (identifier[0]) return texture_index;
{
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == true)
{
const gltexture_t& texture = gltextures[i];
if (!strcmp (identifier, texture.identifier))
{
if (update == qfalse)
{
return i;
}
else
{
texture_index = i;
break;
}
}
}
}
} }
if (update == qfalse || texture_index == -1) if (update == qfalse || texture_index == -1)
{ {
// Out of textures? texture_index = GL_GetTextureIndex();
if (numgltextures == MAX_GLTEXTURES)
{
Sys_Error("Out of OpenGL textures");
}
// Use the next available texture.
numgltextures++;
texture_index = numgltextures;
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == false)
{
texture_index = i;
break;
}
}
gltexture_t& texture = gltextures[texture_index]; gltexture_t& texture = gltextures[texture_index];
gltextures_used[texture_index] = true; gltextures_used[texture_index] = true;
@ -3073,47 +3019,14 @@ GL_LoadImages
int total_overbudget_texturemem; int total_overbudget_texturemem;
int GL_LoadImages (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level, int bpp) int GL_LoadImages (const char *identifier, int width, int height, const byte *data, qboolean stretch_to_power_of_two, int filter, int mipmap_level, int bpp)
{ {
int texture_index = -1; int texture_index = GL_TextureForName(identifier);
if (texture_index >= 0) return texture_index;
tex_scale_down = r_tex_scale_down.value == qtrue; tex_scale_down = r_tex_scale_down.value == qtrue;
// See if the texture is already present. texture_index = GL_GetTextureIndex();
if (identifier[0])
{
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == true)
{
const gltexture_t& texture = gltextures[i];
if (!strcmp (identifier, texture.identifier))
{
return i;
}
}
}
}
// Out of textures?
if (numgltextures == MAX_GLTEXTURES)
{ Sys_Error("Out of OpenGL textures");
}
// Use the next available texture.
numgltextures++;
texture_index = numgltextures;
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == false)
{
texture_index = i;
break;
}
}
gltexture_t& texture = gltextures[texture_index]; gltexture_t& texture = gltextures[texture_index];
gltextures_used[texture_index] = true;
// Fill in the source data. // Fill in the source data.
strcpy(texture.identifier, identifier); strcpy(texture.identifier, identifier);
texture.original_width = width; texture.original_width = width;
@ -3356,42 +3269,11 @@ void GL_Upload4(int texture_index, const byte *data, int width, int height)
int GL_LoadTexture4(const char *identifier, unsigned int width, unsigned int height, const byte *data, int filter, qboolean swizzled) int GL_LoadTexture4(const char *identifier, unsigned int width, unsigned int height, const byte *data, int filter, qboolean swizzled)
{ {
int texture_index = -1; int texture_index = GL_TextureForName(identifier);
if (texture_index >= 0) return texture_index;
if (identifier[0])
{
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == true)
{
const gltexture_t& texture = gltextures[i];
if (!strcmp(identifier, texture.identifier))
{
return i;
}
}
}
}
// Out of textures? texture_index = GL_GetTextureIndex();
if (numgltextures == MAX_GLTEXTURES)
{
Sys_Error("Out of OpenGL textures");
}
// Use the next available texture.
numgltextures++;
texture_index = numgltextures;
for (int i = 0; i < MAX_GLTEXTURES; ++i)
{
if (gltextures_used[i] == false) {
texture_index = i;
break;
}
}
gltexture_t& texture = gltextures[texture_index]; gltexture_t& texture = gltextures[texture_index];
gltextures_used[texture_index] = true;
// Fill in the source data. // Fill in the source data.
strcpy(texture.identifier, identifier); strcpy(texture.identifier, identifier);

View file

@ -1214,6 +1214,7 @@ void Mod_LoadFaces (lump_t *l)
if (l->filelen % sizeof(*in)) if (l->filelen % sizeof(*in))
Con_Printf ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name); Con_Printf ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
count = l->filelen / sizeof(*in); count = l->filelen / sizeof(*in);
Con_Printf("Model faces %d\n", count);
out = static_cast<msurface_t*>(Hunk_AllocName ( count*sizeof(*out), loadname)); out = static_cast<msurface_t*>(Hunk_AllocName ( count*sizeof(*out), loadname));
loadmodel->surfaces = out; loadmodel->surfaces = out;