ref: gl: fix up data types. Engine TMU type is int, rather than GLint, and texture indices are technically unsigned int only (and they aren't GLenum)

This commit is contained in:
Alibek Omarov
2025-09-06 01:55:46 +05:00
parent c0e8827cd5
commit d039a08b4e
3 changed files with 58 additions and 56 deletions

View File

@@ -144,13 +144,14 @@ void GL_LoadIdentityTexMatrix( void )
GL_SelectTexture
=================
*/
void GL_SelectTexture( GLint tmu )
void GL_SelectTexture( int tmu )
{
if( !GL_Support( GL_ARB_MULTITEXTURE ))
return;
// don't allow negative texture units
if( tmu < 0 ) return;
if( tmu < 0 )
return;
if( tmu >= GL_MaxTextureUnits( ))
{
@@ -172,6 +173,49 @@ void GL_SelectTexture( GLint tmu )
}
}
/*
=================
GL_Bind
=================
*/
void GL_Bind( int tmu, unsigned int texnum )
{
const gl_texture_t *texture;
GLuint glTarget;
// missed or invalid texture?
if( texnum <= 0 || texnum >= MAX_TEXTURES )
{
if( texnum != 0 )
gEngfuncs.Con_DPrintf( S_ERROR "%s: invalid texturenum %d\n", __func__, texnum );
texnum = tr.defaultTexture;
}
if( tmu != GL_KEEP_UNIT )
GL_SelectTexture( tmu );
else tmu = glState.activeTMU;
texture = R_GetTexture( texnum );
glTarget = texture->target;
if( glTarget == GL_TEXTURE_2D_ARRAY_EXT )
glTarget = GL_TEXTURE_2D;
if( glState.currentTextureTargets[tmu] != glTarget )
{
GL_EnableTextureUnit( tmu, false );
glState.currentTextureTargets[tmu] = glTarget;
GL_EnableTextureUnit( tmu, true );
}
if( glState.currentTextures[tmu] == texture->texnum )
return;
pglBindTexture( texture->target, texture->texnum );
glState.currentTextures[tmu] = texture->texnum;
glState.currentTexturesIndex[tmu] = texnum;
}
/*
==============
GL_DisableAllTexGens
@@ -230,7 +274,7 @@ void GL_CleanupAllTextureUnits( void )
GL_MultiTexCoord2f
=================
*/
void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t )
void GL_MultiTexCoord2f( int tmu, GLfloat s, GLfloat t )
{
if( !GL_Support( GL_ARB_MULTITEXTURE ))
return;
@@ -238,7 +282,7 @@ void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t )
#ifndef XASH_GL_STATIC
if( pglMultiTexCoord2f != NULL )
#endif
pglMultiTexCoord2f( texture + GL_TEXTURE0_ARB, s, t );
pglMultiTexCoord2f( tmu + GL_TEXTURE0_ARB, s, t );
}
/*

View File

@@ -44,9 +44,9 @@ R_GetTexture
acess to array elem
=================
*/
gl_texture_t *R_GetTexture( GLenum texnum )
gl_texture_t *R_GetTexture( unsigned int texnum )
{
Assert( texnum >= 0 && texnum < MAX_TEXTURES );
Assert( texnum < MAX_TEXTURES );
return &gl_textures[texnum];
}
@@ -77,48 +77,6 @@ const char *GL_TargetToString( GLenum target )
return "??";
}
/*
=================
GL_Bind
=================
*/
void GL_Bind( GLint tmu, GLenum texnum )
{
gl_texture_t *texture;
GLuint glTarget;
// missed or invalid texture?
if( texnum <= 0 || texnum >= MAX_TEXTURES )
{
if( texnum != 0 )
gEngfuncs.Con_DPrintf( S_ERROR "%s: invalid texturenum %d\n", __func__, texnum );
texnum = tr.defaultTexture;
}
if( tmu != GL_KEEP_UNIT )
GL_SelectTexture( tmu );
else tmu = glState.activeTMU;
texture = &gl_textures[texnum];
glTarget = texture->target;
if( glTarget == GL_TEXTURE_2D_ARRAY_EXT )
glTarget = GL_TEXTURE_2D;
if( glState.currentTextureTargets[tmu] != glTarget )
{
GL_EnableTextureUnit( tmu, false );
glState.currentTextureTargets[tmu] = glTarget;
GL_EnableTextureUnit( tmu, true );
}
if( glState.currentTextures[tmu] == texture->texnum )
return;
pglBindTexture( texture->target, texture->texnum );
glState.currentTextures[tmu] = texture->texnum;
glState.currentTexturesIndex[tmu] = texnum;
}
qboolean GL_TextureFilteringEnabled( const gl_texture_t *tex )
{
if( FBitSet( tex->flags, TF_NEAREST ))
@@ -1901,10 +1859,11 @@ int GL_FindTexture( const char *name )
GL_FreeTexture
================
*/
void GL_FreeTexture( GLenum texnum )
void GL_FreeTexture( unsigned int texnum )
{
// number 0 it's already freed
if( texnum <= 0 ) return;
if( texnum == 0 || texnum >= MAX_TEXTURES )
return;
GL_DeleteTexture( &gl_textures[texnum] );
}

View File

@@ -300,13 +300,13 @@ extern float gldepthmin, gldepthmax;
void GL_BackendStartFrame( void );
void GL_BackendEndFrame( void );
void GL_CleanUpTextureUnits( int last );
void GL_Bind( GLint tmu, GLenum texnum );
void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t );
void GL_Bind( int tmu, unsigned int texnum );
void GL_MultiTexCoord2f( int tmu, GLfloat s, GLfloat t );
void GL_SetTexCoordArrayMode( GLenum mode );
void GL_LoadTexMatrixExt( const float *glmatrix );
void GL_LoadMatrix( const matrix4x4 source );
void GL_TexGen( GLenum coord, GLenum mode );
void GL_SelectTexture( GLint texture );
void GL_SelectTexture( int tmu );
void GL_CleanupAllTextureUnits( void );
void GL_LoadIdentityTexMatrix( void );
void GL_DisableAllTexGens( void );
@@ -356,7 +356,7 @@ void R_DrawModelHull( void );
// gl_image.c
//
void R_SetTextureParameters( void );
gl_texture_t *R_GetTexture( GLenum texnum );
gl_texture_t *R_GetTexture( unsigned int texnum );
const char *GL_TargetToString( GLenum target );
#define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false )
#define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true )
@@ -371,8 +371,7 @@ void GL_UpdateTexSize( int texnum, int width, int height, int depth );
qboolean GL_TextureFilteringEnabled( const gl_texture_t *tex );
void GL_ApplyTextureParams( gl_texture_t *tex );
int GL_FindTexture( const char *name );
void GL_FreeTexture( GLenum texnum );
const char *GL_Target( GLenum target );
void GL_FreeTexture( unsigned int texnum );
void R_InitDlightTexture( void );
void R_TextureList_f( void );
void R_InitImages( void );