[gl] Use glGenTextures to allocate texture numbers

While the scheme of using our own allocated did work just fine, fisheye
rendering uses glGenTextures which caused a texture id clash and thus
invalid operations (the cube map texture happened to be the same as the
console background texture). Sure, I could have just "fixed" the fisheye
init code, but this brings gl closer in line with glsl (which makes
extensive use of glGenTextures and glDeleteTextures). This doesn't fix
any texture leaks gl has (plenty, I imagine), but it's a step in the
right direction.
This commit is contained in:
Bill Currie 2022-03-15 13:29:05 +09:00
parent fb4fd979ec
commit 5a57280aa9
17 changed files with 50 additions and 57 deletions

View file

@ -28,6 +28,8 @@
#ifndef __QF_GL_lightmap_h
#define __QF_GL_lightmap_h
#include "QF/GL/types.h"
// LordHavoc: since lightmaps are now allocated only as needed, allow a ridiculous number :)
#define MAX_LIGHTMAPS 1024
#define BLOCK_WIDTH 64
@ -40,7 +42,7 @@ typedef struct glRect_s {
extern int lm_src_blend, lm_dest_blend;
extern model_t *gl_currentmodel;
extern int gl_lightmap_textures;
extern GLuint gl_lightmap_textures[MAX_LIGHTMAPS];
extern qboolean gl_lightmap_modified[MAX_LIGHTMAPS];
extern instsurf_t *gl_lightmap_polys[MAX_LIGHTMAPS];
extern glRect_t gl_lightmap_rectchange[MAX_LIGHTMAPS];

View file

@ -51,6 +51,6 @@ void gl_R_RenderView (void);
void gl_R_ClearState (void);
void gl_R_ViewChanged (void);
void gl_R_LineGraph (int x, int y, int *h_vals, int count, int height);
int gl_R_InitGraphTextures (int base);
void gl_R_InitGraphTextures (void);
#endif // __QF_GL_rmain_h

View file

@ -30,11 +30,14 @@
#include "QF/qtypes.h"
#include "QF/model.h"
#include "QF/GL/types.h"
#define SKY_TEX 2000 // Quake 2 environment sky
extern qboolean gl_skyloaded;
extern vec5_t gl_skyvec[6][4];
extern GLuint gl_solidskytexture;
extern GLuint gl_alphaskytexture;
struct texture_s;

View file

@ -29,6 +29,7 @@
#define __gl_textures_h
#include "QF/qtypes.h"
#include "QF/GL/types.h"
#define MAX_GLTEXTURES 2048
@ -39,7 +40,7 @@ extern int gl_filter_min;
extern int gl_filter_max;
extern qboolean gl_Anisotropy;
extern float gl_aniso;
extern int gl_part_tex;
extern GLuint gl_part_tex;
void GL_Upload8 (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);
void GL_Upload8_EXT (const byte *data, int width, int height, qboolean mipmap, qboolean alpha);

View file

@ -44,7 +44,6 @@ extern qboolean gl_mtex_fullbright;
extern GLenum gl_mtex_enum;
extern qboolean gl_combine_capable;
extern float gl_rgb_scale;
extern int gl_texture_number;
extern qboolean gl_feature_mach64;
extern float gldepthmin, gldepthmax;

View file

@ -120,6 +120,6 @@ void glsl_Skin_InitTranslations (void);
void gl_Skin_SetupSkin (skin_t *skin, int cmap);
void gl_Skin_ProcessTranslation (int cmap, const byte *translation);
void gl_Skin_InitTranslations (void);
int gl_Skin_Init_Textures (int base);
void gl_Skin_Init_Textures (void);
void gl_Skin_SetPlayerSkin (int width, int height, const byte *data);
#endif// __mod_internal_h

View file

@ -137,9 +137,6 @@ extern void SetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
extern int r_skymade;
extern void R_MakeSky (void);
extern int gl_solidskytexture;
extern int gl_alphaskytexture;
// flags in finalvert_t.flags
#define ALIAS_LEFT_CLIP 0x0001
#define ALIAS_TOP_CLIP 0x0002

View file

@ -60,8 +60,8 @@ typedef struct {
qboolean fb;
} glskin_t;
static int skin_textures;
static int skin_fb_textures;
static GLuint skin_textures[MAX_TRANSLATIONS];
static GLuint skin_fb_textures[MAX_TRANSLATIONS];
static byte skin_cmap[MAX_TRANSLATIONS][256];
static glskin_t skins[MAX_TRANSLATIONS];
@ -189,10 +189,10 @@ build_skin (skin_t *skin, int cmap)
if (!s->tex) // we haven't loaded the player model yet
return;
texnum = skin_textures + cmap;
texnum = skin_textures[cmap];
fb_texnum = 0;
if (s->fb)
fb_texnum = skin_fb_textures + cmap;
fb_texnum = skin_fb_textures[cmap];
if (skin) {
skin->texnum = texnum;
skin->auxtex = fb_texnum;
@ -245,9 +245,9 @@ gl_Skin_SetupSkin (skin_t *skin, int cmap)
changed = (s->tex != skin->texels);
s->tex = skin->texels;
if (!changed) {
skin->texnum = skin_textures + cmap;
skin->texnum = skin_textures[cmap];
if (s->fb)
skin->auxtex = skin_fb_textures + cmap;
skin->auxtex = skin_fb_textures[cmap];
return;
}
if (s->tex)
@ -260,12 +260,9 @@ gl_Skin_InitTranslations (void)
{
}
int
gl_Skin_Init_Textures (int base)
void
gl_Skin_Init_Textures (void)
{
skin_textures = base;
base += MAX_TRANSLATIONS;
skin_fb_textures = base;
base += MAX_TRANSLATIONS;
return base;
qfglGenTextures (MAX_TRANSLATIONS, skin_textures);
qfglGenTextures (MAX_TRANSLATIONS, skin_fb_textures);
}

View file

@ -82,7 +82,7 @@ static float *textCoords, *tC;
static qpic_t *draw_backtile;
static cc_cell_t char_cells[256];
static int translate_texture;
static GLuint translate_texture;
static int char_texture;
static int cs_texture; // crosshair texturea
@ -403,7 +403,7 @@ gl_Draw_Init (void)
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// save a texture slot for translated picture
translate_texture = gl_texture_number++;
qfglGenTextures (1, &translate_texture);
// get the other pics we need
draw_backtile = gl_Draw_PicFromWad ("backtile");

View file

@ -46,7 +46,7 @@
#include "r_internal.h"
int gl_part_tex;
GLuint gl_part_tex;
static GLint part_tex_internal_format = 2;
@ -57,7 +57,7 @@ GDT_InitParticleTexture (void)
memset (data, 0, sizeof (data));
gl_part_tex = gl_texture_number++;
qfglGenTextures (1, &gl_part_tex);
qfglBindTexture (GL_TEXTURE_2D, gl_part_tex);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

View file

@ -52,20 +52,16 @@
#define NUM_GRAPH_TEXTURES 8
static byte *graph_texels[NUM_GRAPH_TEXTURES];
static int graph_texture[NUM_GRAPH_TEXTURES];
static GLuint graph_texture[NUM_GRAPH_TEXTURES];
static int graph_index;
static int graph_size[NUM_GRAPH_TEXTURES];
static int graph_width[NUM_GRAPH_TEXTURES];
int
gl_R_InitGraphTextures (int base)
void
gl_R_InitGraphTextures (void)
{
int i;
for (i = 0; i < NUM_GRAPH_TEXTURES; i++)
graph_texture[i] = base++;
return base;
qfglGenTextures (NUM_GRAPH_TEXTURES, graph_texture);
}
void

View file

@ -59,7 +59,7 @@
static int dlightdivtable[8192];
static int gl_internalformat; // 1 or 3
static int lightmap_bytes; // 1, 3, or 4
int gl_lightmap_textures;
GLuint gl_lightmap_textures[MAX_LIGHTMAPS];
// keep lightmap texture data in main memory so texsubimage can update properly
// LordHavoc: changed to be allocated at runtime (typically lower memory usage)
@ -480,7 +480,7 @@ gl_R_CalcLightmaps (void)
if (!gl_lightmap_polys[i])
continue;
if (gl_lightmap_modified[i]) {
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures + i);
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures[i]);
GL_UploadLightmap (i);
gl_lightmap_modified[i] = false;
}
@ -500,7 +500,7 @@ gl_R_BlendLightmaps (void)
for (i = 0; i < MAX_LIGHTMAPS; i++) {
for (sc = gl_lightmap_polys[i]; sc; sc = sc->lm_chain) {
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures + i);
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures[i]);
if (sc->transform) {
qfglPushMatrix ();
qfglLoadMatrixf (sc->transform);
@ -691,9 +691,8 @@ GL_BuildLightmaps (model_t **models, int num_models)
r_framecount = 1; // no dlightcache
if (!gl_lightmap_textures) {
gl_lightmap_textures = gl_texture_number;
gl_texture_number += MAX_LIGHTMAPS;
if (!gl_lightmap_textures[0]) {
qfglGenTextures (MAX_LIGHTMAPS, gl_lightmap_textures);
}
switch (r_lightmap_components->int_val) {
@ -756,7 +755,7 @@ GL_BuildLightmaps (model_t **models, int num_models)
gl_lightmap_rectchange[i].t = BLOCK_HEIGHT;
gl_lightmap_rectchange[i].w = 0;
gl_lightmap_rectchange[i].h = 0;
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures + i);
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures[i]);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (gl_Anisotropy)

View file

@ -187,9 +187,8 @@ gl_R_Init (void)
GDT_Init ();
gl_texture_number = gl_R_InitGraphTextures (gl_texture_number);
gl_texture_number = gl_Skin_Init_Textures (gl_texture_number);
gl_R_InitGraphTextures ();
gl_Skin_Init_Textures ();
r_init = 1;
gl_R_InitParticles ();

View file

@ -397,8 +397,8 @@ DrawTextureChains (int disable_blend, int do_bind)
}
if (s->color && do_bind)
qfglColor4fv (s->color);
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures +
surf->lightmaptexturenum);
qfglBindTexture (GL_TEXTURE_2D,
gl_lightmap_textures[surf->lightmaptexturenum]);
R_RenderBrushPoly_3 (surf);
@ -416,8 +416,8 @@ DrawTextureChains (int disable_blend, int do_bind)
qglActiveTexture (gl_mtex_enum + 1);
for (s = tex->tex_chain; s; s = s->tex_chain) {
surf = s->surface;
qfglBindTexture (GL_TEXTURE_2D, gl_lightmap_textures +
surf->lightmaptexturenum);
qfglBindTexture (GL_TEXTURE_2D,
gl_lightmap_textures[surf->lightmaptexturenum]);
if (s->transform) {
qfglPushMatrix ();

View file

@ -56,8 +56,8 @@
// cube from the outside on the -ve y axis with +x to the right, +y going in,
// +z up, and front is the nearest face.
static const char *suf[6] = { "rt", "bk", "lf", "ft", "up", "dn" };
int gl_solidskytexture;
int gl_alphaskytexture;
GLuint gl_solidskytexture;
GLuint gl_alphaskytexture;
// Set to true if a valid skybox is loaded --KB
qboolean gl_skyloaded = false;
@ -428,8 +428,9 @@ gl_R_InitSky (texture_t *mt)
((byte *) & transpix)[2] = b / (128 * 128);
((byte *) & transpix)[3] = 0;
if (!gl_solidskytexture)
gl_solidskytexture = gl_texture_number++;
if (!gl_solidskytexture) {
qfglGenTextures (1, &gl_solidskytexture);
}
qfglBindTexture (GL_TEXTURE_2D, gl_solidskytexture);
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 128, 128, 0, GL_RGBA,
GL_UNSIGNED_BYTE, trans);
@ -448,8 +449,9 @@ gl_R_InitSky (texture_t *mt)
trans[(i * 128) + j] = d_8to24table[p];
}
if (!gl_alphaskytexture)
gl_alphaskytexture = gl_texture_number++;
if (!gl_alphaskytexture) {
qfglGenTextures (1, &gl_alphaskytexture);
}
qfglBindTexture (GL_TEXTURE_2D, gl_alphaskytexture);
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_alpha_format, 128, 128, 0, GL_RGBA,
GL_UNSIGNED_BYTE, trans);

View file

@ -55,7 +55,7 @@
#include "vid_internal.h"
typedef struct {
int texnum;
GLuint texnum;
char identifier[64];
int width, height;
int bytesperpixel;
@ -584,8 +584,7 @@ GL_LoadTexture (const char *identifier, int width, int height, const byte *data,
strncpy (glt->identifier, identifier, sizeof (glt->identifier) - 1);
glt->identifier[sizeof (glt->identifier) - 1] = '\0';
glt->texnum = gl_texture_number;
gl_texture_number++;
qfglGenTextures (1, &glt->texnum);
SetupTexture:
glt->crc = crc;

View file

@ -79,7 +79,6 @@ int gl_use_bgra;
int gl_va_capable;
static int driver_vaelements;
int vaelements;
int gl_texture_number = 1;
int gl_filter_min = GL_LINEAR_MIPMAP_LINEAR;
int gl_filter_max = GL_LINEAR;
float gldepthmin, gldepthmax;