2016-12-18 04:43:04 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Quake III Arena source code 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#include "tr_local.h"
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
|
|
|
|
backEndData_t* backEndData;
|
2016-12-18 04:43:04 +00:00
|
|
|
backEndState_t backEnd;
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static int64_t startTime;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static void RB_Set2D()
|
|
|
|
{
|
|
|
|
backEnd.projection2D = qtrue;
|
|
|
|
backEnd.pc = backEnd.pc2D;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
// set time for 2D shaders
|
|
|
|
backEnd.refdef.time = ri.Milliseconds();
|
|
|
|
backEnd.refdef.floatTime = (double)backEnd.refdef.time / 1000.0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.Begin2D();
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static const void* RB_SetColor( const void* data )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
const setColorCommand_t* cmd = (const setColorCommand_t*)data;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
backEnd.color2D[0] = (byte)(cmd->color[0] * 255);
|
|
|
|
backEnd.color2D[1] = (byte)(cmd->color[1] * 255);
|
|
|
|
backEnd.color2D[2] = (byte)(cmd->color[2] * 255);
|
|
|
|
backEnd.color2D[3] = (byte)(cmd->color[3] * 255);
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
return (const void*)(cmd + 1);
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static const void* RB_StretchPic( const void* data )
|
|
|
|
{
|
|
|
|
const stretchPicCommand_t* cmd = (const stretchPicCommand_t*)data;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
if ( !backEnd.projection2D )
|
|
|
|
RB_Set2D();
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
const shader_t* shader = cmd->shader;
|
|
|
|
if ( shader != tess.shader ) {
|
|
|
|
if ( tess.numIndexes ) {
|
|
|
|
RB_EndSurface();
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
2019-09-25 03:25:59 +00:00
|
|
|
backEnd.currentEntity = &backEnd.entity2D;
|
|
|
|
RB_BeginSurface( shader, 0 );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
RB_CHECKOVERFLOW( 4, 6 );
|
|
|
|
int numVerts = tess.numVertexes;
|
|
|
|
int numIndexes = tess.numIndexes;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.numVertexes += 4;
|
|
|
|
tess.numIndexes += 6;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.indexes[ numIndexes ] = numVerts + 3;
|
|
|
|
tess.indexes[ numIndexes + 1 ] = numVerts + 0;
|
|
|
|
tess.indexes[ numIndexes + 2 ] = numVerts + 2;
|
|
|
|
tess.indexes[ numIndexes + 3 ] = numVerts + 2;
|
|
|
|
tess.indexes[ numIndexes + 4 ] = numVerts + 0;
|
|
|
|
tess.indexes[ numIndexes + 5 ] = numVerts + 1;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
*(int *)tess.vertexColors[ numVerts ] =
|
|
|
|
*(int *)tess.vertexColors[ numVerts + 1 ] =
|
|
|
|
*(int *)tess.vertexColors[ numVerts + 2 ] =
|
|
|
|
*(int *)tess.vertexColors[ numVerts + 3 ] = *(int *)backEnd.color2D;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts ][0] = cmd->x;
|
|
|
|
tess.xyz[ numVerts ][1] = cmd->y;
|
|
|
|
tess.xyz[ numVerts ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts ][0] = cmd->s1;
|
|
|
|
tess.texCoords[ numVerts ][1] = cmd->t1;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts + 1 ][0] = cmd->x + cmd->w;
|
|
|
|
tess.xyz[ numVerts + 1 ][1] = cmd->y;
|
|
|
|
tess.xyz[ numVerts + 1 ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts + 1 ][0] = cmd->s2;
|
|
|
|
tess.texCoords[ numVerts + 1 ][1] = cmd->t1;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts + 2 ][0] = cmd->x + cmd->w;
|
|
|
|
tess.xyz[ numVerts + 2 ][1] = cmd->y + cmd->h;
|
|
|
|
tess.xyz[ numVerts + 2 ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts + 2 ][0] = cmd->s2;
|
|
|
|
tess.texCoords[ numVerts + 2 ][1] = cmd->t2;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts + 3 ][0] = cmd->x;
|
|
|
|
tess.xyz[ numVerts + 3 ][1] = cmd->y + cmd->h;
|
|
|
|
tess.xyz[ numVerts + 3 ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts + 3 ][0] = cmd->s1;
|
|
|
|
tess.texCoords[ numVerts + 3 ][1] = cmd->t2;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
return (const void*)(cmd + 1);
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static const void* RB_Triangle( const void* data )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
const triangleCommand_t* cmd = (const triangleCommand_t*)data;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
if ( !backEnd.projection2D )
|
|
|
|
RB_Set2D();
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
const shader_t* shader = cmd->shader;
|
|
|
|
if ( shader != tess.shader ) {
|
|
|
|
if ( tess.numIndexes ) {
|
|
|
|
RB_EndSurface();
|
|
|
|
}
|
|
|
|
backEnd.currentEntity = &backEnd.entity2D;
|
|
|
|
RB_BeginSurface( shader, 0 );
|
|
|
|
}
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
RB_CHECKOVERFLOW( 3, 3 );
|
|
|
|
int numVerts = tess.numVertexes;
|
|
|
|
int numIndexes = tess.numIndexes;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.numVertexes += 3;
|
|
|
|
tess.numIndexes += 3;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.indexes[ numIndexes + 0 ] = numVerts + 0;
|
|
|
|
tess.indexes[ numIndexes + 1 ] = numVerts + 1;
|
|
|
|
tess.indexes[ numIndexes + 2 ] = numVerts + 2;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
*(int *)tess.vertexColors[ numVerts ] =
|
|
|
|
*(int *)tess.vertexColors[ numVerts + 1 ] =
|
|
|
|
*(int *)tess.vertexColors[ numVerts + 2 ] = *(int *)backEnd.color2D;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts ][0] = cmd->x0;
|
|
|
|
tess.xyz[ numVerts ][1] = cmd->y0;
|
|
|
|
tess.xyz[ numVerts ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts ][0] = cmd->s0;
|
|
|
|
tess.texCoords[ numVerts ][1] = cmd->t0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts + 1 ][0] = cmd->x1;
|
|
|
|
tess.xyz[ numVerts + 1 ][1] = cmd->y1;
|
|
|
|
tess.xyz[ numVerts + 1 ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts + 1 ][0] = cmd->s1;
|
|
|
|
tess.texCoords[ numVerts + 1 ][1] = cmd->t1;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.xyz[ numVerts + 2 ][0] = cmd->x2;
|
|
|
|
tess.xyz[ numVerts + 2 ][1] = cmd->y2;
|
|
|
|
tess.xyz[ numVerts + 2 ][2] = 0;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.texCoords[ numVerts + 2 ][0] = cmd->s2;
|
|
|
|
tess.texCoords[ numVerts + 2 ][1] = cmd->t2;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
return (const void*)(cmd + 1);
|
|
|
|
}
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static qbool AreShadersStillBatchable( const shader_t* a, const shader_t* b )
|
|
|
|
{
|
|
|
|
if ( a->lightmapIndex != b->lightmapIndex ||
|
|
|
|
a->sort != b->sort ||
|
|
|
|
a->fogPass != FP_NONE ||
|
|
|
|
b->fogPass != FP_NONE ||
|
|
|
|
a->cullType != b->cullType ||
|
|
|
|
a->polygonOffset != b->polygonOffset ||
|
|
|
|
a->imgflags != b->imgflags ||
|
|
|
|
a->numStages != b->numStages ||
|
|
|
|
a->softSprite != b->softSprite )
|
|
|
|
return qfalse;
|
|
|
|
|
|
|
|
for ( int i = 0; i < a->numStages; ++i ) {
|
|
|
|
const shaderStage_t* const sa = a->stages[i];
|
|
|
|
const shaderStage_t* const sb = b->stages[i];
|
|
|
|
if ( sa->active != sb->active ||
|
|
|
|
sa->type != ST_DIFFUSE ||
|
|
|
|
sb->type != ST_DIFFUSE ||
|
|
|
|
sa->stateBits != sb->stateBits ||
|
|
|
|
sa->type != sb->type ||
|
|
|
|
sa->tcGen != sb->tcGen ||
|
|
|
|
sa->mtStages != sb->mtStages ||
|
|
|
|
sa->bundle.isVideoMap != qfalse ||
|
|
|
|
sb->bundle.isVideoMap != qfalse ||
|
|
|
|
sa->bundle.image[0] != sb->bundle.image[0] )
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qtrue;
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static void RB_RenderDrawSurfList( const drawSurf_t* drawSurfs, int numDrawSurfs, qbool beginView )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2016-12-18 11:05:45 +00:00
|
|
|
int i;
|
2016-12-18 04:43:04 +00:00
|
|
|
const shader_t* shader = NULL;
|
|
|
|
unsigned int sort = (unsigned int)-1;
|
|
|
|
|
|
|
|
// save original time for entity shader offsets
|
|
|
|
double originalTime = backEnd.refdef.floatTime;
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
// we will need to change the projection matrix before drawing 2D images again
|
|
|
|
backEnd.projection2D = qfalse;
|
|
|
|
backEnd.pc = backEnd.pc3D;
|
|
|
|
|
|
|
|
if ( beginView )
|
|
|
|
gal.Begin3D();
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
// draw everything
|
|
|
|
int oldEntityNum = -1;
|
|
|
|
backEnd.currentEntity = &tr.worldEntity;
|
|
|
|
qbool oldDepthRange = qfalse;
|
|
|
|
qbool depthRange = qfalse;
|
|
|
|
|
|
|
|
backEnd.pc[RB_SURFACES] += numDrawSurfs;
|
|
|
|
|
|
|
|
const drawSurf_t* drawSurf;
|
|
|
|
for ( i = 0, drawSurf = drawSurfs; i < numDrawSurfs; ++i, ++drawSurf ) {
|
|
|
|
if ( drawSurf->sort == sort ) {
|
|
|
|
// fast path, same as previous sort
|
2019-09-25 03:25:59 +00:00
|
|
|
const int firstVertex = tess.numVertexes;
|
|
|
|
const int firstIndex = tess.numIndexes;
|
2016-12-18 04:43:04 +00:00
|
|
|
rb_surfaceTable[ *drawSurf->surface ]( drawSurf->surface );
|
2019-09-25 03:25:59 +00:00
|
|
|
if ( tess.deformsPreApplied ) {
|
|
|
|
// across multiple shaders though, so we need to compute all the results now
|
|
|
|
const int numVertexes = tess.numVertexes - firstVertex;
|
|
|
|
const int numIndexes = tess.numIndexes - firstIndex;
|
|
|
|
RB_DeformTessGeometry( firstVertex, numVertexes, firstIndex, numIndexes );
|
|
|
|
for ( int i = 0; i < shader->numStages; ++i ) {
|
|
|
|
R_ComputeColors( shader->stages[i], tess.svars[i], firstVertex, numVertexes );
|
|
|
|
R_ComputeTexCoords( shader->stages[i], tess.svars[i], firstVertex, numVertexes, qfalse );
|
|
|
|
}
|
|
|
|
}
|
2016-12-18 04:43:04 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fogNum;
|
|
|
|
const shader_t* shaderPrev = shader;
|
2016-12-18 11:05:45 +00:00
|
|
|
int entityNum;
|
2016-12-18 04:43:04 +00:00
|
|
|
R_DecomposeSort( drawSurf->sort, &entityNum, &shader, &fogNum );
|
2019-09-25 03:25:59 +00:00
|
|
|
const qbool softSpriteChange = shader->softSprite != tess.softSprite;
|
|
|
|
|
|
|
|
// detect and batch surfaces across different (but sufficiently similar) shaders
|
|
|
|
if ( !softSpriteChange &&
|
|
|
|
oldEntityNum == ENTITYNUM_WORLD &&
|
|
|
|
entityNum == ENTITYNUM_WORLD &&
|
|
|
|
AreShadersStillBatchable( shaderPrev, shader ) ) {
|
|
|
|
if ( !tess.deformsPreApplied ) {
|
|
|
|
// this is the second shader in the sequence,
|
|
|
|
// so we need to compute everything added with the first one now
|
|
|
|
tess.shader = shaderPrev;
|
|
|
|
RB_DeformTessGeometry( 0, tess.numVertexes, 0, tess.numIndexes );
|
|
|
|
for ( int i = 0; i < shaderPrev->numStages; ++i ) {
|
|
|
|
R_ComputeColors( shaderPrev->stages[i], tess.svars[i], 0, tess.numVertexes );
|
|
|
|
R_ComputeTexCoords( shaderPrev->stages[i], tess.svars[i], 0, tess.numVertexes, qfalse );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tess.shader = shader;
|
|
|
|
tess.deformsPreApplied = qtrue;
|
|
|
|
const int firstVertex = tess.numVertexes;
|
|
|
|
const int firstIndex = tess.numIndexes;
|
|
|
|
rb_surfaceTable[ *drawSurf->surface ]( drawSurf->surface );
|
|
|
|
const int numVertexes = tess.numVertexes - firstVertex;
|
|
|
|
const int numIndexes = tess.numIndexes - firstIndex;
|
|
|
|
RB_DeformTessGeometry( firstVertex, numVertexes, firstIndex, numIndexes );
|
|
|
|
for ( int i = 0; i < shader->numStages; ++i ) {
|
|
|
|
R_ComputeColors( shader->stages[i], tess.svars[i], firstVertex, numVertexes );
|
|
|
|
R_ComputeTexCoords( shader->stages[i], tess.svars[i], firstVertex, numVertexes, qfalse );
|
|
|
|
}
|
|
|
|
sort = drawSurf->sort;
|
|
|
|
oldEntityNum = entityNum;
|
|
|
|
continue;
|
|
|
|
}
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
// "entityMergable" shaders can have surfaces from multiple refentities
|
|
|
|
// merged into a single batch, like (CONCEPTUALLY) smoke and blood puff sprites
|
|
|
|
// only legacy code still uses them though, because refents are so heavyweight:
|
|
|
|
// modern code just billboards in cgame and submits raw polys, all of which are
|
|
|
|
// ENTITYNUM_WORLD and thus automatically take the "same sort" fast path
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
if ( !shader->entityMergable || ((sort ^ drawSurf->sort) & ~QSORT_ENTITYNUM_MASK) || softSpriteChange ) {
|
2016-12-18 04:43:04 +00:00
|
|
|
if (shaderPrev)
|
|
|
|
RB_EndSurface();
|
|
|
|
RB_BeginSurface( shader, fogNum );
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.softSprite = shader->softSprite;
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort = drawSurf->sort;
|
|
|
|
|
|
|
|
//
|
|
|
|
// change the modelview matrix if needed
|
|
|
|
//
|
|
|
|
if ( entityNum != oldEntityNum ) {
|
|
|
|
depthRange = qfalse;
|
|
|
|
|
|
|
|
if ( entityNum != ENTITYNUM_WORLD ) {
|
|
|
|
backEnd.currentEntity = &backEnd.refdef.entities[entityNum];
|
2017-06-22 05:15:47 +00:00
|
|
|
if (backEnd.currentEntity->intShaderTime)
|
2017-05-18 22:00:08 +00:00
|
|
|
backEnd.refdef.floatTime = originalTime - (double)(backEnd.currentEntity->e.shaderTime.iShaderTime) / 1000.0;
|
2016-12-18 04:43:04 +00:00
|
|
|
else
|
|
|
|
backEnd.refdef.floatTime = originalTime - backEnd.currentEntity->e.shaderTime.fShaderTime;
|
|
|
|
// we have to reset the shaderTime as well otherwise image animations start
|
|
|
|
// from the wrong frame
|
|
|
|
tess.shaderTime = backEnd.refdef.floatTime - tess.shader->timeOffset;
|
|
|
|
|
|
|
|
// set up the transformation matrix
|
2016-12-30 04:13:59 +00:00
|
|
|
R_RotateForEntity( backEnd.currentEntity, &backEnd.viewParms, &backEnd.orient );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
if ( backEnd.currentEntity->e.renderfx & RF_DEPTHHACK ) {
|
|
|
|
// hack the depth range to prevent view model from poking into walls
|
|
|
|
depthRange = qtrue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
backEnd.currentEntity = &tr.worldEntity;
|
|
|
|
backEnd.refdef.floatTime = originalTime;
|
2016-12-30 04:13:59 +00:00
|
|
|
backEnd.orient = backEnd.viewParms.world;
|
2016-12-18 04:43:04 +00:00
|
|
|
// we have to reset the shaderTime as well otherwise image animations on
|
|
|
|
// the world (like water) continue with the wrong frame
|
|
|
|
tess.shaderTime = backEnd.refdef.floatTime - tess.shader->timeOffset;
|
|
|
|
}
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetModelViewMatrix( backEnd.orient.modelMatrix );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// change depthrange if needed
|
|
|
|
//
|
|
|
|
if ( oldDepthRange != depthRange ) {
|
|
|
|
if ( depthRange ) {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 0.3 );
|
2016-12-18 04:43:04 +00:00
|
|
|
} else {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 1 );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
oldDepthRange = depthRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldEntityNum = entityNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the triangles for this surface
|
|
|
|
rb_surfaceTable[ *drawSurf->surface ]( drawSurf->surface );
|
|
|
|
}
|
|
|
|
|
|
|
|
backEnd.refdef.floatTime = originalTime;
|
|
|
|
|
|
|
|
// draw the contents of the last shader batch
|
|
|
|
if (shader) {
|
|
|
|
RB_EndSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
// go back to the world modelview matrix
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetModelViewMatrix( backEnd.viewParms.world.modelMatrix );
|
2016-12-18 04:43:04 +00:00
|
|
|
if ( depthRange ) {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 1 );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static void RB_RenderLitSurfList( dlight_t* dl, qbool opaque )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
if (!dl->head)
|
|
|
|
return;
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
const shader_t* shader = NULL;
|
|
|
|
|
|
|
|
int entityNum, oldEntityNum;
|
|
|
|
qbool depthRange, oldDepthRange;
|
|
|
|
unsigned int sort = (unsigned int)-1;
|
|
|
|
|
|
|
|
// save original time for entity shader offsets
|
|
|
|
double originalTime = backEnd.refdef.floatTime;
|
|
|
|
|
|
|
|
// draw everything
|
2020-02-21 07:26:12 +00:00
|
|
|
const int liquidFlags = CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER;
|
2016-12-18 04:43:04 +00:00
|
|
|
oldEntityNum = -1;
|
|
|
|
backEnd.currentEntity = &tr.worldEntity;
|
2020-02-21 07:26:12 +00:00
|
|
|
backEnd.dlOpaque = opaque;
|
2016-12-18 04:43:04 +00:00
|
|
|
oldDepthRange = qfalse;
|
|
|
|
depthRange = qfalse;
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.light = dl;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
for ( litSurf_t* litSurf = dl->head; litSurf; litSurf = litSurf->next ) {
|
|
|
|
++backEnd.pc[RB_LIT_SURFACES];
|
|
|
|
if ( litSurf->sort == sort ) {
|
|
|
|
// fast path, same as previous sort
|
|
|
|
rb_surfaceTable[ *litSurf->surface ]( litSurf->surface );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fogNum;
|
|
|
|
const shader_t* shaderPrev = shader;
|
|
|
|
R_DecomposeSort( litSurf->sort, &entityNum, &shader, &fogNum );
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
if (opaque && shader->sort > SS_OPAQUE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!opaque && shader->sort <= SS_OPAQUE)
|
2016-12-18 04:43:04 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (shaderPrev)
|
|
|
|
RB_EndSurface();
|
|
|
|
RB_BeginSurface( shader, fogNum );
|
|
|
|
|
2020-02-21 07:26:12 +00:00
|
|
|
// stage index is guaranteed valid by R_AddLitSurface
|
|
|
|
const int stageIndex = tess.shader->lightingStages[ST_DIFFUSE];
|
|
|
|
const shaderStage_t* const stage = tess.xstages[stageIndex];
|
|
|
|
backEnd.dlIntensity = (shader->contentFlags & liquidFlags) != 0 ? 0.5f : 1.0f;
|
|
|
|
backEnd.dlStateBits =
|
|
|
|
(opaque || (stage->stateBits & GLS_ATEST_BITS) != 0) ?
|
|
|
|
(GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL):
|
|
|
|
(GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE);
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
sort = litSurf->sort;
|
|
|
|
|
|
|
|
//
|
|
|
|
// change the modelview matrix if needed
|
|
|
|
//
|
|
|
|
if ( entityNum != oldEntityNum ) {
|
|
|
|
depthRange = qfalse;
|
|
|
|
|
|
|
|
if ( entityNum != ENTITYNUM_WORLD ) {
|
|
|
|
backEnd.currentEntity = &backEnd.refdef.entities[entityNum];
|
2017-06-22 05:15:47 +00:00
|
|
|
if (backEnd.currentEntity->intShaderTime)
|
2016-12-18 04:43:04 +00:00
|
|
|
backEnd.refdef.floatTime = originalTime - (double)backEnd.currentEntity->e.shaderTime.iShaderTime;
|
|
|
|
else
|
|
|
|
backEnd.refdef.floatTime = originalTime - backEnd.currentEntity->e.shaderTime.fShaderTime;
|
|
|
|
// we have to reset the shaderTime as well otherwise image animations start
|
|
|
|
// from the wrong frame
|
|
|
|
tess.shaderTime = backEnd.refdef.floatTime - tess.shader->timeOffset;
|
|
|
|
|
|
|
|
// set up the transformation matrix
|
2016-12-30 04:13:59 +00:00
|
|
|
R_RotateForEntity( backEnd.currentEntity, &backEnd.viewParms, &backEnd.orient );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
if ( backEnd.currentEntity->e.renderfx & RF_DEPTHHACK ) {
|
|
|
|
// hack the depth range to prevent view model from poking into walls
|
|
|
|
depthRange = qtrue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
backEnd.currentEntity = &tr.worldEntity;
|
|
|
|
backEnd.refdef.floatTime = originalTime;
|
2016-12-30 04:13:59 +00:00
|
|
|
backEnd.orient = backEnd.viewParms.world;
|
2016-12-18 04:43:04 +00:00
|
|
|
// we have to reset the shaderTime as well otherwise image animations on
|
|
|
|
// the world (like water) continue with the wrong frame
|
|
|
|
tess.shaderTime = backEnd.refdef.floatTime - tess.shader->timeOffset;
|
2016-12-30 04:13:59 +00:00
|
|
|
R_TransformDlights( 1, dl, &backEnd.orient );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
R_TransformDlights( 1, dl, &backEnd.orient );
|
|
|
|
gal.BeginDynamicLight();
|
|
|
|
|
|
|
|
gal.SetModelViewMatrix( backEnd.orient.modelMatrix );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// change depthrange if needed
|
|
|
|
//
|
|
|
|
if ( oldDepthRange != depthRange ) {
|
|
|
|
if ( depthRange ) {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 0.3 );
|
2016-12-18 04:43:04 +00:00
|
|
|
} else {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 1 );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
oldDepthRange = depthRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldEntityNum = entityNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the triangles for this surface
|
|
|
|
rb_surfaceTable[ *litSurf->surface ]( litSurf->surface );
|
|
|
|
}
|
|
|
|
|
|
|
|
backEnd.refdef.floatTime = originalTime;
|
|
|
|
|
|
|
|
// draw the contents of the last shader batch
|
|
|
|
if (shader) {
|
|
|
|
RB_EndSurface();
|
|
|
|
}
|
|
|
|
|
|
|
|
// go back to the world modelview matrix
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetModelViewMatrix( backEnd.viewParms.world.modelMatrix );
|
2016-12-18 04:43:04 +00:00
|
|
|
if ( depthRange ) {
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 1 );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static void R_DebugPolygon( int colorMask, int numPoints, const float* points )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
RB_PushSingleStageShader( GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE, CT_FRONT_SIDED );
|
|
|
|
shaderStage_t& stage = *tess.shader->stages[0];
|
|
|
|
|
|
|
|
// solid
|
|
|
|
for ( int i = 0; i < numPoints; ++i ) {
|
|
|
|
tess.xyz[i][0] = points[i * 3 + 0];
|
|
|
|
tess.xyz[i][1] = points[i * 3 + 1];
|
|
|
|
tess.xyz[i][2] = points[i * 3 + 2];
|
|
|
|
tess.xyz[i][3] = 1.0f;
|
|
|
|
}
|
|
|
|
for ( int i = 1, n = 0; i < numPoints - 1; ++i ) {
|
|
|
|
tess.indexes[n++] = 0;
|
|
|
|
tess.indexes[n++] = i + 0;
|
|
|
|
tess.indexes[n++] = i + 1;
|
|
|
|
}
|
|
|
|
tess.numVertexes = numPoints;
|
|
|
|
tess.numIndexes = (numPoints - 2) * 3;
|
|
|
|
stage.rgbGen = CGEN_CONST;
|
|
|
|
stage.constantColor[0] = (colorMask & 1) ? 255 : 0;
|
|
|
|
stage.constantColor[1] = ((colorMask >> 1) & 1) ? 255 : 0;
|
|
|
|
stage.constantColor[2] = ((colorMask >> 2) & 1) ? 255 : 0;
|
|
|
|
stage.constantColor[3] = 255;
|
2019-12-26 15:16:30 +00:00
|
|
|
R_ComputeColors( &stage, tess.svars[0], 0, numPoints );
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.Draw( DT_GENERIC );
|
|
|
|
|
|
|
|
// wireframe
|
|
|
|
for ( int i = 0, n = 0; i < numPoints; ++i ) {
|
|
|
|
tess.indexes[n++] = i;
|
|
|
|
tess.indexes[n++] = i;
|
|
|
|
tess.indexes[n++] = (i + 1) % numPoints;
|
|
|
|
}
|
|
|
|
tess.numIndexes = numPoints * 3;
|
|
|
|
stage.stateBits |= GLS_POLYMODE_LINE;
|
|
|
|
stage.rgbGen = CGEN_IDENTITY;
|
2019-12-26 15:16:30 +00:00
|
|
|
R_ComputeColors( &stage, tess.svars[0], 0, numPoints );
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.SetDepthRange( 0, 0 );
|
|
|
|
gal.Draw( DT_GENERIC );
|
|
|
|
gal.SetDepthRange( 0, 1 );
|
2019-12-26 15:16:30 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
RB_PopShader();
|
|
|
|
tess.numVertexes = 0;
|
|
|
|
tess.numIndexes = 0;
|
2017-12-27 04:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
static const void* RB_DrawSurfs( const void* data )
|
|
|
|
{
|
|
|
|
const drawSurfsCommand_t* cmd = (const drawSurfsCommand_t*)data;
|
|
|
|
|
|
|
|
// finish any 2D drawing if needed
|
|
|
|
if ( tess.numIndexes )
|
|
|
|
RB_EndSurface();
|
|
|
|
|
|
|
|
backEnd.refdef = cmd->refdef;
|
|
|
|
backEnd.viewParms = cmd->viewParms;
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
const int opaqueCount = cmd->numDrawSurfs - cmd->numTranspSurfs;
|
|
|
|
const int transpCount = cmd->numTranspSurfs;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.pass = shaderCommands_t::TP_BASE;
|
|
|
|
RB_RenderDrawSurfList( cmd->drawSurfs, opaqueCount, qtrue );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
tess.pass = shaderCommands_t::TP_LIGHT;
|
2019-09-25 03:25:59 +00:00
|
|
|
for ( int i = 0; i < backEnd.refdef.num_dlights; ++i ) {
|
|
|
|
RB_RenderLitSurfList( &backEnd.refdef.dlights[i], qtrue );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.pass = shaderCommands_t::TP_BASE;
|
|
|
|
RB_RenderDrawSurfList( cmd->drawSurfs + opaqueCount, transpCount, qfalse );
|
|
|
|
|
|
|
|
tess.pass = shaderCommands_t::TP_LIGHT;
|
2016-12-18 04:43:04 +00:00
|
|
|
for ( int i = 0; i < backEnd.refdef.num_dlights; ++i ) {
|
2019-09-25 03:25:59 +00:00
|
|
|
RB_RenderLitSurfList( &backEnd.refdef.dlights[i], qfalse );
|
2016-12-18 04:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tess.pass = shaderCommands_t::TP_BASE;
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
// draw main system development information (surface outlines, etc)
|
|
|
|
if ( r_debugSurface->integer )
|
|
|
|
ri.CM_DrawDebugSurface( R_DebugPolygon );
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
return (const void*)(cmd + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-20 23:58:59 +00:00
|
|
|
static const void* RB_BeginFrame( const void* data )
|
2016-12-18 04:43:04 +00:00
|
|
|
{
|
2017-03-20 23:58:59 +00:00
|
|
|
const beginFrameCommand_t* cmd = (const beginFrameCommand_t*)data;
|
2016-12-18 04:43:04 +00:00
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
R_SetColorMappings();
|
|
|
|
gal.BeginFrame();
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
return (const void*)(cmd + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const void* RB_SwapBuffers( const void* data )
|
|
|
|
{
|
|
|
|
// finish any 2D drawing if needed
|
|
|
|
if ( tess.numIndexes ) {
|
|
|
|
RB_EndSurface();
|
|
|
|
}
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
// This has been moved here to make sure the Present/SwapBuffer
|
|
|
|
// call gets ignored for CPU timing as V-Sync would mess it all up.
|
|
|
|
// We can't really "charge" 2D/3D properly, so it all counts as 3D.
|
|
|
|
const int64_t endTime = ri.Microseconds();
|
|
|
|
backEnd.pc3D[RB_USEC] = (int)( endTime - startTime );
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
const swapBuffersCommand_t* cmd = (const swapBuffersCommand_t*)data;
|
2019-09-25 03:25:59 +00:00
|
|
|
gal.EndFrame();
|
|
|
|
Sys_V_EndFrame();
|
|
|
|
const int64_t swapTime = ri.Microseconds();
|
|
|
|
backEnd.pc3D[RB_USEC_END] = (int)( swapTime - endTime );
|
2016-12-18 04:43:04 +00:00
|
|
|
backEnd.projection2D = qfalse;
|
|
|
|
backEnd.pc = backEnd.pc3D;
|
|
|
|
|
|
|
|
return (const void*)(cmd + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RB_ExecuteRenderCommands( const void *data )
|
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
startTime = ri.Microseconds();
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
while ( 1 ) {
|
|
|
|
data = PADP(data, sizeof(void *));
|
|
|
|
|
|
|
|
switch ( *(const int *)data ) {
|
|
|
|
case RC_SET_COLOR:
|
|
|
|
data = RB_SetColor( data );
|
|
|
|
break;
|
|
|
|
case RC_STRETCH_PIC:
|
|
|
|
data = RB_StretchPic( data );
|
|
|
|
break;
|
2017-12-27 04:13:33 +00:00
|
|
|
case RC_TRIANGLE:
|
|
|
|
data = RB_Triangle( data );
|
|
|
|
break;
|
2016-12-18 04:43:04 +00:00
|
|
|
case RC_DRAW_SURFS:
|
|
|
|
data = RB_DrawSurfs( data );
|
|
|
|
break;
|
2017-03-20 23:58:59 +00:00
|
|
|
case RC_BEGIN_FRAME:
|
|
|
|
data = RB_BeginFrame( data );
|
2016-12-18 04:43:04 +00:00
|
|
|
break;
|
|
|
|
case RC_SWAP_BUFFERS:
|
|
|
|
data = RB_SwapBuffers( data );
|
|
|
|
break;
|
|
|
|
case RC_SCREENSHOT:
|
|
|
|
data = RB_TakeScreenshotCmd( (const screenshotCommand_t*)data );
|
|
|
|
break;
|
|
|
|
case RC_VIDEOFRAME:
|
|
|
|
data = RB_TakeVideoFrameCmd( data );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RC_END_OF_LIST:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-06 23:03:42 +00:00
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
static const shader_t* prevShader = NULL;
|
|
|
|
static const shaderStage_t** prevStages = NULL;
|
|
|
|
static shader_t shader;
|
|
|
|
static shaderStage_t stage;
|
|
|
|
static const shaderStage_t* stagePtr = &stage;
|
2018-01-06 23:03:42 +00:00
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
void RB_PushSingleStageShader( int stateBits, cullType_t cullType )
|
|
|
|
{
|
|
|
|
prevShader = tess.shader;
|
|
|
|
prevStages = tess.xstages;
|
|
|
|
tess.xstages = &stagePtr;
|
|
|
|
tess.shader = &shader;
|
|
|
|
|
|
|
|
memset(&stage, 0, sizeof(stage));
|
|
|
|
stage.active = qtrue;
|
|
|
|
stage.bundle.image[0] = tr.whiteImage;
|
|
|
|
stage.stateBits = stateBits;
|
|
|
|
stage.rgbGen = CGEN_IDENTITY;
|
|
|
|
stage.alphaGen = AGEN_IDENTITY;
|
|
|
|
stage.tcGen = TCGEN_TEXTURE;
|
|
|
|
|
|
|
|
memset(&shader, 0, sizeof(shader));
|
|
|
|
shader.cullType = cullType;
|
|
|
|
shader.numStages = 1;
|
|
|
|
shader.stages[0] = &stage;
|
2018-01-06 23:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-25 03:25:59 +00:00
|
|
|
void RB_PopShader()
|
2018-01-06 23:03:42 +00:00
|
|
|
{
|
2019-09-25 03:25:59 +00:00
|
|
|
tess.shader = prevShader;
|
|
|
|
tess.xstages = prevStages;
|
2019-11-12 03:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// used when a player has predicted a teleport, but hasn't arrived yet
|
|
|
|
float RB_HyperspaceColor()
|
|
|
|
{
|
|
|
|
const float c = 0.25f + 0.5f * sinf(M_PI * (backEnd.refdef.time & 0x01FF) / 0x0200);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|