mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: bring back texture replacement
This commit is contained in:
@@ -561,6 +561,8 @@ static void *Mod_LoadAllSkins( model_t *mod, int numskins, daliasskintype_t *psk
|
||||
|
||||
size = m_pAliasHeader->skinwidth * m_pAliasHeader->skinheight;
|
||||
|
||||
// TODO: texture replacement support here
|
||||
|
||||
for( i = 0; i < numskins; i++ )
|
||||
{
|
||||
if( pskintype->type == ALIAS_SKIN_SINGLE )
|
||||
|
||||
@@ -400,6 +400,14 @@ static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
|
||||
}
|
||||
}
|
||||
|
||||
static void GAME_EXPORT R_OverrideTextureSourceSize( unsigned int texnum, uint srcWidth, uint srcHeight )
|
||||
{
|
||||
gl_texture_t *tx = R_GetTexture( texnum );
|
||||
|
||||
tx->srcWidth = srcWidth;
|
||||
tx->srcHeight = srcHeight;
|
||||
}
|
||||
|
||||
static void* GAME_EXPORT R_GetProcAddress( const char *name )
|
||||
{
|
||||
#ifdef XASH_GL4ES
|
||||
@@ -504,6 +512,7 @@ static ref_interface_t gReffuncs =
|
||||
GL_LoadTextureArray,
|
||||
GL_CreateTextureArray,
|
||||
GL_FreeTexture,
|
||||
R_OverrideTextureSourceSize,
|
||||
|
||||
DrawSingleDecal,
|
||||
R_DecalSetupVerts,
|
||||
|
||||
@@ -13,6 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "gl_local.h"
|
||||
#include "crclib.h"
|
||||
|
||||
@@ -2349,3 +2350,38 @@ void R_ShutdownImages( void )
|
||||
memset( gl_textures, 0, sizeof( gl_textures ));
|
||||
gl_numTextures = 0;
|
||||
}
|
||||
|
||||
void R_TextureReplacementReport( const char *modelname, int gl_texturenum, const char *foundpath )
|
||||
{
|
||||
if( host_allow_materials->value != 2.0f )
|
||||
return;
|
||||
|
||||
if( gl_texturenum > 0 )
|
||||
gEngfuncs.Con_Printf( "Looking for %s tex replacement..." S_GREEN "OK (%s)\n", modelname, foundpath );
|
||||
else if( gl_texturenum < 0 )
|
||||
gEngfuncs.Con_Printf( "Looking for %s tex replacement..." S_YELLOW "MISS (%s)\n", modelname, foundpath );
|
||||
else
|
||||
gEngfuncs.Con_Printf( "Looking for %s tex replacement..." S_RED "FAIL (%s)\n", modelname, foundpath );
|
||||
}
|
||||
|
||||
qboolean R_SearchForTextureReplacement( char *out, size_t size, const char *modelname, const char *fmt, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start( ap, fmt );
|
||||
ret = Q_vsnprintf( out, size, fmt, ap );
|
||||
va_end( ap );
|
||||
|
||||
if( ret < 0 )
|
||||
{
|
||||
R_TextureReplacementReport( modelname, -1, "overflow" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if( gEngfuncs.fsapi->FileExists( out, false ))
|
||||
return true;
|
||||
|
||||
R_TextureReplacementReport( modelname, -1, out );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -288,6 +288,7 @@ extern gl_globals_t tr;
|
||||
extern float gldepthmin, gldepthmax;
|
||||
#define r_numEntities (tr.draw_list->num_solid_entities + tr.draw_list->num_trans_entities)
|
||||
#define r_numStatics (r_stats.c_client_ents)
|
||||
#define Mod_AllowMaterials() (host_allow_materials->value && !FBitSet( gp_host->features, ENGINE_DISABLE_HDTEXTURES ))
|
||||
|
||||
//
|
||||
// gl_backend.c
|
||||
@@ -373,6 +374,8 @@ void R_TextureList_f( void );
|
||||
void R_InitImages( void );
|
||||
void R_ShutdownImages( void );
|
||||
int GL_TexMemory( void );
|
||||
qboolean R_SearchForTextureReplacement( char *out, size_t size, const char *modelname, const char *fmt, ... ) _format( 4 );
|
||||
void R_TextureReplacementReport( const char *modelname, int gl_texturenum, const char *foundpath );
|
||||
|
||||
//
|
||||
// gl_rlight.c
|
||||
|
||||
@@ -67,8 +67,21 @@ static const byte *R_SpriteLoadFrame( model_t *mod, const void *pin, mspritefram
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_snprintf( texname, sizeof( texname ), "#%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 );
|
||||
gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height * bytes, r_texFlags );
|
||||
// partial HD-textures support
|
||||
if( Mod_AllowMaterials( ))
|
||||
{
|
||||
if( R_SearchForTextureReplacement( texname, sizeof( texname ), sprite_name, "materials/%s/%s%i%i.tga", sprite_name, group_suffix, num / 10, num % 10 ))
|
||||
{
|
||||
gl_texturenum = GL_LoadTexture( texname, NULL, 0, r_texFlags );
|
||||
R_TextureReplacementReport( sprite_name, gl_texturenum, texname );
|
||||
}
|
||||
}
|
||||
|
||||
if( gl_texturenum == 0 )
|
||||
{
|
||||
Q_snprintf( texname, sizeof( texname ), "#%s(%s:%i%i).spr", sprite_name, group_suffix, num / 10, num % 10 );
|
||||
gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height * bytes, r_texFlags );
|
||||
}
|
||||
}
|
||||
|
||||
// setup frame description
|
||||
|
||||
@@ -3729,6 +3729,7 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture
|
||||
int flags = 0;
|
||||
char texname[128], name[128], mdlname[128];
|
||||
texture_t *tx = NULL;
|
||||
qboolean load_external = false;
|
||||
|
||||
if( ptexture->flags & STUDIO_NF_NORMALMAP )
|
||||
flags |= (TF_NORMALMAP);
|
||||
@@ -3787,17 +3788,31 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture
|
||||
if( FBitSet( ptexture->flags, STUDIO_NF_NOMIPS ))
|
||||
SetBits( flags, TF_NOMIPMAP );
|
||||
|
||||
// NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it
|
||||
//ptexture->index = (int)((byte *)phdr) + ptexture->index;
|
||||
gEngfuncs.Image_SetMDLPointer((byte *)phdr + ptexture->index);
|
||||
size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768;
|
||||
|
||||
if( FBitSet( gp_host->features, ENGINE_IMPROVED_LINETRACE ) && FBitSet( ptexture->flags, STUDIO_NF_MASKED ))
|
||||
flags |= TF_KEEP_SOURCE; // Paranoia2 texture alpha-tracing
|
||||
|
||||
// build the texname
|
||||
Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name );
|
||||
ptexture->index = GL_LoadTexture( texname, (byte *)ptexture, size, flags );
|
||||
// NOTE: colormaps must have the palette for properly work. Ignore them
|
||||
if( Mod_AllowMaterials( ) && !FBitSet( ptexture->flags, STUDIO_NF_COLORMAP ))
|
||||
{
|
||||
if( R_SearchForTextureReplacement( texname, sizeof( texname ), mdlname, "materials/%s/%s.tga", mdlname, name ))
|
||||
{
|
||||
int gl_texturenum = GL_LoadTexture( texname, NULL, 0, flags );
|
||||
R_TextureReplacementReport( mdlname, gl_texturenum, texname );
|
||||
if(( load_external = gl_texturenum != 0 ))
|
||||
ptexture->index = gl_texturenum;
|
||||
}
|
||||
}
|
||||
|
||||
if( !load_external )
|
||||
{
|
||||
// NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it
|
||||
gEngfuncs.Image_SetMDLPointer((byte *)phdr + ptexture->index);
|
||||
size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768;
|
||||
|
||||
// build the texname
|
||||
Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name );
|
||||
ptexture->index = GL_LoadTexture( texname, (byte *)ptexture, size, flags );
|
||||
}
|
||||
|
||||
if( !ptexture->index )
|
||||
{
|
||||
|
||||
@@ -398,6 +398,14 @@ static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
|
||||
{
|
||||
}
|
||||
|
||||
static void GAME_EXPORT R_OverrideTextureSourceSize( unsigned int texnum, uint srcWidth, uint srcHeight )
|
||||
{
|
||||
image_t *tx = R_GetTexture( texnum );
|
||||
|
||||
tx->srcWidth = srcWidth;
|
||||
tx->srcHeight = srcHeight;
|
||||
}
|
||||
|
||||
static const char *R_GetConfigName( void )
|
||||
{
|
||||
return "ref_soft"; // software specific cvars will go to ref_soft.cfg
|
||||
@@ -498,6 +506,7 @@ static ref_interface_t gReffuncs =
|
||||
GL_LoadTextureArray,
|
||||
GL_CreateTextureArray,
|
||||
GL_FreeTexture,
|
||||
R_OverrideTextureSourceSize,
|
||||
|
||||
DrawSingleDecal,
|
||||
R_DecalSetupVerts,
|
||||
|
||||
Reference in New Issue
Block a user