Compare commits

..

12 Commits

Author SHA1 Message Date
Alibek Omarov
0cf571602c ref: common: wscript: fix psvita build 2026-04-13 12:48:55 +05:00
Alibek Omarov
a125f90d12 ref: soft: fix build 2026-04-13 10:00:15 +05:00
Alibek Omarov
313cda5478 ref: add GL_ResampleTexture to libref_common 2026-04-12 23:30:08 +05:00
Alibek Omarov
fc4e7eb18b ref: move remaining light functions to libref_common 2026-04-12 23:18:31 +05:00
Alibek Omarov
0836519b2d ref: gl: refactor R_LightVec 2026-04-12 23:06:43 +05:00
Alibek Omarov
5eeb250907 ref: common: add R_PushDlightsForBmodel 2026-04-12 22:44:55 +05:00
Alibek Omarov
2e579d0dd3 ref: move R_PushDlights and R_MarkLights to ref_common 2026-04-12 22:38:43 +05:00
Alibek Omarov
8cd40db261 ref: move RunLightstyles to ref_common 2026-04-12 22:12:50 +05:00
Alibek Omarov
9d03959196 engine: move sprite texture loading back to engine, only leave rendering for renderer 2026-04-12 17:29:45 +05:00
Alibek Omarov
acd3b0258d ref: common: move malloc and GL_InitRandomTable 2026-04-12 16:10:48 +05:00
Alibek Omarov
0b49e60c22 ref: common: draft new static library, containing shared code for ref_gl and ref_soft 2026-04-12 15:52:33 +05:00
Alibek Omarov
6719443d99 engine: draft new RefAPI 14: remove reserved functions from render api, remove CL_AddCustomBeam 2026-04-12 15:25:19 +05:00
44 changed files with 1438 additions and 925 deletions

View File

@@ -444,16 +444,13 @@ 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;
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 );
ref.dllFuncs.R_DrawStretchRaw( Avi->x, Avi->y, w, h, Avi->xres, Avi->yres, Avi->dst, redraw );
}
else if( redraw && Avi->texture > 0 )
ref.dllFuncs.GL_UpdateTexture( Avi->texture, Avi->xres, Avi->yres, Avi->w, Avi->h, Avi->dst, PF_BGRA_32 );
ref.dllFuncs.AVI_UploadRawFrame( Avi->texture, Avi->xres, Avi->yres, Avi->w, Avi->h, Avi->dst );
if( flushing && !decoded )
return false; // probably hit an EOF

View File

@@ -849,31 +849,6 @@ 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
@@ -886,7 +861,7 @@ BEAM * GAME_EXPORT R_BeamPoints( vec3_t start, vec3_t end, int modelIndex, float
{
BEAM *pbeam;
if( life != 0 && !R_BeamVisible( start, end ))
if( life != 0 && ref.dllFuncs.R_BeamCull( start, end, true ))
return NULL;
pbeam = R_BeamAlloc();

View File

@@ -23,8 +23,6 @@ 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"
@@ -2175,7 +2173,7 @@ pfnGetViewModel
=============
*/
static cl_entity_t *GAME_EXPORT CL_GetViewModel( void )
static cl_entity_t* GAME_EXPORT CL_GetViewModel( void )
{
return &clgame.viewent;
}
@@ -3931,69 +3929,6 @@ 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;
@@ -4131,7 +4066,7 @@ qboolean CL_LoadProgs( const char *name )
// initialize game
clgame.dllFuncs.pfnInit();
CL_InitStudioAPI();
ref.dllFuncs.CL_InitStudioAPI();
return true;
}

View File

@@ -15,7 +15,6 @@ 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"
@@ -1739,8 +1738,6 @@ 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,11 +214,6 @@ 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,
@@ -248,7 +243,7 @@ static render_api_t gRenderAPI =
AVI_GetVideoInfo,
AVI_GetVideoFrameNumber,
AVI_GetVideoFrame,
pfnAVI_UploadRawFrame, // AVI_UploadRawFrame
NULL, // R_UploadStretchRaw,
AVI_FreeVideo,
AVI_IsActive,
pfnAVI_StreamSound,
@@ -288,6 +283,40 @@ 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
@@ -300,15 +329,8 @@ qboolean R_InitRenderAPI( void )
// make sure what render functions is cleared
memset( &clgame.drawFuncs, 0, sizeof( clgame.drawFuncs ));
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 );
// fill missing functions from renderer
R_FillRenderAPIFromRef( &gRenderAPI, &ref.dllFuncs );
if( clgame.dllFuncs.pfnGetRenderInterface )
{

View File

@@ -25,7 +25,6 @@ AVI PLAYING
*/
static movie_state_t *cin_state;
static int cin_texture;
/*
==================
@@ -282,12 +281,6 @@ 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

@@ -360,29 +360,6 @@ qboolean V_PreRender( void )
//============================================================================
/*
====================
V_ApplyRefUnderwater
apply underwater fov effect
====================
*/
static void V_ApplyRefUnderwater( ref_viewpass_t *rvp )
{
if( !FBitSet( rvp->flags, RF_DRAW_CUBEMAP|RF_DRAW_OVERVIEW ))
return;
if( !FBitSet( host.features, ENGINE_QUAKE_COMPATIBLE ))
return;
if( cl.local.waterlevel < 3 )
return;
rvp->fov_x = atan( tan( DEG2RAD( rvp->fov_x ) / 2 ) * ( 0.97f + sin( cl.time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
rvp->fov_y = atan( tan( DEG2RAD( rvp->fov_y ) / 2 ) * ( 1.03f - sin( cl.time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
}
/*
==================
V_RenderView
@@ -412,7 +389,6 @@ void V_RenderView( void )
clgame.dllFuncs.pfnCalcRefdef( &rp );
V_GetRefParams( &rp, &rvp );
V_RefApplyOverview( &rvp );
V_ApplyRefUnderwater( &rvp );
if( viewnum == 0 && FBitSet( rvp.flags, RF_ONLY_CLIENTDRAW ))
{

View File

@@ -874,6 +874,7 @@ 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
@@ -1215,7 +1216,6 @@ 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,6 +287,13 @@ 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];
@@ -322,6 +329,11 @@ 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 =
{
@@ -363,7 +375,7 @@ static const ref_api_t gEngfuncs =
Mod_SampleSizeForFace,
Mod_BoxVisible,
Mod_PointInLeaf,
pfnMod_PointInLeaf,
R_DrawWorldHull,
R_DrawModelHull,
@@ -399,6 +411,7 @@ static const ref_api_t gEngfuncs =
Mod_CacheCheck,
Mod_LoadCacheFile,
Mod_Calloc,
pfnGetStudioModelInterface,
_Mem_AllocPool,
_Mem_FreePool,
@@ -475,82 +488,28 @@ static void R_UnloadProgs( void )
memset( &ref.dllFuncs, 0, sizeof( ref.dllFuncs ));
}
static void CL_FillTriAPI( triangleapi_t *dst )
static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src )
{
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->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 );
dst->FogParams = src->FogParams;
}
static qboolean R_LoadProgs( const char *name )
@@ -596,8 +555,8 @@ static qboolean R_LoadProgs( const char *name )
Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY );
ref.initialized = true;
R_CreateBuiltinTextures();
CL_FillTriAPI( &gTriApi );
// initialize TriAPI callbacks
CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs );
return true;
}

View File

@@ -2989,105 +2989,6 @@ 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,7 +156,6 @@ 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,15 +64,7 @@ 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
// 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 REF_API_VERSION 14
#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP|TF_ALLOW_NEAREST)
#define TF_FONT (TF_NOMIPMAP|TF_CLAMP|TF_ALLOW_NEAREST)
@@ -231,7 +223,7 @@ enum ref_defaultsprite_e
};
// the order of first three is important!
// so you can use this value in IEngineStudio.StudioIsHardware (but shouldn't)
// so you can use this value in IEngineStudio.StudioIsHardware
typedef enum ref_graphic_apis_e
{
REF_SOFTWARE, // hypothetical: just make a surface to draw on, in software
@@ -397,7 +389,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, struct model_s *mod );
mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node );
void (*R_DrawWorldHull)( void );
void (*R_DrawModelHull)( model_t *mod );
@@ -439,6 +431,7 @@ 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 )
@@ -546,6 +539,8 @@ 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 );
@@ -557,6 +552,7 @@ 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
@@ -578,8 +574,7 @@ 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 );
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 (*CL_InitStudioAPI)( void );
// bmodel
void (*R_SetSkyCloudsTextures)( int solidskyTexture, int alphaskyTexture );
@@ -596,27 +591,53 @@ 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 );
// detail texture scale
void (*R_GetDetailScaleForTexture)( int texture, float *xScale, float *yScale );
void (*R_SetDetailScaleForTexture)( int texture, float xScale, float yScale );
// 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
// Texture tools (used by engine directly)
int (*GL_CreateTexture)( const char *name, int width, int height, const void *buffer, texFlags_t flags );
// Texture tools
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
void (*GL_UpdateTexture)( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
// 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)
// glState related calls (used by engine directly)
// 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)
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 );
@@ -630,23 +651,28 @@ 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 (functions used by engine wrappers)
// TriAPI Interface
// NOTE: implementation isn't required to be compatible
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,7 +81,6 @@ 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,20 +475,6 @@ 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

@@ -578,7 +578,7 @@ static void R_AliasDynamicLight( cl_entity_t *ent, alight_t *plight )
if( !plight || !ent )
return;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
if( !RI.drawWorld || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
{
plight->shadelight = 0;
plight->ambientlight = 192;
@@ -1126,7 +1126,7 @@ init current time for a given model
*/
static void R_AliasSetupTimings( void )
{
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
// synchronize with server time
g_alias.time = gp_cl->time;

View File

@@ -61,7 +61,7 @@ void GL_BackendEndFrame( void )
{
mleaf_t *curleaf;
if( r_speeds->value <= 0 || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( r_speeds->value <= 0 || !RI.drawWorld )
return;
if( !RI.viewleaf )
@@ -616,7 +616,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
string basename;
int i = 1, flags, result;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || !WORLDMODEL )
if( !RI.drawWorld || !WORLDMODEL )
return false;
// make sure the specified size is valid
@@ -633,7 +633,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo
r_side = Mem_Calloc( r_temppool, sizeof( rgbdata_t ));
// use client vieworg
if( !vieworg ) vieworg = RI.rvp.vieworigin;
if( !vieworg ) vieworg = RI.vieworg;
for( i = 0; i < 6; i++ )
{

View File

@@ -98,7 +98,7 @@ static void R_BeamComputeNormal( const vec3_t vStartPos, const vec3_t vNextPos,
VectorSubtract( vStartPos, vNextPos, vTangentY );
// vDirToBeam = vector from viewer origin to beam
VectorSubtract( vStartPos, RI.rvp.vieworigin, vDirToBeam );
VectorSubtract( vStartPos, RI.vieworg, vDirToBeam );
// get a vector that is perpendicular to us and perpendicular to the beam.
// this is used to fatten the beam.
@@ -114,7 +114,7 @@ R_BeamCull
Cull the beam by bbox
==============
*/
static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
{
vec3_t mins, maxs;
int i;
@@ -1006,7 +1006,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
float flDistance;
// fade the beam if the player's not looking at the source
VectorSubtract( RI.rvp.vieworigin, pbeam->source, localDir );
VectorSubtract( RI.vieworg, pbeam->source, localDir );
flDot = DotProduct( delta, localDir );
VectorScale( delta, flDot, vecProjection );
VectorSubtract( localDir, vecProjection, tmp );

View File

@@ -244,14 +244,6 @@ 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 );
@@ -319,6 +311,11 @@ 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
@@ -372,6 +369,11 @@ 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 );
@@ -411,85 +413,6 @@ 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,
@@ -516,6 +439,7 @@ const ref_interface_t gReffuncs =
R_AddEntity,
R_ProcessEntData,
R_Flush,
R_ShowTextures,
@@ -525,6 +449,7 @@ const ref_interface_t gReffuncs =
R_SetupSky,
R_Set2DMode,
R_DrawStretchRaw,
R_DrawStretchPic,
CL_FillRGBA,
R_WorldToScreen,
@@ -541,8 +466,7 @@ const ref_interface_t gReffuncs =
R_StudioEstimateFrame,
R_StudioLerpMovement,
R_StudioFillAPI,
R_StudioSetDrawInterface,
CL_InitStudioAPI,
R_SetSkyCloudsTextures,
GL_SubdivideSurface,
@@ -555,23 +479,45 @@ const ref_interface_t gReffuncs =
CL_DrawParticles,
CL_DrawTracers,
CL_DrawBeams,
R_BeamCull,
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_SetDetailScaleForTexture,
R_GetExtraParmsForTexture,
R_GetFrameTime,
R_SetCurrentEntity,
R_SetCurrentModel,
GL_CreateTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,
GL_LoadTexture,
GL_CreateTexture,
GL_LoadTextureArray,
GL_CreateTextureArray,
GL_FreeTexture,
R_OverrideTextureSourceSize,
GL_UpdateTexture,
DrawSingleDecal,
R_DecalSetupVerts,
R_EntityRemoveDecals,
R_UploadStretchRaw,
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,
@@ -579,19 +525,23 @@ 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

@@ -47,7 +47,7 @@ qboolean R_CullModel( const cl_entity_t *e, const vec3_t absmin, const vec3_t ab
if( ENGINE_GET_PARM( PARM_DEV_OVERVIEW ))
return true;
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ) && !ENGINE_GET_PARM( PARM_THIRDPERSON ) && CL_IsViewEntityLocalPlayer())
if( RP_NORMALPASS() && !ENGINE_GET_PARM( PARM_THIRDPERSON ) && CL_IsViewEntityLocalPlayer())
return false;
return true;
@@ -85,7 +85,7 @@ int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint cli
float dist;
// can use normal.z for world (optimisation)
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
if( RI.drawOrtho )
{
vec3_t orthonormal;

View File

@@ -55,69 +55,120 @@ void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, f
/*
=============
GL_UpdateTexture
R_DrawStretchRaw
=============
*/
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
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 ))
{
width = NearestPOW( width, true );
height = NearestPOW( height, false );
}
int width = 1, height = 1;
if( cols != width || rows != height )
{
raw = GL_ResampleTexture( buffer, cols, rows, width, height, false );
cols = width;
rows = height;
// 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 *)buffer;
{
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 );
tex = R_GetTexture( texnum );
GL_Bind( GL_KEEP_UNIT, texnum );
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 )
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, gl_format, GL_UNSIGNED_BYTE, raw );
{
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;
pglTexImage2D( GL_TEXTURE_2D, 0, tex->format, cols, rows, 0, gl_format, GL_UNSIGNED_BYTE, raw );
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 );
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 );
tex = R_GetTexture( texture );
GL_Bind( GL_KEEP_UNIT, texture );
tex->width = cols;
tex->height = rows;
pglTexImage2D( GL_TEXTURE_2D, 0, tex->format, cols, rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, raw );
GL_ApplyTextureParams( tex );
}

View File

@@ -23,6 +23,19 @@ 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 ))
/*
=================
@@ -1686,20 +1699,7 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe
r_empty.size *= 6;
}
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;
return GL_LoadTextureFromBuffer( name, &r_empty, flags, update );
}
/*
@@ -1912,6 +1912,70 @@ 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
@@ -2144,6 +2208,7 @@ void R_InitImages( void )
// validate cvars
R_SetTextureParameters();
GL_CreateInternalTextures();
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
}

View File

@@ -70,9 +70,17 @@ void VGL_ShimEndFrame( void );
#define SHADE_LAMBERT 1.4953241
#define DEFAULT_ALPHATEST 0.0f
// refparams
#define RP_NONE 0
#define RP_ENVVIEW BIT( 0 ) // used for cubemapshot
#define RP_OLDVIEWLEAF BIT( 1 )
#define RP_CLIPPLANE BIT( 2 )
#define RP_NONVIEWERREF (RP_ENVVIEW)
#define R_ModelOpaque( rm ) ( rm == kRenderNormal )
#define R_StaticEntity( ent ) ( VectorIsNull( ent->origin ) && VectorIsNull( ent->angles ))
#define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( gp_cl->playernum + 1 ) && e->player )
#define RP_NORMALPASS() ( FBitSet( RI.params, RP_NONVIEWERREF ) == 0 )
#define CL_IsViewEntityLocalPlayer() ( gp_cl->viewentity == ( gp_cl->playernum + 1 ))
@@ -119,16 +127,27 @@ typedef struct gltexture_s
typedef struct
{
ref_viewpass_t rvp;
int params; // rendering parameters
qboolean drawWorld; // ignore world for drawing PlayerModel
qboolean isSkyVisible; // sky is visible
qboolean onlyClientDraw; // disabled by client request
qboolean drawOrtho; // draw world as orthogonal projection
float fov_x, fov_y; // current view fov
cl_entity_t *currententity;
model_t *currentmodel;
cl_entity_t *currentbeam; // same as above but for beams
int viewport[4];
gl_frustum_t frustum;
mleaf_t *viewleaf;
mleaf_t *oldviewleaf;
vec3_t pvsorigin;
vec3_t vieworg; // locked vieworigin
vec3_t viewangles;
vec3_t vforward;
vec3_t vright;
vec3_t vup;
@@ -187,6 +206,8 @@ 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
@@ -294,6 +315,7 @@ 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
@@ -316,7 +338,7 @@ void R_ClearDecals( void );
// gl_draw.c
//
void R_Set2DMode( qboolean enable );
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data );
//
// gl_image.c
@@ -366,6 +388,10 @@ void R_DrawFog( void );
int CL_FxBlend( cl_entity_t *e );
//
// gl_rmisc.c
//
void R_NewMap( void );
//
// gl_rsurf.c
//
@@ -409,11 +435,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 );
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 CL_InitStudioAPI( void );
void Mod_StudioLoadTextures( model_t *mod, void *data );
void Mod_StudioUnloadTextures( void *data );
@@ -456,6 +482,7 @@ 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

@@ -101,7 +101,7 @@ static int R_TransEntityCompare( const void *a, const void *b )
{
VectorAverage( ent1->model->mins, ent1->model->maxs, org );
VectorAdd( ent1->origin, org, org );
VectorSubtract( RI.rvp.vieworigin, org, vecLen );
VectorSubtract( RI.vieworg, org, vecLen );
dist1 = DotProduct( vecLen, vecLen );
}
else dist1 = 1000000000;
@@ -110,7 +110,7 @@ static int R_TransEntityCompare( const void *a, const void *b )
{
VectorAverage( ent2->model->mins, ent2->model->maxs, org );
VectorAdd( ent2->origin, org, org );
VectorSubtract( RI.rvp.vieworigin, org, vecLen );
VectorSubtract( RI.vieworg, org, vecLen );
dist2 = DotProduct( vecLen, vecLen );
}
else dist2 = 1000000000;
@@ -317,7 +317,7 @@ static void R_Clear( int bitMask )
pglClear( bits );
// change ordering for overview
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
if( RI.drawOrtho )
{
gldepthmin = 1.0f;
gldepthmax = 0.0f;
@@ -340,7 +340,7 @@ R_GetFarClip
*/
static float R_GetFarClip( void )
{
if( WORLDMODEL && FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( WORLDMODEL && RI.drawWorld )
return tr.movevars->zmax * 1.73f;
return 2048.0f;
}
@@ -352,26 +352,28 @@ R_SetupFrustum
*/
void R_SetupFrustum( void )
{
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
if( RP_NORMALPASS() && FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE ) && ( ENGINE_GET_PARM( PARM_WATER_LEVEL ) >= 3 ))
{
RI.fov_x = atan( tan( DEG2RAD( RI.fov_x ) / 2 ) * ( 0.97f + sin( gp_cl->time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
RI.fov_y = atan( tan( DEG2RAD( RI.fov_y ) / 2 ) * ( 1.03f - sin( gp_cl->time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
}
// build the transformation matrix for the given view angles
AngleVectors( RI.rvp.viewangles, RI.vforward, RI.vright, RI.vup );
AngleVectors( RI.viewangles, RI.vforward, RI.vright, RI.vup );
if( !r_lockfrustum.value )
{
VectorCopy( RI.rvp.vieworigin, RI.cullorigin );
VectorCopy( RI.vieworg, RI.cullorigin );
VectorCopy( RI.vforward, RI.cull_vforward );
VectorCopy( RI.vright, RI.cull_vright );
VectorCopy( RI.vup, RI.cull_vup );
}
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
{
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
if( RI.drawOrtho )
GL_FrustumInitOrtho( &RI.frustum, ov->xLeft, ov->xRight, ov->yTop, ov->yBottom, ov->zNear, ov->zFar );
}
else
{
GL_FrustumInitProj( &RI.frustum, 0.0f, R_GetFarClip(), RI.rvp.fov_x, RI.rvp.fov_y ); // NOTE: we ignore nearplane here (mirrors only)
}
else GL_FrustumInitProj( &RI.frustum, 0.0f, R_GetFarClip(), RI.fov_x, RI.fov_y ); // NOTE: we ignore nearplane here (mirrors only)
}
/*
@@ -383,7 +385,7 @@ static void R_SetupProjectionMatrix( matrix4x4 m )
{
GLfloat xMin, xMax, yMin, yMax, zNear, zFar;
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
if( RI.drawOrtho )
{
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
Matrix4x4_CreateOrtho( m, ov->xLeft, ov->xRight, ov->yTop, ov->yBottom, ov->zNear, ov->zFar );
@@ -395,10 +397,10 @@ static void R_SetupProjectionMatrix( matrix4x4 m )
zNear = 4.0f;
zFar = Q_max( 256.0f, RI.farClip );
yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f );
yMax = zNear * tan( RI.fov_y * M_PI_F / 360.0f );
yMin = -yMax;
xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f );
xMax = zNear * tan( RI.fov_x * M_PI_F / 360.0f );
xMin = -xMax;
if( tr.rotation & 1 )
@@ -421,17 +423,17 @@ static void R_SetupModelviewMatrix( matrix4x4 m )
Matrix4x4_CreateModelview( m );
if( tr.rotation & 1 )
{
Matrix4x4_ConcatRotate( m, anglemod( -RI.rvp.viewangles[2] + 90 ), 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[1], 0, 0, 1 );
Matrix4x4_ConcatRotate( m, anglemod( -RI.viewangles[2] + 90 ), 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[1], 0, 0, 1 );
}
else
{
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[2], 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[1], 0, 0, 1 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[2], 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[1], 0, 0, 1 );
}
Matrix4x4_ConcatTranslate( m, -RI.rvp.vieworigin[0], -RI.rvp.vieworigin[1], -RI.rvp.vieworigin[2] );
Matrix4x4_ConcatTranslate( m, -RI.vieworg[0], -RI.vieworg[1], -RI.vieworg[2] );
}
/*
@@ -511,7 +513,7 @@ R_FindViewLeaf
void R_FindViewLeaf( void )
{
RI.oldviewleaf = RI.viewleaf;
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.pvsorigin, WORLDMODEL->nodes );
}
/*
@@ -522,7 +524,7 @@ R_SetupFrame
static void R_SetupFrame( void )
{
// setup viewplane dist
RI.viewplanedist = DotProduct( RI.rvp.vieworigin, RI.vforward );
RI.viewplanedist = DotProduct( RI.vieworg, RI.vforward );
// NOTE: this request is the fps-killer on some NVidia drivers
glState.isFogEnabled = pglIsEnabled( GL_FOG );
@@ -534,8 +536,11 @@ static void R_SetupFrame( void )
}
// current viewleaf
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
RI.isSkyVisible = false; // unknown at this moment
R_FindViewLeaf();
}
}
/*
@@ -552,15 +557,15 @@ void R_SetupGL( qboolean set_gl_state )
if( !set_gl_state ) return;
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
int x, x2, y, y2;
// set up viewport (main, playersetup)
x = floor( RI.rvp.viewport[0] * gpGlobals->width / gpGlobals->width );
x2 = ceil(( RI.rvp.viewport[0] + RI.rvp.viewport[2] ) * gpGlobals->width / gpGlobals->width );
y = floor( gpGlobals->height - RI.rvp.viewport[1] * gpGlobals->height / gpGlobals->height );
y2 = ceil( gpGlobals->height - ( RI.rvp.viewport[1] + RI.rvp.viewport[3] ) * gpGlobals->height / gpGlobals->height );
x = floor( RI.viewport[0] * gpGlobals->width / gpGlobals->width );
x2 = ceil(( RI.viewport[0] + RI.viewport[2] ) * gpGlobals->width / gpGlobals->width );
y = floor( gpGlobals->height - RI.viewport[1] * gpGlobals->height / gpGlobals->height );
y2 = ceil( gpGlobals->height - ( RI.viewport[1] + RI.viewport[3] ) * gpGlobals->height / gpGlobals->height );
if( tr.rotation & 1 )
pglViewport( y2, x, y - y2, x2 - x );
@@ -569,7 +574,7 @@ void R_SetupGL( qboolean set_gl_state )
else
{
// envpass, mirrorpass
pglViewport( RI.rvp.viewport[0], RI.rvp.viewport[1], RI.rvp.viewport[2], RI.rvp.viewport[3] );
pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );
}
pglMatrixMode( GL_PROJECTION );
@@ -578,6 +583,20 @@ void R_SetupGL( qboolean set_gl_state )
pglMatrixMode( GL_MODELVIEW );
GL_LoadMatrix( RI.worldviewMatrix );
if( FBitSet( RI.params, RP_CLIPPLANE ))
{
GLdouble clip[4];
mplane_t *p = &RI.clipPlane;
clip[0] = p->normal[0];
clip[1] = p->normal[1];
clip[2] = p->normal[2];
clip[3] = -p->dist;
pglClipPlane( GL_CLIP_PLANE0, clip );
pglEnable( GL_CLIP_PLANE0 );
}
GL_Cull( GL_FRONT );
pglDisable( GL_BLEND );
@@ -585,6 +604,17 @@ void R_SetupGL( qboolean set_gl_state )
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
}
/*
=============
R_EndGL
=============
*/
static void R_EndGL( void )
{
if( RI.params & RP_CLIPPLANE )
pglDisable( GL_CLIP_PLANE0 );
}
/*
=============
R_RecursiveFindWaterTexture
@@ -701,7 +731,7 @@ static void R_CheckFog( void )
RI.fogEnabled = false;
if( FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ) || ENGINE_GET_PARM( PARM_WATER_LEVEL ) < 3 || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || !RI.viewleaf )
if( RI.onlyClientDraw || ENGINE_GET_PARM( PARM_WATER_LEVEL ) < 3 || !RI.drawWorld || !RI.viewleaf )
{
if( RI.cached_waterlevel == 3 )
{
@@ -717,7 +747,7 @@ static void R_CheckFog( void )
return;
}
ent = gEngfuncs.CL_GetWaterEntity( RI.rvp.vieworigin );
ent = gEngfuncs.CL_GetWaterEntity( RI.vieworg );
if( ent && ent->model && ent->model->type == mod_brush && ent->curstate.skin < 0 )
cnt = ent->curstate.skin;
else cnt = RI.viewleaf->contents;
@@ -823,7 +853,7 @@ static void R_DrawEntitiesOnList( void )
GL_CheckForErrors();
// first draw solid entities
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->solid_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -855,7 +885,7 @@ static void R_DrawEntitiesOnList( void )
GL_CheckForErrors();
// draw sprites seperately, because of alpha blending
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->solid_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -873,20 +903,20 @@ static void R_DrawEntitiesOnList( void )
GL_CheckForErrors();
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
{
gEngfuncs.CL_DrawEFX( tr.frametime, false );
}
GL_CheckForErrors();
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
gEngfuncs.pfnDrawNormalTriangles();
GL_CheckForErrors();
// then draw translucent entities
for( i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_trans_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->trans_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -922,7 +952,7 @@ static void R_DrawEntitiesOnList( void )
GL_CheckForErrors();
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
gEngfuncs.pfnDrawTransparentTriangles ();
@@ -930,7 +960,7 @@ static void R_DrawEntitiesOnList( void )
GL_CheckForErrors();
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
{
R_AllowFog( false );
gEngfuncs.CL_DrawEFX( tr.frametime, true );
@@ -941,7 +971,7 @@ static void R_DrawEntitiesOnList( void )
pglDisable( GL_BLEND ); // Trinity Render issues
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
R_DrawViewModel();
gEngfuncs.CL_ExtraUpdate();
@@ -957,11 +987,11 @@ R_SetupRefParams must be called right before
*/
void R_RenderScene( void )
{
if( !WORLDMODEL && FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !WORLDMODEL && RI.drawWorld )
gEngfuncs.Host_Error( "%s: NULL worldmodel\n", __func__ );
// frametime is valid only for normal pass
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
tr.frametime = gp_cl->time - gp_cl->oldtime;
else tr.frametime = 0.0;
@@ -977,7 +1007,7 @@ void R_RenderScene( void )
R_MarkLeaves();
R_DrawFog ();
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
R_AnimateRipples();
R_CheckGLFog();
@@ -989,6 +1019,8 @@ void R_RenderScene( void )
R_DrawEntitiesOnList();
R_DrawWaterSurfaces();
R_EndGL();
}
void R_GammaChanged( qboolean do_reset_gamma )
@@ -1077,9 +1109,28 @@ set initial params for renderer
*/
void R_SetupRefParams( const ref_viewpass_t *rvp )
{
RI.rvp = *rvp;
RI.params = RP_NONE;
RI.drawWorld = FBitSet( rvp->flags, RF_DRAW_WORLD );
RI.onlyClientDraw = FBitSet( rvp->flags, RF_ONLY_CLIENTDRAW );
RI.farClip = 0;
if( !FBitSet( rvp->flags, RF_DRAW_CUBEMAP ))
RI.drawOrtho = FBitSet( rvp->flags, RF_DRAW_OVERVIEW );
else RI.drawOrtho = false;
// setup viewport
RI.viewport[0] = rvp->viewport[0];
RI.viewport[1] = rvp->viewport[1];
RI.viewport[2] = rvp->viewport[2];
RI.viewport[3] = rvp->viewport[3];
// calc FOV
RI.fov_x = rvp->fov_x;
RI.fov_y = rvp->fov_y;
VectorCopy( rvp->vieworigin, RI.vieworg );
VectorCopy( rvp->viewangles, RI.viewangles );
VectorCopy( rvp->vieworigin, RI.pvsorigin );
}
/*
@@ -1095,7 +1146,7 @@ void R_RenderFrame( const ref_viewpass_t *rvp )
// setup the initial render params
R_SetupRefParams( rvp );
if( gl_finish.value && FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( gl_finish.value && RI.drawWorld )
pglFinish();
// completely override rendering
@@ -1105,7 +1156,7 @@ void R_RenderFrame( const ref_viewpass_t *rvp )
if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp ))
{
R_GatherPlayerLight( tr.viewent );
R_GatherPlayerLight();
tr.realframecount++;
tr.fResetVis = true;
return;
@@ -1113,7 +1164,7 @@ void R_RenderFrame( const ref_viewpass_t *rvp )
}
tr.fCustomRendering = false;
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
R_RunViewmodelEvents();
tr.realframecount++; // right called after viewmodel events
@@ -1195,7 +1246,7 @@ int CL_FxBlend( cl_entity_t *e )
blend = e->curstate.renderamt + 0x10 * sin( gp_cl->time * 8 + offset );
break;
case kRenderFxFadeSlow:
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt > 0 )
e->curstate.renderamt -= 1;
@@ -1204,7 +1255,7 @@ int CL_FxBlend( cl_entity_t *e )
blend = e->curstate.renderamt;
break;
case kRenderFxFadeFast:
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt > 3 )
e->curstate.renderamt -= 4;
@@ -1213,7 +1264,7 @@ int CL_FxBlend( cl_entity_t *e )
blend = e->curstate.renderamt;
break;
case kRenderFxSolidSlow:
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt < 255 )
e->curstate.renderamt += 1;
@@ -1222,7 +1273,7 @@ int CL_FxBlend( cl_entity_t *e )
blend = e->curstate.renderamt;
break;
case kRenderFxSolidFast:
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt < 252 )
e->curstate.renderamt += 4;
@@ -1258,7 +1309,7 @@ int CL_FxBlend( cl_entity_t *e )
case kRenderFxHologram:
case kRenderFxDistort:
VectorCopy( e->origin, tmp );
VectorSubtract( tmp, RI.rvp.vieworigin, tmp );
VectorSubtract( tmp, RI.vieworg, tmp );
dist = DotProduct( tmp, RI.vforward );
// turn off distance fade

161
ref/gl/gl_rmisc.c Normal file
View File

@@ -0,0 +1,161 @@
/*
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

@@ -73,9 +73,9 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float
size = partsize; // get initial size of particle
// scale up to keep particles from disappearing
size += (p->org[0] - RI.rvp.vieworigin[0]) * RI.cull_vforward[0];
size += (p->org[1] - RI.rvp.vieworigin[1]) * RI.cull_vforward[1];
size += (p->org[2] - RI.rvp.vieworigin[2]) * RI.cull_vforward[2];
size += (p->org[0] - RI.vieworg[0]) * RI.cull_vforward[0];
size += (p->org[1] - RI.vieworg[1]) * RI.cull_vforward[1];
size += (p->org[2] - RI.vieworg[2]) * RI.cull_vforward[2];
if( size < 20.0f ) size = partsize;
else size = partsize + size * 0.002f;

View File

@@ -956,7 +956,7 @@ static void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples
if( !warp->polys ) return;
// set the current waveheight
if( warp->polys->verts[0][2] >= RI.rvp.vieworigin[2] )
if( warp->polys->verts[0][2] >= RI.vieworg[2] )
waveHeight = -RI.currententity->curstate.scale;
else waveHeight = RI.currententity->curstate.scale;
@@ -1610,7 +1610,7 @@ void R_DrawWaterSurfaces( void )
msurface_t *s;
texture_t *t;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.drawWorld || RI.onlyClientDraw )
return;
// non-transparent water is already drawed
@@ -1792,8 +1792,7 @@ void R_DrawBrushModel( cl_entity_t *e )
qboolean rotated;
qboolean allow_vbo = R_HasEnabledVBO();
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
return;
if( !RI.drawWorld ) return;
model_t *clmodel = e->model;
@@ -3684,7 +3683,7 @@ void R_DrawWorld( void )
return;
RI.currentmodel = RI.currententity->model;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.drawWorld || RI.onlyClientDraw )
return;
VectorCopy( RI.cullorigin, tr.modelorg );
@@ -3700,7 +3699,7 @@ void R_DrawWorld( void )
R_ClearSkyBox ();
start = gEngfuncs.pfnTime();
if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ))
if( RI.drawOrtho )
R_DrawWorldTopView( WORLDMODEL->nodes, RI.frustum.clipFlags );
else R_RecursiveWorldNode( WORLDMODEL->nodes, RI.frustum.clipFlags );
end = gEngfuncs.pfnTime();
@@ -3749,8 +3748,7 @@ void R_MarkLeaves( void )
vec3_t test;
int i;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
return;
if( !RI.drawWorld ) return;
if( FBitSet( r_novis.flags, FCVAR_CHANGED ) || tr.fResetVis )
{
@@ -3760,17 +3758,17 @@ void R_MarkLeaves( void )
RI.viewleaf = NULL;
}
VectorCopy( RI.rvp.vieworigin, test );
VectorCopy( RI.pvsorigin, test );
if( RI.viewleaf != NULL )
{
// merge two leafs that can be a crossed-line contents
if( RI.viewleaf->contents == CONTENTS_EMPTY )
VectorSet( test, RI.rvp.vieworigin[0], RI.rvp.vieworigin[1], RI.rvp.vieworigin[2] - 16.0f );
VectorSet( test, RI.pvsorigin[0], RI.pvsorigin[1], RI.pvsorigin[2] - 16.0f );
else
VectorSet( test, RI.rvp.vieworigin[0], RI.rvp.vieworigin[1], RI.rvp.vieworigin[2] + 16.0f );
VectorSet( test, RI.pvsorigin[0], RI.pvsorigin[1], RI.pvsorigin[2] + 16.0f );
leaf = gEngfuncs.Mod_PointInLeaf( test, WORLDMODEL->nodes, WORLDMODEL );
leaf = gEngfuncs.Mod_PointInLeaf( test, WORLDMODEL->nodes );
if(( leaf->contents != CONTENTS_SOLID ) && ( RI.viewleaf != leaf ))
force = true;
@@ -3786,10 +3784,10 @@ void R_MarkLeaves( void )
RI.oldviewleaf = RI.viewleaf;
tr.visframecount++;
if( r_novis.value || FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW ) || !RI.viewleaf || !WORLDMODEL->visdata )
if( r_novis.value || RI.drawOrtho || !RI.viewleaf || !WORLDMODEL->visdata )
novis = true;
gEngfuncs.R_FatPVS( RI.rvp.vieworigin, r_pvs_radius->value, RI.visbytes, false, novis );
gEngfuncs.R_FatPVS( RI.pvsorigin, r_pvs_radius->value, RI.visbytes, FBitSet( RI.params, RP_OLDVIEWLEAF ), novis );
if( force && !novis )
gEngfuncs.R_FatPVS( test, r_pvs_radius->value, RI.visbytes, true, novis );

View File

@@ -143,7 +143,7 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old
{
// e.g. doom-style sprite monsters
float yaw = ent->angles[YAW];
int angleframe = (int)(Q_rint(( RI.rvp.viewangles[1] - yaw + 45.0f ) / 360 * 8) - 4) & 7;
int angleframe = (int)(Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8) - 4) & 7;
if( m_fDoInterp )
{
@@ -233,12 +233,12 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo
vec3_t glowDist;
pmtrace_t *tr;
VectorSubtract( origin, RI.rvp.vieworigin, glowDist );
VectorSubtract( origin, RI.vieworg, glowDist );
dist = VectorLength( glowDist );
if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RP_NORMALPASS( ))
{
tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE));
tr = gEngfuncs.EV_VisTraceLine( RI.vieworg, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE));
if(( 1.0f - tr->fraction ) * dist > 8.0f )
return 0.0f;
@@ -270,9 +270,9 @@ static qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale )
TriWorldToScreen( origin, v );
if( v[0] < RI.rvp.viewport[0] || v[0] > RI.rvp.viewport[0] + RI.rvp.viewport[2] )
if( v[0] < RI.viewport[0] || v[0] > RI.viewport[0] + RI.viewport[2] )
return true; // do scissor
if( v[1] < RI.rvp.viewport[1] || v[1] > RI.rvp.viewport[1] + RI.rvp.viewport[3] )
if( v[1] < RI.viewport[1] || v[1] > RI.viewport[1] + RI.viewport[3] )
return true; // do scissor
blend = R_SpriteGlowBlend( origin, e->curstate.rendermode, e->curstate.renderfx, pscale );
@@ -386,7 +386,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
vec3_t v_forward, v_right, v_up;
vec3_t origin, color, color2 = { 0.0f };
if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( RI.params & RP_ENVVIEW )
return;
model = e->model;
@@ -495,7 +495,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
VectorSubtract( origin, v_forward, origin );
break;
case SPR_FACING_UPRIGHT:
VectorSet( v_right, origin[1] - RI.rvp.vieworigin[1], -(origin[0] - RI.rvp.vieworigin[0]), 0.0f );
VectorSet( v_right, origin[1] - RI.vieworg[1], -(origin[0] - RI.vieworg[0]), 0.0f );
VectorSet( v_up, 0.0f, 0.0f, 1.0f );
VectorNormalize( v_right );
break;

View File

@@ -167,7 +167,7 @@ init current time for a given model
*/
static void R_StudioSetupTimings( void )
{
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
// synchronize with server time
g_studio.time = gp_cl->time;
@@ -369,12 +369,23 @@ pfnPlayerInfo
*/
player_info_t *pfnPlayerInfo( int index )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
index = -1;
return gEngfuncs.pfnPlayerInfo( index );
}
/*
===============
pfnMod_ForName
===============
*/
static model_t *pfnMod_ForName( const char *model, int crash )
{
return gEngfuncs.Mod_ForName( model, crash, false );
}
/*
===============
pfnGetPlayerState
@@ -383,12 +394,23 @@ pfnGetPlayerState
*/
static entity_state_t *R_StudioGetPlayerState( int index )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
return &RI.currententity->curstate;
return gEngfuncs.pfnGetPlayerState( index );
}
/*
===============
pfnGetViewEntity
===============
*/
static cl_entity_t *pfnGetViewEntity( void )
{
return tr.viewent;
}
/*
===============
pfnGetEngineTimes
@@ -410,12 +432,23 @@ pfnGetViewInfo
*/
static void pfnGetViewInfo( float *origin, float *upv, float *rightv, float *forwardv )
{
if( origin ) VectorCopy( RI.rvp.vieworigin, origin );
if( origin ) VectorCopy( RI.vieworg, origin );
if( forwardv ) VectorCopy( RI.vforward, forwardv );
if( rightv ) VectorCopy( RI.vright, rightv );
if( upv ) VectorCopy( RI.vup, upv );
}
/*
===============
R_GetChromeSprite
===============
*/
static model_t *R_GetChromeSprite( void )
{
return gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE );
}
/*
===============
pfnGetModelCounters
@@ -428,6 +461,18 @@ 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
@@ -450,6 +495,17 @@ static float ****pfnStudioGetLightTransform( void )
return (float ****)g_studio.lighttransform;
}
/*
===============
pfnStudioGetAliasTransform
===============
*/
static float ***pfnStudioGetAliasTransform( void )
{
return NULL;
}
/*
===============
pfnStudioGetRotationMatrix
@@ -1272,7 +1328,7 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight )
if( !plight || !ent || !ent->model )
return;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
if( !RI.drawWorld || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
{
plight->shadelight = 0;
plight->ambientlight = 192;
@@ -2606,7 +2662,7 @@ static model_t *R_StudioSetupPlayerModel( int index )
state = &g_studio.player_models[index];
// g-cont: force for "dev-mode", non-local games and menu preview
if(( gpGlobals->developer || !ENGINE_GET_PARM( PARM_LOCAL_GAME ) || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) ) && info->model[0] )
if(( gpGlobals->developer || !ENGINE_GET_PARM( PARM_LOCAL_GAME ) || !RI.drawWorld ) && info->model[0] )
{
if( Q_strcmp( state->name, info->model ))
{
@@ -2858,7 +2914,19 @@ R_StudioSetChromeOrigin
*/
static void R_StudioSetChromeOrigin( void )
{
VectorCopy( RI.rvp.vieworigin, g_studio.chrome_origin );
VectorCopy( RI.vieworg, 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
}
/*
@@ -3097,7 +3165,7 @@ static void R_StudioRenderModel( void )
R_StudioRenderFinal( );
R_StudioSetForceFaceFlags( STUDIO_NF_CHROME );
TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE ), 0 );
TriSpriteTexture( R_GetChromeSprite(), 0 );
RI.currententity->curstate.renderfx = kRenderFxGlowShell;
R_StudioRenderFinal( );
@@ -3330,7 +3398,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer )
if( flags & STUDIO_RENDER )
{
// change body if it's a menu entity
if( cl_himodels->value && ( RI.currentmodel != RI.currententity->model || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD )))
if( cl_himodels->value && ( RI.currentmodel != RI.currententity->model || !RI.drawWorld ))
{
// show highest resolution multiplayer model
RI.currententity->curstate.body = 255;
@@ -3486,7 +3554,7 @@ R_StudioDrawModelInternal
*/
static void R_StudioDrawModelInternal( cl_entity_t *e, int flags )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
{
if( e->player )
R_StudioDrawPlayer( flags, &e->curstate );
@@ -3521,7 +3589,7 @@ R_DrawStudioModel
*/
void R_DrawStudioModel( cl_entity_t *e )
{
if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ))
if( FBitSet( RI.params, RP_ENVVIEW ))
return;
R_StudioSetupTimings();
@@ -3576,7 +3644,7 @@ void R_RunViewmodelEvents( void )
return;
// ignore in thirdperson, camera view or client is died
if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ) || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
if( !RP_NORMALPASS() || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
return;
RI.currententity = tr.viewent;
@@ -3594,6 +3662,20 @@ 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
@@ -3603,7 +3685,7 @@ void R_DrawViewModel( void )
{
cl_entity_t *view = tr.viewent;
R_GatherPlayerLight( view );
R_GatherPlayerLight();
if( r_drawviewmodel->value == 0 )
return;
@@ -3612,7 +3694,7 @@ void R_DrawViewModel( void )
return;
// ignore in thirdperson, camera view or client is died
if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP ) || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
if( !RP_NORMALPASS() || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
return;
tr.blend = CL_FxBlend( view ) / 255.0f;
@@ -3799,53 +3881,115 @@ void Mod_StudioUnloadTextures( void *data )
}
}
qboolean R_StudioFillAPI( engine_studio_api_t *api, r_studio_interface_t *pDefaultDraw )
static model_t *pfnModelHandle( int modelindex )
{
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" );
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;
// Xash will be used internal StudioModelRenderer
if( gEngfuncs.pfnGetStudioModelInterface( STUDIO_INTERFACE_VERSION, &pStudioDraw, &gStudioAPI ))
return;
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;
// 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;
}

View File

@@ -226,10 +226,10 @@ int TriWorldToScreen( const float *world, float *screen )
retval = R_WorldToScreen( world, screen );
screen[0] = 0.5f * screen[0] * (float)RI.rvp.viewport[2];
screen[1] = -0.5f * screen[1] * (float)RI.rvp.viewport[3];
screen[0] += 0.5f * (float)RI.rvp.viewport[2];
screen[1] += 0.5f * (float)RI.rvp.viewport[3];
screen[0] = 0.5f * screen[0] * (float)RI.viewport[2];
screen[1] = -0.5f * screen[1] * (float)RI.viewport[3];
screen[0] += 0.5f * (float)RI.viewport[2];
screen[1] += 0.5f * (float)RI.viewport[3];
return retval;
}

View File

@@ -339,6 +339,10 @@ R_DrawSkybox
*/
void R_DrawSkyBox( void )
{
int i;
RI.isSkyVisible = true;
// don't fogging skybox (this fix old Half-Life bug)
if( !RI.fogSkybox ) R_AllowFog( false );
@@ -349,7 +353,7 @@ void R_DrawSkyBox( void )
pglDisable( GL_ALPHA_TEST );
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
for( int i = 0; i < SKYBOX_MAX_SIDES; i++ )
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
{
if( RI.skyMins[0][i] >= RI.skyMaxs[0][i] || RI.skyMins[1][i] >= RI.skyMaxs[1][i] )
continue;
@@ -417,7 +421,7 @@ static void R_CloudTexCoord( const vec3_t v, float speed, float *s, float *t )
speedscale = gp_cl->time * speed;
speedscale -= (int)speedscale & ~127;
VectorSubtract( v, RI.rvp.vieworigin, dir );
VectorSubtract( v, RI.vieworg, dir );
dir[2] *= 3.0f; // flatten the sphere
length = VectorLength( dir );
@@ -529,12 +533,16 @@ Quake-style clouds
*/
void R_DrawClouds( void )
{
int i;
RI.isSkyVisible = true;
if( RI.fogEnabled )
pglFogf( GL_FOG_DENSITY, RI.fogDensity * 0.25f );
pglDepthFunc( GL_GEQUAL );
pglDepthMask( GL_FALSE );
for( int i = 0; i < SKYBOX_MAX_SIDES; i++ )
for( i = 0; i < SKYBOX_MAX_SIDES; i++ )
{
if( RI.skyMins[0][i] >= RI.skyMaxs[0][i] || RI.skyMins[1][i] >= RI.skyMaxs[1][i] )
continue;

View File

@@ -49,37 +49,6 @@ 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 );
@@ -131,6 +100,11 @@ 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 )
{
;
@@ -314,7 +288,7 @@ static void R_EntityRemoveDecals( struct model_s *mod )
;
}
static void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
static void AVI_UploadRawFrame( int texture, int cols, int rows, int width, int height, const byte *data )
{
;
}
@@ -435,6 +409,11 @@ 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,
@@ -461,6 +440,7 @@ static const ref_interface_t gReffuncs =
.R_AddEntity = R_AddEntity,
.R_ProcessEntData = R_ProcessEntData,
.R_Flush = R_SimpleStubUInt,
.R_ShowTextures = R_SimpleStub,
@@ -470,6 +450,7 @@ 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,
@@ -486,8 +467,7 @@ static const ref_interface_t gReffuncs =
.R_StudioEstimateFrame = R_StudioEstimateFrame,
.R_StudioLerpMovement = R_StudioLerpMovement,
.R_StudioFillAPI = R_StudioFillAPI,
.R_StudioSetDrawInterface = R_StudioSetDrawInterface,
.CL_InitStudioAPI = R_SimpleStub,
.R_SetSkyCloudsTextures = R_SetSkyCloudsTextures,
.GL_SubdivideSurface = GL_SubdivideSurface,
@@ -500,23 +480,45 @@ static const ref_interface_t gReffuncs =
.CL_DrawParticles = CL_DrawParticles,
.CL_DrawTracers = CL_DrawTracers,
.CL_DrawBeams = CL_DrawBeams,
.R_BeamCull = R_BeamCull,
.RefGetParm = RefGetParm,
.RefGetParm = RefGetParm,
.GetDetailScaleForTexture = GetDetailScaleForTexture,
.GetExtraParmsForTexture = GetExtraParmsForTexture,
.GetFrameTime = GetFrameTime,
.R_GetDetailScaleForTexture = R_GetDetailScaleForTexture,
.R_SetDetailScaleForTexture = R_SetDetailScaleForTexture,
.R_SetCurrentEntity = R_SetCurrentEntity,
.R_SetCurrentModel = R_SetCurrentModel,
.GL_CreateTexture = GL_CreateTexture,
.GL_FindTexture = GL_FindTexture,
.GL_TextureName = GL_TextureName,
.GL_TextureData = GL_TextureData,
.GL_LoadTexture = GL_LoadTexture,
.GL_FreeTexture = R_SimpleStubUInt,
.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,
.R_OverrideTextureSourceSize = R_OverrideTextureSourceSize,
.GL_UpdateTexture = GL_UpdateTexture,
.DrawSingleDecal = DrawSingleDecal,
.R_DecalSetupVerts = R_DecalSetupVerts,
.R_EntityRemoveDecals = R_EntityRemoveDecals,
.GL_Bind = GL_Bind,
.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_RenderFrame = GL_RenderFrame,
.GL_OrthoBounds = GL_OrthoBounds,
@@ -524,20 +526,24 @@ 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

@@ -100,7 +100,7 @@ static void R_BeamComputeNormal( const vec3_t vStartPos, const vec3_t vNextPos,
VectorSubtract( vStartPos, vNextPos, vTangentY );
// vDirToBeam = vector from viewer origin to beam
VectorSubtract( vStartPos, RI.rvp.vieworigin, vDirToBeam );
VectorSubtract( vStartPos, RI.vieworg, vDirToBeam );
// get a vector that is perpendicular to us and perpendicular to the beam.
// this is used to fatten the beam.
@@ -116,7 +116,7 @@ R_BeamCull
Cull the beam by bbox
==============
*/
static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
qboolean GAME_EXPORT R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly )
{
// culling is undone in ref_soft
return false;
@@ -1000,7 +1000,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime )
float flDistance;
// fade the beam if the player's not looking at the source
VectorSubtract( RI.rvp.vieworigin, pbeam->source, localDir );
VectorSubtract( RI.vieworg, pbeam->source, localDir );
flDot = DotProduct( delta, localDir );
VectorScale( delta, flDot, vecProjection );
VectorSubtract( localDir, vecProjection, tmp );

View File

@@ -643,14 +643,14 @@ R_RenderWorld
*/
void R_RenderWorld( void )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
return;
// auto cycle the world frame for texture animation
RI.currententity = CL_GetEntityByIndex( 0 );
// RI.currententity->frame = (int)(gp_cl->time*2);
VectorCopy( RI.rvp.vieworigin, tr.modelorg );
VectorCopy( RI.vieworg, tr.modelorg );
RI.currentmodel = WORLDMODEL;
r_pcurrentvertbase = RI.currentmodel->vertexes;

View File

@@ -198,13 +198,8 @@ static void GAME_EXPORT R_GetDetailScaleForTexture( int texture, float *xScale,
{
// details are not implemented in ref_soft
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
if( xScale ) *xScale = 0.0f;
if( yScale ) *yScale = 0.0f;
}
static void GAME_EXPORT R_GetExtraParmsForTexture( int texture, byte *red, byte *green, byte *blue, byte *density )
@@ -263,6 +258,11 @@ 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,6 +372,10 @@ 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 )
{
}
@@ -394,41 +398,6 @@ 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,
@@ -455,6 +424,7 @@ const ref_interface_t gReffuncs =
R_AddEntity,
R_ProcessEntData,
R_Flush,
R_ShowTextures,
@@ -464,6 +434,7 @@ const ref_interface_t gReffuncs =
R_SetupSky,
R_Set2DMode,
R_DrawStretchRaw,
R_DrawStretchPic,
CL_FillRGBA,
R_WorldToScreen,
@@ -480,8 +451,7 @@ const ref_interface_t gReffuncs =
R_StudioEstimateFrame,
R_StudioLerpMovement,
R_StudioFillAPI,
R_StudioSetDrawInterface,
CL_InitStudioAPI,
R_SetSkyCloudsTextures,
GL_SubdivideSurface,
@@ -494,23 +464,45 @@ const ref_interface_t gReffuncs =
CL_DrawParticles,
CL_DrawTracers,
CL_DrawBeams,
R_BeamCull,
GL_RefGetParm,
R_GetDetailScaleForTexture,
R_SetDetailScaleForTexture,
R_GetExtraParmsForTexture,
R_GetFrameTime,
R_SetCurrentEntity,
R_SetCurrentModel,
GL_CreateTexture,
GL_FindTexture,
GL_TextureName,
GL_TextureData,
GL_LoadTexture,
GL_CreateTexture,
GL_LoadTextureArray,
GL_CreateTextureArray,
GL_FreeTexture,
R_OverrideTextureSourceSize,
GL_UpdateTexture,
DrawSingleDecal,
R_DecalSetupVerts,
R_EntityRemoveDecals,
R_UploadStretchRaw,
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,
@@ -518,19 +510,23 @@ 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,10 +219,19 @@ void Draw_Fill( int x, int y, int w, int h )
/*
=============
GL_UpdateTexture
R_DrawStretchRaw
=============
*/
void GAME_EXPORT GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt )
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 )
{
}

View File

@@ -877,7 +877,7 @@ static void D_TurbulentSurf( surf_t *s )
// TODO: store once at start of frame
RI.currententity = s->entity; // FIXME: make this passed in to
// R_RotateBmodel ()
VectorSubtract( RI.rvp.vieworigin, RI.currententity->origin,
VectorSubtract( RI.vieworg, RI.currententity->origin,
local_modelorg );
TransformVector( local_modelorg, transformed_modelorg );
@@ -940,7 +940,7 @@ static void D_AlphaSurf( surf_t *s )
// TODO: store once at start of frame
RI.currententity = s->entity; // FIXME: make this passed in to
// R_RotateBmodel ()
VectorSubtract( RI.rvp.vieworigin, RI.currententity->origin, local_modelorg );
VectorSubtract( RI.vieworg, RI.currententity->origin, local_modelorg );
TransformVector( local_modelorg, transformed_modelorg );
R_RotateBmodel(); // FIXME: don't mess with the frustum,
@@ -1021,7 +1021,7 @@ static void D_SolidSurf( surf_t *s )
// TODO: store once at start of frame
RI.currententity = s->entity; // FIXME: make this passed in to
// R_RotateBmodel ()
VectorSubtract( RI.rvp.vieworigin, RI.currententity->origin, local_modelorg );
VectorSubtract( RI.vieworg, RI.currententity->origin, local_modelorg );
TransformVector( local_modelorg, transformed_modelorg );
R_RotateBmodel(); // FIXME: don't mess with the frustum,
@@ -1123,7 +1123,7 @@ void D_DrawSurfaces( void )
surf_t *s;
// currententity = NULL; //&r_worldentity;
VectorSubtract( RI.rvp.vieworigin, vec3_origin, tr.modelorg );
VectorSubtract( RI.vieworg, vec3_origin, tr.modelorg );
TransformVector( tr.modelorg, transformed_modelorg );
VectorCopy( transformed_modelorg, world_transformed_modelorg );
@@ -1148,7 +1148,7 @@ void D_DrawSurfaces( void )
D_DrawflatSurfaces();
// RI.currententity = NULL; //&r_worldentity;
VectorSubtract( RI.rvp.vieworigin, vec3_origin, tr.modelorg );
VectorSubtract( RI.vieworg, vec3_origin, tr.modelorg );
R_TransformFrustum();
}

View File

@@ -659,20 +659,7 @@ int GAME_EXPORT GL_CreateTexture( const char *name, int width, int height, const
return 0;
}
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;
return GL_LoadTextureInternal( name, &r_empty, flags );
}
/*
@@ -851,6 +838,74 @@ 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
@@ -916,6 +971,7 @@ void R_InitImages( void )
r_numImages = 1;
// validate cvars
GL_CreateInternalTextures();
gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" );
}

View File

@@ -61,9 +61,17 @@ typedef int fixed16_t;
#define SHADE_LAMBERT 1.4953241
#define DEFAULT_ALPHATEST 0.0f
// refparams
#define RP_NONE 0
#define RP_ENVVIEW BIT( 0 ) // used for cubemapshot
#define RP_OLDVIEWLEAF BIT( 1 )
#define RP_CLIPPLANE BIT( 2 )
#define RP_NONVIEWERREF ( RP_ENVVIEW )
#define R_ModelOpaque( rm ) ( rm == kRenderNormal )
#define R_StaticEntity( ent ) ( VectorIsNull( ent->origin ) && VectorIsNull( ent->angles ))
#define RP_LOCALCLIENT( e ) (( e ) != NULL && ( e )->index == ( gp_cl->playernum + 1 ) && e->player )
#define RP_NORMALPASS() ( FBitSet( RI.params, RP_NONVIEWERREF ) == 0 )
#define CL_IsViewEntityLocalPlayer() ( gp_cl->viewentity == ( gp_cl->playernum + 1 ))
@@ -122,16 +130,27 @@ extern viddef_t vid;
typedef struct
{
ref_viewpass_t rvp;
int params; // rendering parameters
qboolean drawWorld; // ignore world for drawing PlayerModel
qboolean isSkyVisible; // sky is visible
qboolean onlyClientDraw; // disabled by client request
qboolean drawOrtho; // draw world as orthogonal projection
float fov_x, fov_y; // current view fov
cl_entity_t *currententity;
model_t *currentmodel;
cl_entity_t *currentbeam; // same as above but for beams
int viewport[4];
// gl_frustum_t frustum;
mleaf_t *viewleaf;
mleaf_t *oldviewleaf;
vec3_t pvsorigin;
vec3_t vieworg; // locked vieworigin
vec3_t viewangles;
vec3_t vforward;
vec3_t vright;
vec3_t vup;
@@ -205,6 +224,7 @@ 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];
@@ -316,6 +336,7 @@ 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
@@ -334,7 +355,7 @@ void GL_Bind( int tmu, unsigned int texnum );
// gl_draw.c
//
void R_Set2DMode( qboolean enable );
void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt );
void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data ); //
// gl_image.c
//
@@ -399,11 +420,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 );
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 CL_InitStudioAPI( void );
void Mod_StudioLoadTextures( model_t *mod, void *data );
void Mod_StudioUnloadTextures( void *data );
@@ -449,6 +470,7 @@ 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

@@ -172,7 +172,7 @@ static int R_TransEntityCompare( const cl_entity_t **a, const cl_entity_t **b )
{
VectorAverage( ent1->model->mins, ent1->model->maxs, org );
VectorAdd( ent1->origin, org, org );
VectorSubtract( RI.rvp.vieworigin, org, vecLen );
VectorSubtract( RI.vieworg, org, vecLen );
dist1 = DotProduct( vecLen, vecLen );
}
else
@@ -182,7 +182,7 @@ static int R_TransEntityCompare( const cl_entity_t **a, const cl_entity_t **b )
{
VectorAverage( ent2->model->mins, ent2->model->maxs, org );
VectorAdd( ent2->origin, org, org );
VectorSubtract( RI.rvp.vieworigin, org, vecLen );
VectorSubtract( RI.vieworg, org, vecLen );
dist2 = DotProduct( vecLen, vecLen );
}
else
@@ -379,7 +379,7 @@ R_GetFarClip
*/
static float R_GetFarClip( void )
{
if( WORLDMODEL && FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( WORLDMODEL && RI.drawWorld )
return tr.movevars->zmax * 1.73f;
return 2048.0f;
}
@@ -392,10 +392,10 @@ R_SetupFrustum
void R_SetupFrustum( void )
{
// build the transformation matrix for the given view angles
AngleVectors( RI.rvp.viewangles, RI.vforward, RI.vright, RI.vup );
AngleVectors( RI.viewangles, RI.vforward, RI.vright, RI.vup );
{
VectorCopy( RI.rvp.vieworigin, RI.cullorigin );
VectorCopy( RI.vieworg, RI.cullorigin );
VectorCopy( RI.vforward, RI.cull_vforward );
VectorCopy( RI.vright, RI.cull_vright );
VectorCopy( RI.vup, RI.cull_vup );
@@ -411,15 +411,22 @@ static void R_SetupProjectionMatrix( matrix4x4 m )
{
float xMin, xMax, yMin, yMax, zNear, zFar;
if( RI.drawOrtho )
{
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
Matrix4x4_CreateOrtho( m, ov->xLeft, ov->xRight, ov->yTop, ov->yBottom, ov->zNear, ov->zFar );
return;
}
RI.farClip = R_GetFarClip();
zNear = 4.0f;
zFar = Q_max( 256.0f, RI.farClip );
yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f );
yMax = zNear * tan( RI.fov_y * M_PI_F / 360.0f );
yMin = -yMax;
xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f );
xMax = zNear * tan( RI.fov_x * M_PI_F / 360.0f );
xMin = -xMax;
Matrix4x4_CreateProjection( m, xMax, xMin, yMax, yMin, zNear, zFar );
@@ -433,10 +440,10 @@ R_SetupModelviewMatrix
static void R_SetupModelviewMatrix( matrix4x4 m )
{
Matrix4x4_CreateModelview( m );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[2], 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.rvp.viewangles[1], 0, 0, 1 );
Matrix4x4_ConcatTranslate( m, -RI.rvp.vieworigin[0], -RI.rvp.vieworigin[1], -RI.rvp.vieworigin[2] );
Matrix4x4_ConcatRotate( m, -RI.viewangles[2], 1, 0, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[0], 0, 1, 0 );
Matrix4x4_ConcatRotate( m, -RI.viewangles[1], 0, 0, 1 );
Matrix4x4_ConcatTranslate( m, -RI.vieworg[0], -RI.vieworg[1], -RI.vieworg[2] );
}
/*
@@ -474,7 +481,7 @@ R_FindViewLeaf
void R_FindViewLeaf( void )
{
RI.oldviewleaf = RI.viewleaf;
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.pvsorigin, WORLDMODEL->nodes );
}
/*
@@ -485,7 +492,7 @@ R_SetupFrame
static void R_SetupFrame( void )
{
// setup viewplane dist
RI.viewplanedist = DotProduct( RI.rvp.vieworigin, RI.vforward );
RI.viewplanedist = DotProduct( RI.vieworg, RI.vforward );
// if( !gl_nosort->value )
{
@@ -494,8 +501,11 @@ static void R_SetupFrame( void )
}
// current viewleaf
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
RI.isSkyVisible = false; // unknown at this moment
R_FindViewLeaf();
}
// setup twice until globals fully refactored
R_SetupFrameQ();
@@ -517,7 +527,7 @@ static void R_DrawEntitiesOnList( void )
d_pdrawspans = R_PolysetFillSpans8;
GL_SetRenderMode( kRenderNormal );
// first draw solid entities
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->solid_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -545,7 +555,7 @@ static void R_DrawEntitiesOnList( void )
R_SetUpWorldTransform();
// draw sprites seperately, because of alpha blending
for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_solid_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->solid_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -561,17 +571,17 @@ static void R_DrawEntitiesOnList( void )
}
}
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
{
gEngfuncs.CL_DrawEFX( tr.frametime, false );
}
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
gEngfuncs.pfnDrawNormalTriangles();
d_pdrawspans = R_PolysetDrawSpans8_33;
// then draw translucent entities
for( i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_trans_entities && !RI.onlyClientDraw; i++ )
{
RI.currententity = tr.draw_list->trans_entities[i];
RI.currentmodel = RI.currententity->model;
@@ -609,10 +619,12 @@ static void R_DrawEntitiesOnList( void )
}
}
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
gEngfuncs.pfnDrawTransparentTriangles();
}
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
{
R_AllowFog( false );
gEngfuncs.CL_DrawEFX( tr.frametime, true );
@@ -621,7 +633,7 @@ static void R_DrawEntitiesOnList( void )
GL_SetRenderMode( kRenderNormal );
R_SetUpWorldTransform();
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
R_DrawViewModel();
gEngfuncs.CL_ExtraUpdate();
@@ -792,7 +804,7 @@ static void R_DrawBEntitiesOnList( void )
VectorCopy( tr.modelorg, oldorigin );
insubmodel = true;
for( i = 0; i < tr.draw_list->num_edge_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ )
for( i = 0; i < tr.draw_list->num_edge_entities && !RI.onlyClientDraw; i++ )
{
int k;
RI.currententity = tr.draw_list->edge_entities[i];
@@ -820,7 +832,7 @@ static void R_DrawBEntitiesOnList( void )
continue; // no part in a visible leaf
VectorCopy( RI.currententity->origin, r_entorigin );
VectorSubtract( RI.rvp.vieworigin, r_entorigin, tr.modelorg );
VectorSubtract( RI.vieworg, r_entorigin, tr.modelorg );
// VectorSubtract (r_origin, RI.currententity->origin, modelorg);
r_pcurrentvertbase = RI.currentmodel->vertexes;
@@ -878,7 +890,7 @@ void R_DrawBrushModel( cl_entity_t *pent )
surf_t lsurfs[NUMSTACKSURFACES
+ (( CACHE_SIZE - 1 ) / sizeof( surf_t )) + 1];
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
return;
if( auxedges )
@@ -932,7 +944,7 @@ void R_DrawBrushModel( cl_entity_t *pent )
alphaspans = true;
VectorCopy( RI.currententity->origin, r_entorigin );
VectorSubtract( RI.rvp.vieworigin, r_entorigin, tr.modelorg );
VectorSubtract( RI.vieworg, r_entorigin, tr.modelorg );
// VectorSubtract (r_origin, RI.currententity->origin, modelorg);
r_pcurrentvertbase = RI.currentmodel->vertexes;
@@ -986,7 +998,7 @@ static void R_EdgeDrawing( void )
surf_t lsurfs[NUMSTACKSURFACES
+ (( CACHE_SIZE - 1 ) / sizeof( surf_t )) + 1];
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
return;
if( auxedges )
@@ -1041,7 +1053,7 @@ static void R_MarkLeaves( void )
tr.visframecount++;
r_oldviewcluster = r_viewcluster;
gEngfuncs.R_FatPVS( RI.rvp.vieworigin, r_pvs_radius->value, RI.visbytes, false, false );
gEngfuncs.R_FatPVS( RI.pvsorigin, r_pvs_radius->value, RI.visbytes, FBitSet( RI.params, RP_OLDVIEWLEAF ), false );
vis = RI.visbytes;
for( i = 0; i < WORLDMODEL->numleafs; i++ )
@@ -1070,11 +1082,14 @@ R_SetupRefParams must be called right before
*/
void GAME_EXPORT R_RenderScene( void )
{
if( !WORLDMODEL && FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !WORLDMODEL && RI.drawWorld )
gEngfuncs.Host_Error( "%s: NULL worldmodel\n", __func__ );
// frametime is valid only for normal pass
tr.frametime = gp_cl->time - gp_cl->oldtime;
if( RP_NORMALPASS( ))
tr.frametime = gp_cl->time - gp_cl->oldtime;
else
tr.frametime = 0.0;
// begin a new frame
tr.framecount++;
@@ -1145,7 +1160,28 @@ set initial params for renderer
*/
void R_SetupRefParams( const ref_viewpass_t *rvp )
{
RI.rvp = *rvp;
RI.params = RP_NONE;
RI.drawWorld = FBitSet( rvp->flags, RF_DRAW_WORLD );
RI.onlyClientDraw = FBitSet( rvp->flags, RF_ONLY_CLIENTDRAW );
if( !FBitSet( rvp->flags, RF_DRAW_CUBEMAP ))
RI.drawOrtho = FBitSet( rvp->flags, RF_DRAW_OVERVIEW );
else
RI.drawOrtho = false;
// setup viewport
RI.viewport[0] = rvp->viewport[0];
RI.viewport[1] = rvp->viewport[1];
RI.viewport[2] = rvp->viewport[2];
RI.viewport[3] = rvp->viewport[3];
// calc FOV
RI.fov_x = rvp->fov_x;
RI.fov_y = rvp->fov_y;
VectorCopy( rvp->vieworigin, RI.vieworg );
VectorCopy( rvp->viewangles, RI.viewangles );
VectorCopy( rvp->vieworigin, RI.pvsorigin );
}
/*
@@ -1172,7 +1208,7 @@ void GAME_EXPORT R_RenderFrame( const ref_viewpass_t *rvp )
if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp ))
{
// R_GatherPlayerLight( tr.viewent );
// R_GatherPlayerLight();
tr.realframecount++;
tr.fResetVis = true;
return;
@@ -1180,7 +1216,7 @@ void GAME_EXPORT R_RenderFrame( const ref_viewpass_t *rvp )
}
tr.fCustomRendering = false;
if( !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ))
if( !RI.onlyClientDraw )
R_RunViewmodelEvents();
tr.realframecount++; // right called after viewmodel events
@@ -1446,31 +1482,43 @@ int CL_FxBlend( cl_entity_t *e )
blend = e->curstate.renderamt + 0x10 * sin( gp_cl->time * 8 + offset );
break;
case kRenderFxFadeSlow:
if( e->curstate.renderamt > 0 )
e->curstate.renderamt -= 1;
else
e->curstate.renderamt = 0;
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt > 0 )
e->curstate.renderamt -= 1;
else
e->curstate.renderamt = 0;
}
blend = e->curstate.renderamt;
break;
case kRenderFxFadeFast:
if( e->curstate.renderamt > 3 )
e->curstate.renderamt -= 4;
else
e->curstate.renderamt = 0;
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt > 3 )
e->curstate.renderamt -= 4;
else
e->curstate.renderamt = 0;
}
blend = e->curstate.renderamt;
break;
case kRenderFxSolidSlow:
if( e->curstate.renderamt < 255 )
e->curstate.renderamt += 1;
else
e->curstate.renderamt = 255;
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt < 255 )
e->curstate.renderamt += 1;
else
e->curstate.renderamt = 255;
}
blend = e->curstate.renderamt;
break;
case kRenderFxSolidFast:
if( e->curstate.renderamt < 252 )
e->curstate.renderamt += 4;
else
e->curstate.renderamt = 255;
if( RP_NORMALPASS( ))
{
if( e->curstate.renderamt < 252 )
e->curstate.renderamt += 4;
else
e->curstate.renderamt = 255;
}
blend = e->curstate.renderamt;
break;
case kRenderFxStrobeSlow:
@@ -1511,7 +1559,7 @@ int CL_FxBlend( cl_entity_t *e )
case kRenderFxHologram:
case kRenderFxDistort:
VectorCopy( e->origin, tmp );
VectorSubtract( tmp, RI.rvp.vieworigin, tmp );
VectorSubtract( tmp, RI.vieworg, tmp );
dist = DotProduct( tmp, RI.vforward );
// turn off distance fade

View File

@@ -87,8 +87,10 @@ void D_ViewChanged( void )
/*
** clear Z-buffer and color-buffers if we're doing the gallery
*/
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
{
memset( d_pzbuffer, 0xff, vid.width * vid.height * sizeof( d_pzbuffer[0] ));
}
D_Patch();
}
@@ -182,8 +184,8 @@ static void R_ViewChanged( vrect_t *vr )
RI.vrect = *vr;
horizontalFieldOfView = 2 * tan((float)RI.rvp.fov_x / 360.0f * M_PI_F );
verticalFieldOfView = 2 * tan((float)RI.rvp.fov_y / 360.0f * M_PI_F );
horizontalFieldOfView = 2 * tan((float)RI.fov_x / 360.0f * M_PI_F );
verticalFieldOfView = 2 * tan((float)RI.fov_y / 360.0f * M_PI_F );
RI.fvrectx = (float)RI.vrect.x;
RI.fvrectx_adj = (float)RI.vrect.x - 0.5f;
@@ -286,14 +288,14 @@ void R_SetupFrameQ( void )
// build the transformation matrix for the given view angles
VectorCopy( RI.rvp.vieworigin, tr.modelorg );
VectorCopy( RI.vieworg, tr.modelorg );
// AngleVectors (RI.rvp.viewangles, RI.vforward, RI.vright, RI.vup);
// AngleVectors (RI.viewangles, RI.vforward, RI.vright, RI.vup);
// current viewleaf
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.rvp.vieworigin, WORLDMODEL->nodes, WORLDMODEL );
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.vieworg, WORLDMODEL->nodes );
r_viewcluster = RI.viewleaf->cluster;
}
@@ -305,10 +307,10 @@ void R_SetupFrameQ( void )
vrect.y = 0;//r_newrefdef.y;
vrect.width = gpGlobals->width;
vrect.height = gpGlobals->height;*/
vrect.x = RI.rvp.viewport[0];
vrect.y = RI.rvp.viewport[1];
vrect.width = RI.rvp.viewport[2];
vrect.height = RI.rvp.viewport[3];
vrect.x = RI.viewport[0];
vrect.y = RI.viewport[1];
vrect.width = RI.viewport[2];
vrect.height = RI.viewport[3];
d_viewbuffer = (void *)vid.buffer;
r_screenwidth = vid.rowbytes;

View File

@@ -72,9 +72,9 @@ void GAME_EXPORT CL_DrawParticles( double frametime, particle_t *cl_active_parti
size = partsize; // get initial size of particle
// scale up to keep particles from disappearing
size += ( p->org[0] - RI.rvp.vieworigin[0] ) * RI.cull_vforward[0];
size += ( p->org[1] - RI.rvp.vieworigin[1] ) * RI.cull_vforward[1];
size += ( p->org[2] - RI.rvp.vieworigin[2] ) * RI.cull_vforward[2];
size += ( p->org[0] - RI.vieworg[0] ) * RI.cull_vforward[0];
size += ( p->org[1] - RI.vieworg[1] ) * RI.cull_vforward[1];
size += ( p->org[2] - RI.vieworg[2] ) * RI.cull_vforward[2];
if( size < 20.0f )
size = partsize;

View File

@@ -65,12 +65,16 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo
float dist, brightness;
vec3_t glowDist;
VectorSubtract( origin, RI.rvp.vieworigin, glowDist );
VectorSubtract( origin, RI.vieworg, glowDist );
dist = VectorLength( glowDist );
pmtrace_t *tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : ( PM_GLASS_IGNORE | PM_STUDIO_IGNORE ));
if(( 1.0f - tr->fraction ) * dist > 8.0f )
return 0.0f;
if( RP_NORMALPASS( ))
{
pmtrace_t *tr = gEngfuncs.EV_VisTraceLine( RI.vieworg, origin, r_traceglow.value ? PM_GLASS_IGNORE : ( PM_GLASS_IGNORE | PM_STUDIO_IGNORE ));
if(( 1.0f - tr->fraction ) * dist > 8.0f )
return 0.0f;
}
if( renderfx == kRenderFxNoDissipation )
return 1.0f;
@@ -98,9 +102,9 @@ static qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale )
TriWorldToScreen( origin, v );
if( v[0] < RI.rvp.viewport[0] || v[0] > RI.rvp.viewport[0] + RI.rvp.viewport[2] )
if( v[0] < RI.viewport[0] || v[0] > RI.viewport[0] + RI.viewport[2] )
return true; // do scissor
if( v[1] < RI.rvp.viewport[1] || v[1] > RI.rvp.viewport[1] + RI.rvp.viewport[3] )
if( v[1] < RI.viewport[1] || v[1] > RI.viewport[1] + RI.viewport[3] )
return true; // do scissor
blend = R_SpriteGlowBlend( origin, e->curstate.rendermode, e->curstate.renderfx, pscale );
@@ -168,6 +172,9 @@ void R_DrawSpriteModel( cl_entity_t *e )
vec3_t v_forward, v_right, v_up;
vec3_t origin, color;
if( RI.params & RP_ENVVIEW )
return;
model = e->model;
psprite = (msprite_t *)model->cache.data;
VectorCopy( e->origin, origin ); // set render origin
@@ -235,7 +242,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
VectorSubtract( origin, v_forward, origin );
break;
case SPR_FACING_UPRIGHT:
VectorSet( v_right, origin[1] - RI.rvp.vieworigin[1], -( origin[0] - RI.rvp.vieworigin[0] ), 0.0f );
VectorSet( v_right, origin[1] - RI.vieworg[1], -( origin[0] - RI.vieworg[0] ), 0.0f );
VectorSet( v_up, 0.0f, 0.0f, 1.0f );
VectorNormalize( v_right );
break;

View File

@@ -147,7 +147,7 @@ init current time for a given model
*/
static void R_StudioSetupTimings( void )
{
if( FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( RI.drawWorld )
{
// synchronize with server time
g_studio.time = gp_cl->time;
@@ -353,12 +353,23 @@ pfnPlayerInfo
*/
player_info_t *pfnPlayerInfo( int index )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
index = -1;
return gEngfuncs.pfnPlayerInfo( index );
}
/*
===============
pfnMod_ForName
===============
*/
static model_t *pfnMod_ForName( const char *model, int crash )
{
return gEngfuncs.Mod_ForName( model, crash, false );
}
/*
===============
pfnGetPlayerState
@@ -367,12 +378,23 @@ pfnGetPlayerState
*/
static entity_state_t *R_StudioGetPlayerState( int index )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
return &RI.currententity->curstate;
return gEngfuncs.pfnGetPlayerState( index );
}
/*
===============
pfnGetViewEntity
===============
*/
static cl_entity_t *pfnGetViewEntity( void )
{
return tr.viewent;
}
/*
===============
pfnGetEngineTimes
@@ -398,7 +420,7 @@ pfnGetViewInfo
static void pfnGetViewInfo( float *origin, float *upv, float *rightv, float *forwardv )
{
if( origin )
VectorCopy( RI.rvp.vieworigin, origin );
VectorCopy( RI.vieworg, origin );
if( forwardv )
VectorCopy( RI.vforward, forwardv );
if( rightv )
@@ -407,6 +429,17 @@ 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
@@ -419,6 +452,20 @@ 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
@@ -441,6 +488,17 @@ static float ****pfnStudioGetLightTransform( void )
return (float ****)g_studio.lighttransform;
}
/*
===============
pfnStudioGetAliasTransform
===============
*/
static float ***pfnStudioGetAliasTransform( void )
{
return NULL;
}
/*
===============
pfnStudioGetRotationMatrix
@@ -1294,7 +1352,7 @@ static void R_StudioDynamicLight( cl_entity_t *ent, alight_t *plight )
if( !plight || !ent || !ent->model )
return;
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
if( !RI.drawWorld || r_fullbright->value || FBitSet( ent->curstate.effects, EF_FULLBRIGHT ))
{
plight->shadelight = 0;
plight->ambientlight = 192;
@@ -2275,7 +2333,7 @@ static model_t *R_StudioSetupPlayerModel( int index )
state = &g_studio.player_models[index];
// g-cont: force for "dev-mode", non-local games and menu preview
if(( gpGlobals->developer || !ENGINE_GET_PARM( PARM_LOCAL_GAME ) || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD )) && info->model[0] )
if(( gpGlobals->developer || !ENGINE_GET_PARM( PARM_LOCAL_GAME ) || !RI.drawWorld ) && info->model[0] )
{
if( Q_strcmp( state->name, info->model ))
{
@@ -2514,7 +2572,19 @@ R_StudioSetChromeOrigin
*/
static void R_StudioSetChromeOrigin( void )
{
VectorCopy( RI.rvp.vieworigin, g_studio.chrome_origin );
VectorCopy( RI.vieworg, 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
}
/*
@@ -2613,7 +2683,7 @@ static void R_StudioRenderModel( void )
R_StudioRenderFinal( );
R_StudioSetForceFaceFlags( STUDIO_NF_CHROME );
TriSpriteTexture( gEngfuncs.GetDefaultSprite( REF_CHROME_SPRITE ), 0 );
TriSpriteTexture( R_GetChromeSprite(), 0 );
RI.currententity->curstate.renderfx = kRenderFxGlowShell;
R_StudioRenderFinal( );
@@ -2856,7 +2926,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer )
if( flags & STUDIO_RENDER )
{
// change body if it's a menu entity
if( cl_himodels->value && ( RI.currentmodel != RI.currententity->model || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD )))
if( cl_himodels->value && ( RI.currentmodel != RI.currententity->model || !RI.drawWorld ))
{
// show highest resolution multiplayer model
RI.currententity->curstate.body = 255;
@@ -3017,7 +3087,7 @@ R_StudioDrawModelInternal
*/
static void R_StudioDrawModelInternal( cl_entity_t *e, int flags )
{
if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ))
if( !RI.drawWorld )
{
if( e->player )
R_StudioDrawPlayer( flags, &e->curstate );
@@ -3054,6 +3124,9 @@ R_DrawStudioModel
*/
void R_DrawStudioModel( cl_entity_t *e )
{
if( FBitSet( RI.params, RP_ENVVIEW ))
return;
R_StudioSetupTimings();
if( e->player )
@@ -3107,7 +3180,7 @@ void R_RunViewmodelEvents( void )
return;
// ignore in thirdperson, camera view or client is died
if( ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
if( !RP_NORMALPASS() || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
return;
RI.currententity = tr.viewent;
@@ -3125,6 +3198,20 @@ 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
@@ -3134,7 +3221,7 @@ void R_DrawViewModel( void )
{
cl_entity_t *view = tr.viewent;
R_GatherPlayerLight( view );
R_GatherPlayerLight();
if( r_drawviewmodel->value == 0 )
return;
@@ -3143,7 +3230,7 @@ void R_DrawViewModel( void )
return;
// ignore in thirdperson, camera view or client is died
if( ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
if( !RP_NORMALPASS() || ENGINE_GET_PARM( PARM_LOCAL_HEALTH ) <= 0 || !CL_IsViewEntityLocalPlayer())
return;
tr.blend = CL_FxBlend( view ) / 255.0f;
@@ -3331,53 +3418,113 @@ void Mod_StudioUnloadTextures( void *data )
}
}
qboolean R_StudioFillAPI( engine_studio_api_t *api, r_studio_interface_t *pDefaultDraw )
static model_t *pfnModelHandle( int modelindex )
{
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" );
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;
// Xash will be used internal StudioModelRenderer
if( gEngfuncs.pfnGetStudioModelInterface( STUDIO_INTERFACE_VERSION, &pStudioDraw, &gStudioAPI ))
return;
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;
// 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;
}

View File

@@ -78,9 +78,9 @@ void R_SetUpWorldTransform( void )
aliasoldworldtransform[i][0] = aliasworldtransform[i][2] = s_alias_up[i];
}
aliasworldtransform[0][3] = -RI.rvp.vieworigin[0];
aliasworldtransform[1][3] = -RI.rvp.vieworigin[1];
aliasworldtransform[2][3] = -RI.rvp.vieworigin[2];
aliasworldtransform[0][3] = -RI.vieworg[0];
aliasworldtransform[1][3] = -RI.vieworg[1];
aliasworldtransform[2][3] = -RI.vieworg[2];
// aliasoldworldtransform[0][3] = RI.currententity->oldorigin[0]-r_origin[0];
// aliasoldworldtransform[1][3] = RI.currententity->oldorigin[1]-r_origin[1];