2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
gl_rmain.c - renderer main loop
|
|
|
|
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"
|
2020-02-10 11:07:06 +01:00
|
|
|
#include "xash3d_mathlib.h"
|
2018-04-13 18:23:45 +02:00
|
|
|
#include "library.h"
|
|
|
|
#include "beamdef.h"
|
|
|
|
#include "particledef.h"
|
|
|
|
#include "entity_types.h"
|
|
|
|
|
|
|
|
#define IsLiquidContents( cnt ) ( cnt == CONTENTS_WATER || cnt == CONTENTS_SLIME || cnt == CONTENTS_LAVA )
|
|
|
|
|
|
|
|
float gldepthmin, gldepthmax;
|
|
|
|
ref_instance_t RI;
|
|
|
|
|
|
|
|
static int R_RankForRenderMode( int rendermode )
|
|
|
|
{
|
|
|
|
switch( rendermode )
|
|
|
|
{
|
|
|
|
case kRenderTransTexture:
|
|
|
|
return 1; // draw second
|
|
|
|
case kRenderTransAdd:
|
|
|
|
return 2; // draw third
|
|
|
|
case kRenderGlow:
|
|
|
|
return 3; // must be last!
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-15 19:23:59 +01:00
|
|
|
void R_AllowFog( qboolean allowed )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( allowed )
|
|
|
|
{
|
2019-05-19 14:01:23 +02:00
|
|
|
if( glState.isFogEnabled )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglEnable( GL_FOG );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-19 14:01:23 +02:00
|
|
|
if( glState.isFogEnabled )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglDisable( GL_FOG );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_OpaqueEntity
|
|
|
|
|
|
|
|
Opaque entity can be brush or studio model but sprite
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static qboolean R_OpaqueEntity( cl_entity_t *ent )
|
|
|
|
{
|
|
|
|
if( R_GetEntityRenderMode( ent ) == kRenderNormal )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_TransEntityCompare
|
|
|
|
|
|
|
|
Sorting translucent entities by rendermode then by distance
|
|
|
|
===============
|
|
|
|
*/
|
2019-05-02 18:12:23 +02:00
|
|
|
static int R_TransEntityCompare( const void *a, const void *b )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
cl_entity_t *ent1, *ent2;
|
|
|
|
vec3_t vecLen, org;
|
|
|
|
float dist1, dist2;
|
|
|
|
int rendermode1;
|
|
|
|
int rendermode2;
|
|
|
|
|
2019-05-02 18:12:23 +02:00
|
|
|
ent1 = *(cl_entity_t **)a;
|
|
|
|
ent2 = *(cl_entity_t **)b;
|
2018-04-13 18:23:45 +02:00
|
|
|
rendermode1 = R_GetEntityRenderMode( ent1 );
|
|
|
|
rendermode2 = R_GetEntityRenderMode( ent2 );
|
|
|
|
|
|
|
|
// sort by distance
|
|
|
|
if( ent1->model->type != mod_brush || rendermode1 != kRenderTransAlpha )
|
|
|
|
{
|
|
|
|
VectorAverage( ent1->model->mins, ent1->model->maxs, org );
|
|
|
|
VectorAdd( ent1->origin, org, org );
|
|
|
|
VectorSubtract( RI.vieworg, org, vecLen );
|
|
|
|
dist1 = DotProduct( vecLen, vecLen );
|
|
|
|
}
|
|
|
|
else dist1 = 1000000000;
|
|
|
|
|
|
|
|
if( ent2->model->type != mod_brush || rendermode2 != kRenderTransAlpha )
|
|
|
|
{
|
|
|
|
VectorAverage( ent2->model->mins, ent2->model->maxs, org );
|
|
|
|
VectorAdd( ent2->origin, org, org );
|
|
|
|
VectorSubtract( RI.vieworg, org, vecLen );
|
|
|
|
dist2 = DotProduct( vecLen, vecLen );
|
|
|
|
}
|
|
|
|
else dist2 = 1000000000;
|
|
|
|
|
|
|
|
if( dist1 > dist2 )
|
|
|
|
return -1;
|
|
|
|
if( dist1 < dist2 )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// then sort by rendermode
|
|
|
|
if( R_RankForRenderMode( rendermode1 ) > R_RankForRenderMode( rendermode2 ))
|
|
|
|
return 1;
|
|
|
|
if( R_RankForRenderMode( rendermode1 ) < R_RankForRenderMode( rendermode2 ))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_WorldToScreen
|
|
|
|
|
|
|
|
Convert a given point from world into screen space
|
|
|
|
Returns true if we behind to screen
|
|
|
|
===============
|
|
|
|
*/
|
2018-04-23 22:07:54 +02:00
|
|
|
int R_WorldToScreen( const vec3_t point, vec3_t screen )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
matrix4x4 worldToScreen;
|
|
|
|
qboolean behind;
|
|
|
|
float w;
|
|
|
|
|
|
|
|
if( !point || !screen )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Matrix4x4_Copy( worldToScreen, RI.worldviewProjectionMatrix );
|
|
|
|
screen[0] = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3];
|
|
|
|
screen[1] = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3];
|
|
|
|
w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3];
|
|
|
|
screen[2] = 0.0f; // just so we have something valid here
|
|
|
|
|
|
|
|
if( w < 0.001f )
|
|
|
|
{
|
|
|
|
behind = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float invw = 1.0f / w;
|
|
|
|
screen[0] *= invw;
|
|
|
|
screen[1] *= invw;
|
|
|
|
behind = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return behind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_ScreenToWorld
|
|
|
|
|
|
|
|
Convert a given point from screen into world space
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_ScreenToWorld( const vec3_t screen, vec3_t point )
|
|
|
|
{
|
|
|
|
matrix4x4 screenToWorld;
|
|
|
|
float w;
|
|
|
|
|
|
|
|
if( !point || !screen )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Matrix4x4_Invert_Full( screenToWorld, RI.worldviewProjectionMatrix );
|
|
|
|
|
|
|
|
point[0] = screen[0] * screenToWorld[0][0] + screen[1] * screenToWorld[0][1] + screen[2] * screenToWorld[0][2] + screenToWorld[0][3];
|
|
|
|
point[1] = screen[0] * screenToWorld[1][0] + screen[1] * screenToWorld[1][1] + screen[2] * screenToWorld[1][2] + screenToWorld[1][3];
|
|
|
|
point[2] = screen[0] * screenToWorld[2][0] + screen[1] * screenToWorld[2][1] + screen[2] * screenToWorld[2][2] + screenToWorld[2][3];
|
|
|
|
w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3];
|
|
|
|
if( w != 0.0f ) VectorScale( point, ( 1.0f / w ), point );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_PushScene
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_PushScene( void )
|
|
|
|
{
|
|
|
|
if( ++tr.draw_stack_pos >= MAX_DRAW_STACK )
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Host_Error( "draw stack overflow\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
tr.draw_list = &tr.draw_stack[tr.draw_stack_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
2018-05-28 17:17:25 +02:00
|
|
|
R_PopScene
|
2018-04-13 18:23:45 +02:00
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_PopScene( void )
|
|
|
|
{
|
|
|
|
if( --tr.draw_stack_pos < 0 )
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Host_Error( "draw stack underflow\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
tr.draw_list = &tr.draw_stack[tr.draw_stack_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_ClearScene
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_ClearScene( void )
|
|
|
|
{
|
|
|
|
tr.draw_list->num_solid_entities = 0;
|
|
|
|
tr.draw_list->num_trans_entities = 0;
|
|
|
|
tr.draw_list->num_beam_entities = 0;
|
2019-03-17 15:19:24 +01:00
|
|
|
|
|
|
|
// clear the scene befor start new frame
|
|
|
|
if( gEngfuncs.drawFuncs->R_ClearScene != NULL )
|
|
|
|
gEngfuncs.drawFuncs->R_ClearScene();
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_AddEntity
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
qboolean R_AddEntity( struct cl_entity_s *clent, int type )
|
|
|
|
{
|
|
|
|
if( !r_drawentities->value )
|
|
|
|
return false; // not allow to drawing
|
|
|
|
|
|
|
|
if( !clent || !clent->model )
|
|
|
|
return false; // if set to invisible, skip
|
|
|
|
|
2018-06-09 00:28:35 +02:00
|
|
|
if( FBitSet( clent->curstate.effects, EF_NODRAW ))
|
2018-04-13 18:23:45 +02:00
|
|
|
return false; // done
|
|
|
|
|
2019-04-15 00:19:05 +02:00
|
|
|
if( !R_ModelOpaque( clent->curstate.rendermode ) && CL_FxBlend( clent ) <= 0 )
|
2018-04-13 18:23:45 +02:00
|
|
|
return true; // invisible
|
|
|
|
|
2019-04-15 01:17:43 +02:00
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case ET_FRAGMENTED:
|
2018-04-13 18:23:45 +02:00
|
|
|
r_stats.c_client_ents++;
|
2019-04-15 01:17:43 +02:00
|
|
|
break;
|
|
|
|
case ET_TEMPENTITY:
|
|
|
|
r_stats.c_active_tents_count++;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( R_OpaqueEntity( clent ))
|
|
|
|
{
|
|
|
|
// opaque
|
|
|
|
if( tr.draw_list->num_solid_entities >= MAX_VISIBLE_PACKET )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tr.draw_list->solid_entities[tr.draw_list->num_solid_entities] = clent;
|
|
|
|
tr.draw_list->num_solid_entities++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// translucent
|
|
|
|
if( tr.draw_list->num_trans_entities >= MAX_VISIBLE_PACKET )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
tr.draw_list->trans_entities[tr.draw_list->num_trans_entities] = clent;
|
|
|
|
tr.draw_list->num_trans_entities++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_Clear
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
static void R_Clear( int bitMask )
|
|
|
|
{
|
|
|
|
int bits;
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
if( ENGINE_GET_PARM( PARM_DEV_OVERVIEW ))
|
2018-04-13 18:23:45 +02:00
|
|
|
pglClearColor( 0.0f, 1.0f, 0.0f, 1.0f ); // green background (Valve rules)
|
|
|
|
else pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
|
|
|
|
|
|
|
|
bits = GL_DEPTH_BUFFER_BIT;
|
|
|
|
|
|
|
|
if( glState.stencilEnabled )
|
|
|
|
bits |= GL_STENCIL_BUFFER_BIT;
|
|
|
|
|
|
|
|
bits &= bitMask;
|
|
|
|
|
|
|
|
pglClear( bits );
|
|
|
|
|
|
|
|
// change ordering for overview
|
|
|
|
if( RI.drawOrtho )
|
|
|
|
{
|
|
|
|
gldepthmin = 1.0f;
|
|
|
|
gldepthmax = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gldepthmin = 0.0f;
|
|
|
|
gldepthmax = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
pglDepthFunc( GL_LEQUAL );
|
|
|
|
pglDepthRange( gldepthmin, gldepthmax );
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_GetFarClip
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static float R_GetFarClip( void )
|
|
|
|
{
|
2019-02-23 19:49:46 +01:00
|
|
|
if( WORLDMODEL && RI.drawWorld )
|
|
|
|
return MOVEVARS->zmax * 1.73f;
|
2018-04-13 18:23:45 +02:00
|
|
|
return 2048.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_SetupFrustum
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_SetupFrustum( void )
|
|
|
|
{
|
2019-03-22 14:36:46 +01:00
|
|
|
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-12-05 09:59:29 +01:00
|
|
|
if( RP_NORMALPASS() && ( ENGINE_GET_PARM( PARM_WATER_LEVEL ) >= 3 ) && ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-10-06 05:51:28 +02:00
|
|
|
RI.fov_x = atan( tan( DEG2RAD( RI.fov_x ) / 2 ) * ( 0.97f + sin( gpGlobals->time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
|
|
|
|
RI.fov_y = atan( tan( DEG2RAD( RI.fov_y ) / 2 ) * ( 1.03f - sin( gpGlobals->time * 1.5f ) * 0.03f )) * 2 / (M_PI_F / 180.0f);
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// build the transformation matrix for the given view angles
|
|
|
|
AngleVectors( RI.viewangles, RI.vforward, RI.vright, RI.vup );
|
|
|
|
|
2023-05-20 19:27:15 +02:00
|
|
|
if( !r_lockfrustum.value )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
VectorCopy( RI.vieworg, RI.cullorigin );
|
|
|
|
VectorCopy( RI.vforward, RI.cull_vforward );
|
|
|
|
VectorCopy( RI.vright, RI.cull_vright );
|
|
|
|
VectorCopy( RI.vup, RI.cull_vup );
|
|
|
|
}
|
|
|
|
|
|
|
|
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.fov_x, RI.fov_y ); // NOTE: we ignore nearplane here (mirrors only)
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_SetupProjectionMatrix
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
static void R_SetupProjectionMatrix( matrix4x4 m )
|
|
|
|
{
|
2019-10-06 05:51:28 +02:00
|
|
|
GLfloat xMin, xMax, yMin, yMax, zNear, zFar;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( RI.drawOrtho )
|
|
|
|
{
|
2019-03-22 14:36:46 +01:00
|
|
|
const ref_overview_t *ov = gEngfuncs.GetOverviewParms();
|
2018-04-13 18:23:45 +02:00
|
|
|
Matrix4x4_CreateOrtho( m, ov->xLeft, ov->xRight, ov->yTop, ov->yBottom, ov->zNear, ov->zFar );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RI.farClip = R_GetFarClip();
|
|
|
|
|
|
|
|
zNear = 4.0f;
|
2021-12-23 17:17:11 +01:00
|
|
|
zFar = Q_max( 256.0f, RI.farClip );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2019-10-06 05:51:28 +02:00
|
|
|
yMax = zNear * tan( RI.fov_y * M_PI_F / 360.0f );
|
2018-04-13 18:23:45 +02:00
|
|
|
yMin = -yMax;
|
|
|
|
|
2019-10-06 05:51:28 +02:00
|
|
|
xMax = zNear * tan( RI.fov_x * M_PI_F / 360.0f );
|
2018-04-13 18:23:45 +02:00
|
|
|
xMin = -xMax;
|
|
|
|
|
|
|
|
Matrix4x4_CreateProjection( m, xMax, xMin, yMax, yMin, zNear, zFar );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_SetupModelviewMatrix
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
static void R_SetupModelviewMatrix( matrix4x4 m )
|
|
|
|
{
|
|
|
|
Matrix4x4_CreateModelview( m );
|
|
|
|
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] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_LoadIdentity
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_LoadIdentity( void )
|
|
|
|
{
|
|
|
|
if( tr.modelviewIdentity ) return;
|
|
|
|
|
|
|
|
Matrix4x4_LoadIdentity( RI.objectMatrix );
|
|
|
|
Matrix4x4_Copy( RI.modelviewMatrix, RI.worldviewMatrix );
|
|
|
|
|
|
|
|
pglMatrixMode( GL_MODELVIEW );
|
|
|
|
GL_LoadMatrix( RI.modelviewMatrix );
|
|
|
|
tr.modelviewIdentity = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_RotateForEntity
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_RotateForEntity( cl_entity_t *e )
|
|
|
|
{
|
|
|
|
float scale = 1.0f;
|
|
|
|
|
2019-02-24 16:45:27 +01:00
|
|
|
if( e == gEngfuncs.GetEntityByIndex( 0 ) )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
R_LoadIdentity();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( e->model->type != mod_brush && e->curstate.scale > 0.0f )
|
|
|
|
scale = e->curstate.scale;
|
|
|
|
|
|
|
|
Matrix4x4_CreateFromEntity( RI.objectMatrix, e->angles, e->origin, scale );
|
|
|
|
Matrix4x4_ConcatTransforms( RI.modelviewMatrix, RI.worldviewMatrix, RI.objectMatrix );
|
|
|
|
|
|
|
|
pglMatrixMode( GL_MODELVIEW );
|
|
|
|
GL_LoadMatrix( RI.modelviewMatrix );
|
|
|
|
tr.modelviewIdentity = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_TranslateForEntity
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_TranslateForEntity( cl_entity_t *e )
|
|
|
|
{
|
|
|
|
float scale = 1.0f;
|
|
|
|
|
2019-02-24 16:45:27 +01:00
|
|
|
if( e == gEngfuncs.GetEntityByIndex( 0 ) )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
R_LoadIdentity();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( e->model->type != mod_brush && e->curstate.scale > 0.0f )
|
|
|
|
scale = e->curstate.scale;
|
|
|
|
|
|
|
|
Matrix4x4_CreateFromEntity( RI.objectMatrix, vec3_origin, e->origin, scale );
|
|
|
|
Matrix4x4_ConcatTransforms( RI.modelviewMatrix, RI.worldviewMatrix, RI.objectMatrix );
|
|
|
|
|
|
|
|
pglMatrixMode( GL_MODELVIEW );
|
|
|
|
GL_LoadMatrix( RI.modelviewMatrix );
|
|
|
|
tr.modelviewIdentity = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_FindViewLeaf
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_FindViewLeaf( void )
|
|
|
|
{
|
|
|
|
RI.oldviewleaf = RI.viewleaf;
|
2019-03-06 14:23:33 +01:00
|
|
|
RI.viewleaf = gEngfuncs.Mod_PointInLeaf( RI.pvsorigin, WORLDMODEL->nodes );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_SetupFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
static void R_SetupFrame( void )
|
|
|
|
{
|
|
|
|
// setup viewplane dist
|
|
|
|
RI.viewplanedist = DotProduct( RI.vieworg, RI.vforward );
|
|
|
|
|
2019-05-19 14:01:23 +02:00
|
|
|
// NOTE: this request is the fps-killer on some NVidia drivers
|
|
|
|
glState.isFogEnabled = pglIsEnabled( GL_FOG );
|
|
|
|
|
2023-05-20 19:27:15 +02:00
|
|
|
if( !gl_nosort.value )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
// sort translucents entities by rendermode and distance
|
|
|
|
qsort( tr.draw_list->trans_entities, tr.draw_list->num_trans_entities, sizeof( cl_entity_t* ), R_TransEntityCompare );
|
|
|
|
}
|
|
|
|
|
|
|
|
// current viewleaf
|
|
|
|
if( RI.drawWorld )
|
|
|
|
{
|
|
|
|
RI.isSkyVisible = false; // unknown at this moment
|
|
|
|
R_FindViewLeaf();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_SetupGL
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_SetupGL( qboolean set_gl_state )
|
|
|
|
{
|
|
|
|
R_SetupModelviewMatrix( RI.worldviewMatrix );
|
|
|
|
R_SetupProjectionMatrix( RI.projectionMatrix );
|
|
|
|
|
|
|
|
Matrix4x4_Concat( RI.worldviewProjectionMatrix, RI.projectionMatrix, RI.worldviewMatrix );
|
|
|
|
|
|
|
|
if( !set_gl_state ) return;
|
|
|
|
|
|
|
|
if( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
int x, x2, y, y2;
|
|
|
|
|
|
|
|
// set up viewport (main, playersetup)
|
2019-02-27 00:23:03 +01:00
|
|
|
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 );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
pglViewport( x, y2, x2 - x, y - y2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// envpass, mirrorpass
|
|
|
|
pglViewport( RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3] );
|
|
|
|
}
|
|
|
|
|
|
|
|
pglMatrixMode( GL_PROJECTION );
|
|
|
|
GL_LoadMatrix( RI.projectionMatrix );
|
|
|
|
|
|
|
|
pglMatrixMode( GL_MODELVIEW );
|
|
|
|
GL_LoadMatrix( RI.worldviewMatrix );
|
|
|
|
|
2018-06-09 00:28:35 +02:00
|
|
|
if( FBitSet( RI.params, RP_CLIPPLANE ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
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 );
|
|
|
|
pglDisable( GL_ALPHA_TEST );
|
|
|
|
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
|
|
|
|
|
|
|
|
using to find source waterleaf with
|
|
|
|
watertexture to grab fog values from it
|
|
|
|
=============
|
|
|
|
*/
|
2018-10-04 08:08:48 +02:00
|
|
|
static gl_texture_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mnode_t *ignore, qboolean down )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2018-10-04 08:08:48 +02:00
|
|
|
gl_texture_t *tex = NULL;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// assure the initial node is not null
|
2021-01-03 02:28:45 +01:00
|
|
|
// we could check it here, but we would rather check it
|
2018-04-13 18:23:45 +02:00
|
|
|
// outside the call to get rid of one additional recursion level
|
|
|
|
Assert( node != NULL );
|
|
|
|
|
|
|
|
// ignore solid nodes
|
|
|
|
if( node->contents == CONTENTS_SOLID )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if( node->contents < 0 )
|
|
|
|
{
|
|
|
|
mleaf_t *pleaf;
|
|
|
|
msurface_t **mark;
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
// ignore non-liquid leaves
|
|
|
|
if( node->contents != CONTENTS_WATER && node->contents != CONTENTS_LAVA && node->contents != CONTENTS_SLIME )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// find texture
|
|
|
|
pleaf = (mleaf_t *)node;
|
|
|
|
mark = pleaf->firstmarksurface;
|
2021-01-03 02:28:45 +01:00
|
|
|
c = pleaf->nummarksurfaces;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
for( i = 0; i < c; i++, mark++ )
|
|
|
|
{
|
|
|
|
if( (*mark)->flags & SURF_DRAWTURB && (*mark)->texinfo && (*mark)->texinfo->texture )
|
|
|
|
return R_GetTexture( (*mark)->texinfo->texture->gl_texturenum );
|
|
|
|
}
|
|
|
|
|
|
|
|
// texture not found
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this is a regular node
|
|
|
|
// traverse children
|
|
|
|
if( node->children[0] && ( node->children[0] != ignore ))
|
|
|
|
{
|
|
|
|
tex = R_RecursiveFindWaterTexture( node->children[0], node, true );
|
|
|
|
if( tex ) return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( node->children[1] && ( node->children[1] != ignore ))
|
|
|
|
{
|
|
|
|
tex = R_RecursiveFindWaterTexture( node->children[1], node, true );
|
|
|
|
if( tex ) return tex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for down recursion, return immediately
|
|
|
|
if( down ) return NULL;
|
|
|
|
|
|
|
|
// texture not found, step up if any
|
|
|
|
if( node->parent )
|
|
|
|
return R_RecursiveFindWaterTexture( node->parent, node, false );
|
|
|
|
|
|
|
|
// top-level node, bail out
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_CheckFog
|
|
|
|
|
|
|
|
check for underwater fog
|
|
|
|
Using backward recursion to find waterline leaf
|
|
|
|
from underwater leaf (idea: XaeroX)
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
static void R_CheckFog( void )
|
|
|
|
{
|
|
|
|
cl_entity_t *ent;
|
2018-10-04 08:08:48 +02:00
|
|
|
gl_texture_t *tex;
|
2018-04-13 18:23:45 +02:00
|
|
|
int i, cnt, count;
|
|
|
|
|
|
|
|
// quake global fog
|
2019-03-22 14:36:46 +01:00
|
|
|
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-02-23 19:49:46 +01:00
|
|
|
if( !MOVEVARS->fog_settings )
|
2018-11-27 14:11:26 +01:00
|
|
|
{
|
|
|
|
if( pglIsEnabled( GL_FOG ))
|
|
|
|
pglDisable( GL_FOG );
|
|
|
|
RI.fogEnabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// quake-style global fog
|
2019-02-23 19:49:46 +01:00
|
|
|
RI.fogColor[0] = ((MOVEVARS->fog_settings & 0xFF000000) >> 24) / 255.0f;
|
|
|
|
RI.fogColor[1] = ((MOVEVARS->fog_settings & 0xFF0000) >> 16) / 255.0f;
|
|
|
|
RI.fogColor[2] = ((MOVEVARS->fog_settings & 0xFF00) >> 8) / 255.0f;
|
|
|
|
RI.fogDensity = ((MOVEVARS->fog_settings & 0xFF) / 255.0f) * 0.01f;
|
2018-04-13 18:23:45 +02:00
|
|
|
RI.fogStart = RI.fogEnd = 0.0f;
|
|
|
|
RI.fogColor[3] = 1.0f;
|
|
|
|
RI.fogCustom = false;
|
|
|
|
RI.fogEnabled = true;
|
|
|
|
RI.fogSkybox = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RI.fogEnabled = false;
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
if( RI.onlyClientDraw || ENGINE_GET_PARM( PARM_WATER_LEVEL ) < 3 || !RI.drawWorld || !RI.viewleaf )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( RI.cached_waterlevel == 3 )
|
2019-03-22 14:36:46 +01:00
|
|
|
{
|
2018-04-13 18:23:45 +02:00
|
|
|
// in some cases waterlevel jumps from 3 to 1. Catch it
|
2019-03-22 14:36:46 +01:00
|
|
|
RI.cached_waterlevel = ENGINE_GET_PARM( PARM_WATER_LEVEL );
|
2018-04-13 18:23:45 +02:00
|
|
|
RI.cached_contents = CONTENTS_EMPTY;
|
2019-05-19 14:01:23 +02:00
|
|
|
if( !RI.fogCustom )
|
|
|
|
{
|
|
|
|
glState.isFogEnabled = false;
|
|
|
|
pglDisable( GL_FOG );
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-06 14:23:33 +01:00
|
|
|
ent = gEngfuncs.CL_GetWaterEntity( RI.vieworg );
|
2018-04-13 18:23:45 +02:00
|
|
|
if( ent && ent->model && ent->model->type == mod_brush && ent->curstate.skin < 0 )
|
|
|
|
cnt = ent->curstate.skin;
|
|
|
|
else cnt = RI.viewleaf->contents;
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
RI.cached_waterlevel = ENGINE_GET_PARM( PARM_WATER_LEVEL );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !IsLiquidContents( RI.cached_contents ) && IsLiquidContents( cnt ))
|
|
|
|
{
|
|
|
|
tex = NULL;
|
|
|
|
|
|
|
|
// check for water texture
|
|
|
|
if( ent && ent->model && ent->model->type == mod_brush )
|
|
|
|
{
|
|
|
|
msurface_t *surf;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
count = ent->model->nummodelsurfaces;
|
|
|
|
|
|
|
|
for( i = 0, surf = &ent->model->surfaces[ent->model->firstmodelsurface]; i < count; i++, surf++ )
|
|
|
|
{
|
|
|
|
if( surf->flags & SURF_DRAWTURB && surf->texinfo && surf->texinfo->texture )
|
|
|
|
{
|
|
|
|
tex = R_GetTexture( surf->texinfo->texture->gl_texturenum );
|
|
|
|
RI.cached_contents = ent->curstate.skin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tex = R_RecursiveFindWaterTexture( RI.viewleaf->parent, NULL, false );
|
|
|
|
if( tex ) RI.cached_contents = RI.viewleaf->contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !tex ) return; // no valid fogs
|
|
|
|
|
|
|
|
// copy fog params
|
|
|
|
RI.fogColor[0] = tex->fogParams[0] / 255.0f;
|
|
|
|
RI.fogColor[1] = tex->fogParams[1] / 255.0f;
|
|
|
|
RI.fogColor[2] = tex->fogParams[2] / 255.0f;
|
|
|
|
RI.fogDensity = tex->fogParams[3] * 0.000025f;
|
|
|
|
RI.fogStart = RI.fogEnd = 0.0f;
|
|
|
|
RI.fogColor[3] = 1.0f;
|
|
|
|
RI.fogCustom = false;
|
|
|
|
RI.fogEnabled = true;
|
|
|
|
RI.fogSkybox = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RI.fogCustom = false;
|
|
|
|
RI.fogEnabled = true;
|
|
|
|
RI.fogSkybox = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 08:08:48 +02:00
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_CheckGLFog
|
|
|
|
|
|
|
|
special condition for Spirit 1.9
|
|
|
|
that used direct calls of glFog-functions
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
static void R_CheckGLFog( void )
|
|
|
|
{
|
|
|
|
#ifdef HACKS_RELATED_HLMODS
|
|
|
|
if(( !RI.fogEnabled && !RI.fogCustom ) && pglIsEnabled( GL_FOG ) && VectorIsNull( RI.fogColor ))
|
|
|
|
{
|
|
|
|
// fill the fog color from GL-state machine
|
|
|
|
pglGetFloatv( GL_FOG_COLOR, RI.fogColor );
|
|
|
|
RI.fogSkybox = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_DrawFog
|
|
|
|
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_DrawFog( void )
|
|
|
|
{
|
|
|
|
if( !RI.fogEnabled ) return;
|
|
|
|
|
|
|
|
pglEnable( GL_FOG );
|
2019-03-22 14:36:46 +01:00
|
|
|
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
|
2018-11-27 14:11:26 +01:00
|
|
|
pglFogi( GL_FOG_MODE, GL_EXP2 );
|
|
|
|
else pglFogi( GL_FOG_MODE, GL_EXP );
|
2018-04-13 18:23:45 +02:00
|
|
|
pglFogf( GL_FOG_DENSITY, RI.fogDensity );
|
|
|
|
pglFogfv( GL_FOG_COLOR, RI.fogColor );
|
|
|
|
pglHint( GL_FOG_HINT, GL_NICEST );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
R_DrawEntitiesOnList
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void R_DrawEntitiesOnList( void )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
tr.blend = 1.0f;
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
// first draw solid entities
|
|
|
|
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;
|
|
|
|
|
|
|
|
Assert( RI.currententity != NULL );
|
|
|
|
Assert( RI.currentmodel != NULL );
|
|
|
|
|
|
|
|
switch( RI.currentmodel->type )
|
|
|
|
{
|
|
|
|
case mod_brush:
|
|
|
|
R_DrawBrushModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
case mod_alias:
|
|
|
|
R_DrawAliasModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
case mod_studio:
|
|
|
|
R_DrawStudioModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
// quake-specific feature
|
|
|
|
R_DrawAlphaTextureChains();
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
// draw sprites seperately, because of alpha blending
|
|
|
|
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;
|
|
|
|
|
|
|
|
Assert( RI.currententity != NULL );
|
|
|
|
Assert( RI.currentmodel != NULL );
|
|
|
|
|
|
|
|
switch( RI.currentmodel->type )
|
|
|
|
{
|
|
|
|
case mod_sprite:
|
|
|
|
R_DrawSpriteModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
if( !RI.onlyClientDraw )
|
2019-02-24 16:45:27 +01:00
|
|
|
{
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.CL_DrawEFX( tr.frametime, false );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
if( RI.drawWorld )
|
2019-02-27 00:23:03 +01:00
|
|
|
gEngfuncs.pfnDrawNormalTriangles();
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
// then draw translucent entities
|
|
|
|
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;
|
|
|
|
|
|
|
|
// handle studiomodels with custom rendermodes on texture
|
|
|
|
if( RI.currententity->curstate.rendermode != kRenderNormal )
|
2019-04-15 00:19:05 +02:00
|
|
|
tr.blend = CL_FxBlend( RI.currententity ) / 255.0f;
|
2018-04-13 18:23:45 +02:00
|
|
|
else tr.blend = 1.0f; // draw as solid but sorted by distance
|
|
|
|
|
|
|
|
if( tr.blend <= 0.0f ) continue;
|
2021-01-03 02:28:45 +01:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
Assert( RI.currententity != NULL );
|
|
|
|
Assert( RI.currentmodel != NULL );
|
|
|
|
|
|
|
|
switch( RI.currentmodel->type )
|
|
|
|
{
|
|
|
|
case mod_brush:
|
|
|
|
R_DrawBrushModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
case mod_alias:
|
|
|
|
R_DrawAliasModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
case mod_studio:
|
|
|
|
R_DrawStudioModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
case mod_sprite:
|
|
|
|
R_DrawSpriteModel( RI.currententity );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
if( RI.drawWorld )
|
|
|
|
{
|
|
|
|
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
2019-02-27 00:23:03 +01:00
|
|
|
gEngfuncs.pfnDrawTransparentTriangles ();
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
if( !RI.onlyClientDraw )
|
|
|
|
{
|
|
|
|
R_AllowFog( false );
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.CL_DrawEFX( tr.frametime, true );
|
2018-04-13 18:23:45 +02:00
|
|
|
R_AllowFog( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
|
|
|
|
pglDisable( GL_BLEND ); // Trinity Render issues
|
|
|
|
|
|
|
|
if( !RI.onlyClientDraw )
|
|
|
|
R_DrawViewModel();
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.CL_ExtraUpdate();
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
GL_CheckForErrors();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_RenderScene
|
|
|
|
|
|
|
|
R_SetupRefParams must be called right before
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void R_RenderScene( void )
|
|
|
|
{
|
2019-02-23 19:49:46 +01:00
|
|
|
if( !WORLDMODEL && RI.drawWorld )
|
2019-03-06 14:23:33 +01:00
|
|
|
gEngfuncs.Host_Error( "R_RenderView: NULL worldmodel\n" );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// frametime is valid only for normal pass
|
|
|
|
if( RP_NORMALPASS( ))
|
2019-02-24 16:45:27 +01:00
|
|
|
tr.frametime = gpGlobals->time - gpGlobals->oldtime;
|
2018-04-13 18:23:45 +02:00
|
|
|
else tr.frametime = 0.0;
|
|
|
|
|
|
|
|
// begin a new frame
|
|
|
|
tr.framecount++;
|
|
|
|
|
|
|
|
R_PushDlights();
|
|
|
|
|
|
|
|
R_SetupFrustum();
|
|
|
|
R_SetupFrame();
|
|
|
|
R_SetupGL( true );
|
|
|
|
R_Clear( ~0 );
|
|
|
|
|
|
|
|
R_MarkLeaves();
|
|
|
|
R_DrawFog ();
|
2018-10-04 08:08:48 +02:00
|
|
|
|
2021-01-03 02:28:45 +01:00
|
|
|
R_CheckGLFog();
|
2018-04-13 18:23:45 +02:00
|
|
|
R_DrawWorld();
|
|
|
|
R_CheckFog();
|
|
|
|
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.CL_ExtraUpdate (); // don't let sound get messed up if going slow
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
R_DrawEntitiesOnList();
|
|
|
|
|
|
|
|
R_DrawWaterSurfaces();
|
|
|
|
|
|
|
|
R_EndGL();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
2019-06-17 06:05:36 +02:00
|
|
|
R_CheckGamma
|
2018-04-13 18:23:45 +02:00
|
|
|
===============
|
|
|
|
*/
|
2019-06-17 06:05:36 +02:00
|
|
|
void R_CheckGamma( void )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-06-17 06:36:46 +02:00
|
|
|
if( gEngfuncs.R_DoResetGamma( ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2019-06-17 06:05:36 +02:00
|
|
|
// paranoia cubemaps uses this
|
2019-06-17 07:37:34 +02:00
|
|
|
gEngfuncs.BuildGammaTable( 1.8f, 0.0f );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2019-06-17 06:05:36 +02:00
|
|
|
// paranoia cubemap rendering
|
2019-06-17 07:37:34 +02:00
|
|
|
if( gEngfuncs.drawFuncs->GL_BuildLightmaps )
|
|
|
|
gEngfuncs.drawFuncs->GL_BuildLightmaps( );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
else if( FBitSet( vid_gamma->flags, FCVAR_CHANGED ) || FBitSet( vid_brightness->flags, FCVAR_CHANGED ))
|
|
|
|
{
|
2019-06-17 07:37:34 +02:00
|
|
|
gEngfuncs.BuildGammaTable( vid_gamma->value, vid_brightness->value );
|
2018-04-13 18:23:45 +02:00
|
|
|
glConfig.softwareGammaUpdate = true;
|
|
|
|
GL_RebuildLightmaps();
|
|
|
|
glConfig.softwareGammaUpdate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_BeginFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_BeginFrame( qboolean clearScene )
|
|
|
|
{
|
|
|
|
glConfig.softwareGammaUpdate = false; // in case of possible fails
|
|
|
|
|
2019-03-22 14:36:46 +01:00
|
|
|
if(( gl_clear->value || ENGINE_GET_PARM( PARM_DEV_OVERVIEW )) &&
|
|
|
|
clearScene && ENGINE_GET_PARM( PARM_CONNSTATE ) != ca_cinematic )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
pglClear( GL_COLOR_BUFFER_BIT );
|
|
|
|
}
|
|
|
|
|
2019-06-17 06:05:36 +02:00
|
|
|
R_CheckGamma();
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
R_Set2DMode( true );
|
|
|
|
|
|
|
|
// draw buffer stuff
|
|
|
|
pglDrawBuffer( GL_BACK );
|
|
|
|
|
|
|
|
// update texture parameters
|
2023-05-20 19:27:15 +02:00
|
|
|
if( FBitSet( gl_texture_nearest.flags|gl_lightmap_nearest.flags|gl_texture_anisotropy.flags|gl_texture_lodbias.flags, FCVAR_CHANGED ))
|
2018-04-13 18:23:45 +02:00
|
|
|
R_SetTextureParameters();
|
|
|
|
|
2019-03-06 15:14:25 +01:00
|
|
|
gEngfuncs.CL_ExtraUpdate ();
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_SetupRefParams
|
|
|
|
|
|
|
|
set initial params for renderer
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_SetupRefParams( const ref_viewpass_t *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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_RenderFrame
|
|
|
|
===============
|
|
|
|
*/
|
2019-05-12 17:02:59 +02:00
|
|
|
void R_RenderFrame( const ref_viewpass_t *rvp )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( r_norefresh->value )
|
2019-05-12 17:02:59 +02:00
|
|
|
return;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
// setup the initial render params
|
|
|
|
R_SetupRefParams( rvp );
|
|
|
|
|
2023-05-20 19:27:15 +02:00
|
|
|
if( gl_finish.value && RI.drawWorld )
|
2018-04-13 18:23:45 +02:00
|
|
|
pglFinish();
|
|
|
|
|
2023-05-20 19:27:15 +02:00
|
|
|
if( glConfig.max_multisamples > 1 && FBitSet( gl_msaa.flags, FCVAR_CHANGED ))
|
2018-06-09 00:28:35 +02:00
|
|
|
{
|
2023-05-20 19:27:15 +02:00
|
|
|
if( gl_msaa.value )
|
2018-06-09 00:28:35 +02:00
|
|
|
pglEnable( GL_MULTISAMPLE_ARB );
|
2018-10-04 08:08:48 +02:00
|
|
|
else pglDisable( GL_MULTISAMPLE_ARB );
|
2023-05-20 19:27:15 +02:00
|
|
|
ClearBits( gl_msaa.flags, FCVAR_CHANGED );
|
2018-06-09 00:28:35 +02:00
|
|
|
}
|
2018-04-20 10:41:02 +02:00
|
|
|
|
2018-04-13 18:23:45 +02:00
|
|
|
// completely override rendering
|
2019-03-16 02:24:27 +01:00
|
|
|
if( gEngfuncs.drawFuncs->GL_RenderFrame != NULL )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
tr.fCustomRendering = true;
|
|
|
|
|
2019-03-16 02:24:27 +01:00
|
|
|
if( gEngfuncs.drawFuncs->GL_RenderFrame( rvp ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2018-06-09 00:28:35 +02:00
|
|
|
R_GatherPlayerLight();
|
2018-04-13 18:23:45 +02:00
|
|
|
tr.realframecount++;
|
|
|
|
tr.fResetVis = true;
|
2019-05-12 17:02:59 +02:00
|
|
|
return;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tr.fCustomRendering = false;
|
|
|
|
if( !RI.onlyClientDraw )
|
|
|
|
R_RunViewmodelEvents();
|
|
|
|
|
|
|
|
tr.realframecount++; // right called after viewmodel events
|
|
|
|
R_RenderScene();
|
2019-03-15 19:23:59 +01:00
|
|
|
|
2019-05-12 17:02:59 +02:00
|
|
|
return;
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_EndFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_EndFrame( void )
|
|
|
|
{
|
2023-02-21 23:32:47 +01:00
|
|
|
#if XASH_PSVITA
|
|
|
|
VGL_ShimEndFrame();
|
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
// flush any remaining 2D bits
|
|
|
|
R_Set2DMode( false );
|
2019-03-16 05:58:44 +01:00
|
|
|
gEngfuncs.GL_SwapBuffers();
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
R_DrawCubemapView
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void R_DrawCubemapView( const vec3_t origin, const vec3_t angles, int size )
|
|
|
|
{
|
|
|
|
ref_viewpass_t rvp;
|
|
|
|
|
|
|
|
// basic params
|
|
|
|
rvp.flags = rvp.viewentity = 0;
|
|
|
|
SetBits( rvp.flags, RF_DRAW_WORLD );
|
|
|
|
SetBits( rvp.flags, RF_DRAW_CUBEMAP );
|
|
|
|
|
|
|
|
rvp.viewport[0] = rvp.viewport[1] = 0;
|
|
|
|
rvp.viewport[2] = rvp.viewport[3] = size;
|
|
|
|
rvp.fov_x = rvp.fov_y = 90.0f; // this is a final fov value
|
|
|
|
|
|
|
|
// setup origin & angles
|
|
|
|
VectorCopy( origin, rvp.vieworigin );
|
|
|
|
VectorCopy( angles, rvp.viewangles );
|
|
|
|
|
|
|
|
R_RenderFrame( &rvp );
|
|
|
|
|
|
|
|
RI.viewleaf = NULL; // force markleafs next frame
|
|
|
|
}
|
2019-04-15 00:19:05 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
CL_FxBlend
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
int CL_FxBlend( cl_entity_t *e )
|
|
|
|
{
|
|
|
|
int blend = 0;
|
|
|
|
float offset, dist;
|
|
|
|
vec3_t tmp;
|
|
|
|
|
|
|
|
offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx
|
|
|
|
|
|
|
|
switch( e->curstate.renderfx )
|
|
|
|
{
|
|
|
|
case kRenderFxPulseSlowWide:
|
|
|
|
blend = e->curstate.renderamt + 0x40 * sin( gpGlobals->time * 2 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseFastWide:
|
|
|
|
blend = e->curstate.renderamt + 0x40 * sin( gpGlobals->time * 8 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseSlow:
|
|
|
|
blend = e->curstate.renderamt + 0x10 * sin( gpGlobals->time * 2 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxPulseFast:
|
|
|
|
blend = e->curstate.renderamt + 0x10 * sin( gpGlobals->time * 8 + offset );
|
|
|
|
break;
|
|
|
|
case kRenderFxFadeSlow:
|
|
|
|
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( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt > 3 )
|
|
|
|
e->curstate.renderamt -= 4;
|
|
|
|
else e->curstate.renderamt = 0;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxSolidSlow:
|
|
|
|
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( RP_NORMALPASS( ))
|
|
|
|
{
|
|
|
|
if( e->curstate.renderamt < 252 )
|
|
|
|
e->curstate.renderamt += 4;
|
|
|
|
else e->curstate.renderamt = 255;
|
|
|
|
}
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeSlow:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 4 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeFast:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 16 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxStrobeFaster:
|
|
|
|
blend = 20 * sin( gpGlobals->time * 36 + offset );
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxFlickerSlow:
|
|
|
|
blend = 20 * (sin( gpGlobals->time * 2 ) + sin( gpGlobals->time * 17 + offset ));
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxFlickerFast:
|
|
|
|
blend = 20 * (sin( gpGlobals->time * 16 ) + sin( gpGlobals->time * 23 + offset ));
|
|
|
|
if( blend < 0 ) blend = 0;
|
|
|
|
else blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
case kRenderFxHologram:
|
|
|
|
case kRenderFxDistort:
|
|
|
|
VectorCopy( e->origin, tmp );
|
|
|
|
VectorSubtract( tmp, RI.vieworg, tmp );
|
|
|
|
dist = DotProduct( tmp, RI.vforward );
|
|
|
|
|
|
|
|
// turn off distance fade
|
|
|
|
if( e->curstate.renderfx == kRenderFxDistort )
|
|
|
|
dist = 1;
|
|
|
|
|
|
|
|
if( dist <= 0 )
|
|
|
|
{
|
|
|
|
blend = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->curstate.renderamt = 180;
|
|
|
|
if( dist <= 100 ) blend = e->curstate.renderamt;
|
|
|
|
else blend = (int) ((1.0f - ( dist - 100 ) * ( 1.0f / 400.0f )) * e->curstate.renderamt );
|
|
|
|
blend += gEngfuncs.COM_RandomLong( -32, 31 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blend = e->curstate.renderamt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
blend = bound( 0, blend, 255 );
|
|
|
|
|
|
|
|
return blend;
|
|
|
|
}
|