Skip to content

Commit

Permalink
Add picmip2 general shader keyword for RTCW SP
Browse files Browse the repository at this point in the history
It's used for allowing different picmip levels for characters.
  • Loading branch information
zturtleman committed Jan 16, 2014
1 parent 5b14bf7 commit 37f96ba
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 17 deletions.
1 change: 1 addition & 0 deletions code/renderercommon/tr_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef enum
IMGFLAG_SRGB = 0x0080,
IMGFLAG_GENNORMALMAP = 0x0100,
IMGFLAG_LIGHTMAP = 0x0200,
IMGFLAG_PICMIP2 = 0x0400,
} imgFlags_t;

typedef struct image_s {
Expand Down
16 changes: 12 additions & 4 deletions code/renderergl1/tr_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ extern qboolean charSet;
static void Upload32( unsigned *data,
int width, int height,
qboolean mipmap,
qboolean picmip,
int picmip,
qboolean lightMap,
int *format,
int *pUploadWidth, int *pUploadHeight )
Expand Down Expand Up @@ -594,8 +594,8 @@ static void Upload32( unsigned *data,
// perform optional picmip operation
//
if ( picmip ) {
scaled_width >>= r_picmip->integer;
scaled_height >>= r_picmip->integer;
scaled_width >>= picmip;
scaled_height >>= picmip;
}

//
Expand Down Expand Up @@ -846,6 +846,7 @@ image_t *R_CreateImage( const char *name, byte *pic, int width, int height,
imgType_t type, imgFlags_t flags, int internalFormat ) {
image_t *image;
qboolean isLightmap = qfalse;
int picmip;
long hash;
int glWrapClampMode;

Expand Down Expand Up @@ -889,9 +890,16 @@ image_t *R_CreateImage( const char *name, byte *pic, int width, int height,

GL_Bind(image);

if ( image->flags & IMGFLAG_PICMIP2 )
picmip = r_picmip2->integer;
else if ( image->flags & IMGFLAG_PICMIP )
picmip = r_picmip->integer;
else
picmip = 0;

Upload32( (unsigned *)pic, image->width, image->height,
image->flags & IMGFLAG_MIPMAP,
image->flags & IMGFLAG_PICMIP,
picmip,
isLightmap,
&image->internalFormat,
&image->uploadWidth,
Expand Down
6 changes: 6 additions & 0 deletions code/renderergl1/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ cvar_t *r_singleShader;
cvar_t *r_roundImagesDown;
cvar_t *r_colorMipLevels;
cvar_t *r_picmip;
cvar_t *r_picmip2;
cvar_t *r_showtris;
cvar_t *r_showsky;
cvar_t *r_shownormals;
Expand Down Expand Up @@ -1035,6 +1036,9 @@ void GfxInfo_f( void )

ri.Printf( PRINT_ALL, "texturemode: %s\n", r_textureMode->string );
ri.Printf( PRINT_ALL, "picmip: %d\n", r_picmip->integer );
if ( r_picmip->integer != r_picmip2->integer ) {
ri.Printf( PRINT_ALL, "picmip2: %d\n", r_picmip2->integer );
}
ri.Printf( PRINT_ALL, "texture bits: %d\n", r_texturebits->integer );
ri.Printf( PRINT_ALL, "multitexture: %s\n", enablestrings[qglActiveTextureARB != 0] );
ri.Printf( PRINT_ALL, "compiled vertex arrays: %s\n", enablestrings[qglLockArraysEXT != 0 ] );
Expand Down Expand Up @@ -1074,9 +1078,11 @@ void R_Register( void )
r_ext_max_anisotropy = ri.Cvar_Get( "r_ext_max_anisotropy", "2", CVAR_ARCHIVE | CVAR_LATCH );

r_picmip = ri.Cvar_Get ("r_picmip", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_picmip2 = ri.Cvar_Get ("r_picmip2", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH );
ri.Cvar_CheckRange( r_picmip, 0, 16, qtrue );
ri.Cvar_CheckRange( r_picmip2, 0, 16, qtrue );
r_detailTextures = ri.Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shaderlod = ri.Cvar_Get( "r_shaderlod", "0.5", CVAR_ARCHIVE | CVAR_LATCH );
r_texturebits = ri.Cvar_Get( "r_texturebits", "32", CVAR_ARCHIVE | CVAR_LATCH );
Expand Down
1 change: 1 addition & 0 deletions code/renderergl1/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ extern cvar_t *r_singleShader; // make most world faces use default shader
extern cvar_t *r_roundImagesDown;
extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
extern cvar_t *r_picmip; // controls picmip values
extern cvar_t *r_picmip2;
extern cvar_t *r_finish;
extern cvar_t *r_textureMode;
extern cvar_t *r_offsetFactor;
Expand Down
18 changes: 13 additions & 5 deletions code/renderergl1/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static char *s_shaderText;
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
static imgFlags_t shader_picmipFlag;

// these are here because they are only referenced while parsing a shader
static char implicitMap[ MAX_QPATH ];
Expand Down Expand Up @@ -1025,7 +1026,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

stage->bundle[0].image[0] = R_FindImageFile( token, type, flags );

Expand Down Expand Up @@ -1055,7 +1056,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

stage->bundle[0].image[0] = R_FindImageFile( token, type, flags );
if ( !stage->bundle[0].image[0] )
Expand Down Expand Up @@ -1129,7 +1130,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

stage->bundle[0].image[num] = R_FindImageFile( token, IMGTYPE_COLORALPHA, flags );
if ( !stage->bundle[0].image[num] )
Expand Down Expand Up @@ -1694,7 +1695,7 @@ static void ParseSkyParms( char **text ) {
static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
char pathname[MAX_QPATH];
int i;
imgFlags_t imgFlags = IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
imgFlags_t imgFlags = IMGFLAG_MIPMAP | shader_picmipFlag;

// outerbox
token = COM_ParseExt( text, qfalse );
Expand Down Expand Up @@ -2001,6 +2002,11 @@ static qboolean ParseShader( char **text )
shader.noPicMip = qtrue;
continue;
}
// character picmip adjustment
else if ( !Q_stricmp( token, "picmip2" ) ) {
shader_picmipFlag = IMGFLAG_PICMIP2;
continue;
}
// polygonOffset
else if ( !Q_stricmp( token, "polygonOffset" ) )
{
Expand Down Expand Up @@ -3409,6 +3415,8 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
stages[i].bundle[0].texMods = texMods[i];
}

shader_picmipFlag = IMGFLAG_PICMIP;

// FIXME: set these "need" values apropriately
shader.needsNormal = qtrue;
shader.needsST1 = qtrue;
Expand Down Expand Up @@ -3470,7 +3478,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag

if (mipRawImage)
{
flags |= IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
flags |= IMGFLAG_MIPMAP | shader_picmipFlag;
}
else
{
Expand Down
13 changes: 10 additions & 3 deletions code/renderergl2/tr_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,10 +1575,17 @@ static void RawImage_ScaleToPower2( byte **data, int *inout_width, int *inout_he
int height = *inout_height;
int scaled_width;
int scaled_height;
qboolean picmip = flags & IMGFLAG_PICMIP;
int picmip;
qboolean mipmap = flags & IMGFLAG_MIPMAP;
qboolean clampToEdge = flags & IMGFLAG_CLAMPTOEDGE;

if ( flags & IMGFLAG_PICMIP2 )
picmip = r_picmip2->integer;
else if ( flags & IMGFLAG_PICMIP )
picmip = r_picmip->integer;
else
picmip = 0;

//
// convert to exact power of 2 sizes
//
Expand Down Expand Up @@ -1685,8 +1692,8 @@ static void RawImage_ScaleToPower2( byte **data, int *inout_width, int *inout_he
// perform optional picmip operation
//
if ( picmip ) {
scaled_width >>= r_picmip->integer;
scaled_height >>= r_picmip->integer;
scaled_width >>= picmip;
scaled_height >>= picmip;
}

//
Expand Down
6 changes: 6 additions & 0 deletions code/renderergl2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ cvar_t *r_singleShader;
cvar_t *r_roundImagesDown;
cvar_t *r_colorMipLevels;
cvar_t *r_picmip;
cvar_t *r_picmip2;
cvar_t *r_showtris;
cvar_t *r_showsky;
cvar_t *r_shownormals;
Expand Down Expand Up @@ -1096,6 +1097,9 @@ void GfxInfo_f( void )

ri.Printf( PRINT_ALL, "texturemode: %s\n", r_textureMode->string );
ri.Printf( PRINT_ALL, "picmip: %d\n", r_picmip->integer );
if ( r_picmip->integer != r_picmip2->integer ) {
ri.Printf( PRINT_ALL, "picmip2: %d\n", r_picmip2->integer );
}
ri.Printf( PRINT_ALL, "texture bits: %d\n", r_texturebits->integer );
ri.Printf( PRINT_ALL, "multitexture: %s\n", enablestrings[qglActiveTextureARB != 0] );
ri.Printf( PRINT_ALL, "compiled vertex arrays: %s\n", enablestrings[qglLockArraysEXT != 0 ] );
Expand Down Expand Up @@ -1196,9 +1200,11 @@ void R_Register( void )
r_ext_max_anisotropy = ri.Cvar_Get( "r_ext_max_anisotropy", "2", CVAR_ARCHIVE | CVAR_LATCH );

r_picmip = ri.Cvar_Get ("r_picmip", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_picmip2 = ri.Cvar_Get ("r_picmip2", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH );
ri.Cvar_CheckRange( r_picmip, 0, 16, qtrue );
ri.Cvar_CheckRange( r_picmip2, 0, 16, qtrue );
r_detailTextures = ri.Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shaderlod = ri.Cvar_Get( "r_shaderlod", "0.5", CVAR_ARCHIVE | CVAR_LATCH );
r_texturebits = ri.Cvar_Get( "r_texturebits", "32", CVAR_ARCHIVE | CVAR_LATCH );
Expand Down
1 change: 1 addition & 0 deletions code/renderergl2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,7 @@ extern cvar_t *r_singleShader; // make most world faces use default shader
extern cvar_t *r_roundImagesDown;
extern cvar_t *r_colorMipLevels; // development aid to see texture mip usage
extern cvar_t *r_picmip; // controls picmip values
extern cvar_t *r_picmip2;
extern cvar_t *r_finish;
extern cvar_t *r_textureMode;
extern cvar_t *r_offsetFactor;
Expand Down
18 changes: 13 additions & 5 deletions code/renderergl2/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static char *s_shaderText;
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
static imgFlags_t shader_picmipFlag;

// these are here because they are only referenced while parsing a shader
static char implicitMap[ MAX_QPATH ];
Expand Down Expand Up @@ -1082,7 +1083,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP)
{
Expand Down Expand Up @@ -1129,7 +1130,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

if (stage->type == ST_NORMALMAP || stage->type == ST_NORMALPARALLAXMAP)
{
Expand Down Expand Up @@ -1221,7 +1222,7 @@ static qboolean ParseStage( shaderStage_t *stage, char **text, int *ifIndent )
flags |= IMGFLAG_MIPMAP;

if (!shader.noPicMip)
flags |= IMGFLAG_PICMIP;
flags |= shader_picmipFlag;

if (r_srgb->integer)
flags |= IMGFLAG_SRGB;
Expand Down Expand Up @@ -1888,7 +1889,7 @@ static void ParseSkyParms( char **text ) {
static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
char pathname[MAX_QPATH];
int i;
imgFlags_t imgFlags = IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
imgFlags_t imgFlags = IMGFLAG_MIPMAP | shader_picmipFlag;

if (r_srgb->integer)
imgFlags |= IMGFLAG_SRGB;
Expand Down Expand Up @@ -2234,6 +2235,11 @@ static qboolean ParseShader( char **text )
shader.noPicMip = qtrue;
continue;
}
// character picmip adjustment
else if ( !Q_stricmp( token, "picmip2" ) ) {
shader_picmipFlag = IMGFLAG_PICMIP2;
continue;
}
// polygonOffset
else if ( !Q_stricmp( token, "polygonOffset" ) )
{
Expand Down Expand Up @@ -4152,6 +4158,8 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag
stages[i].bundle[0].texMods = texMods[i];
}

shader_picmipFlag = IMGFLAG_PICMIP;

// default to no implicit mappings
implicitMap[ 0 ] = '\0';
implicitStateBits = GLS_DEFAULT;
Expand Down Expand Up @@ -4210,7 +4218,7 @@ shader_t *R_FindShader( const char *name, int lightmapIndex, qboolean mipRawImag

if (mipRawImage)
{
flags |= IMGFLAG_MIPMAP | IMGFLAG_PICMIP;
flags |= IMGFLAG_MIPMAP | shader_picmipFlag;

if (r_genNormalMaps->integer)
flags |= IMGFLAG_GENNORMALMAP;
Expand Down

0 comments on commit 37f96ba

Please sign in to comment.