Merge branch 'refapi-15'

This commit is contained in:
Alibek Omarov
2026-04-16 23:19:06 +05:00
31 changed files with 702 additions and 1084 deletions

View File

@@ -444,13 +444,16 @@ qboolean AVI_Think( movie_state_t *Avi )
if( Avi->texture == 0 )
{
int cinTexture = SCR_GetCinematicTexture();
int w = Avi->w >= 0 ? Avi->w : refState.width;
int h = Avi->h >= 0 ? Avi->h : refState.height;
ref.dllFuncs.R_DrawStretchRaw( Avi->x, Avi->y, w, h, Avi->xres, Avi->yres, Avi->dst, redraw );
if( redraw )
ref.dllFuncs.GL_UpdateTexture( cinTexture, Avi->xres, Avi->yres, Avi->xres, Avi->yres, Avi->dst, PF_BGRA_32 );
ref.dllFuncs.R_DrawStretchPic( Avi->x, Avi->y, w, h, 0, 0, 1, 1, cinTexture );
}
else if( redraw && Avi->texture > 0 )
ref.dllFuncs.AVI_UploadRawFrame( Avi->texture, Avi->xres, Avi->yres, Avi->w, Avi->h, Avi->dst );
ref.dllFuncs.GL_UpdateTexture( Avi->texture, Avi->xres, Avi->yres, Avi->w, Avi->h, Avi->dst, PF_BGRA_32 );
if( flushing && !decoded )
return false; // probably hit an EOF

View File

@@ -849,6 +849,31 @@ BEAM * GAME_EXPORT R_BeamEnts( int startEnt, int endEnt, int modelIndex, float l
return pbeam;
}
static qboolean R_BeamVisible( const vec3_t start, const vec3_t end )
{
vec3_t mins, maxs;
for( int i = 0; i < 3; i++ )
{
if( start[i] < end[i] )
{
mins[i] = start[i];
maxs[i] = end[i];
}
else
{
mins[i] = end[i];
maxs[i] = start[i];
}
// don't let it be zero sized
if( mins[i] == maxs[i] )
maxs[i] += 1.0f;
}
return Mod_BoxVisible( mins, maxs, ref.dllFuncs.Mod_GetCurrentVis( ));
}
/*
==============
R_BeamPoints
@@ -861,7 +886,7 @@ BEAM * GAME_EXPORT R_BeamPoints( vec3_t start, vec3_t end, int modelIndex, float
{
BEAM *pbeam;
if( life != 0 && ref.dllFuncs.R_BeamCull( start, end, true ))
if( life != 0 && !R_BeamVisible( start, end ))
return NULL;
pbeam = R_BeamAlloc();

View File

@@ -23,6 +23,8 @@ GNU General Public License for more details.
#include "client.h"
#include "const.h"
#include "triangleapi.h"
#include "r_studioint.h"
#include "mod_local.h"
#include "r_efx.h"
#include "demo_api.h"
#include "ivoicetweak.h"
@@ -2173,7 +2175,7 @@ pfnGetViewModel
=============
*/
static cl_entity_t* GAME_EXPORT CL_GetViewModel( void )
static cl_entity_t *GAME_EXPORT CL_GetViewModel( void )
{
return &clgame.viewent;
}
@@ -3929,6 +3931,69 @@ void CL_UnloadProgs( void )
memset( &clgame, 0, sizeof( clgame ));
}
static model_t *pfnStudio_Mod_ForName( const char *name, int crash )
{
return Mod_ForName( name, crash, false );
}
static void *pfnStudio_Mod_Extradata( model_t *mod )
{
return Mod_StudioExtradata( mod );
}
static void pfnStudio_GetAliasScale( float *x, float *y )
{
if( x ) *x = 1.0f;
if( y ) *y = 1.0f;
}
static float ***pfnStudio_GetAliasTransform( void )
{
return NULL;
}
static model_t *pfnStudio_GetChromeSprite( void )
{
return cl_sprite_shell;
}
static int pfnStudio_IsHardware( void )
{
return 1;
}
static engine_studio_api_t gStudioAPI =
{
.Mem_Calloc = Mod_Calloc,
.Cache_Check = Mod_CacheCheck,
.LoadCacheFile = Mod_LoadCacheFile,
.Mod_ForName = pfnStudio_Mod_ForName,
.Mod_Extradata = pfnStudio_Mod_Extradata,
.GetModelByIndex = CL_ModelHandle,
.GetCvar = pfnCVarGetPointer,
.GetChromeSprite = pfnStudio_GetChromeSprite,
.GetAliasScale = pfnStudio_GetAliasScale,
.StudioGetAliasTransform = pfnStudio_GetAliasTransform,
.GetViewEntity = CL_GetViewModel,
.IsHardware = pfnStudio_IsHardware,
};
static void CL_InitStudioAPI( void )
{
static r_studio_interface_t gDefaultStudioDraw;
r_studio_interface_t *pStudioDraw;
if( !ref.dllFuncs.R_StudioFillAPI( &gStudioAPI, &gDefaultStudioDraw ))
return;
pStudioDraw = &gDefaultStudioDraw;
if( clgame.dllFuncs.pfnGetStudioModelInterface )
clgame.dllFuncs.pfnGetStudioModelInterface( STUDIO_INTERFACE_VERSION, &pStudioDraw, &gStudioAPI );
ref.dllFuncs.R_StudioSetDrawInterface( pStudioDraw );
}
qboolean CL_LoadProgs( const char *name )
{
static playermove_t gpMove;
@@ -4066,7 +4131,7 @@ qboolean CL_LoadProgs( const char *name )
// initialize game
clgame.dllFuncs.pfnInit();
ref.dllFuncs.CL_InitStudioAPI();
CL_InitStudioAPI();
return true;
}

View File

@@ -15,6 +15,7 @@ GNU General Public License for more details.
#include "common.h"
#include "client.h"
#include "mod_local.h"
#include "net_encode.h"
#include "cl_tent.h"
#include "shake.h"
@@ -1738,6 +1739,8 @@ void CL_RegisterResources( sizebuf_t *msg, connprotocol_t proto )
// tell rendering system we have a new set of models.
ref.dllFuncs.R_NewMap ();
Mod_LoadDetailTextures( cl.worldmodel );
// check if this map must start from dark screen
CL_StartDark ();

View File

@@ -214,6 +214,11 @@ static void pfnAVI_StreamSound( movie_state_t *avi, int entnum, float fvol, floa
return; // stub, use AVI_SetParm and AVI_Think to stream AVI sound
}
static void pfnAVI_UploadRawFrame( int texture, int cols, int rows, int width, int height, const byte *data )
{
ref.dllFuncs.GL_UpdateTexture( texture, cols, rows, width, height, data, PF_BGRA_32 );
}
static render_api_t gRenderAPI =
{
pfnRenderGetParm, // GL_RenderGetParm,
@@ -243,7 +248,7 @@ static render_api_t gRenderAPI =
AVI_GetVideoInfo,
AVI_GetVideoFrameNumber,
AVI_GetVideoFrame,
NULL, // R_UploadStretchRaw,
pfnAVI_UploadRawFrame, // AVI_UploadRawFrame
AVI_FreeVideo,
AVI_IsActive,
pfnAVI_StreamSound,
@@ -283,40 +288,6 @@ static render_api_t gRenderAPI =
COM_SetRandomSeed,
};
static void R_FillRenderAPIFromRef( render_api_t *to, const ref_interface_t *from )
{
to->GetDetailScaleForTexture = from->GetDetailScaleForTexture;
to->GetExtraParmsForTexture = from->GetExtraParmsForTexture;
to->GetFrameTime = from->GetFrameTime;
to->R_SetCurrentEntity = from->R_SetCurrentEntity;
to->R_SetCurrentModel = from->R_SetCurrentModel;
to->GL_FindTexture = from->GL_FindTexture;
to->GL_TextureName = from->GL_TextureName;
to->GL_TextureData = from->GL_TextureData;
to->GL_LoadTexture = from->GL_LoadTexture;
to->GL_CreateTexture = from->GL_CreateTexture;
to->GL_LoadTextureArray = from->GL_LoadTextureArray;
to->GL_CreateTextureArray = from->GL_CreateTextureArray;
to->GL_FreeTexture = from->GL_FreeTexture;
to->DrawSingleDecal = from->DrawSingleDecal;
to->R_DecalSetupVerts = from->R_DecalSetupVerts;
to->R_EntityRemoveDecals = from->R_EntityRemoveDecals;
to->AVI_UploadRawFrame = from->AVI_UploadRawFrame;
to->GL_Bind = from->GL_Bind;
to->GL_SelectTexture = from->GL_SelectTexture;
to->GL_LoadTextureMatrix = from->GL_LoadTextureMatrix;
to->GL_TexMatrixIdentity = from->GL_TexMatrixIdentity;
to->GL_CleanUpTextureUnits = from->GL_CleanUpTextureUnits;
to->GL_TexGen = from->GL_TexGen;
to->GL_TextureTarget = from->GL_TextureTarget;
to->GL_TexCoordArrayMode = from->GL_TexCoordArrayMode;
to->GL_UpdateTexSize = from->GL_UpdateTexSize;
to->GL_DrawParticles = from->GL_DrawParticles;
to->LightVec = from->LightVec;
to->StudioGetTexture = from->StudioGetTexture;
to->GL_GetProcAddress = from->R_GetProcAddress;
}
/*
===============
R_InitRenderAPI
@@ -329,8 +300,15 @@ qboolean R_InitRenderAPI( void )
// make sure what render functions is cleared
memset( &clgame.drawFuncs, 0, sizeof( clgame.drawFuncs ));
// fill missing functions from renderer
R_FillRenderAPIFromRef( &gRenderAPI, &ref.dllFuncs );
gRenderAPI.GetDetailScaleForTexture = ref.dllFuncs.R_GetDetailScaleForTexture;
gRenderAPI.GL_FindTexture = ref.dllFuncs.GL_FindTexture;
gRenderAPI.GL_TextureName = ref.dllFuncs.GL_TextureName;
gRenderAPI.GL_TextureData = ref.dllFuncs.GL_TextureData;
gRenderAPI.GL_LoadTexture = ref.dllFuncs.GL_LoadTexture;
gRenderAPI.GL_FreeTexture = ref.dllFuncs.GL_FreeTexture;
gRenderAPI.GL_Bind = ref.dllFuncs.GL_Bind;
ref.dllFuncs.R_FillRenderAPI( &gRenderAPI );
if( clgame.dllFuncs.pfnGetRenderInterface )
{

View File

@@ -25,6 +25,7 @@ AVI PLAYING
*/
static movie_state_t *cin_state;
static int cin_texture;
/*
==================
@@ -281,6 +282,12 @@ void SCR_InitCinematic( void )
{
AVI_Initailize ();
cin_state = AVI_GetState( CIN_MAIN );
cin_texture = ref.dllFuncs.GL_CreateTexture( "*cintexture", 64, 64, NULL, TF_NOMIPMAP|TF_CLAMP );
}
int SCR_GetCinematicTexture( void )
{
return cin_texture;
}
/*

View File

@@ -874,7 +874,6 @@ struct msurface_s *pfnTraceSurface( int ground, float *vstart, float *vend );
void CL_EnableScissor( scissor_state_t *scissor, int x, int y, int width, int height );
void CL_DisableScissor( scissor_state_t *scissor );
qboolean CL_Scissor( const scissor_state_t *scissor, float *x, float *y, float *width, float *height, float *u0, float *v0, float *u1, float *v1 );
static inline cl_entity_t *CL_EDICT_NUM( int index )
{
if( unlikely( !clgame.entities )) // not in game yet
@@ -1216,6 +1215,7 @@ void SteamBroker_TerminateGameConnection( void );
// cl_video.c
//
void SCR_InitCinematic( void );
int SCR_GetCinematicTexture( void );
void SCR_FreeCinematic( void );
qboolean SCR_PlayCinematic( const char *name );
qboolean SCR_DrawCinematic( void );

View File

@@ -287,13 +287,6 @@ static entity_state_t *R_StudioGetPlayerState( int index )
return &cl.frames[cl.parsecountmod].playerstate[index];
}
static int pfnGetStudioModelInterface( int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio )
{
return clgame.dllFuncs.pfnGetStudioModelInterface ?
clgame.dllFuncs.pfnGetStudioModelInterface( version, ppinterface, pstudio ) :
0;
}
static const bpc_desc_t *pfnImage_GetPFDesc( int idx )
{
return &PFDesc[idx];
@@ -329,11 +322,6 @@ static qboolean R_Init_Video_( ref_graphic_apis_t type )
return R_Init_Video( type );
}
static mleaf_t *pfnMod_PointInLeaf( const vec3_t p, mnode_t *node )
{
// FIXME: get rid of this on next RefAPI update
return Mod_PointInLeaf( p, node, cl.models[1] );
}
static const ref_api_t gEngfuncs =
{
@@ -375,7 +363,7 @@ static const ref_api_t gEngfuncs =
Mod_SampleSizeForFace,
Mod_BoxVisible,
pfnMod_PointInLeaf,
Mod_PointInLeaf,
R_DrawWorldHull,
R_DrawModelHull,
@@ -411,7 +399,6 @@ static const ref_api_t gEngfuncs =
Mod_CacheCheck,
Mod_LoadCacheFile,
Mod_Calloc,
pfnGetStudioModelInterface,
_Mem_AllocPool,
_Mem_FreePool,
@@ -488,28 +475,82 @@ static void R_UnloadProgs( void )
memset( &ref.dllFuncs, 0, sizeof( ref.dllFuncs ));
}
static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src )
static void CL_FillTriAPI( triangleapi_t *dst )
{
dst->version = TRI_API_VERSION;
dst->Begin = src->Begin;
dst->RenderMode = TriRenderMode;
dst->End = src->End;
dst->Color4f = TriColor4f;
dst->Color4ub = TriColor4ub;
dst->TexCoord2f = src->TexCoord2f;
dst->Vertex3f = src->Vertex3f;
dst->Vertex3fv = src->Vertex3fv;
dst->Brightness = TriBrightness;
dst->CullFace = TriCullFace;
dst->SpriteTexture = TriSpriteTexture;
dst->WorldToScreen = TriWorldToScreen;
dst->Fog = src->Fog;
dst->ScreenToWorld = src->ScreenToWorld;
dst->GetMatrix = src->GetMatrix;
dst->BoxInPVS = TriBoxInPVS;
dst->LightAtPoint = TriLightAtPoint;
dst->Color4fRendermode = TriColor4fRendermode;
dst->FogParams = src->FogParams;
dst->Begin = ref.dllFuncs.Begin;
dst->End = ref.dllFuncs.End;
dst->Vertex3f = ref.dllFuncs.Vertex3f;
dst->Vertex3fv = ref.dllFuncs.Vertex3fv;
ref.dllFuncs.R_FillTriAPI( dst );
}
static const byte dottexture[8][8] =
{
{ 0, 1, 1, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 0, 0 },
{ 0, 1, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0 },
};
static void R_CreateBuiltinTextures( void )
{
uint data4x4[16];
uint data16x16[256];
byte particle[8 * 8 * 4];
int x, y;
// default checkerboard
for( y = 0; y < 16; y++ )
{
for( x = 0; x < 16; x++ )
{
if(( y < 8 ) ^ ( x < 8 ))
data16x16[y * 16 + x] = 0xFFFF00FF;
else
data16x16[y * 16 + x] = 0xFF000000;
}
}
ref.dllFuncs.GL_CreateTexture( REF_DEFAULT_TEXTURE, 16, 16, data16x16, TF_COLORMAP );
// particle texture
memset( particle, 0, sizeof( particle ));
for( x = 0; x < 8; x++ )
{
for( y = 0; y < 8; y++ )
{
if( dottexture[x][y] )
particle[( y * 8 + x ) * 4 + 3] = 255;
}
}
ref.dllFuncs.GL_CreateTexture( REF_PARTICLE_TEXTURE, 8, 8, particle, TF_CLAMP );
// solid colors
memset( data4x4, 0xFF, sizeof( data4x4 ));
ref.dllFuncs.GL_CreateTexture( REF_WHITE_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
for( x = 0; x < 16; x++ )
data4x4[x] = 0xFF7F7F7F;
ref.dllFuncs.GL_CreateTexture( REF_GRAY_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
for( x = 0; x < 16; x++ )
data4x4[x] = 0xFF000000;
ref.dllFuncs.GL_CreateTexture( REF_BLACK_TEXTURE, 4, 4, data4x4, TF_COLORMAP );
}
static qboolean R_LoadProgs( const char *name )
@@ -555,8 +596,8 @@ static qboolean R_LoadProgs( const char *name )
Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY );
ref.initialized = true;
// initialize TriAPI callbacks
CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs );
R_CreateBuiltinTextures();
CL_FillTriAPI( &gTriApi );
return true;
}

View File

@@ -2989,6 +2989,105 @@ static void Mod_LoadTextures( model_t *mod, dbspmodel_t *bmod )
Mod_SequenceAllAnimatedTextures( mod );
}
#if !XASH_DEDICATED
static void Mod_ParseDetailTextures( model_t *mod )
{
byte *afile;
char *pfile;
string token, texname;
string detail_texname;
string detail_path;
float xScale, yScale;
texture_t *tex;
int i;
string filepath;
Q_strncpy( filepath, mod->name, sizeof( filepath ));
COM_StripExtension( filepath );
Q_strncat( filepath, "_detail.txt", sizeof( filepath ));
afile = FS_LoadFile( filepath, 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 < mod->numtextures; i++ )
{
tex = mod->textures[i];
if( Q_stricmp( tex->name, texname ))
continue;
tex->dt_texturenum = ref.dllFuncs.GL_LoadTexture( detail_path, NULL, 0, TF_FORCE_COLOR|TF_NOFLIP_TGA );
if( tex->dt_texturenum )
ref.dllFuncs.R_SetDetailScaleForTexture( tex->gl_texturenum, xScale, yScale );
break;
}
}
Mem_Free( afile );
}
void Mod_LoadDetailTextures( model_t *mod )
{
convar_t *r_detailtextures = Cvar_FindVar( "r_detailtextures" );
if( !r_detailtextures || !r_detailtextures->value )
return;
Mod_ParseDetailTextures( mod );
}
#endif // !XASH_DEDICATED
/*
=================
Mod_LoadTexInfo

View File

@@ -156,6 +156,7 @@ model_t *Mod_ForName( const char *name, qboolean crash, qboolean trackCRC );
qboolean Mod_ValidateCRC( const char *name, uint32_t crc );
void Mod_NeedCRC( const char *name, qboolean needCRC );
void Mod_FreeUnused( void );
void Mod_LoadDetailTextures( model_t *mod );
//
// mod_alias.c

View File

@@ -64,7 +64,15 @@ GNU General Public License for more details.
// 13. Removed ignore_flags argument from GetCvarPointer
// 14. Removed reserved functions, they are leftover from RenderAPI
// Removed CL_AddCustomBeam, it's now handled through R_AddEntity
#define REF_API_VERSION 14
// 15. Replaced CL_InitStudioAPI with R_StudioFillAPI + R_StudioSetDrawInterface
// Engine now builds engine_studio_api_t and handles client DLL negotiation
// Replaced R_DrawStretchRaw and AVI_UploadRawFrame with GL_UpdateTexture
// Added GL_CreateTexture, R_GetDetailScaleForTexture, R_SetDetailScaleForTexture
// Removed R_Flush, VGUI_UploadTextureBlock, R_BeamCull, pfnGetStudioModelInterface
// Moved RenderAPI and TriAPI filling to renderer via R_FillRenderAPI and R_FillTriAPI
// Moved detail textures parsing and cinematic texture management to engine
// Moved creation of default textures to the engine
#define REF_API_VERSION 15
#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP|TF_ALLOW_NEAREST)
#define TF_FONT (TF_NOMIPMAP|TF_CLAMP|TF_ALLOW_NEAREST)
@@ -223,7 +231,7 @@ enum ref_defaultsprite_e
};
// the order of first three is important!
// so you can use this value in IEngineStudio.StudioIsHardware
// so you can use this value in IEngineStudio.StudioIsHardware (but shouldn't)
typedef enum ref_graphic_apis_e
{
REF_SOFTWARE, // hypothetical: just make a surface to draw on, in software
@@ -389,7 +397,7 @@ typedef struct ref_api_s
// brushes
int (*Mod_SampleSizeForFace)( const struct msurface_s *surf );
qboolean (*Mod_BoxVisible)( const vec3_t mins, const vec3_t maxs, const byte *visbits );
mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node );
mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node, struct model_s *mod );
void (*R_DrawWorldHull)( void );
void (*R_DrawModelHull)( model_t *mod );
@@ -431,7 +439,6 @@ typedef struct ref_api_s
void *(*Mod_CacheCheck)( struct cache_user_s *c );
void (*Mod_LoadCacheFile)( const char *path, struct cache_user_s *cu );
void *(*Mod_Calloc)( int number, size_t size );
int (*pfnGetStudioModelInterface)( int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio );
// memory
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline )
@@ -539,8 +546,6 @@ typedef struct ref_interface_s
qboolean (*R_AddEntity)( struct cl_entity_s *clent, int type );
void (*R_ProcessEntData)( qboolean allocate, cl_entity_t *entities, unsigned int max_entities );
void (*R_Flush)( unsigned int flush_flags );
// debug
void (*R_ShowTextures)( void );
@@ -552,7 +557,6 @@ typedef struct ref_interface_s
// 2D
void (*R_Set2DMode)( qboolean enable );
void (*R_DrawStretchRaw)( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty );
void (*R_DrawStretchPic)( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum );
void (*FillRGBA)( int rendermode, float x, float y, float w, float h, byte r, byte g, byte b, byte a ); // in screen space
int (*WorldToScreen)( const vec3_t world, vec3_t screen ); // Returns 1 if it's z clipped
@@ -574,7 +578,8 @@ typedef struct ref_interface_s
// studio interface
float (*R_StudioEstimateFrame)( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time );
void (*R_StudioLerpMovement)( cl_entity_t *e, double time, vec3_t origin, vec3_t angles );
void (*CL_InitStudioAPI)( void );
qboolean (*R_StudioFillAPI)( struct engine_studio_api_s *api, struct r_studio_interface_s *pDefaultDraw );
void (*R_StudioSetDrawInterface)( struct r_studio_interface_s *pDraw );
// bmodel
void (*R_SetSkyCloudsTextures)( int solidskyTexture, int alphaskyTexture );
@@ -591,53 +596,27 @@ typedef struct ref_interface_s
void (*CL_DrawParticles)( double frametime, particle_t *particles, float partsize );
void (*CL_DrawTracers)( double frametime, particle_t *tracers );
void (*CL_DrawBeams)( int fTrans , BEAM *beams );
qboolean (*R_BeamCull)( const vec3_t start, const vec3_t end, qboolean pvsOnly );
// Xash3D Render Interface
// Get renderer info (doesn't changes engine state at all)
int (*RefGetParm)( int parm, int arg ); // generic
void (*GetDetailScaleForTexture)( int texture, float *xScale, float *yScale );
void (*GetExtraParmsForTexture)( int texture, byte *red, byte *green, byte *blue, byte *alpha );
float (*GetFrameTime)( void );
// Set renderer info (tell engine about changes)
void (*R_SetCurrentEntity)( struct cl_entity_s *ent ); // tell engine about both currententity and currentmodel
void (*R_SetCurrentModel)( struct model_s *mod ); // change currentmodel but leave currententity unchanged
// detail texture scale
void (*R_GetDetailScaleForTexture)( int texture, float *xScale, float *yScale );
void (*R_SetDetailScaleForTexture)( int texture, float xScale, float yScale );
// Texture tools
// Texture tools (used by engine directly)
int (*GL_CreateTexture)( const char *name, int width, int height, const void *buffer, texFlags_t flags );
int (*GL_FindTexture)( const char *name );
const char* (*GL_TextureName)( unsigned int texnum );
const byte* (*GL_TextureData)( unsigned int texnum ); // may be NULL
int (*GL_LoadTexture)( const char *name, const byte *buf, size_t size, int flags );
int (*GL_CreateTexture)( const char *name, int width, int height, const void *buffer, texFlags_t flags );
int (*GL_LoadTextureArray)( const char **names, int flags );
int (*GL_CreateTextureArray)( const char *name, int width, int height, int depth, const void *buffer, texFlags_t flags );
void (*GL_FreeTexture)( unsigned int texnum );
void (*R_OverrideTextureSourceSize)( unsigned int texnum, unsigned int srcWidth, unsigned int srcHeight ); // used to override decal size for texture replacement
// Decals manipulating (draw & remove)
void (*DrawSingleDecal)( struct decal_s *pDecal, struct msurface_s *fa );
float *(*R_DecalSetupVerts)( struct decal_s *pDecal, struct msurface_s *surf, int texture, int *outCount );
void (*R_EntityRemoveDecals)( struct model_s *mod ); // remove all the decals from specified entity (BSP only)
void (*GL_UpdateTexture)( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
// AVI
void (*AVI_UploadRawFrame)( int texture, int cols, int rows, int width, int height, const byte *data );
// glState related calls (must use this instead of normal gl-calls to prevent de-synchornize local states between engine and the client)
// glState related calls (used by engine directly)
void (*GL_Bind)( int tmu, unsigned int texnum );
void (*GL_SelectTexture)( int tmu );
void (*GL_LoadTextureMatrix)( const float *glmatrix );
void (*GL_TexMatrixIdentity)( void );
void (*GL_CleanUpTextureUnits)( int last ); // pass 0 for clear all the texture units
void (*GL_TexGen)( unsigned int coord, unsigned int mode );
void (*GL_TextureTarget)( unsigned int target ); // change texture unit mode without bind texture
void (*GL_TexCoordArrayMode)( unsigned int texmode );
void (*GL_UpdateTexSize)( int texnum, int width, int height, int depth ); // recalc statistics
// Misc renderer functions
void (*GL_DrawParticles)( const struct ref_viewpass_s *rvp, qboolean trans_pass, float frametime );
colorVec (*LightVec)( const float *start, const float *end, float *lightspot, float *lightvec );
struct mstudiotex_s *( *StudioGetTexture )( struct cl_entity_s *e );
// passed through R_RenderFrame (0 - use engine renderer, 1 - use custom client renderer)
void (*GL_RenderFrame)( const struct ref_viewpass_s *rvp );
@@ -651,28 +630,23 @@ typedef struct ref_interface_s
void (*R_NewMap)( void );
// clear the render entities before each frame
void (*R_ClearScene)( void );
// GL_GetProcAddress for client renderer
void* (*R_GetProcAddress)( const char *name );
// TriAPI Interface
// NOTE: implementation isn't required to be compatible
// TriAPI Interface (functions used by engine wrappers)
void (*TriRenderMode)( int mode );
void (*Begin)( int primitiveCode );
void (*End)( void );
void (*Color4f)( float r, float g, float b, float a ); // real glColor4f
void (*Color4ub)( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); // real glColor4ub
void (*TexCoord2f)( float u, float v );
void (*Vertex3fv)( const float *worldPnt );
void (*Vertex3f)( float x, float y, float z );
void (*Fog)( float flFogColor[3], float flStart, float flEnd, int bOn ); //Works just like GL_FOG, flFogColor is r/g/b.
void (*ScreenToWorld)( const float *screen, float *world );
void (*GetMatrix)( const int pname, float *matrix );
void (*FogParams)( float flDensity, int iFogSkybox );
void (*CullFace)( TRICULLSTYLE mode );
// fill render_api_t and triangleapi_t with renderer-specific functions
void (*R_FillRenderAPI)( struct render_api_s *api );
void (*R_FillTriAPI)( struct triangleapi_s *api );
// vgui drawing implementation
void (*VGUI_SetupDrawing)( qboolean rect );
void (*VGUI_UploadTextureBlock)( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
} ref_interface_t;
typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals );

View File

@@ -81,6 +81,7 @@ void R_PushDlightsForBmodel( model_t *model, int framecount, const matrix4x4 obj
int R_PushDlights( model_t *model, int framecount );
colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot, vec3_t lvec );
colorVec R_LightPoint( const vec3_t p0 );
void R_GatherPlayerLight( cl_entity_t *view );
void R_UpdateSurfaceCachedLight( msurface_t *surf );
//

View File

@@ -475,6 +475,20 @@ colorVec R_LightPoint( const vec3_t p0 )
return R_LightVec( p0, p1, NULL, NULL );
}
/*
=================
R_GatherPlayerLight
get light level of an entity and set it as player's light level
=================
*/
void R_GatherPlayerLight( cl_entity_t *view )
{
colorVec c = R_LightPoint( view->origin );
gEngfuncs.SetLocalLightLevel(( c.r + c.g + c.b ) / 3 );
}
/*
================
R_SetCacheState

View File

@@ -114,7 +114,7 @@ R_BeamCull
Cull the beam by bbox
==============
*/
qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
{
vec3_t mins, maxs;
int i;

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 );
@@ -311,11 +319,6 @@ static void R_ProcessEntData( qboolean allocate, cl_entity_t *entities, unsigned
gEngfuncs.drawFuncs->R_ProcessEntData( allocate );
}
static void GAME_EXPORT R_Flush( unsigned int flags )
{
// stub
}
/*
=============
R_SetSkyCloudsTextures
@@ -369,11 +372,6 @@ static qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_
return ret;
}
static void GAME_EXPORT VGUI_UploadTextureBlock( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
{
pglTexSubImage2D( GL_TEXTURE_2D, 0, drawX, drawY, blockWidth, blockHeight, GL_RGBA, GL_UNSIGNED_BYTE, rgba );
}
static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
{
pglEnable( GL_BLEND );
@@ -413,6 +411,85 @@ 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->GetExtraParmsForTexture = R_GetExtraParmsForTexture;
api->GetFrameTime = R_GetFrameTime;
api->R_SetCurrentEntity = R_SetCurrentEntity;
api->R_SetCurrentModel = R_SetCurrentModel;
api->GL_CreateTexture = GL_CreateTexture;
api->GL_LoadTextureArray = GL_LoadTextureArray;
api->GL_CreateTextureArray = GL_CreateTextureArray;
api->DrawSingleDecal = DrawSingleDecal;
api->R_DecalSetupVerts = R_DecalSetupVerts;
api->R_EntityRemoveDecals = R_EntityRemoveDecals;
api->GL_SelectTexture = GL_SelectTexture;
api->GL_LoadTextureMatrix = GL_LoadTexMatrixExt;
api->GL_TexMatrixIdentity = GL_LoadIdentityTexMatrix;
api->GL_CleanUpTextureUnits = GL_CleanUpTextureUnits;
api->GL_TexGen = GL_TexGen;
api->GL_TextureTarget = GL_TextureTarget;
api->GL_TexCoordArrayMode = GL_SetTexCoordArrayMode;
api->GL_UpdateTexSize = GL_UpdateTexSize;
api->GL_DrawParticles = CL_DrawParticlesExternal;
api->LightVec = R_LightVec;
api->StudioGetTexture = R_StudioGetTexture;
api->GL_GetProcAddress = R_GetProcAddress;
}
static void R_FillTriAPI( triangleapi_t *api )
{
api->TexCoord2f = TriTexCoord2f;
api->Fog = TriFog;
api->ScreenToWorld = R_ScreenToWorld;
api->GetMatrix = TriGetMatrix;
api->FogParams = TriFogParams;
}
const ref_interface_t gReffuncs =
{
R_Init,
@@ -439,7 +516,6 @@ const ref_interface_t gReffuncs =
R_AddEntity,
R_ProcessEntData,
R_Flush,
R_ShowTextures,
@@ -449,7 +525,6 @@ const ref_interface_t gReffuncs =
R_SetupSky,
R_Set2DMode,
R_DrawStretchRaw,
R_DrawStretchPic,
CL_FillRGBA,
R_WorldToScreen,
@@ -466,7 +541,8 @@ const ref_interface_t gReffuncs =
R_StudioEstimateFrame,
R_StudioLerpMovement,
CL_InitStudioAPI,
R_StudioFillAPI,
R_StudioSetDrawInterface,
R_SetSkyCloudsTextures,
GL_SubdivideSurface,
@@ -479,45 +555,23 @@ const ref_interface_t gReffuncs =
CL_DrawParticles,
CL_DrawTracers,
CL_DrawBeams,
R_BeamCull,
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_GetExtraParmsForTexture,
R_GetFrameTime,
R_SetCurrentEntity,
R_SetCurrentModel,
R_SetDetailScaleForTexture,
GL_CreateTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,
GL_LoadTexture,
GL_CreateTexture,
GL_LoadTextureArray,
GL_CreateTextureArray,
GL_FreeTexture,
R_OverrideTextureSourceSize,
DrawSingleDecal,
R_DecalSetupVerts,
R_EntityRemoveDecals,
R_UploadStretchRaw,
GL_UpdateTexture,
GL_Bind,
GL_SelectTexture,
GL_LoadTexMatrixExt,
GL_LoadIdentityTexMatrix,
GL_CleanUpTextureUnits,
GL_TexGen,
GL_TextureTarget,
GL_SetTexCoordArrayMode,
GL_UpdateTexSize,
CL_DrawParticlesExternal,
R_LightVec,
R_StudioGetTexture,
R_RenderFrame,
Mod_SetOrthoBounds,
@@ -525,23 +579,19 @@ const ref_interface_t gReffuncs =
Mod_GetCurrentVis,
R_NewMap,
R_ClearScene,
R_GetProcAddress,
TriRenderMode,
TriBegin,
TriEnd,
_TriColor4f,
_TriColor4ub,
TriTexCoord2f,
TriVertex3fv,
TriVertex3f,
TriFog,
R_ScreenToWorld,
TriGetMatrix,
TriFogParams,
TriCullFace,
R_FillRenderAPI,
R_FillTriAPI,
VGUI_SetupDrawing,
VGUI_UploadTextureBlock,
};

View File

@@ -55,120 +55,69 @@ void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, f
/*
=============
R_DrawStretchRaw
GL_UpdateTexture
=============
*/
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
{
byte *raw = NULL;
gl_texture_t *tex;
GLenum gl_format;
switch( fmt )
{
case PF_RGBA_32:
gl_format = GL_RGBA;
break;
case PF_BGRA_32:
gl_format = GL_BGRA;
break;
case PF_RGB_24:
gl_format = GL_RGB;
break;
case PF_BGR_24:
gl_format = GL_BGR;
break;
case PF_LUMINANCE:
gl_format = GL_LUMINANCE;
break;
default:
gEngfuncs.Con_DPrintf( S_ERROR "%s: unsupported pixel format %i\n", __func__, fmt );
return;
}
if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT ))
{
int width = 1, height = 1;
// check the dimensions
width = NearestPOW( cols, true );
height = NearestPOW( rows, false );
if( cols != width || rows != height )
{
raw = GL_ResampleTexture( data, cols, rows, width, height, false );
cols = width;
rows = height;
}
}
else
{
raw = (byte *)data;
}
if( cols > glConfig.max_2d_texture_size )
gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, cols );
if( rows > glConfig.max_2d_texture_size )
gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, rows );
pglDisable( GL_BLEND );
pglDisable( GL_ALPHA_TEST );
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
tex = R_GetTexture( tr.cinTexture );
GL_Bind( XASH_TEXTURE0, tr.cinTexture );
if( cols == tex->width && rows == tex->height )
{
if( dirty )
{
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_BGRA, GL_UNSIGNED_BYTE, raw );
}
}
else
{
tex->size = cols * rows * 4;
tex->width = cols;
tex->height = rows;
if( dirty )
{
pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, cols, rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, raw );
}
}
pglBegin( GL_QUADS );
pglTexCoord2f( 0, 0 );
pglVertex2f( x, y );
pglTexCoord2f( 1, 0 );
pglVertex2f( x + w, y );
pglTexCoord2f( 1, 1 );
pglVertex2f( x + w, y + h );
pglTexCoord2f( 0, 1 );
pglVertex2f( x, y + h );
pglEnd();
}
/*
=============
R_UploadStretchRaw
=============
*/
void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data )
{
byte *raw = NULL;
gl_texture_t *tex;
if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT ))
{
// check the dimensions
width = NearestPOW( width, true );
height = NearestPOW( height, false );
}
else
{
width = bound( 128, width, glConfig.max_2d_texture_size );
height = bound( 128, height, glConfig.max_2d_texture_size );
}
if( cols != width || rows != height )
{
raw = GL_ResampleTexture( data, cols, rows, width, height, false );
raw = GL_ResampleTexture( buffer, cols, rows, width, height, false );
cols = width;
rows = height;
}
else
{
raw = (byte *)data;
}
raw = (byte *)buffer;
if( cols > glConfig.max_2d_texture_size )
gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, cols );
if( rows > glConfig.max_2d_texture_size )
gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, rows );
tex = R_GetTexture( texture );
GL_Bind( GL_KEEP_UNIT, texture );
tex->width = cols;
tex->height = rows;
tex = R_GetTexture( texnum );
GL_Bind( GL_KEEP_UNIT, texnum );
if( cols == tex->width && rows == tex->height )
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, gl_format, GL_UNSIGNED_BYTE, raw );
else
{
tex->width = cols;
tex->height = rows;
pglTexImage2D( GL_TEXTURE_2D, 0, tex->format, cols, rows, 0, gl_format, GL_UNSIGNED_BYTE, raw );
}
pglTexImage2D( GL_TEXTURE_2D, 0, tex->format, cols, rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, raw );
GL_ApplyTextureParams( tex );
}

View File

@@ -23,19 +23,6 @@ static gl_texture_t gl_textures[MAX_TEXTURES];
static gl_texture_t* gl_texturesHashTable[TEXTURES_HASH_SIZE];
static uint gl_numTextures;
static byte dottexture[8][8] =
{
{0,1,1,0,0,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,1,0,0,0,0},
{0,1,1,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
};
#define IsLightMap( tex ) ( FBitSet(( tex )->flags, TF_ATLAS_PAGE ))
/*
=================
@@ -1699,7 +1686,20 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
r_empty.size *= 6;
}
return GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
int texnum = GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
if( !Q_strcmp( name, REF_DEFAULT_TEXTURE ))
tr.defaultTexture = texnum;
else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE ))
tr.particleTexture = texnum;
else if( !Q_strcmp( name, REF_WHITE_TEXTURE ))
tr.whiteTexture = texnum;
else if( !Q_strcmp( name, REF_GRAY_TEXTURE ))
tr.grayTexture = texnum;
else if( !Q_strcmp( name, REF_BLACK_TEXTURE ))
tr.blackTexture = texnum;
return texnum;
}
/*
@@ -1912,70 +1912,6 @@ void R_InitDlightTexture( void )
tr.dlightTexture = GL_LoadTextureFromBuffer( "*dlight", &r_image, TF_NOMIPMAP|TF_CLAMP|TF_ATLAS_PAGE, update );
}
/*
==================
GL_CreateInternalTextures
==================
*/
static void GL_CreateInternalTextures( void )
{
int dx2, dy, d;
int x, y;
rgbdata_t *pic;
// emo-texture from quake1
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR );
for( y = 0; y < 16; y++ )
{
for( x = 0; x < 16; x++ )
{
if(( y < 8 ) ^ ( x < 8 ))
((uint *)pic->buffer)[y*16+x] = 0xFFFF00FF;
else ((uint *)pic->buffer)[y*16+x] = 0xFF000000;
}
}
tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP );
// particle texture from quake1
pic = GL_FakeImage( 8, 8, 1, IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA );
for( x = 0; x < 8; x++ )
{
for( y = 0; y < 8; y++ )
{
if( dottexture[x][y] )
pic->buffer[( y * 8 + x ) * 4 + 3] = 255;
else pic->buffer[( y * 8 + x ) * 4 + 3] = 0;
}
}
tr.particleTexture = GL_LoadTextureInternal( REF_PARTICLE_TEXTURE, pic, TF_CLAMP );
// white texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer)[x] = 0xFFFFFFFF;
tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP );
// gray texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer)[x] = 0xFF7F7F7F;
tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP );
// black texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer)[x] = 0xFF000000;
tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP );
// cinematic dummy
pic = GL_FakeImage( 640, 100, 1, IMAGE_HAS_COLOR );
tr.cinTexture = GL_LoadTextureInternal( "*cintexture", pic, TF_NOMIPMAP|TF_CLAMP );
}
/*
===============
R_TextureList_f
@@ -2208,7 +2144,6 @@ void R_InitImages( void )
// validate cvars
R_SetTextureParameters();
GL_CreateInternalTextures();
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
}

View File

@@ -187,8 +187,6 @@ typedef struct
int lightmapTextures[MAX_LIGHTMAPS];
int dlightTexture; // custom dlight texture
int skyboxTextures[SKYBOX_MAX_SIDES]; // skybox sides
int cinTexture; // cinematic texture
int skytexturenum; // this not a gl_texturenum!
int skyboxbasenum; // start with 5800
@@ -296,7 +294,6 @@ void SCR_TimeRefresh_f( void );
// gl_beams.c
//
void CL_DrawBeams( int fTrans, BEAM *active_beams );
qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly );
//
// gl_cull.c
@@ -319,7 +316,7 @@ void R_ClearDecals( void );
// gl_draw.c
//
void R_Set2DMode( qboolean enable );
void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data );
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
//
// gl_image.c
@@ -369,10 +366,6 @@ void R_DrawFog( void );
int CL_FxBlend( cl_entity_t *e );
//
// gl_rmisc.c
//
void R_NewMap( void );
//
// gl_rsurf.c
//
@@ -416,11 +409,11 @@ struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e );
int R_GetEntityRenderMode( cl_entity_t *ent );
void R_DrawStudioModel( cl_entity_t *e );
player_info_t *pfnPlayerInfo( int index );
void R_GatherPlayerLight( void );
float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time );
void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles );
void R_StudioResetPlayerModels( void );
void CL_InitStudioAPI( void );
qboolean R_StudioFillAPI( struct engine_studio_api_s *api, struct r_studio_interface_s *pDefaultDraw );
void R_StudioSetDrawInterface( struct r_studio_interface_s *pDraw );
void Mod_StudioLoadTextures( model_t *mod, void *data );
void Mod_StudioUnloadTextures( void *data );
@@ -463,7 +456,6 @@ void R_RenderFrame( const struct ref_viewpass_s *vp );
void R_EndFrame( void );
void R_ClearScene( void );
void R_GetTextureParms( int *w, int *h, int texnum );
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty );
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum );
qboolean R_SpeedsMessage( char *out, size_t size );
qboolean R_CullBox( const vec3_t mins, const vec3_t maxs );

View File

@@ -511,7 +511,7 @@ R_FindViewLeaf
void R_FindViewLeaf( void )
{
RI.oldviewleaf = RI.viewleaf;
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
}
/*
@@ -1105,7 +1105,7 @@ void R_RenderFrame( const ref_viewpass_t *rvp )
if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp ))
{
R_GatherPlayerLight();
R_GatherPlayerLight( tr.viewent );
tr.realframecount++;
tr.fResetVis = true;
return;

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

@@ -3770,7 +3770,7 @@ void R_MarkLeaves( void )
else
VectorSet( test, RI.rvp.vieworigin[0], RI.rvp.vieworigin[1], RI.rvp.vieworigin[2] + 16.0f );
leaf = gEngfuncs.Mod_PointInLeaf( test, WORLDMODEL->nodes );
leaf = gEngfuncs.Mod_PointInLeaf( test, WORLDMODEL->nodes, WORLDMODEL );
if(( leaf->contents != CONTENTS_SOLID ) && ( RI.viewleaf != leaf ))
force = true;

View File

@@ -375,17 +375,6 @@ player_info_t *pfnPlayerInfo( int index )
return gEngfuncs.pfnPlayerInfo( index );
}
/*
===============
pfnMod_ForName
===============
*/
static model_t *pfnMod_ForName( const char *model, int crash )
{
return gEngfuncs.Mod_ForName( model, crash, false );
}
/*
===============
pfnGetPlayerState
@@ -400,17 +389,6 @@ static entity_state_t *R_StudioGetPlayerState( int index )
return gEngfuncs.pfnGetPlayerState( index );
}
/*
===============
pfnGetViewEntity
===============
*/
static cl_entity_t *pfnGetViewEntity( void )
{
return tr.viewent;
}
/*
===============
pfnGetEngineTimes
@@ -438,17 +416,6 @@ static void pfnGetViewInfo( float *origin, float *upv, float *rightv, float *for
if( upv ) VectorCopy( RI.vup, upv );
}
/*
===============
R_GetChromeSprite
===============
*/
static model_t *R_GetChromeSprite( void )
{
return gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE );
}
/*
===============
pfnGetModelCounters
@@ -461,18 +428,6 @@ static void pfnGetModelCounters( int **s, int **a )
*a = &r_stats.c_studio_models_drawn;
}
/*
===============
pfnGetAliasScale
===============
*/
static void pfnGetAliasScale( float *x, float *y )
{
if( x ) *x = 1.0f;
if( y ) *y = 1.0f;
}
/*
===============
pfnStudioGetBoneTransform
@@ -495,17 +450,6 @@ static float ****pfnStudioGetLightTransform( void )
return (float ****)g_studio.lighttransform;
}
/*
===============
pfnStudioGetAliasTransform
===============
*/
static float ***pfnStudioGetAliasTransform( void )
{
return NULL;
}
/*
===============
pfnStudioGetRotationMatrix
@@ -2917,18 +2861,6 @@ static void R_StudioSetChromeOrigin( void )
VectorCopy( RI.rvp.vieworigin, g_studio.chrome_origin );
}
/*
===============
pfnIsHardware
Xash3D is always works in hardware mode
===============
*/
static int pfnIsHardware( void )
{
return 1; // 0 is Software, 1 is OpenGL, 2 is Direct3D
}
/*
===============
R_StudioDrawPointsShadow
@@ -3165,7 +3097,7 @@ static void R_StudioRenderModel( void )
R_StudioRenderFinal( );
R_StudioSetForceFaceFlags( STUDIO_NF_CHROME );
TriSpriteTexture( R_GetChromeSprite(), 0 );
TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE ), 0 );
RI.currententity->curstate.renderfx = kRenderFxGlowShell;
R_StudioRenderFinal( );
@@ -3662,20 +3594,6 @@ void R_RunViewmodelEvents( void )
R_StudioDrawModelInternal( RI.currententity, STUDIO_EVENTS );
}
/*
=================
R_GatherPlayerLight
=================
*/
void R_GatherPlayerLight( void )
{
cl_entity_t *view = tr.viewent;
colorVec c;
c = R_LightPoint( view->origin );
gEngfuncs.SetLocalLightLevel( ( c.r + c.g + c.b ) / 3 );
}
/*
=================
R_DrawViewModel
@@ -3685,7 +3603,7 @@ void R_DrawViewModel( void )
{
cl_entity_t *view = tr.viewent;
R_GatherPlayerLight();
R_GatherPlayerLight( view );
if( r_drawviewmodel->value == 0 )
return;
@@ -3881,115 +3799,53 @@ void Mod_StudioUnloadTextures( void *data )
}
}
static model_t *pfnModelHandle( int modelindex )
qboolean R_StudioFillAPI( engine_studio_api_t *api, r_studio_interface_t *pDefaultDraw )
{
if( modelindex < 0 || modelindex >= MAX_MODELS )
return NULL;
return CL_ModelHandle( modelindex );
}
static void *pfnMod_CacheCheck( struct cache_user_s *c )
{
return gEngfuncs.Mod_CacheCheck( c );
}
static void *pfnMod_StudioExtradata( model_t *mod )
{
return gEngfuncs.Mod_Extradata( mod_studio, mod );
}
static void pfnMod_LoadCacheFile( const char *path, struct cache_user_s *cu )
{
gEngfuncs.Mod_LoadCacheFile( path, cu );
}
static cvar_t *pfnGetCvarPointer( const char *name )
{
return (cvar_t*)gEngfuncs.pfnGetCvarPointer( name );
}
static void *pfnMod_Calloc( int number, size_t size )
{
return gEngfuncs.Mod_Calloc( number, size );
}
static engine_studio_api_t gStudioAPI =
{
pfnMod_Calloc,
pfnMod_CacheCheck,
pfnMod_LoadCacheFile,
pfnMod_ForName,
pfnMod_StudioExtradata,
pfnModelHandle,
pfnGetCurrentEntity,
pfnPlayerInfo,
R_StudioGetPlayerState,
pfnGetViewEntity,
pfnGetEngineTimes,
pfnGetCvarPointer,
pfnGetViewInfo,
R_GetChromeSprite,
pfnGetModelCounters,
pfnGetAliasScale,
pfnStudioGetBoneTransform,
pfnStudioGetLightTransform,
pfnStudioGetAliasTransform,
pfnStudioGetRotationMatrix,
R_StudioSetupModel,
R_StudioCheckBBox,
R_StudioDynamicLight,
R_StudioEntityLight,
R_StudioSetupLighting,
R_StudioDrawPoints,
R_StudioDrawHulls,
R_StudioDrawAbsBBox,
R_StudioDrawBones,
(void*)R_StudioSetupSkin,
R_StudioSetRemapColors,
R_StudioSetupPlayerModel,
R_StudioClientEvents,
R_StudioGetForceFaceFlags,
R_StudioSetForceFaceFlags,
(void*)R_StudioSetHeader,
R_StudioSetRenderModel,
R_StudioSetupRenderer,
R_StudioRestoreRenderer,
R_StudioSetChromeOrigin,
pfnIsHardware,
GL_StudioDrawShadow,
GL_StudioSetRenderMode,
R_StudioSetRenderamt,
R_StudioSetCullState,
R_StudioRenderShadow,
};
static r_studio_interface_t gStudioDraw =
{
STUDIO_INTERFACE_VERSION,
R_StudioDrawModel,
R_StudioDrawPlayer,
};
/*
===============
CL_InitStudioAPI
Initialize client studio
===============
*/
void CL_InitStudioAPI( void )
{
pStudioDraw = &gStudioDraw;
// trying to grab them from client.dll
cl_righthand = gEngfuncs.pfnGetCvarPointer( "cl_righthand" );
// Xash will be used internal StudioModelRenderer
if( gEngfuncs.pfnGetStudioModelInterface( STUDIO_INTERFACE_VERSION, &pStudioDraw, &gStudioAPI ))
return;
api->GetCurrentEntity = pfnGetCurrentEntity;
api->PlayerInfo = pfnPlayerInfo;
api->GetPlayerState = R_StudioGetPlayerState;
api->GetTimes = pfnGetEngineTimes;
api->GetViewInfo = pfnGetViewInfo;
api->GetModelCounters = pfnGetModelCounters;
api->StudioGetBoneTransform = pfnStudioGetBoneTransform;
api->StudioGetLightTransform = pfnStudioGetLightTransform;
api->StudioGetRotationMatrix = pfnStudioGetRotationMatrix;
api->StudioSetupModel = R_StudioSetupModel;
api->StudioCheckBBox = R_StudioCheckBBox;
api->StudioDynamicLight = R_StudioDynamicLight;
api->StudioEntityLight = R_StudioEntityLight;
api->StudioSetupLighting = R_StudioSetupLighting;
api->StudioDrawPoints = R_StudioDrawPoints;
api->StudioDrawHulls = R_StudioDrawHulls;
api->StudioDrawAbsBBox = R_StudioDrawAbsBBox;
api->StudioDrawBones = R_StudioDrawBones;
api->StudioSetupSkin = (void *)R_StudioSetupSkin;
api->StudioSetRemapColors = R_StudioSetRemapColors;
api->SetupPlayerModel = R_StudioSetupPlayerModel;
api->StudioClientEvents = R_StudioClientEvents;
api->GetForceFaceFlags = R_StudioGetForceFaceFlags;
api->SetForceFaceFlags = R_StudioSetForceFaceFlags;
api->StudioSetHeader = (void *)R_StudioSetHeader;
api->SetRenderModel = R_StudioSetRenderModel;
api->SetupRenderer = R_StudioSetupRenderer;
api->RestoreRenderer = R_StudioRestoreRenderer;
api->SetChromeOrigin = R_StudioSetChromeOrigin;
api->GL_StudioDrawShadow = GL_StudioDrawShadow;
api->GL_SetRenderMode = GL_StudioSetRenderMode;
api->StudioSetRenderamt = R_StudioSetRenderamt;
api->StudioSetCullState = R_StudioSetCullState;
api->StudioRenderShadow = R_StudioRenderShadow;
// NOTE: we always return true even if game interface was not correct
// because we need Draw our StudioModels
// just restore pointer to builtin function
pStudioDraw = &gStudioDraw;
pDefaultDraw->version = STUDIO_INTERFACE_VERSION;
pDefaultDraw->StudioDrawModel = R_StudioDrawModel;
pDefaultDraw->StudioDrawPlayer = R_StudioDrawPlayer;
return true;
}
void R_StudioSetDrawInterface( r_studio_interface_t *pDraw )
{
pStudioDraw = pDraw;
}

View File

@@ -49,6 +49,37 @@ static void R_SimpleStubBool( qboolean unused )
;
}
static qboolean R_StudioFillAPI( struct engine_studio_api_s *api, struct r_studio_interface_s *pDefaultDraw )
{
return false;
}
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 )
{
;
}
static void R_FillTriAPI( triangleapi_t *api )
{
;
}
static qboolean R_Init( void )
{
gEngfuncs.R_Init_Video( REF_SOFTWARE );
@@ -100,11 +131,6 @@ static void R_SetupSky( int *skytextures )
;
}
static void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
;
}
static void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum )
{
;
@@ -288,7 +314,7 @@ static void R_EntityRemoveDecals( struct model_s *mod )
;
}
static void AVI_UploadRawFrame( int texture, int cols, int rows, int width, int height, const byte *data )
static void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
{
;
}
@@ -409,11 +435,6 @@ static void VGUI_SetupDrawing( qboolean rect )
;
}
static void VGUI_UploadTextureBlock( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
{
;
}
static const ref_interface_t gReffuncs =
{
.R_Init = R_Init,
@@ -440,7 +461,6 @@ static const ref_interface_t gReffuncs =
.R_AddEntity = R_AddEntity,
.R_ProcessEntData = R_ProcessEntData,
.R_Flush = R_SimpleStubUInt,
.R_ShowTextures = R_SimpleStub,
@@ -450,7 +470,6 @@ static const ref_interface_t gReffuncs =
.R_SetupSky = R_SetupSky,
.R_Set2DMode = R_SimpleStubBool,
.R_DrawStretchRaw = R_DrawStretchRaw,
.R_DrawStretchPic = R_DrawStretchPic,
.FillRGBA = FillRGBA,
.WorldToScreen = WorldToScreen,
@@ -467,7 +486,8 @@ static const ref_interface_t gReffuncs =
.R_StudioEstimateFrame = R_StudioEstimateFrame,
.R_StudioLerpMovement = R_StudioLerpMovement,
.CL_InitStudioAPI = R_SimpleStub,
.R_StudioFillAPI = R_StudioFillAPI,
.R_StudioSetDrawInterface = R_StudioSetDrawInterface,
.R_SetSkyCloudsTextures = R_SetSkyCloudsTextures,
.GL_SubdivideSurface = GL_SubdivideSurface,
@@ -480,45 +500,23 @@ static const ref_interface_t gReffuncs =
.CL_DrawParticles = CL_DrawParticles,
.CL_DrawTracers = CL_DrawTracers,
.CL_DrawBeams = CL_DrawBeams,
.R_BeamCull = R_BeamCull,
.RefGetParm = RefGetParm,
.GetDetailScaleForTexture = GetDetailScaleForTexture,
.GetExtraParmsForTexture = GetExtraParmsForTexture,
.GetFrameTime = GetFrameTime,
.RefGetParm = RefGetParm,
.R_SetCurrentEntity = R_SetCurrentEntity,
.R_SetCurrentModel = R_SetCurrentModel,
.R_GetDetailScaleForTexture = R_GetDetailScaleForTexture,
.R_SetDetailScaleForTexture = R_SetDetailScaleForTexture,
.GL_FindTexture = GL_FindTexture,
.GL_TextureName = GL_TextureName,
.GL_TextureData = GL_TextureData,
.GL_LoadTexture = GL_LoadTexture,
.GL_CreateTexture = GL_CreateTexture,
.GL_LoadTextureArray = GL_LoadTextureArray,
.GL_CreateTextureArray = GL_CreateTextureArray,
.GL_FreeTexture = R_SimpleStubUInt,
.GL_CreateTexture = GL_CreateTexture,
.GL_FindTexture = GL_FindTexture,
.GL_TextureName = GL_TextureName,
.GL_TextureData = GL_TextureData,
.GL_LoadTexture = GL_LoadTexture,
.GL_FreeTexture = R_SimpleStubUInt,
.R_OverrideTextureSourceSize = R_OverrideTextureSourceSize,
.DrawSingleDecal = DrawSingleDecal,
.R_DecalSetupVerts = R_DecalSetupVerts,
.R_EntityRemoveDecals = R_EntityRemoveDecals,
.GL_UpdateTexture = GL_UpdateTexture,
.AVI_UploadRawFrame = AVI_UploadRawFrame,
.GL_Bind = GL_Bind,
.GL_SelectTexture = R_SimpleStubInt,
.GL_LoadTextureMatrix = GL_LoadTextureMatrix,
.GL_TexMatrixIdentity = R_SimpleStub,
.GL_CleanUpTextureUnits = R_SimpleStubInt,
.GL_TexGen = GL_TexGen,
.GL_TextureTarget = R_SimpleStubUInt,
.GL_TexCoordArrayMode = R_SimpleStubUInt,
.GL_UpdateTexSize = GL_UpdateTexSize,
.GL_DrawParticles = GL_DrawParticles,
.LightVec = LightVec,
.StudioGetTexture = StudioGetTexture,
.GL_Bind = GL_Bind,
.GL_RenderFrame = GL_RenderFrame,
.GL_OrthoBounds = GL_OrthoBounds,
@@ -526,24 +524,20 @@ static const ref_interface_t gReffuncs =
.Mod_GetCurrentVis = Mod_GetCurrentVis,
.R_NewMap = R_SimpleStub,
.R_ClearScene = R_SimpleStub,
.R_GetProcAddress = R_GetProcAddress,
.TriRenderMode = R_SimpleStubInt,
.Begin = R_SimpleStubInt,
.End = R_SimpleStub,
.Color4f = Color4f,
.Color4ub = Color4ub,
.TexCoord2f = TexCoord2f,
.Vertex3fv = Vertex3fv,
.Vertex3f = Vertex3f,
.Fog = Fog,
.ScreenToWorld = ScreenToWorld,
.GetMatrix = GetMatrix,
.FogParams = FogParams,
.CullFace = CullFace,
.R_FillRenderAPI = R_FillRenderAPI,
.R_FillTriAPI = R_FillTriAPI,
.VGUI_SetupDrawing = VGUI_SetupDrawing,
.VGUI_UploadTextureBlock = VGUI_UploadTextureBlock,
};
int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals );

View File

@@ -116,7 +116,7 @@ R_BeamCull
Cull the beam by bbox
==============
*/
qboolean GAME_EXPORT R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
{
// culling is undone in ref_soft
return false;

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 )
@@ -258,11 +263,6 @@ static void GAME_EXPORT R_ProcessEntData( qboolean allocate, cl_entity_t *entiti
tr.max_entities = max_entities;
}
static void GAME_EXPORT R_Flush( unsigned int flags )
{
// stub
}
// stubs
static void GAME_EXPORT GL_SetTexCoordArrayMode( uint mode )
@@ -372,10 +372,6 @@ byte *GAME_EXPORT Mod_GetCurrentVis( void )
return NULL;
}
static void GAME_EXPORT VGUI_UploadTextureBlock( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
{
}
static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
{
}
@@ -398,6 +394,41 @@ static void * GAME_EXPORT R_GetProcAddress( const char *name )
return gEngfuncs.GL_GetProcAddress( name );
}
static void R_FillRenderAPI( render_api_t *api )
{
api->GetExtraParmsForTexture = R_GetExtraParmsForTexture;
api->GetFrameTime = R_GetFrameTime;
api->R_SetCurrentEntity = R_SetCurrentEntity;
api->R_SetCurrentModel = R_SetCurrentModel;
api->GL_CreateTexture = GL_CreateTexture;
api->GL_LoadTextureArray = GL_LoadTextureArray;
api->GL_CreateTextureArray = GL_CreateTextureArray;
api->DrawSingleDecal = DrawSingleDecal;
api->R_DecalSetupVerts = R_DecalSetupVerts;
api->R_EntityRemoveDecals = R_EntityRemoveDecals;
api->GL_SelectTexture = GL_SelectTexture;
api->GL_LoadTextureMatrix = GL_LoadTexMatrixExt;
api->GL_TexMatrixIdentity = GL_LoadIdentityTexMatrix;
api->GL_CleanUpTextureUnits = GL_CleanUpTextureUnits;
api->GL_TexGen = GL_TexGen;
api->GL_TextureTarget = GL_TextureTarget;
api->GL_TexCoordArrayMode = GL_SetTexCoordArrayMode;
api->GL_UpdateTexSize = GL_UpdateTexSize;
api->GL_DrawParticles = CL_DrawParticlesExternal;
api->LightVec = R_LightVec;
api->StudioGetTexture = R_StudioGetTexture;
api->GL_GetProcAddress = R_GetProcAddress;
}
static void R_FillTriAPI( triangleapi_t *api )
{
api->TexCoord2f = TriTexCoord2f;
api->Fog = TriFog;
api->ScreenToWorld = R_ScreenToWorld;
api->GetMatrix = TriGetMatrix;
api->FogParams = TriFogParams;
}
const ref_interface_t gReffuncs =
{
R_Init,
@@ -424,7 +455,6 @@ const ref_interface_t gReffuncs =
R_AddEntity,
R_ProcessEntData,
R_Flush,
R_ShowTextures,
@@ -434,7 +464,6 @@ const ref_interface_t gReffuncs =
R_SetupSky,
R_Set2DMode,
R_DrawStretchRaw,
R_DrawStretchPic,
CL_FillRGBA,
R_WorldToScreen,
@@ -451,7 +480,8 @@ const ref_interface_t gReffuncs =
R_StudioEstimateFrame,
R_StudioLerpMovement,
CL_InitStudioAPI,
R_StudioFillAPI,
R_StudioSetDrawInterface,
R_SetSkyCloudsTextures,
GL_SubdivideSurface,
@@ -464,45 +494,23 @@ const ref_interface_t gReffuncs =
CL_DrawParticles,
CL_DrawTracers,
CL_DrawBeams,
R_BeamCull,
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_GetExtraParmsForTexture,
R_GetFrameTime,
R_SetCurrentEntity,
R_SetCurrentModel,
R_SetDetailScaleForTexture,
GL_CreateTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,
GL_LoadTexture,
GL_CreateTexture,
GL_LoadTextureArray,
GL_CreateTextureArray,
GL_FreeTexture,
R_OverrideTextureSourceSize,
DrawSingleDecal,
R_DecalSetupVerts,
R_EntityRemoveDecals,
R_UploadStretchRaw,
GL_UpdateTexture,
GL_Bind,
GL_SelectTexture,
GL_LoadTexMatrixExt,
GL_LoadIdentityTexMatrix,
GL_CleanUpTextureUnits,
GL_TexGen,
GL_TextureTarget,
GL_SetTexCoordArrayMode,
GL_UpdateTexSize,
CL_DrawParticlesExternal,
R_LightVec,
R_StudioGetTexture,
R_RenderFrame,
Mod_SetOrthoBounds,
@@ -510,23 +518,19 @@ const ref_interface_t gReffuncs =
Mod_GetCurrentVis,
R_NewMap,
R_ClearScene,
R_GetProcAddress,
TriRenderMode,
TriBegin,
TriEnd,
_TriColor4f,
_TriColor4ub,
TriTexCoord2f,
TriVertex3fv,
TriVertex3f,
TriFog,
R_ScreenToWorld,
TriGetMatrix,
TriFogParams,
TriCullFace,
R_FillRenderAPI,
R_FillTriAPI,
VGUI_SetupDrawing,
VGUI_UploadTextureBlock,
};

View File

@@ -219,19 +219,10 @@ void Draw_Fill( int x, int y, int w, int h )
/*
=============
R_DrawStretchRaw
GL_UpdateTexture
=============
*/
void GAME_EXPORT R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
}
/*
=============
R_UploadStretchRaw
=============
*/
void GAME_EXPORT R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data )
void GAME_EXPORT GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
{
}

View File

@@ -659,7 +659,20 @@ int GAME_EXPORT GL_CreateTexture( const char *name, int width, int height, const
return 0;
}
return GL_LoadTextureInternal( name, &r_empty, flags );
int texnum = GL_LoadTextureInternal( name, &r_empty, flags );
if( !Q_strcmp( name, REF_DEFAULT_TEXTURE ))
tr.defaultTexture = texnum;
else if( !Q_strcmp( name, REF_PARTICLE_TEXTURE ))
tr.particleTexture = texnum;
else if( !Q_strcmp( name, REF_WHITE_TEXTURE ))
tr.whiteTexture = texnum;
else if( !Q_strcmp( name, REF_GRAY_TEXTURE ))
tr.grayTexture = texnum;
else if( !Q_strcmp( name, REF_BLACK_TEXTURE ))
tr.blackTexture = texnum;
return texnum;
}
/*
@@ -838,74 +851,6 @@ void R_InitDlightTexture( void )
tr.dlightTexture = GL_LoadTextureInternal( "*dlight", &r_image, TF_NOMIPMAP | TF_CLAMP | TF_ATLAS_PAGE );
}
/*
==================
GL_CreateInternalTextures
==================
*/
static void GL_CreateInternalTextures( void )
{
int dx2, dy, d;
int x, y;
rgbdata_t *pic;
// emo-texture from quake1
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR );
for( y = 0; y < 16; y++ )
{
for( x = 0; x < 16; x++ )
{
if(( y < 8 ) ^ ( x < 8 ))
((uint *)pic->buffer )[y * 16 + x] = 0xFFFF00FF;
else
((uint *)pic->buffer )[y * 16 + x] = 0xFF000000;
}
}
tr.defaultTexture = GL_LoadTextureInternal( REF_DEFAULT_TEXTURE, pic, TF_COLORMAP );
// particle texture from quake1
pic = GL_FakeImage( 16, 16, 1, IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA );
for( x = 0; x < 16; x++ )
{
dx2 = x - 8;
dx2 = dx2 * dx2;
for( y = 0; y < 16; y++ )
{
dy = y - 8;
d = 255 - 35 * sqrt( dx2 + dy * dy );
pic->buffer[( y * 16 + x ) * 4 + 3] = bound( 0, d, 255 );
}
}
tr.particleTexture = GL_LoadTextureInternal( "*particle", pic, TF_CLAMP );
// white texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer )[x] = 0xFFFFFFFF;
tr.whiteTexture = GL_LoadTextureInternal( REF_WHITE_TEXTURE, pic, TF_COLORMAP );
// gray texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer )[x] = 0xFF7F7F7F;
tr.grayTexture = GL_LoadTextureInternal( REF_GRAY_TEXTURE, pic, TF_COLORMAP );
// black texture
pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR );
for( x = 0; x < 16; x++ )
((uint *)pic->buffer )[x] = 0xFF000000;
tr.blackTexture = GL_LoadTextureInternal( REF_BLACK_TEXTURE, pic, TF_COLORMAP );
// cinematic dummy
pic = GL_FakeImage( 640, 100, 1, IMAGE_HAS_COLOR );
tr.cinTexture = GL_LoadTextureInternal( "*cintexture", pic, TF_NOMIPMAP | TF_CLAMP );
}
/*
===============
R_TextureList_f
@@ -971,7 +916,6 @@ void R_InitImages( void )
r_numImages = 1;
// validate cvars
GL_CreateInternalTextures();
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
}

View File

@@ -205,7 +205,6 @@ typedef struct
int lightmapTextures[MAX_LIGHTMAPS];
int dlightTexture; // custom dlight texture
int skyboxTextures[6]; // skybox sides
int cinTexture; // cinematic texture
// entity lists
draw_list_t draw_stack[MAX_DRAW_STACK];
@@ -317,7 +316,6 @@ typedef struct image_s
// gl_beams.c
//
void CL_DrawBeams( int fTrans, BEAM *active_beams );
qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly );
//
// gl_decals.c
@@ -336,7 +334,7 @@ void GL_Bind( int tmu, unsigned int texnum );
// gl_draw.c
//
void R_Set2DMode( qboolean enable );
void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data ); //
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
// gl_image.c
//
@@ -401,11 +399,11 @@ struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e );
int R_GetEntityRenderMode( cl_entity_t *ent );
void R_DrawStudioModel( cl_entity_t *e );
player_info_t *pfnPlayerInfo( int index );
void R_GatherPlayerLight( void );
float R_StudioEstimateFrame( cl_entity_t *e, mstudioseqdesc_t *pseqdesc, double time );
void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t angles );
void R_StudioResetPlayerModels( void );
void CL_InitStudioAPI( void );
qboolean R_StudioFillAPI( struct engine_studio_api_s *api, struct r_studio_interface_s *pDefaultDraw );
void R_StudioSetDrawInterface( struct r_studio_interface_s *pDraw );
void Mod_StudioLoadTextures( model_t *mod, void *data );
void Mod_StudioUnloadTextures( void *data );
@@ -451,7 +449,6 @@ void R_RenderFrame( const struct ref_viewpass_s *vp );
void R_EndFrame( void );
void R_ClearScene( void );
void R_GetTextureParms( int *w, int *h, int texnum );
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty );
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum );
qboolean R_SpeedsMessage( char *out, size_t size );
qboolean R_CullBox( const vec3_t mins, const vec3_t maxs );

View File

@@ -474,7 +474,7 @@ R_FindViewLeaf
void R_FindViewLeaf( void )
{
RI.oldviewleaf = RI.viewleaf;
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
}
/*
@@ -1172,7 +1172,7 @@ void GAME_EXPORT R_RenderFrame( const ref_viewpass_t *rvp )
if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp ))
{
// R_GatherPlayerLight();
// R_GatherPlayerLight( tr.viewent );
tr.realframecount++;
tr.fResetVis = true;
return;

View File

@@ -293,7 +293,7 @@ void R_SetupFrameQ( void )
// current viewleaf
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
{
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
r_viewcluster = RI.viewleaf->cluster;
}

View File

@@ -359,17 +359,6 @@ player_info_t *pfnPlayerInfo( int index )
return gEngfuncs.pfnPlayerInfo( index );
}
/*
===============
pfnMod_ForName
===============
*/
static model_t *pfnMod_ForName( const char *model, int crash )
{
return gEngfuncs.Mod_ForName( model, crash, false );
}
/*
===============
pfnGetPlayerState
@@ -384,17 +373,6 @@ static entity_state_t *R_StudioGetPlayerState( int index )
return gEngfuncs.pfnGetPlayerState( index );
}
/*
===============
pfnGetViewEntity
===============
*/
static cl_entity_t *pfnGetViewEntity( void )
{
return tr.viewent;
}
/*
===============
pfnGetEngineTimes
@@ -429,17 +407,6 @@ static void pfnGetViewInfo( float *origin, float *upv, float *rightv, float *for
VectorCopy( RI.vup, upv );
}
/*
===============
R_GetChromeSprite
===============
*/
static model_t *R_GetChromeSprite( void )
{
return gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE );
}
/*
===============
pfnGetModelCounters
@@ -452,20 +419,6 @@ static void pfnGetModelCounters( int **s, int **a )
*a = &r_stats.c_studio_models_drawn;
}
/*
===============
pfnGetAliasScale
===============
*/
static void pfnGetAliasScale( float *x, float *y )
{
if( x )
*x = 1.0f;
if( y )
*y = 1.0f;
}
/*
===============
pfnStudioGetBoneTransform
@@ -488,17 +441,6 @@ static float ****pfnStudioGetLightTransform( void )
return (float ****)g_studio.lighttransform;
}
/*
===============
pfnStudioGetAliasTransform
===============
*/
static float ***pfnStudioGetAliasTransform( void )
{
return NULL;
}
/*
===============
pfnStudioGetRotationMatrix
@@ -2575,18 +2517,6 @@ static void R_StudioSetChromeOrigin( void )
VectorCopy( RI.rvp.vieworigin, g_studio.chrome_origin );
}
/*
===============
pfnIsHardware
Xash3D is always works in hardware mode
===============
*/
static int pfnIsHardware( void )
{
return 1; // 0 is Software, 1 is OpenGL, 2 is Direct3D
}
/*
===============
GL_StudioSetRenderMode
@@ -2683,7 +2613,7 @@ static void R_StudioRenderModel( void )
R_StudioRenderFinal( );
R_StudioSetForceFaceFlags( STUDIO_NF_CHROME );
TriSpriteTexture( R_GetChromeSprite(), 0 );
TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE ), 0 );
RI.currententity->curstate.renderfx = kRenderFxGlowShell;
R_StudioRenderFinal( );
@@ -3195,20 +3125,6 @@ void R_RunViewmodelEvents( void )
R_StudioDrawModelInternal( RI.currententity, STUDIO_EVENTS );
}
/*
=================
R_GatherPlayerLight
=================
*/
void R_GatherPlayerLight( void )
{
cl_entity_t *view = tr.viewent;
colorVec c;
c = R_LightPoint( view->origin );
gEngfuncs.SetLocalLightLevel(( c.r + c.g + c.b ) / 3 );
}
/*
=================
R_DrawViewModel
@@ -3218,7 +3134,7 @@ void R_DrawViewModel( void )
{
cl_entity_t *view = tr.viewent;
R_GatherPlayerLight();
R_GatherPlayerLight( view );
if( r_drawviewmodel->value == 0 )
return;
@@ -3415,113 +3331,53 @@ void Mod_StudioUnloadTextures( void *data )
}
}
static model_t *pfnModelHandle( int modelindex )
qboolean R_StudioFillAPI( engine_studio_api_t *api, r_studio_interface_t *pDefaultDraw )
{
return CL_ModelHandle( modelindex );
}
static void *pfnMod_CacheCheck( struct cache_user_s *c )
{
return gEngfuncs.Mod_CacheCheck( c );
}
static void *pfnMod_StudioExtradata( model_t *mod )
{
return gEngfuncs.Mod_Extradata( mod_studio, mod );
}
static void pfnMod_LoadCacheFile( const char *path, struct cache_user_s *cu )
{
gEngfuncs.Mod_LoadCacheFile( path, cu );
}
static cvar_t *pfnGetCvarPointer( const char *name )
{
return (cvar_t *)gEngfuncs.pfnGetCvarPointer( name );
}
static void *pfnMod_Calloc( int number, size_t size )
{
return gEngfuncs.Mod_Calloc( number, size );
}
static engine_studio_api_t gStudioAPI =
{
pfnMod_Calloc,
pfnMod_CacheCheck,
pfnMod_LoadCacheFile,
pfnMod_ForName,
pfnMod_StudioExtradata,
pfnModelHandle,
pfnGetCurrentEntity,
pfnPlayerInfo,
R_StudioGetPlayerState,
pfnGetViewEntity,
pfnGetEngineTimes,
pfnGetCvarPointer,
pfnGetViewInfo,
R_GetChromeSprite,
pfnGetModelCounters,
pfnGetAliasScale,
pfnStudioGetBoneTransform,
pfnStudioGetLightTransform,
pfnStudioGetAliasTransform,
pfnStudioGetRotationMatrix,
R_StudioSetupModel,
R_StudioCheckBBox,
R_StudioDynamicLight,
R_StudioEntityLight,
R_StudioSetupLighting,
R_StudioDrawPoints,
R_StudioDrawHulls,
R_StudioDrawAbsBBox,
R_StudioDrawBones,
(void *)R_StudioSetupSkin,
R_StudioSetRemapColors,
R_StudioSetupPlayerModel,
R_StudioClientEvents,
R_StudioGetForceFaceFlags,
R_StudioSetForceFaceFlags,
(void *)R_StudioSetHeader,
R_StudioSetRenderModel,
R_StudioSetupRenderer,
R_StudioRestoreRenderer,
R_StudioSetChromeOrigin,
pfnIsHardware,
GL_StudioDrawShadow,
GL_StudioSetRenderMode,
R_StudioSetRenderamt,
R_StudioSetCullState,
R_StudioRenderShadow,
};
static r_studio_interface_t gStudioDraw =
{
STUDIO_INTERFACE_VERSION,
R_StudioDrawModel,
R_StudioDrawPlayer,
};
/*
===============
CL_InitStudioAPI
Initialize client studio
===============
*/
void GAME_EXPORT CL_InitStudioAPI( void )
{
pStudioDraw = &gStudioDraw;
// trying to grab them from client.dll
cl_righthand = gEngfuncs.pfnGetCvarPointer( "cl_righthand" );
// Xash will be used internal StudioModelRenderer
if( gEngfuncs.pfnGetStudioModelInterface( STUDIO_INTERFACE_VERSION, &pStudioDraw, &gStudioAPI ))
return;
api->GetCurrentEntity = pfnGetCurrentEntity;
api->PlayerInfo = pfnPlayerInfo;
api->GetPlayerState = R_StudioGetPlayerState;
api->GetTimes = pfnGetEngineTimes;
api->GetViewInfo = pfnGetViewInfo;
api->GetModelCounters = pfnGetModelCounters;
api->StudioGetBoneTransform = pfnStudioGetBoneTransform;
api->StudioGetLightTransform = pfnStudioGetLightTransform;
api->StudioGetRotationMatrix = pfnStudioGetRotationMatrix;
api->StudioSetupModel = R_StudioSetupModel;
api->StudioCheckBBox = R_StudioCheckBBox;
api->StudioDynamicLight = R_StudioDynamicLight;
api->StudioEntityLight = R_StudioEntityLight;
api->StudioSetupLighting = R_StudioSetupLighting;
api->StudioDrawPoints = R_StudioDrawPoints;
api->StudioDrawHulls = R_StudioDrawHulls;
api->StudioDrawAbsBBox = R_StudioDrawAbsBBox;
api->StudioDrawBones = R_StudioDrawBones;
api->StudioSetupSkin = (void *)R_StudioSetupSkin;
api->StudioSetRemapColors = R_StudioSetRemapColors;
api->SetupPlayerModel = R_StudioSetupPlayerModel;
api->StudioClientEvents = R_StudioClientEvents;
api->GetForceFaceFlags = R_StudioGetForceFaceFlags;
api->SetForceFaceFlags = R_StudioSetForceFaceFlags;
api->StudioSetHeader = (void *)R_StudioSetHeader;
api->SetRenderModel = R_StudioSetRenderModel;
api->SetupRenderer = R_StudioSetupRenderer;
api->RestoreRenderer = R_StudioRestoreRenderer;
api->SetChromeOrigin = R_StudioSetChromeOrigin;
api->GL_StudioDrawShadow = GL_StudioDrawShadow;
api->GL_SetRenderMode = GL_StudioSetRenderMode;
api->StudioSetRenderamt = R_StudioSetRenderamt;
api->StudioSetCullState = R_StudioSetCullState;
api->StudioRenderShadow = R_StudioRenderShadow;
// NOTE: we always return true even if game interface was not correct
// because we need Draw our StudioModels
// just restore pointer to builtin function
pStudioDraw = &gStudioDraw;
pDefaultDraw->version = STUDIO_INTERFACE_VERSION;
pDefaultDraw->StudioDrawModel = R_StudioDrawModel;
pDefaultDraw->StudioDrawPlayer = R_StudioDrawPlayer;
return true;
}
void R_StudioSetDrawInterface( r_studio_interface_t *pDraw )
{
pStudioDraw = pDraw;
}