2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
2012-12-22 15:18:19 +00:00
|
|
|
#include "precompiled.h"
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
#include "tr_local.h"
|
|
|
|
#include "Model_local.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
==========================================================================================
|
|
|
|
|
|
|
|
GUI SURFACES
|
|
|
|
|
|
|
|
==========================================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_SurfaceToTextureAxis
|
|
|
|
|
|
|
|
Calculates two axis for the surface such that a point dotted against
|
|
|
|
the axis will give a 0.0 to 1.0 range in S and T when inside the gui surface
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_SurfaceToTextureAxis( const srfTriangles_t* tri, idVec3& origin, idVec3 axis[3] )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// find the bounds of the texture
|
|
|
|
idVec2 boundsMin( 999999.0f, 999999.0f );
|
|
|
|
idVec2 boundsMax( -999999.0f, -999999.0f );
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < tri->numVerts ; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
const idVec2 uv = tri->verts[i].GetTexCoord();
|
|
|
|
boundsMin.x = Min( uv.x, boundsMin.x );
|
|
|
|
boundsMax.x = Max( uv.x, boundsMax.x );
|
|
|
|
boundsMin.y = Min( uv.y, boundsMin.y );
|
|
|
|
boundsMax.y = Max( uv.y, boundsMax.y );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// use the floor of the midpoint as the origin of the
|
|
|
|
// surface, which will prevent a slight misalignment
|
|
|
|
// from throwing it an entire cycle off
|
|
|
|
const idVec2 boundsOrg( floor( ( boundsMin.x + boundsMax.x ) * 0.5f ), floor( ( boundsMin.y + boundsMax.y ) * 0.5f ) );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// determine the world S and T vectors from the first drawSurf triangle
|
2012-11-28 15:47:07 +00:00
|
|
|
const idJointMat* joints = ( tri->staticModelWithJoints != NULL && r_useGPUSkinning.GetBool() ) ? tri->staticModelWithJoints->jointsInverted : NULL;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const idVec3 aXYZ = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[0] ], joints );
|
|
|
|
const idVec3 bXYZ = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[1] ], joints );
|
|
|
|
const idVec3 cXYZ = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[2] ], joints );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const idVec2 aST = tri->verts[ tri->indexes[0] ].GetTexCoord();
|
|
|
|
const idVec2 bST = tri->verts[ tri->indexes[1] ].GetTexCoord();
|
|
|
|
const idVec2 cST = tri->verts[ tri->indexes[2] ].GetTexCoord();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float d0[5];
|
|
|
|
d0[0] = bXYZ[0] - aXYZ[0];
|
|
|
|
d0[1] = bXYZ[1] - aXYZ[1];
|
|
|
|
d0[2] = bXYZ[2] - aXYZ[2];
|
|
|
|
d0[3] = bST.x - aST.x;
|
|
|
|
d0[4] = bST.y - aST.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float d1[5];
|
|
|
|
d1[0] = cXYZ[0] - aXYZ[0];
|
|
|
|
d1[1] = cXYZ[1] - aXYZ[1];
|
|
|
|
d1[2] = cXYZ[2] - aXYZ[2];
|
|
|
|
d1[3] = cST.x - aST.x;
|
|
|
|
d1[4] = cST.y - aST.y;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
const float area = d0[3] * d1[4] - d0[4] * d1[3];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( area == 0.0f )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
axis[0].Zero();
|
|
|
|
axis[1].Zero();
|
|
|
|
axis[2].Zero();
|
|
|
|
return; // degenerate
|
|
|
|
}
|
|
|
|
const float inva = 1.0f / area;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
axis[0][0] = ( d0[0] * d1[4] - d0[4] * d1[0] ) * inva;
|
|
|
|
axis[0][1] = ( d0[1] * d1[4] - d0[4] * d1[1] ) * inva;
|
|
|
|
axis[0][2] = ( d0[2] * d1[4] - d0[4] * d1[2] ) * inva;
|
|
|
|
|
|
|
|
axis[1][0] = ( d0[3] * d1[0] - d0[0] * d1[3] ) * inva;
|
|
|
|
axis[1][1] = ( d0[3] * d1[1] - d0[1] * d1[3] ) * inva;
|
|
|
|
axis[1][2] = ( d0[3] * d1[2] - d0[2] * d1[3] ) * inva;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idPlane plane;
|
|
|
|
plane.FromPoints( aXYZ, bXYZ, cXYZ );
|
|
|
|
axis[2][0] = plane[0];
|
|
|
|
axis[2][1] = plane[1];
|
|
|
|
axis[2][2] = plane[2];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// take point 0 and project the vectors to the texture origin
|
|
|
|
VectorMA( aXYZ, boundsOrg.x - aST.x, axis[0], origin );
|
|
|
|
VectorMA( origin, boundsOrg.y - aST.y, axis[1], origin );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
R_RenderGuiSurf
|
|
|
|
|
|
|
|
Create a texture space on the given surface and
|
|
|
|
call the GUI generator to create quads for it.
|
|
|
|
=================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
static void R_RenderGuiSurf( idUserInterface* gui, const drawSurf_t* drawSurf )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SCOPED_PROFILE_EVENT( "R_RenderGuiSurf" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// for testing the performance hit
|
2012-11-28 15:47:07 +00:00
|
|
|
if( r_skipGuiShaders.GetInteger() == 1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// don't allow an infinite recursion loop
|
2012-11-28 15:47:07 +00:00
|
|
|
if( tr.guiRecursionLevel == 4 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tr.pc.c_guiSurfs++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// create the new matrix to draw on this surface
|
|
|
|
idVec3 origin, axis[3];
|
|
|
|
R_SurfaceToTextureAxis( drawSurf->frontEndGeo, origin, axis );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float guiModelMatrix[16];
|
|
|
|
float modelMatrix[16];
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
guiModelMatrix[0 * 4 + 0] = axis[0][0] * ( 1.0f / 640.0f );
|
|
|
|
guiModelMatrix[1 * 4 + 0] = axis[1][0] * ( 1.0f / 480.0f );
|
|
|
|
guiModelMatrix[2 * 4 + 0] = axis[2][0];
|
|
|
|
guiModelMatrix[3 * 4 + 0] = origin[0];
|
|
|
|
|
|
|
|
guiModelMatrix[0 * 4 + 1] = axis[0][1] * ( 1.0f / 640.0f );
|
|
|
|
guiModelMatrix[1 * 4 + 1] = axis[1][1] * ( 1.0f / 480.0f );
|
|
|
|
guiModelMatrix[2 * 4 + 1] = axis[2][1];
|
|
|
|
guiModelMatrix[3 * 4 + 1] = origin[1];
|
|
|
|
|
|
|
|
guiModelMatrix[0 * 4 + 2] = axis[0][2] * ( 1.0f / 640.0f );
|
|
|
|
guiModelMatrix[1 * 4 + 2] = axis[1][2] * ( 1.0f / 480.0f );
|
|
|
|
guiModelMatrix[2 * 4 + 2] = axis[2][2];
|
|
|
|
guiModelMatrix[3 * 4 + 2] = origin[2];
|
|
|
|
|
|
|
|
guiModelMatrix[0 * 4 + 3] = 0.0f;
|
|
|
|
guiModelMatrix[1 * 4 + 3] = 0.0f;
|
|
|
|
guiModelMatrix[2 * 4 + 3] = 0.0f;
|
|
|
|
guiModelMatrix[3 * 4 + 3] = 1.0f;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
R_MatrixMultiply( guiModelMatrix, drawSurf->space->modelMatrix, modelMatrix );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tr.guiRecursionLevel++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// call the gui, which will call the 2D drawing functions
|
|
|
|
tr.guiModel->Clear();
|
|
|
|
gui->Redraw( tr.viewDef->renderView.time[0] );
|
|
|
|
tr.guiModel->EmitToCurrentView( modelMatrix, drawSurf->space->weaponDepthHack );
|
|
|
|
tr.guiModel->Clear();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
tr.guiRecursionLevel--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
R_AddInGameGuis
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_AddInGameGuis( const drawSurf_t* const drawSurfs[], const int numDrawSurfs )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SCOPED_PROFILE_EVENT( "R_AddInGameGuis" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// check for gui surfaces
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < numDrawSurfs; i++ )
|
|
|
|
{
|
|
|
|
const drawSurf_t* drawSurf = drawSurfs[i];
|
|
|
|
|
|
|
|
idUserInterface* gui = drawSurf->material->GlobalGui();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int guiNum = drawSurf->material->GetEntityGui() - 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( guiNum >= 0 && guiNum < MAX_RENDERENTITY_GUI )
|
|
|
|
{
|
|
|
|
if( drawSurf->space->entityDef != NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui = drawSurf->space->entityDef->parms.gui[ guiNum ];
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gui == NULL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds ndcBounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !R_PreciseCullSurface( drawSurf, ndcBounds ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
// did we ever use this to forward an entity color to a gui that didn't set color?
|
|
|
|
// memcpy( tr.guiShaderParms, shaderParms, sizeof( tr.guiShaderParms ) );
|
|
|
|
R_RenderGuiSurf( gui, drawSurf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================,
|
|
|
|
R_ReloadGuis_f
|
|
|
|
|
|
|
|
Reloads any guis that have had their file timestamps changed.
|
|
|
|
An optional "all" parameter will cause all models to reload, even
|
|
|
|
if they are not out of date.
|
|
|
|
|
|
|
|
Should we also reload the map models?
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_ReloadGuis_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool all;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !idStr::Icmp( args.Argv( 1 ), "all" ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
all = true;
|
|
|
|
common->Printf( "Reloading all gui files...\n" );
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
all = false;
|
|
|
|
common->Printf( "Checking for changed gui files...\n" );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
uiManager->Reload( all );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================,
|
|
|
|
R_ListGuis_f
|
|
|
|
================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void R_ListGuis_f( const idCmdArgs& args )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
uiManager->ListGuis();
|
|
|
|
}
|