engine: move details textures parser to the engine

This commit is contained in:
Alibek Omarov
2026-04-14 11:50:35 +05:00
parent e6924844da
commit dd3583d11a
10 changed files with 187 additions and 169 deletions

View File

@@ -244,6 +244,14 @@ static void R_GetDetailScaleForTexture( int texture, float *xScale, float *yScal
if( yScale ) *yScale = glt->yscale;
}
static void R_SetDetailScaleForTexture( int texture, float xScale, float yScale )
{
gl_texture_t *glt = R_GetTexture( texture );
glt->xscale = xScale;
glt->yscale = yScale;
}
static void R_GetExtraParmsForTexture( int texture, byte *red, byte *green, byte *blue, byte *density )
{
gl_texture_t *glt = R_GetTexture( texture );
@@ -413,9 +421,52 @@ static const char *R_GetConfigName( void )
return "opengl";
}
static void R_NewMap( void )
{
texture_t *tx;
int i;
tr.worldmodel = gp_cl->models[1];
R_ClearDecals(); // clear all level decals
R_StudioResetPlayerModels();
// clear out efrags in case the level hasn't been reloaded
for( i = 0; i < WORLDMODEL->numleafs; i++ )
WORLDMODEL->leafs[i+1].efrags = NULL;
glState.isFogEnabled = false;
tr.skytexturenum = -1;
pglDisable( GL_FOG );
// clearing texture chains
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
if( !WORLDMODEL->textures[i] )
continue;
tx = WORLDMODEL->textures[i];
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
tr.skytexturenum = i;
tx->texturechain = NULL;
}
GL_BuildLightmaps ();
R_ClearVBO();
if( R_HasEnabledVBO( ))
R_GenerateVBO();
R_ResetRipples();
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
gEngfuncs.drawFuncs->R_NewMap();
}
static void R_FillRenderAPI( render_api_t *api )
{
api->GetDetailScaleForTexture = R_GetDetailScaleForTexture;
api->GetExtraParmsForTexture = R_GetExtraParmsForTexture;
api->GetFrameTime = R_GetFrameTime;
api->R_SetCurrentEntity = R_SetCurrentEntity;
@@ -520,6 +571,9 @@ const ref_interface_t gReffuncs =
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_SetDetailScaleForTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,

View File

@@ -369,10 +369,6 @@ void R_DrawFog( void );
int CL_FxBlend( cl_entity_t *e );
//
// gl_rmisc.c
//
void R_NewMap( void );
//
// gl_rsurf.c
//

View File

@@ -1,161 +0,0 @@
/*
gl_rmisc.c - renderer misceallaneous
Copyright (C) 2010 Uncle Mike
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.
*/
#include "gl_local.h"
#include "shake.h"
#include "screenfade.h"
#include "cdll_int.h"
static void R_ParseDetailTextures( const char *filename )
{
byte *afile;
char *pfile;
string token, texname;
string detail_texname;
string detail_path;
float xScale, yScale;
texture_t *tex;
int i;
afile = gEngfuncs.fsapi->LoadFile( filename, NULL, false );
if( !afile ) return;
pfile = (char *)afile;
// format: 'texturename' 'detailtexture' 'xScale' 'yScale'
while(( pfile = COM_ParseFile( pfile, token, sizeof( token ))) != NULL )
{
texname[0] = '\0';
detail_texname[0] = '\0';
// read texname
if( token[0] == '{' )
{
// NOTE: COM_ParseFile handled some symbols seperately
// this code will be fix it
pfile = COM_ParseFile( pfile, token, sizeof( token ));
Q_snprintf( texname, sizeof( texname ), "{%s", token );
}
else Q_strncpy( texname, token, sizeof( texname ));
// read detailtexture name
pfile = COM_ParseFile( pfile, token, sizeof( token ));
Q_strncpy( detail_texname, token, sizeof( detail_texname ));
// trying the scales or '{'
pfile = COM_ParseFile( pfile, token, sizeof( token ));
// read second part of detailtexture name
if( token[0] == '{' )
{
Q_strncat( detail_texname, token, sizeof( detail_texname ));
pfile = COM_ParseFile( pfile, token, sizeof( token )); // read scales
Q_strncat( detail_texname, token, sizeof( detail_texname ));
pfile = COM_ParseFile( pfile, token, sizeof( token )); // parse scales
}
Q_snprintf( detail_path, sizeof( detail_path ), "gfx/%s", detail_texname );
// read scales
xScale = Q_atof( token );
pfile = COM_ParseFile( pfile, token, sizeof( token ));
yScale = Q_atof( token );
if( xScale <= 0.0f || yScale <= 0.0f )
continue;
// search for existing texture and uploading detail texture
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
tex = WORLDMODEL->textures[i];
if( Q_stricmp( tex->name, texname ))
continue;
tex->dt_texturenum = GL_LoadTexture( detail_path, NULL, 0, TF_FORCE_COLOR|TF_NOFLIP_TGA );
// texture is loaded
if( tex->dt_texturenum )
{
gl_texture_t *glt;
glt = R_GetTexture( tex->gl_texturenum );
glt->xscale = xScale;
glt->yscale = yScale;
}
break;
}
}
Mem_Free( afile );
}
void R_NewMap( void )
{
texture_t *tx;
int i;
tr.worldmodel = gp_cl->models[1];
R_ClearDecals(); // clear all level decals
R_StudioResetPlayerModels();
// upload detailtextures
if( r_detailtextures.value )
{
string mapname, filepath;
Q_strncpy( mapname, WORLDMODEL->name, sizeof( mapname ));
COM_StripExtension( mapname );
Q_snprintf( filepath, sizeof( filepath ), "%s_detail.txt", mapname );
R_ParseDetailTextures( filepath );
}
// clear out efrags in case the level hasn't been reloaded
for( i = 0; i < WORLDMODEL->numleafs; i++ )
WORLDMODEL->leafs[i+1].efrags = NULL;
glState.isFogEnabled = false;
tr.skytexturenum = -1;
pglDisable( GL_FOG );
// clearing texture chains
for( i = 0; i < WORLDMODEL->numtextures; i++ )
{
if( !WORLDMODEL->textures[i] )
continue;
tx = WORLDMODEL->textures[i];
if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 ))
tr.skytexturenum = i;
tx->texturechain = NULL;
}
GL_BuildLightmaps ();
R_ClearVBO();
if( R_HasEnabledVBO( ))
R_GenerateVBO();
R_ResetRipples();
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
gEngfuncs.drawFuncs->R_NewMap();
}

View File

@@ -59,6 +59,17 @@ static void R_StudioSetDrawInterface( struct r_studio_interface_s *pDraw )
;
}
static void R_GetDetailScaleForTexture( int texture, float *xScale, float *yScale )
{
if( xScale ) *xScale = 1.0f;
if( yScale ) *yScale = 1.0f;
}
static void R_SetDetailScaleForTexture( int texture, float xScale, float yScale )
{
;
}
static void R_FillRenderAPI( render_api_t *api )
{
;
@@ -505,6 +516,9 @@ static const ref_interface_t gReffuncs =
.RefGetParm = RefGetParm,
.R_GetDetailScaleForTexture = R_GetDetailScaleForTexture,
.R_SetDetailScaleForTexture = R_SetDetailScaleForTexture,
.GL_FindTexture = GL_FindTexture,
.GL_TextureName = GL_TextureName,
.GL_TextureData = GL_TextureData,

View File

@@ -198,8 +198,13 @@ static void GAME_EXPORT R_GetDetailScaleForTexture( int texture, float *xScale,
{
// details are not implemented in ref_soft
if( xScale ) *xScale = 0.0f;
if( yScale ) *yScale = 0.0f;
if( xScale ) *xScale = 1.0f;
if( yScale ) *yScale = 1.0f;
}
static void GAME_EXPORT R_SetDetailScaleForTexture( int texture, float xScale, float yScale )
{
// details are not implemented in ref_soft
}
static void GAME_EXPORT R_GetExtraParmsForTexture( int texture, byte *red, byte *green, byte *blue, byte *density )
@@ -400,7 +405,6 @@ static void * GAME_EXPORT R_GetProcAddress( const char *name )
static void R_FillRenderAPI( render_api_t *api )
{
api->GetDetailScaleForTexture = R_GetDetailScaleForTexture;
api->GetExtraParmsForTexture = R_GetExtraParmsForTexture;
api->GetFrameTime = R_GetFrameTime;
api->R_SetCurrentEntity = R_SetCurrentEntity;
@@ -505,6 +509,9 @@ const ref_interface_t gReffuncs =
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_SetDetailScaleForTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,