ref_gu: cleanup, added texture wrap mode in GL_Bind

This commit is contained in:
Crow-bar
2022-05-17 11:50:04 +03:00
parent fe8fea742d
commit 89ec7122fe
5 changed files with 119 additions and 370 deletions

View File

@@ -107,6 +107,10 @@ typedef enum
TF_ARB_FLOAT = (1<<26), // float textures
TF_NOCOMPARE = (1<<27), // disable comparing for depth textures
TF_ARB_16BIT = (1<<28), // keep image as 16-bit (not 24)
#if XASH_PSP
TF_IMG_SWIZZLED = (1<<29),
TF_IMG_INVRAM = (1<<30),
#endif
} texFlags_t;
typedef enum

View File

@@ -187,14 +187,14 @@ static int GL_RefGetParm( int parm, int arg )
glt = R_GetTexture( arg );
return glt->format;
case PARM_TEX_ENCODE:
glt = R_GetTexture( arg );
return glt->encode;
/*glt = R_GetTexture( arg );*/
return /*glt->encode*/0;
case PARM_TEX_MIPCOUNT:
glt = R_GetTexture( arg );
return glt->numMips;
case PARM_TEX_DEPTH:
glt = R_GetTexture( arg );
return glt->depth;
/*glt = R_GetTexture( arg );*/
return /*glt->depth*/1;
case PARM_TEX_SKYBOX:
Assert( arg >= 0 && arg < 6 );
return tr.skyboxTextures[arg];

View File

@@ -1,74 +1,67 @@
/*
gl_helper.h - gu helper
Copyright (C) 2021 Sergey Galushko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef GU_HELPER_H
#define GU_HELPER_H
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef APIENTRY_LINKAGE
#define APIENTRY_LINKAGE extern
#endif
// GL types wrapping
typedef uint GLenum;
typedef byte GLboolean;
typedef uint GLbitfield;
typedef void GLvoid;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef byte GLubyte;
typedef word GLushort;
typedef uint GLuint;
typedef int GLsizei;
typedef float GLfloat;
typedef float GLclampf;
typedef double GLdouble;
typedef double GLclampd;
typedef int GLintptrARB;
typedef int GLsizeiptrARB;
typedef char GLcharARB;
typedef uint GLhandleARB;
typedef float GLmatrix[16];
// GL_Cull wrapping
#define GL_NONE 0
#define GL_FRONT GU_CW + 1
#define GL_BACK GU_CCW + 1
// color functions wrapping
#define GUCOLOR4F( r, g, b, a ) GU_COLOR( ( r ), ( g ), ( b ), ( a ) )
#define GUCOLOR4FV( v ) GU_COLOR( ( v )[0], ( v )[1], ( v )[2], ( v )[3] )
#define GUCOLOR4UB( r, g, b, a ) GU_RGBA( ( r ), ( g ), ( b ), ( a ) )
#define GUCOLOR4UBV( v ) GU_RGBA( ( v )[0], ( v )[1], ( v )[2], ( v )[3] )
#define GUCOLOR3F( r, g, b ) GU_COLOR( ( r ), ( g ), ( b ), 1.0f )
#define GUCOLOR3FV( v ) GU_COLOR( ( v )[0], ( v )[1], ( v )[2], 1.0f )
#define GUCOLOR3UB( r, g, b ) GU_RGBA( ( r ), ( g ), ( b ), 255 )
#define GUCOLOR3UBV( v ) GU_RGBA( ( v )[0], ( v )[1], ( v )[2], 255 )
// blend function wrapping
#define GUBLEND1 0xffffff
#define GUBLEND0 0x000000
// texture flags
#define GUFLAGTEXNONE 0x00
#define GUFLAGTEXUSED 0x01
#define GUFLAGTEXSWIZZLED 0x02
#define GUFLAGTEXINVRAM 0x04
/*#define GUFLAGMIP 0x08*/
#endif // GU_HELPER_H
/*
gl_helper.h - gu helper
Copyright (C) 2021 Sergey Galushko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef GU_HELPER_H
#define GU_HELPER_H
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef APIENTRY_LINKAGE
#define APIENTRY_LINKAGE extern
#endif
// GL types wrapping
typedef uint GLenum;
typedef byte GLboolean;
typedef uint GLbitfield;
typedef void GLvoid;
typedef signed char GLbyte;
typedef short GLshort;
typedef int GLint;
typedef byte GLubyte;
typedef word GLushort;
typedef uint GLuint;
typedef int GLsizei;
typedef float GLfloat;
typedef float GLclampf;
typedef double GLdouble;
typedef double GLclampd;
typedef int GLintptrARB;
typedef int GLsizeiptrARB;
typedef char GLcharARB;
typedef uint GLhandleARB;
typedef float GLmatrix[16];
// GL_Cull wrapping
#define GL_NONE 0
#define GL_FRONT GU_CW + 1
#define GL_BACK GU_CCW + 1
// color functions wrapping
#define GUCOLOR4F( r, g, b, a ) GU_COLOR( ( r ), ( g ), ( b ), ( a ) )
#define GUCOLOR4FV( v ) GU_COLOR( ( v )[0], ( v )[1], ( v )[2], ( v )[3] )
#define GUCOLOR4UB( r, g, b, a ) GU_RGBA( ( r ), ( g ), ( b ), ( a ) )
#define GUCOLOR4UBV( v ) GU_RGBA( ( v )[0], ( v )[1], ( v )[2], ( v )[3] )
#define GUCOLOR3F( r, g, b ) GU_COLOR( ( r ), ( g ), ( b ), 1.0f )
#define GUCOLOR3FV( v ) GU_COLOR( ( v )[0], ( v )[1], ( v )[2], 1.0f )
#define GUCOLOR3UB( r, g, b ) GU_RGBA( ( r ), ( g ), ( b ), 255 )
#define GUCOLOR3UBV( v ) GU_RGBA( ( v )[0], ( v )[1], ( v )[2], 255 )
// blend function wrapping
#define GUBLEND1 0xffffff
#define GUBLEND0 0x000000
#endif // GU_HELPER_H

View File

@@ -77,7 +77,7 @@ void GL_Bind( GLint tmu, GLenum texnum )
if( glState.currentTexture == texnum )
return;
texture = &gl_textures[texnum];
// Set palette
@@ -88,18 +88,31 @@ void GL_Bind( GLint tmu, GLenum texnum )
}
// Set texture parameters
sceGuTexMode( texture->format, texture->numMips - 1, 0, FBitSet( texture->guFlags, GUFLAGTEXSWIZZLED ) ? GU_TRUE : GU_FALSE );
sceGuTexMode( texture->format, texture->numMips - 1, 0, FBitSet( texture->flags, TF_IMG_SWIZZLED ) ? GU_TRUE : GU_FALSE );
if( texture->numMips > 1 )
{
sceGuTexFilter( GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR_MIPMAP_LINEAR );
//sceGuTexFilter( GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR_MIPMAP_LINEAR );
if( FBitSet( texture->flags, TF_NEAREST ) || gl_texture_nearest->value )
sceGuTexFilter( GU_NEAREST_MIPMAP_NEAREST, GU_NEAREST );
else
sceGuTexFilter( GU_LINEAR_MIPMAP_LINEAR, GU_LINEAR );
sceGuTexLevelMode( gl_texture_lodfunc->value, gl_texture_lodbias->value );
sceGuTexSlope( gl_texture_lodslope->value );
}
else
{
sceGuTexFilter( GU_LINEAR, GU_LINEAR );
if( FBitSet( texture->flags, TF_NEAREST ) || ( IsLightMap( texture ) && gl_lightmap_nearest->value ))
sceGuTexFilter( GU_NEAREST, GU_NEAREST );
else
sceGuTexFilter( GU_LINEAR, GU_LINEAR );
}
if( FBitSet( texture->flags, TF_CLAMP ) || FBitSet( texture->flags, TF_BORDER ) )
sceGuTexWrap( GU_CLAMP, GU_CLAMP );
else
sceGuTexWrap( GU_REPEAT, GU_REPEAT );
// Set base texture
sceGuTexImage( 0, texture->width, texture->height, texture->width, texture->dstTexture );
@@ -118,234 +131,6 @@ void GL_Bind( GLint tmu, GLenum texnum )
glState.currentTexture = texnum;
}
/*
=================
GL_ApplyTextureParams
=================
*/
void GL_ApplyTextureParams( gl_texture_t *tex )
{
#if 0
vec4_t border = { 0.0f, 0.0f, 0.0f, 1.0f };
if( !glw_state.initialized )
return;
Assert( tex != NULL );
// set texture filter
if( FBitSet( tex->flags, TF_DEPTHMAP ))
{
if( !FBitSet( tex->flags, TF_NOCOMPARE ))
{
pglTexParameteri( tex->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
pglTexParameteri( tex->target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );
}
if( FBitSet( tex->flags, TF_LUMINANCE ))
pglTexParameteri( tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE );
else pglTexParameteri( tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY );
if( FBitSet( tex->flags, TF_NEAREST ))
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
// allow max anisotropy as 1.0f on depth textures
if( GL_Support( GL_ANISOTROPY_EXT ))
pglTexParameterf( tex->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f );
}
else if( FBitSet( tex->flags, TF_NOMIPMAP ) || tex->numMips <= 1 )
{
if( FBitSet( tex->flags, TF_NEAREST ) || ( IsLightMap( tex ) && gl_lightmap_nearest->value ))
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
}
else
{
if( FBitSet( tex->flags, TF_NEAREST ) || gl_texture_nearest->value )
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
// set texture anisotropy if available
if( GL_Support( GL_ANISOTROPY_EXT ) && ( tex->numMips > 1 ) && !FBitSet( tex->flags, TF_ALPHACONTRAST ))
pglTexParameterf( tex->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_anisotropy->value );
// set texture LOD bias if available
if( GL_Support( GL_TEXTURE_LOD_BIAS ) && ( tex->numMips > 1 ))
pglTexParameterf( tex->target, GL_TEXTURE_LOD_BIAS_EXT, gl_texture_lodbias->value );
}
// check if border is not supported
if( FBitSet( tex->flags, TF_BORDER ) && !GL_Support( GL_CLAMP_TEXBORDER_EXT ))
{
ClearBits( tex->flags, TF_BORDER );
SetBits( tex->flags, TF_CLAMP );
}
// only seamless cubemaps allows wrap 'clamp_to_border"
if( tex->target == GL_TEXTURE_CUBE_MAP_ARB && !GL_Support( GL_ARB_SEAMLESS_CUBEMAP ) && FBitSet( tex->flags, TF_BORDER ))
ClearBits( tex->flags, TF_BORDER );
// set texture wrap
if( FBitSet( tex->flags, TF_BORDER ))
{
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
if( tex->target != GL_TEXTURE_1D )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER );
pglTexParameterfv( tex->target, GL_TEXTURE_BORDER_COLOR, border );
}
else if( FBitSet( tex->flags, TF_CLAMP ))
{
if( GL_Support( GL_CLAMPTOEDGE_EXT ))
{
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
if( tex->target != GL_TEXTURE_1D )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_S, GL_CLAMP );
if( tex->target != GL_TEXTURE_1D )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_T, GL_CLAMP );
if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_CLAMP );
}
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_S, GL_REPEAT );
if( tex->target != GL_TEXTURE_1D )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_T, GL_REPEAT );
if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB )
pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_REPEAT );
}
#endif
}
/*
=================
GL_UpdateTextureParams
=================
*/
static void GL_UpdateTextureParams( int iTexture )
{
#if 0
gl_texture_t *tex = &gl_textures[iTexture];
Assert( tex != NULL );
if( !tex->texnum ) return; // free slot
GL_Bind( XASH_TEXTURE0, iTexture );
// set texture anisotropy if available
if( GL_Support( GL_ANISOTROPY_EXT ) && ( tex->numMips > 1 ) && !FBitSet( tex->flags, TF_DEPTHMAP|TF_ALPHACONTRAST ))
pglTexParameterf( tex->target, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_anisotropy->value );
// set texture LOD bias if available
if( GL_Support( GL_TEXTURE_LOD_BIAS ) && ( tex->numMips > 1 ) && !FBitSet( tex->flags, TF_DEPTHMAP ))
pglTexParameterf( tex->target, GL_TEXTURE_LOD_BIAS_EXT, gl_texture_lodbias->value );
if( IsLightMap( tex ))
{
if( gl_lightmap_nearest->value )
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
}
if( tex->numMips <= 1 ) return;
if( FBitSet( tex->flags, TF_NEAREST ) || gl_texture_nearest->value )
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
else
{
pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
pglTexParameteri( tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
#endif
}
/*
=================
R_SetTextureParameters
=================
*/
void R_SetTextureParameters( void )
{
#if 0
int i;
if( GL_Support( GL_ANISOTROPY_EXT ))
{
if( gl_texture_anisotropy->value > glConfig.max_texture_anisotropy )
gEngfuncs.Cvar_SetValue( "gl_anisotropy", glConfig.max_texture_anisotropy );
else if( gl_texture_anisotropy->value < 1.0f )
gEngfuncs.Cvar_SetValue( "gl_anisotropy", 1.0f );
}
if( GL_Support( GL_TEXTURE_LOD_BIAS ))
{
if( gl_texture_lodbias->value < -glConfig.max_texture_lod_bias )
gEngfuncs.Cvar_SetValue( "gl_texture_lodbias", -glConfig.max_texture_lod_bias );
else if( gl_texture_lodbias->value > glConfig.max_texture_lod_bias )
gEngfuncs.Cvar_SetValue( "gl_texture_lodbias", glConfig.max_texture_lod_bias );
}
ClearBits( gl_texture_anisotropy->flags, FCVAR_CHANGED );
ClearBits( gl_texture_lodbias->flags, FCVAR_CHANGED );
ClearBits( gl_texture_nearest->flags, FCVAR_CHANGED );
ClearBits( gl_lightmap_nearest->flags, FCVAR_CHANGED );
// change all the existing mipmapped texture objects
for( i = 0; i < gl_numTextures; i++ )
GL_UpdateTextureParams( i );
#endif
}
/*
==================
GL_CalcImageSize
@@ -433,7 +218,7 @@ static int GL_CalcMipmapCount( gl_texture_t *tex, qboolean haveBuffer, size_t *m
if( !haveBuffer )
return 1;
#if 0
#if 0
// brush model only
if( !FBitSet( tex->flags, TF_ALLOW_EMBOSS ) )
return 1;
@@ -470,13 +255,13 @@ static void GL_SetTextureDimensions( gl_texture_t *tex, int width, int height )
int stepWidth, stepHeight;
Assert( tex != NULL );
maxTextureSize = glConfig.max_texture_size;
// store original sizes
tex->srcWidth = width;
tex->srcHeight = height;
#if 0 // scale up
stepWidth = ( int )ceilf( logf( width ) * 1.0f / logf( 2.0f ) );
stepHeight = ( int )ceilf( logf( height ) * 1.0f / logf( 2.0f ) );
@@ -995,14 +780,14 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
if( !pic->buffer )
return true;
// Prepare sizes
offset = GL_CalcImageSize( pic->type, pic->width, pic->height, /* pic->depth */ 1 );
texSize = GL_CalcTextureSize( tex->format, tex->width, tex->height );
normalMap = FBitSet( tex->flags, TF_NORMALMAP ) ? true : false;
tex->numMips = ImageIND( pic->type ) ? GL_CalcMipmapCount( tex, ( pic->buffer != NULL ), &texSize) : 1;
// Volatile memory for temporary buffer
// Volatile memory for temporary buffer
volUid = sceKernelVolatileMemLock( 0, &volBuff, &volSize );
if( volUid != 0)
gEngfuncs.Host_Error( "GL_AllocTexture: volatile memory lock error 0x%08x ! \n", volUid);
@@ -1010,13 +795,13 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
// Check allocation size
if( tex->dstTexture && ( tex->size != texSize ) )
{
if( FBitSet( tex->guFlags, GUFLAGTEXINVRAM ) )
if( FBitSet( tex->flags, TF_IMG_INVRAM ) )
vfree( tex->dstTexture );
else
free( tex->dstTexture );
tex->dstTexture = NULL;
ClearBits( tex->guFlags, GUFLAGTEXINVRAM );
ClearBits( tex->flags, TF_IMG_INVRAM );
}
// already allocated?
@@ -1034,7 +819,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
}
else
{
SetBits( tex->guFlags, GUFLAGTEXINVRAM );
SetBits( tex->flags, TF_IMG_INVRAM );
}
}
@@ -1072,7 +857,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
GL_TextureSwizzle( tex->dstTexture + mip_offset, volBuff, width, height );
mip_offset += GL_CalcTextureSize( tex->format, width, height );
}
SetBits( tex->guFlags, GUFLAGTEXSWIZZLED );
SetBits( tex->flags, TF_IMG_SWIZZLED );
}
else // RGBA32
{
@@ -1095,7 +880,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
else
{
GL_TextureSwizzle( tex->dstTexture, volBuff, tex->width * 4, tex->height );
SetBits( tex->guFlags, GUFLAGTEXSWIZZLED );
SetBits( tex->flags, TF_IMG_SWIZZLED );
}
}
else
@@ -1113,7 +898,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic )
*/
GL_PixelConverter( volBuff + offset, volBuff, tex->width * tex->height, true, tex->format );
GL_TextureSwizzle( tex->dstTexture, volBuff + offset, tex->width * 2, tex->height );
SetBits( tex->guFlags, GUFLAGTEXSWIZZLED );
SetBits( tex->flags, TF_IMG_SWIZZLED );
}
}
}
@@ -1169,13 +954,13 @@ qboolean GL_UpdateDlightTexture( int texnum, int xoff, int yoff, int width, int
{
if( tex->dstTexture )
{
if( FBitSet( tex->guFlags, GUFLAGTEXINVRAM ) )
if( FBitSet( tex->flags, TF_IMG_INVRAM ) )
vfree( tex->dstTexture );
else
free( tex->dstTexture );
tex->dstTexture = NULL;
ClearBits( tex->guFlags, GUFLAGTEXINVRAM );
ClearBits( tex->flags, TF_IMG_INVRAM );
}
}
@@ -1190,7 +975,7 @@ qboolean GL_UpdateDlightTexture( int texnum, int xoff, int yoff, int width, int
}
else
{
SetBits( tex->guFlags, GUFLAGTEXINVRAM );
SetBits( tex->flags, TF_IMG_INVRAM );
}
memset( tex->dstTexture, 0x00, texsize );
SetBits( tex->flags, TF_IMG_UPLOADED ); // done
@@ -1226,9 +1011,9 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic )
// force upload texture as RGB or RGBA (detail textures requires this)
if( tex->flags & TF_FORCE_COLOR ) pic->flags |= IMAGE_HAS_COLOR;
if( pic->flags & IMAGE_HAS_ALPHA ) tex->flags |= TF_HAS_ALPHA;
#if 0
tex->encode = pic->encode; // share encode method
#endif
if( ImageDXT( pic->type ))
{
if( !pic->numMips )
@@ -1406,7 +1191,7 @@ static void GL_DeleteTexture( gl_texture_t *tex )
if( tex->dstTexture )
{
if( FBitSet( tex->guFlags, GUFLAGTEXINVRAM ) )
if( FBitSet( tex->flags, TF_IMG_INVRAM ) )
vfree( tex->dstTexture );
else
free( tex->dstTexture );
@@ -1492,7 +1277,6 @@ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags )
return 0;
}
GL_ApplyTextureParams( tex ); // update texture filter, wrap etc
gEngfuncs.FS_FreeImage( pic ); // release source texture
// NOTE: always return texnum as index in array or engine will stop work !!!
@@ -1683,7 +1467,6 @@ int GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags
return 0;
}
GL_ApplyTextureParams( tex ); // update texture filter, wrap etc
return (tex - gl_textures);
}
@@ -1730,6 +1513,9 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
SetBits( r_empty.flags, IMAGE_CUBEMAP );
r_empty.size *= 6;
}
#else
if( FBitSet( flags, TF_CUBEMAP ))
return 0;
#endif
return GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
}
@@ -1861,7 +1647,6 @@ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor )
gEngfuncs.Image_Process( &pic, topColor, bottomColor, flags, 0.0f );
GL_UploadTexture( image, pic );
GL_ApplyTextureParams( image ); // update texture filter, wrap etc
gEngfuncs.FS_FreeImage( pic );
}
@@ -2019,7 +1804,7 @@ void R_TextureList_f( void )
int i, texCount, ram_bytes = 0, vram_bytes = 0;
gEngfuncs.Con_Printf( "\n" );
gEngfuncs.Con_Printf( " -id- -w- -h- -size- -fmt- -type- -encode- -wrap- -depth- -name--------\n" );
gEngfuncs.Con_Printf( " -id- -w- -h- -size- -fmt- -type- -wrap- -name--------\n" );
for( i = texCount = 0, image = gl_textures; i < gl_numTextures; i++, image++ )
{
@@ -2027,8 +1812,8 @@ void R_TextureList_f( void )
if( image->dstPalette ) ram_bytes += PALETTE_SIZE;
vram_bytes += ( FBitSet( image->guFlags, GUFLAGTEXINVRAM ) ) ? image->size : 0;
ram_bytes += ( FBitSet( image->guFlags, GUFLAGTEXINVRAM ) ) ? 0 : image->size;
vram_bytes += ( FBitSet( image->flags, TF_IMG_INVRAM ) ) ? image->size : 0;
ram_bytes += ( FBitSet( image->flags, TF_IMG_INVRAM ) ) ? 0 : image->size;
texCount++;
gEngfuncs.Con_Printf( "%4i: ", i );
@@ -2075,41 +1860,12 @@ void R_TextureList_f( void )
break;
}
if( image->flags & TF_NORMALMAP )
gEngfuncs.Con_Printf( "normal " );
else gEngfuncs.Con_Printf( "diffuse " );
switch( image->encode )
{
case DXT_ENCODE_COLOR_YCoCg:
gEngfuncs.Con_Printf( "YCoCg " );
break;
case DXT_ENCODE_NORMAL_AG_ORTHO:
gEngfuncs.Con_Printf( "ortho " );
break;
case DXT_ENCODE_NORMAL_AG_STEREO:
gEngfuncs.Con_Printf( "stereo " );
break;
case DXT_ENCODE_NORMAL_AG_PARABOLOID:
gEngfuncs.Con_Printf( "parabolic " );
break;
case DXT_ENCODE_NORMAL_AG_QUARTIC:
gEngfuncs.Con_Printf( "quartic " );
break;
case DXT_ENCODE_NORMAL_AG_AZIMUTHAL:
gEngfuncs.Con_Printf( "azimuthal " );
break;
default:
gEngfuncs.Con_Printf( "default " );
break;
}
if( image->flags & TF_CLAMP )
gEngfuncs.Con_Printf( "clamp " );
else if( image->flags & TF_BORDER )
gEngfuncs.Con_Printf( "border " );
else gEngfuncs.Con_Printf( "repeat " );
gEngfuncs.Con_Printf( " %d ", image->depth );
gEngfuncs.Con_Printf( " %s\n", image->name );
}
@@ -2140,7 +1896,6 @@ void R_InitImages( void )
gl_numTextures = 1;
// validate cvars
R_SetTextureParameters();
GL_CreateInternalTextures();
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );

View File

@@ -129,13 +129,12 @@ typedef struct gltexture_s
short srcHeight;
short width; // upload width\height
short height;
short depth; // texture depth or count of layers for 2D_ARRAY
//short depth; // texture depth or count of layers for 2D_ARRAY
byte numMips; // mipmap count
byte *dstTexture; // texture pointer
byte *dstPalette;
byte guFlags;
int format; // uploaded format
GLint encode; // using GLSL decoder
//GLint encode; // using GLSL decoder
texFlags_t flags;
rgba_t fogParams; // some water textures
@@ -420,7 +419,6 @@ void R_DrawModelHull( void );
//
// gu_image.c
//
void R_SetTextureParameters( void );
gl_texture_t *R_GetTexture( GLenum texnum );
#define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false )
#define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true )
@@ -433,7 +431,6 @@ int GL_CreateTextureArray( const char *name, int width, int height, int depth, c
void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor );
qboolean GL_UpdateDlightTexture( int texnum, int xoff, int yoff, int width, int height, const void *buffer );
void GL_UpdateTexSize( int texnum, int width, int height, int depth );
void GL_ApplyTextureParams( gl_texture_t *tex );
int GL_FindTexture( const char *name );
void GL_FreeTexture( GLenum texnum );
const char *GL_Target( GLenum target );