doom3-bfg/neo/renderer/tr_backend_rendertools.cpp

2990 lines
64 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
===========================================================================
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
2012-11-26 18:58:24 +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
#include "../idlib/precompiled.h"
#include "tr_local.h"
#include "simplex.h" // line font definition
idCVar r_showCenterOfProjection( "r_showCenterOfProjection", "0", CVAR_RENDERER | CVAR_BOOL, "Draw a cross to show the center of projection" );
idCVar r_showLines( "r_showLines", "0", CVAR_RENDERER | CVAR_INTEGER, "1 = draw alternate horizontal lines, 2 = draw alternate vertical lines" );
#define MAX_DEBUG_LINES 16384
typedef struct debugLine_s
{
2012-11-26 18:58:24 +00:00
idVec4 rgb;
idVec3 start;
idVec3 end;
bool depthTest;
int lifeTime;
} debugLine_t;
debugLine_t rb_debugLines[ MAX_DEBUG_LINES ];
int rb_numDebugLines = 0;
int rb_debugLineTime = 0;
#define MAX_DEBUG_TEXT 512
typedef struct debugText_s
{
2012-11-26 18:58:24 +00:00
idStr text;
idVec3 origin;
float scale;
idVec4 color;
idMat3 viewAxis;
int align;
int lifeTime;
bool depthTest;
} debugText_t;
debugText_t rb_debugText[ MAX_DEBUG_TEXT ];
int rb_numDebugText = 0;
int rb_debugTextTime = 0;
#define MAX_DEBUG_POLYGONS 8192
typedef struct debugPolygon_s
{
2012-11-26 18:58:24 +00:00
idVec4 rgb;
idWinding winding;
bool depthTest;
int lifeTime;
} debugPolygon_t;
debugPolygon_t rb_debugPolygons[ MAX_DEBUG_POLYGONS ];
int rb_numDebugPolygons = 0;
int rb_debugPolygonTime = 0;
static void RB_DrawText( const char* text, const idVec3& origin, float scale, const idVec4& color, const idMat3& viewAxis, const int align );
2012-11-26 18:58:24 +00:00
void RB_SetMVP( const idRenderMatrix& mvp );
2012-11-26 18:58:24 +00:00
/*
================
RB_DrawBounds
================
*/
void RB_DrawBounds( const idBounds& bounds )
{
if( bounds.IsCleared() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-12-17 16:30:59 +00:00
glBegin( GL_LINE_LOOP );
glVertex3f( bounds[0][0], bounds[0][1], bounds[0][2] );
glVertex3f( bounds[0][0], bounds[1][1], bounds[0][2] );
glVertex3f( bounds[1][0], bounds[1][1], bounds[0][2] );
glVertex3f( bounds[1][0], bounds[0][1], bounds[0][2] );
glEnd();
glBegin( GL_LINE_LOOP );
glVertex3f( bounds[0][0], bounds[0][1], bounds[1][2] );
glVertex3f( bounds[0][0], bounds[1][1], bounds[1][2] );
glVertex3f( bounds[1][0], bounds[1][1], bounds[1][2] );
glVertex3f( bounds[1][0], bounds[0][1], bounds[1][2] );
glEnd();
glBegin( GL_LINES );
glVertex3f( bounds[0][0], bounds[0][1], bounds[0][2] );
glVertex3f( bounds[0][0], bounds[0][1], bounds[1][2] );
glVertex3f( bounds[0][0], bounds[1][1], bounds[0][2] );
glVertex3f( bounds[0][0], bounds[1][1], bounds[1][2] );
glVertex3f( bounds[1][0], bounds[0][1], bounds[0][2] );
glVertex3f( bounds[1][0], bounds[0][1], bounds[1][2] );
glVertex3f( bounds[1][0], bounds[1][1], bounds[0][2] );
glVertex3f( bounds[1][0], bounds[1][1], bounds[1][2] );
glEnd();
2012-11-26 18:58:24 +00:00
}
/*
================
RB_SimpleSurfaceSetup
================
*/
static void RB_SimpleSurfaceSetup( const drawSurf_t* drawSurf )
{
2012-11-26 18:58:24 +00:00
// change the matrix if needed
if( drawSurf->space != backEnd.currentSpace )
{
2012-12-17 16:30:59 +00:00
glLoadMatrixf( drawSurf->space->modelViewMatrix );
2012-11-26 18:58:24 +00:00
backEnd.currentSpace = drawSurf->space;
}
2012-11-26 18:58:24 +00:00
// change the scissor if needed
if( !backEnd.currentScissor.Equals( drawSurf->scissorRect ) && r_useScissor.GetBool() )
{
GL_Scissor( backEnd.viewDef->viewport.x1 + drawSurf->scissorRect.x1,
2012-11-26 18:58:24 +00:00
backEnd.viewDef->viewport.y1 + drawSurf->scissorRect.y1,
drawSurf->scissorRect.x2 + 1 - drawSurf->scissorRect.x1,
drawSurf->scissorRect.y2 + 1 - drawSurf->scissorRect.y1 );
backEnd.currentScissor = drawSurf->scissorRect;
}
}
/*
================
RB_SimpleWorldSetup
================
*/
static void RB_SimpleWorldSetup()
{
2012-11-26 18:58:24 +00:00
backEnd.currentSpace = &backEnd.viewDef->worldSpace;
2012-12-17 16:30:59 +00:00
glLoadMatrixf( backEnd.viewDef->worldSpace.modelViewMatrix );
2012-11-26 18:58:24 +00:00
GL_Scissor( backEnd.viewDef->viewport.x1 + backEnd.viewDef->scissor.x1,
backEnd.viewDef->viewport.y1 + backEnd.viewDef->scissor.y1,
backEnd.viewDef->scissor.x2 + 1 - backEnd.viewDef->scissor.x1,
backEnd.viewDef->scissor.y2 + 1 - backEnd.viewDef->scissor.y1 );
backEnd.currentScissor = backEnd.viewDef->scissor;
}
/*
=================
RB_PolygonClear
This will cover the entire screen with normal rasterization.
Texturing is disabled, but the existing glColor, glDepthMask,
glColorMask, and the enabled state of depth buffering and
stenciling will matter.
=================
*/
void RB_PolygonClear()
{
2012-12-17 16:30:59 +00:00
glPushMatrix();
glPushAttrib( GL_ALL_ATTRIB_BITS );
glLoadIdentity();
glDisable( GL_TEXTURE_2D );
glDisable( GL_DEPTH_TEST );
glDisable( GL_CULL_FACE );
glDisable( GL_SCISSOR_TEST );
glBegin( GL_POLYGON );
glVertex3f( -20, -20, -10 );
glVertex3f( 20, -20, -10 );
glVertex3f( 20, 20, -10 );
glVertex3f( -20, 20, -10 );
glEnd();
glPopAttrib();
glPopMatrix();
2012-11-26 18:58:24 +00:00
}
/*
====================
RB_ShowDestinationAlpha
====================
*/
void RB_ShowDestinationAlpha()
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_SRCBLEND_DST_ALPHA | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS );
GL_Color( 1, 1, 1 );
RB_PolygonClear();
}
/*
===================
RB_ScanStencilBuffer
Debugging tool to see what values are in the stencil buffer
===================
*/
void RB_ScanStencilBuffer()
{
2012-11-26 18:58:24 +00:00
int counts[256];
int i;
byte* stencilReadback;
2012-11-26 18:58:24 +00:00
memset( counts, 0, sizeof( counts ) );
stencilReadback = ( byte* )R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight(), TAG_RENDER_TOOLS );
2012-12-17 16:30:59 +00:00
glReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilReadback );
for( i = 0; i < renderSystem->GetWidth() * renderSystem->GetHeight(); i++ )
{
2012-11-26 18:58:24 +00:00
counts[ stencilReadback[i] ]++;
}
2012-11-26 18:58:24 +00:00
R_StaticFree( stencilReadback );
2012-11-26 18:58:24 +00:00
// print some stats (not supposed to do from back end in SMP...)
common->Printf( "stencil values:\n" );
for( i = 0; i < 255; i++ )
{
if( counts[i] )
{
2012-11-26 18:58:24 +00:00
common->Printf( "%i: %i\n", i, counts[i] );
}
}
}
/*
===================
RB_CountStencilBuffer
Print an overdraw count based on stencil index values
===================
*/
static void RB_CountStencilBuffer()
{
2012-11-26 18:58:24 +00:00
int count;
int i;
byte* stencilReadback;
stencilReadback = ( byte* )R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight(), TAG_RENDER_TOOLS );
2012-12-17 16:30:59 +00:00
glReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilReadback );
2012-11-26 18:58:24 +00:00
count = 0;
for( i = 0; i < renderSystem->GetWidth() * renderSystem->GetHeight(); i++ )
{
2012-11-26 18:58:24 +00:00
count += stencilReadback[i];
}
2012-11-26 18:58:24 +00:00
R_StaticFree( stencilReadback );
2012-11-26 18:58:24 +00:00
// print some stats (not supposed to do from back end in SMP...)
common->Printf( "overdraw: %5.1f\n", ( float )count / ( renderSystem->GetWidth() * renderSystem->GetHeight() ) );
2012-11-26 18:58:24 +00:00
}
/*
===================
R_ColorByStencilBuffer
Sets the screen colors based on the contents of the
stencil buffer. Stencil of 0 = black, 1 = red, 2 = green,
3 = blue, ..., 7+ = white
===================
*/
static void R_ColorByStencilBuffer()
{
2012-11-26 18:58:24 +00:00
int i;
static float colors[8][3] =
{
{0, 0, 0},
{1, 0, 0},
{0, 1, 0},
{0, 0, 1},
{0, 1, 1},
{1, 0, 1},
{1, 1, 0},
{1, 1, 1},
2012-11-26 18:58:24 +00:00
};
2012-11-26 18:58:24 +00:00
// clear color buffer to white (>6 passes)
GL_Clear( true, false, false, 0, 1.0f, 1.0f, 1.0f, 1.0f );
2012-11-26 18:58:24 +00:00
// now draw color for each stencil value
2012-12-17 16:30:59 +00:00
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
for( i = 0; i < 6; i++ )
{
2012-11-26 18:58:24 +00:00
GL_Color( colors[i] );
renderProgManager.BindShader_Color();
2012-12-17 16:30:59 +00:00
glStencilFunc( GL_EQUAL, i, 255 );
2012-11-26 18:58:24 +00:00
RB_PolygonClear();
}
2012-12-17 16:30:59 +00:00
glStencilFunc( GL_ALWAYS, 0, 255 );
2012-11-26 18:58:24 +00:00
}
//======================================================================
/*
==================
RB_ShowOverdraw
==================
*/
void RB_ShowOverdraw()
{
const idMaterial* material;
2012-11-26 18:58:24 +00:00
int i;
drawSurf_t * * drawSurfs;
const drawSurf_t* surf;
2012-11-26 18:58:24 +00:00
int numDrawSurfs;
viewLight_t* vLight;
if( r_showOverDraw.GetInteger() == 0 )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
material = declManager->FindMaterial( "textures/common/overdrawtest", false );
if( material == NULL )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
drawSurfs = backEnd.viewDef->drawSurfs;
numDrawSurfs = backEnd.viewDef->numDrawSurfs;
2012-11-26 18:58:24 +00:00
int interactions = 0;
for( vLight = backEnd.viewDef->viewLights; vLight; vLight = vLight->next )
{
for( surf = vLight->localInteractions; surf; surf = surf->nextOnLight )
{
2012-11-26 18:58:24 +00:00
interactions++;
}
for( surf = vLight->globalInteractions; surf; surf = surf->nextOnLight )
{
2012-11-26 18:58:24 +00:00
interactions++;
}
}
2012-11-26 18:58:24 +00:00
// FIXME: can't frame alloc from the renderer back-end
drawSurf_t** newDrawSurfs = ( drawSurf_t** )R_FrameAlloc( numDrawSurfs + interactions * sizeof( newDrawSurfs[0] ), FRAME_ALLOC_DRAW_SURFACE_POINTER );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
surf = drawSurfs[i];
if( surf->material )
{
const_cast<drawSurf_t*>( surf )->material = material;
2012-11-26 18:58:24 +00:00
}
newDrawSurfs[i] = const_cast<drawSurf_t*>( surf );
2012-11-26 18:58:24 +00:00
}
for( vLight = backEnd.viewDef->viewLights; vLight; vLight = vLight->next )
{
for( surf = vLight->localInteractions; surf; surf = surf->nextOnLight )
{
const_cast<drawSurf_t*>( surf )->material = material;
newDrawSurfs[i++] = const_cast<drawSurf_t*>( surf );
}
for( surf = vLight->globalInteractions; surf; surf = surf->nextOnLight )
{
const_cast<drawSurf_t*>( surf )->material = material;
newDrawSurfs[i++] = const_cast<drawSurf_t*>( surf );
2012-11-26 18:58:24 +00:00
}
vLight->localInteractions = NULL;
vLight->globalInteractions = NULL;
}
switch( r_showOverDraw.GetInteger() )
{
2012-11-26 18:58:24 +00:00
case 1: // geometry overdraw
const_cast<viewDef_t*>( backEnd.viewDef )->drawSurfs = newDrawSurfs;
const_cast<viewDef_t*>( backEnd.viewDef )->numDrawSurfs = numDrawSurfs;
2012-11-26 18:58:24 +00:00
break;
case 2: // light interaction overdraw
const_cast<viewDef_t*>( backEnd.viewDef )->drawSurfs = &newDrawSurfs[numDrawSurfs];
const_cast<viewDef_t*>( backEnd.viewDef )->numDrawSurfs = interactions;
2012-11-26 18:58:24 +00:00
break;
case 3: // geometry + light interaction overdraw
const_cast<viewDef_t*>( backEnd.viewDef )->drawSurfs = newDrawSurfs;
const_cast<viewDef_t*>( backEnd.viewDef )->numDrawSurfs += interactions;
2012-11-26 18:58:24 +00:00
break;
}
}
/*
===================
RB_ShowIntensity
Debugging tool to see how much dynamic range a scene is using.
The greatest of the rgb values at each pixel will be used, with
the resulting color shading from red at 0 to green at 128 to blue at 255
===================
*/
static void RB_ShowIntensity()
{
byte* colorReadback;
2012-11-26 18:58:24 +00:00
int i, j, c;
if( !r_showIntensity.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
colorReadback = ( byte* )R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight() * 4, TAG_RENDER_TOOLS );
2012-12-17 16:30:59 +00:00
glReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, colorReadback );
2012-11-26 18:58:24 +00:00
c = renderSystem->GetWidth() * renderSystem->GetHeight() * 4;
for( i = 0; i < c; i += 4 )
{
2012-11-26 18:58:24 +00:00
j = colorReadback[i];
if( colorReadback[i + 1] > j )
{
j = colorReadback[i + 1];
}
if( colorReadback[i + 2] > j )
{
j = colorReadback[i + 2];
2012-11-26 18:58:24 +00:00
}
if( j < 128 )
{
colorReadback[i + 0] = 2 * ( 128 - j );
colorReadback[i + 1] = 2 * j;
colorReadback[i + 2] = 0;
2012-11-26 18:58:24 +00:00
}
else
{
colorReadback[i + 0] = 0;
colorReadback[i + 1] = 2 * ( 255 - j );
colorReadback[i + 2] = 2 * ( j - 128 );
2012-11-26 18:58:24 +00:00
}
}
2012-11-26 18:58:24 +00:00
// draw it back to the screen
2012-12-17 16:30:59 +00:00
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
2012-12-17 16:30:59 +00:00
glPushMatrix();
glLoadIdentity();
glOrtho( 0, 1, 0, 1, -1, 1 );
glRasterPos2f( 0, 0 );
glPopMatrix();
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1 );
globalImages->BindNull();
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_MODELVIEW );
2012-12-17 16:30:59 +00:00
glDrawPixels( renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA , GL_UNSIGNED_BYTE, colorReadback );
2012-11-26 18:58:24 +00:00
R_StaticFree( colorReadback );
}
/*
===================
RB_ShowDepthBuffer
Draw the depth buffer as colors
===================
*/
static void RB_ShowDepthBuffer()
{
void* depthReadback;
if( !r_showDepth.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-12-17 16:30:59 +00:00
glPushMatrix();
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho( 0, 1, 0, 1, -1, 1 );
glRasterPos2f( 0, 0 );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
GL_Color( 1, 1, 1 );
globalImages->BindNull();
depthReadback = R_StaticAlloc( renderSystem->GetWidth() * renderSystem->GetHeight() * 4, TAG_RENDER_TOOLS );
memset( depthReadback, 0, renderSystem->GetWidth() * renderSystem->GetHeight() * 4 );
2012-12-17 16:30:59 +00:00
glReadPixels( 0, 0, renderSystem->GetWidth(), renderSystem->GetHeight(), GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );
2012-11-26 18:58:24 +00:00
#if 0
for( i = 0; i < renderSystem->GetWidth() * renderSystem->GetHeight(); i++ )
{
( ( byte* )depthReadback )[i * 4] =
( ( byte* )depthReadback )[i * 4 + 1] =
( ( byte* )depthReadback )[i * 4 + 2] = 255 * ( ( float* )depthReadback )[i];
( ( byte* )depthReadback )[i * 4 + 3] = 1;
2012-11-26 18:58:24 +00:00
}
#endif
2012-12-17 16:30:59 +00:00
glDrawPixels( renderSystem->GetWidth(), renderSystem->GetHeight(), GL_RGBA , GL_UNSIGNED_BYTE, depthReadback );
2012-11-26 18:58:24 +00:00
R_StaticFree( depthReadback );
}
/*
=================
RB_ShowLightCount
This is a debugging tool that will draw each surface with a color
based on how many lights are effecting it
=================
*/
static void RB_ShowLightCount()
{
2012-11-26 18:58:24 +00:00
int i;
const drawSurf_t* surf;
const viewLight_t* vLight;
if( !r_showLightCount.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
RB_SimpleWorldSetup();
2012-11-26 18:58:24 +00:00
GL_Clear( false, false, true, 0, 0.0f, 0.0f, 0.0f, 0.0f );
2012-11-26 18:58:24 +00:00
// optionally count everything through walls
if( r_showLightCount.GetInteger() >= 2 )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_EQUAL | GLS_STENCIL_OP_FAIL_KEEP | GLS_STENCIL_OP_ZFAIL_INCR | GLS_STENCIL_OP_PASS_INCR );
}
else
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_EQUAL | GLS_STENCIL_OP_FAIL_KEEP | GLS_STENCIL_OP_ZFAIL_KEEP | GLS_STENCIL_OP_PASS_INCR );
}
2012-11-26 18:58:24 +00:00
globalImages->defaultImage->Bind();
for( vLight = backEnd.viewDef->viewLights; vLight; vLight = vLight->next )
{
for( i = 0; i < 2; i++ )
{
for( surf = i ? vLight->localInteractions : vLight->globalInteractions; surf; surf = ( drawSurf_t* )surf->nextOnLight )
{
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( surf );
RB_DrawElementsWithCounters( surf );
}
}
}
2012-11-26 18:58:24 +00:00
// display the results
R_ColorByStencilBuffer();
if( r_showLightCount.GetInteger() > 2 )
{
2012-11-26 18:58:24 +00:00
RB_CountStencilBuffer();
}
}
/*
===============
RB_SetWeaponDepthHack
===============
*/
static void RB_SetWeaponDepthHack()
{
2012-11-26 18:58:24 +00:00
}
/*
===============
RB_SetModelDepthHack
===============
*/
static void RB_SetModelDepthHack( float depth )
{
2012-11-26 18:58:24 +00:00
}
/*
===============
RB_EnterWeaponDepthHack
===============
*/
static void RB_EnterWeaponDepthHack()
{
2012-11-26 18:58:24 +00:00
float matrix[16];
2012-11-26 18:58:24 +00:00
memcpy( matrix, backEnd.viewDef->projectionMatrix, sizeof( matrix ) );
2012-11-26 18:58:24 +00:00
const float modelDepthHack = 0.25f;
matrix[2] *= modelDepthHack;
matrix[6] *= modelDepthHack;
matrix[10] *= modelDepthHack;
matrix[14] *= modelDepthHack;
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( matrix );
glMatrixMode( GL_MODELVIEW );
2012-11-26 18:58:24 +00:00
}
/*
===============
RB_EnterModelDepthHack
===============
*/
static void RB_EnterModelDepthHack( float depth )
{
2012-11-26 18:58:24 +00:00
float matrix[16];
2012-11-26 18:58:24 +00:00
memcpy( matrix, backEnd.viewDef->projectionMatrix, sizeof( matrix ) );
2012-11-26 18:58:24 +00:00
matrix[14] -= depth;
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( matrix );
glMatrixMode( GL_MODELVIEW );
2012-11-26 18:58:24 +00:00
}
/*
===============
RB_LeaveDepthHack
===============
*/
static void RB_LeaveDepthHack()
{
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( backEnd.viewDef->projectionMatrix );
glMatrixMode( GL_MODELVIEW );
2012-11-26 18:58:24 +00:00
}
/*
=============
RB_LoadMatrixWithBypass
does a glLoadMatrixf after optionally applying the low-latency bypass matrix
=============
*/
static void RB_LoadMatrixWithBypass( const float m[16] )
{
2012-11-26 18:58:24 +00:00
glLoadMatrixf( m );
}
/*
====================
RB_RenderDrawSurfListWithFunction
The triangle functions can check backEnd.currentSpace != surf->space
to see if they need to perform any new matrix setup. The modelview
matrix will already have been loaded, and backEnd.currentSpace will
be updated after the triangle function completes.
====================
*/
static void RB_RenderDrawSurfListWithFunction( drawSurf_t** drawSurfs, int numDrawSurfs, void ( *triFunc_ )( const drawSurf_t* ) )
{
2012-11-26 18:58:24 +00:00
backEnd.currentSpace = NULL;
for( int i = 0 ; i < numDrawSurfs ; i++ )
{
const drawSurf_t* drawSurf = drawSurfs[i];
if( drawSurf == NULL )
{
2012-11-26 18:58:24 +00:00
continue;
}
assert( drawSurf->space != NULL );
if( drawSurf->space != NULL ) // is it ever NULL? Do we need to check?
{
2012-11-26 18:58:24 +00:00
// Set these values ahead of time so we don't have to reconstruct the matrices on the consoles
if( drawSurf->space->weaponDepthHack )
{
2012-11-26 18:58:24 +00:00
RB_SetWeaponDepthHack();
}
if( drawSurf->space->modelDepthHack != 0.0f )
{
2012-11-26 18:58:24 +00:00
RB_SetModelDepthHack( drawSurf->space->modelDepthHack );
}
2012-11-26 18:58:24 +00:00
// change the matrix if needed
if( drawSurf->space != backEnd.currentSpace )
{
2012-11-26 18:58:24 +00:00
RB_LoadMatrixWithBypass( drawSurf->space->modelViewMatrix );
}
if( drawSurf->space->weaponDepthHack )
{
2012-11-26 18:58:24 +00:00
RB_EnterWeaponDepthHack();
}
if( drawSurf->space->modelDepthHack != 0.0f )
{
2012-11-26 18:58:24 +00:00
RB_EnterModelDepthHack( drawSurf->space->modelDepthHack );
}
}
2012-11-26 18:58:24 +00:00
// change the scissor if needed
if( r_useScissor.GetBool() && !backEnd.currentScissor.Equals( drawSurf->scissorRect ) )
{
2012-11-26 18:58:24 +00:00
backEnd.currentScissor = drawSurf->scissorRect;
GL_Scissor( backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1,
backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1,
backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1,
backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1 );
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
// render it
triFunc_( drawSurf );
if( drawSurf->space != NULL && ( drawSurf->space->weaponDepthHack || drawSurf->space->modelDepthHack != 0.0f ) )
{
2012-11-26 18:58:24 +00:00
RB_LeaveDepthHack();
}
2012-11-26 18:58:24 +00:00
backEnd.currentSpace = drawSurf->space;
}
}
/*
=================
RB_ShowSilhouette
Blacks out all edges, then adds color for each edge that a shadow
plane extends from, allowing you to see doubled edges
FIXME: not thread safe!
=================
*/
static void RB_ShowSilhouette()
{
2012-11-26 18:58:24 +00:00
int i;
const drawSurf_t* surf;
const viewLight_t* vLight;
if( !r_showSilhouette.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
//
// clear all triangle edges to black
//
globalImages->BindNull();
2012-12-17 16:30:59 +00:00
glDisable( GL_TEXTURE_2D );
2012-11-26 18:58:24 +00:00
GL_Color( 0, 0, 0 );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_POLYMODE_LINE );
2012-11-26 18:58:24 +00:00
GL_Cull( CT_TWO_SIDED );
RB_RenderDrawSurfListWithFunction( backEnd.viewDef->drawSurfs, backEnd.viewDef->numDrawSurfs,
RB_DrawElementsWithCounters );
2012-11-26 18:58:24 +00:00
//
// now blend in edges that cast silhouettes
//
RB_SimpleWorldSetup();
GL_Color( 0.5, 0, 0 );
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
for( vLight = backEnd.viewDef->viewLights; vLight; vLight = vLight->next )
{
for( i = 0; i < 2; i++ )
{
for( surf = i ? vLight->localShadows : vLight->globalShadows
; surf; surf = ( drawSurf_t* )surf->nextOnLight )
{
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( surf );
const srfTriangles_t* tri = surf->frontEndGeo;
2012-11-26 18:58:24 +00:00
idVertexBuffer vertexBuffer;
if( !vertexCache.GetVertexBuffer( tri->shadowCache, &vertexBuffer ) )
{
2012-11-26 18:58:24 +00:00
continue;
}
// RB: 64 bit fixes, changed GLuint to GLintptrARB
2012-12-17 16:30:59 +00:00
glBindBufferARB( GL_ARRAY_BUFFER_ARB, ( GLintptrARB )vertexBuffer.GetAPIObject() );
GLintptrARB vertOffset = vertexBuffer.GetOffset();
// RB end
2012-12-17 16:30:59 +00:00
glVertexPointer( 3, GL_FLOAT, sizeof( idShadowVert ), ( void* )vertOffset );
glBegin( GL_LINES );
for( int j = 0; j < tri->numIndexes; j += 3 )
{
int i1 = tri->indexes[j + 0];
int i2 = tri->indexes[j + 1];
int i3 = tri->indexes[j + 2];
if( ( i1 & 1 ) + ( i2 & 1 ) + ( i3 & 1 ) == 1 )
{
if( ( i1 & 1 ) + ( i2 & 1 ) == 0 )
{
2012-12-17 16:30:59 +00:00
glArrayElement( i1 );
glArrayElement( i2 );
}
else if( ( i1 & 1 ) + ( i3 & 1 ) == 0 )
{
2012-12-17 16:30:59 +00:00
glArrayElement( i1 );
glArrayElement( i3 );
2012-11-26 18:58:24 +00:00
}
}
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
GL_Color( 1, 1, 1 );
2012-11-26 18:58:24 +00:00
GL_Cull( CT_FRONT_SIDED );
}
/*
=====================
RB_ShowTris
Debugging tool
=====================
*/
static void RB_ShowTris( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
modelTrace_t mt;
idVec3 end;
if( r_showTris.GetInteger() == 0 )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
float color[4] = { 1, 1, 1, 1 };
2012-11-26 18:58:24 +00:00
GL_PolygonOffset( -1.0f, -2.0f );
switch( r_showTris.GetInteger() )
{
2012-11-26 18:58:24 +00:00
case 1: // only draw visible ones
GL_State( GLS_DEPTHMASK | GLS_ALPHAMASK | GLS_POLYMODE_LINE | GLS_POLYGON_OFFSET );
break;
case 2: // draw all front facing
case 3: // draw all
GL_State( GLS_DEPTHMASK | GLS_ALPHAMASK | GLS_POLYMODE_LINE | GLS_POLYGON_OFFSET | GLS_DEPTHFUNC_ALWAYS );
break;
case 4: // only draw visible ones with blended lines
GL_State( GLS_DEPTHMASK | GLS_ALPHAMASK | GLS_POLYMODE_LINE | GLS_POLYGON_OFFSET | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
color[3] = 0.4f;
break;
}
if( r_showTris.GetInteger() == 3 )
{
2012-11-26 18:58:24 +00:00
GL_Cull( CT_TWO_SIDED );
}
2012-11-26 18:58:24 +00:00
GL_Color( color );
renderProgManager.BindShader_Color();
2012-11-26 18:58:24 +00:00
RB_RenderDrawSurfListWithFunction( drawSurfs, numDrawSurfs, RB_DrawElementsWithCounters );
if( r_showTris.GetInteger() == 3 )
{
2012-11-26 18:58:24 +00:00
GL_Cull( CT_FRONT_SIDED );
}
}
/*
=====================
RB_ShowSurfaceInfo
Debugging tool
=====================
*/
static void RB_ShowSurfaceInfo( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
modelTrace_t mt;
idVec3 start, end;
if( !r_showSurfaceInfo.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// start far enough away that we don't hit the player model
start = tr.primaryView->renderView.vieworg + tr.primaryView->renderView.viewaxis[0] * 16;
end = start + tr.primaryView->renderView.viewaxis[0] * 1000.0f;
if( !tr.primaryWorld->Trace( mt, start, end, 0.0f, false ) )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-12-17 16:30:59 +00:00
glDisable( GL_TEXTURE_2D );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1 );
2012-11-26 18:58:24 +00:00
static float scale = -1;
static float bias = -2;
2012-11-26 18:58:24 +00:00
GL_PolygonOffset( scale, bias );
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_POLYMODE_LINE | GLS_POLYGON_OFFSET );
2012-11-26 18:58:24 +00:00
idVec3 trans[3];
float matrix[16];
2012-11-26 18:58:24 +00:00
// transform the object verts into global space
R_AxisToModelMatrix( mt.entity->axis, mt.entity->origin, matrix );
2012-11-26 18:58:24 +00:00
tr.primaryWorld->DrawText( mt.entity->hModel->Name(), mt.point + tr.primaryView->renderView.viewaxis[2] * 12,
0.35f, colorRed, tr.primaryView->renderView.viewaxis );
tr.primaryWorld->DrawText( mt.material->GetName(), mt.point,
0.35f, colorBlue, tr.primaryView->renderView.viewaxis );
2012-11-26 18:58:24 +00:00
}
/*
=====================
RB_ShowViewEntitys
Debugging tool
=====================
*/
static void RB_ShowViewEntitys( viewEntity_t* vModels )
{
if( !r_showViewEntitys.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
if( r_showViewEntitys.GetInteger() >= 2 )
{
2012-11-26 18:58:24 +00:00
common->Printf( "view entities: " );
for( const viewEntity_t* vModel = vModels; vModel; vModel = vModel->next )
{
if( vModel->entityDef->IsDirectlyVisible() )
{
2012-11-26 18:58:24 +00:00
common->Printf( "<%i> ", vModel->entityDef->index );
}
else
{
2012-11-26 18:58:24 +00:00
common->Printf( "%i ", vModel->entityDef->index );
}
}
common->Printf( "\n" );
}
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
renderProgManager.BindShader_Color();
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1 );
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_POLYMODE_LINE );
GL_Cull( CT_TWO_SIDED );
for( const viewEntity_t* vModel = vModels; vModel; vModel = vModel->next )
{
2012-11-26 18:58:24 +00:00
idBounds b;
2012-12-17 16:30:59 +00:00
glLoadMatrixf( vModel->modelViewMatrix );
const idRenderEntityLocal* edef = vModel->entityDef;
if( !edef )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
// draw the model bounds in white if directly visible,
// or, blue if it is only-for-sahdow
idVec4 color;
if( edef->IsDirectlyVisible() )
{
2012-11-26 18:58:24 +00:00
color.Set( 1, 1, 1, 1 );
}
else
{
2012-11-26 18:58:24 +00:00
color.Set( 0, 0, 1, 1 );
}
GL_Color( color[0], color[1], color[2] );
RB_DrawBounds( edef->localReferenceBounds );
2012-11-26 18:58:24 +00:00
// transform the upper bounds corner into global space
if( r_showViewEntitys.GetInteger() >= 2 )
{
2012-11-26 18:58:24 +00:00
idVec3 corner;
R_LocalPointToGlobal( vModel->modelMatrix, edef->localReferenceBounds[1], corner );
tr.primaryWorld->DrawText(
va( "%i:%s", edef->index, edef->parms.hModel->Name() ),
2012-11-26 18:58:24 +00:00
corner,
0.25f, color,
2012-11-26 18:58:24 +00:00
tr.primaryView->renderView.viewaxis );
}
2012-11-26 18:58:24 +00:00
// draw the actual bounds in yellow if different
if( r_showViewEntitys.GetInteger() >= 3 )
{
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 0 );
// FIXME: cannot instantiate a dynamic model from the renderer back-end
idRenderModel* model = R_EntityDefDynamicModel( vModel->entityDef );
if( !model )
{
2012-11-26 18:58:24 +00:00
continue; // particles won't instantiate without a current view
}
b = model->Bounds( &vModel->entityDef->parms );
if( b != vModel->entityDef->localReferenceBounds )
{
2012-11-26 18:58:24 +00:00
RB_DrawBounds( b );
}
}
}
}
/*
=====================
RB_ShowTexturePolarity
Shade triangle red if they have a positive texture area
green if they have a negative texture area, or blue if degenerate area
=====================
*/
static void RB_ShowTexturePolarity( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
if( !r_showTexturePolarity.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1 );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-12-17 16:30:59 +00:00
glBegin( GL_TRIANGLES );
for( j = 0; j < tri->numIndexes; j += 3 )
{
idDrawVert* a, *b, *c;
2012-11-26 18:58:24 +00:00
float d0[5], d1[5];
float area;
2012-11-26 18:58:24 +00:00
a = tri->verts + tri->indexes[j];
b = tri->verts + tri->indexes[j + 1];
c = tri->verts + tri->indexes[j + 2];
2012-11-26 18:58:24 +00:00
const idVec2 aST = a->GetTexCoord();
const idVec2 bST = b->GetTexCoord();
const idVec2 cST = c->GetTexCoord();
2012-11-26 18:58:24 +00:00
d0[3] = bST[0] - aST[0];
d0[4] = bST[1] - aST[1];
2012-11-26 18:58:24 +00:00
d1[3] = cST[0] - aST[0];
d1[4] = cST[1] - aST[1];
2012-11-26 18:58:24 +00:00
area = d0[3] * d1[4] - d0[4] * d1[3];
if( idMath::Fabs( area ) < 0.0001 )
{
2012-11-26 18:58:24 +00:00
GL_Color( 0, 0, 1, 0.5 );
}
else if( area < 0 )
{
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0, 0.5 );
}
else
{
2012-11-26 18:58:24 +00:00
GL_Color( 0, 1, 0, 0.5 );
}
2012-12-17 16:30:59 +00:00
glVertex3fv( a->xyz.ToFloatPtr() );
glVertex3fv( b->xyz.ToFloatPtr() );
glVertex3fv( c->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
=====================
RB_ShowUnsmoothedTangents
Shade materials that are using unsmoothed tangents
=====================
*/
static void RB_ShowUnsmoothedTangents( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
if( !r_showUnsmoothedTangents.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
2012-11-26 18:58:24 +00:00
GL_Color( 0, 1, 0, 0.5 );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
if( !drawSurf->material->UseUnsmoothedTangents() )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
2012-12-17 16:30:59 +00:00
glBegin( GL_TRIANGLES );
for( j = 0; j < tri->numIndexes; j += 3 )
{
idDrawVert* a, *b, *c;
2012-11-26 18:58:24 +00:00
a = tri->verts + tri->indexes[j];
b = tri->verts + tri->indexes[j + 1];
c = tri->verts + tri->indexes[j + 2];
2012-12-17 16:30:59 +00:00
glVertex3fv( a->xyz.ToFloatPtr() );
glVertex3fv( b->xyz.ToFloatPtr() );
glVertex3fv( c->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
=====================
RB_ShowTangentSpace
Shade a triangle by the RGB colors of its tangent space
1 = tangents[0]
2 = tangents[1]
3 = normal
=====================
*/
static void RB_ShowTangentSpace( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
if( !r_showTangentSpace.GetInteger() )
{
2012-11-26 18:58:24 +00:00
return;
}
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-12-17 16:30:59 +00:00
glBegin( GL_TRIANGLES );
for( j = 0; j < tri->numIndexes; j++ )
{
const idDrawVert* v;
2012-11-26 18:58:24 +00:00
v = &tri->verts[tri->indexes[j]];
if( r_showTangentSpace.GetInteger() == 1 )
{
2012-11-26 18:58:24 +00:00
const idVec3 vertexTangent = v->GetTangent();
GL_Color( 0.5 + 0.5 * vertexTangent[0], 0.5 + 0.5 * vertexTangent[1],
0.5 + 0.5 * vertexTangent[2], 0.5 );
}
else if( r_showTangentSpace.GetInteger() == 2 )
{
2012-11-26 18:58:24 +00:00
const idVec3 vertexBiTangent = v->GetBiTangent();
GL_Color( 0.5 + 0.5 * vertexBiTangent[0], 0.5 + 0.5 * vertexBiTangent[1],
0.5 + 0.5 * vertexBiTangent[2], 0.5 );
}
else
{
2012-11-26 18:58:24 +00:00
const idVec3 vertexNormal = v->GetNormal();
GL_Color( 0.5 + 0.5 * vertexNormal[0], 0.5 + 0.5 * vertexNormal[1],
0.5 + 0.5 * vertexNormal[2], 0.5 );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glVertex3fv( v->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
=====================
RB_ShowVertexColor
Draw each triangle with the solid vertex colors
=====================
*/
static void RB_ShowVertexColor( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
if( !r_showVertexColor.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_LESS );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-12-17 16:30:59 +00:00
glBegin( GL_TRIANGLES );
for( j = 0; j < tri->numIndexes; j++ )
{
const idDrawVert* v;
2012-11-26 18:58:24 +00:00
v = &tri->verts[tri->indexes[j]];
2012-12-17 16:30:59 +00:00
glColor4ubv( v->color );
glVertex3fv( v->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
=====================
RB_ShowNormals
Debugging tool
=====================
*/
static void RB_ShowNormals( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
2012-11-26 18:58:24 +00:00
idVec3 end;
const srfTriangles_t* tri;
2012-11-26 18:58:24 +00:00
float size;
bool showNumbers;
idVec3 pos;
if( r_showNormals.GetFloat() == 0.0f )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
if( !r_debugLineDepthTest.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE | GLS_DEPTHFUNC_ALWAYS );
}
else
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE );
}
2012-11-26 18:58:24 +00:00
size = r_showNormals.GetFloat();
if( size < 0.0f )
{
2012-11-26 18:58:24 +00:00
size = -size;
showNumbers = true;
}
else
{
2012-11-26 18:58:24 +00:00
showNumbers = false;
}
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( j = 0; j < tri->numVerts; j++ )
{
2012-11-26 18:58:24 +00:00
const idVec3 normal = tri->verts[j].GetNormal();
const idVec3 tangent = tri->verts[j].GetTangent();
const idVec3 bitangent = tri->verts[j].GetBiTangent();
GL_Color( 0, 0, 1 );
2012-12-17 16:30:59 +00:00
glVertex3fv( tri->verts[j].xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( tri->verts[j].xyz, size, normal, end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( tri->verts[j].xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( tri->verts[j].xyz, size, tangent, end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 0, 1, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( tri->verts[j].xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( tri->verts[j].xyz, size, bitangent, end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
if( showNumbers )
{
2012-11-26 18:58:24 +00:00
RB_SimpleWorldSetup();
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
for( j = 0; j < tri->numVerts; j++ )
{
2012-11-26 18:58:24 +00:00
const idVec3 normal = tri->verts[j].GetNormal();
const idVec3 tangent = tri->verts[j].GetTangent();
R_LocalPointToGlobal( drawSurf->space->modelMatrix, tri->verts[j].xyz + tangent + normal * 0.2f, pos );
RB_DrawText( va( "%d", j ), pos, 0.01f, colorWhite, backEnd.viewDef->renderView.viewaxis, 1 );
}
for( j = 0; j < tri->numIndexes; j += 3 )
{
2012-11-26 18:58:24 +00:00
const idVec3 normal = tri->verts[ tri->indexes[ j + 0 ] ].GetNormal();
R_LocalPointToGlobal( drawSurf->space->modelMatrix, ( tri->verts[ tri->indexes[ j + 0 ] ].xyz + tri->verts[ tri->indexes[ j + 1 ] ].xyz + tri->verts[ tri->indexes[ j + 2 ] ].xyz ) * ( 1.0f / 3.0f ) + normal * 0.2f, pos );
RB_DrawText( va( "%d", j / 3 ), pos, 0.01f, colorCyan, backEnd.viewDef->renderView.viewaxis, 1 );
}
}
}
}
#if 0 // compiler warning
/*
=====================
RB_ShowNormals
Debugging tool
=====================
*/
static void RB_AltShowNormals( drawSurf_t** drawSurfs, int numDrawSurfs )
{
if( r_showNormals.GetFloat() == 0.0f )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
for( int i = 0; i < numDrawSurfs; i++ )
{
drawSurf_t* drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
const srfTriangles_t* tri = drawSurf->geo;
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( int j = 0; j < tri->numIndexes; j += 3 )
{
const idDrawVert* v[3] =
{
&tri->verts[tri->indexes[j + 0]],
&tri->verts[tri->indexes[j + 1]],
&tri->verts[tri->indexes[j + 2]]
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
const idPlane plane( v[0]->xyz, v[1]->xyz, v[2]->xyz );
2012-11-26 18:58:24 +00:00
// make the midpoint slightly above the triangle
const idVec3 mid = ( v[0]->xyz + v[1]->xyz + v[2]->xyz ) * ( 1.0f / 3.0f ) + 0.1f * plane.Normal();
for( int k = 0; k < 3; k++ )
{
2012-11-26 18:58:24 +00:00
const idVec3 pos = ( mid + v[k]->xyz * 3.0f ) * 0.25f;
idVec3 end;
2012-11-26 18:58:24 +00:00
GL_Color( 0, 0, 1 );
2012-12-17 16:30:59 +00:00
glVertex3fv( pos.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( pos, r_showNormals.GetFloat(), v[k]->normal, end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( pos.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( pos, r_showNormals.GetFloat(), v[k]->tangents[0], end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 0, 1, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( pos.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
VectorMA( pos, r_showNormals.GetFloat(), v[k]->tangents[1], end );
2012-12-17 16:30:59 +00:00
glVertex3fv( end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1 );
2012-12-17 16:30:59 +00:00
glVertex3fv( pos.ToFloatPtr() );
glVertex3fv( v[k]->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
#endif
/*
=====================
RB_ShowTextureVectors
Draw texture vectors in the center of each triangle
=====================
*/
static void RB_ShowTextureVectors( drawSurf_t** drawSurfs, int numDrawSurfs )
{
if( r_showTextureVectors.GetFloat() == 0.0f )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_LESS );
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
for( int i = 0; i < numDrawSurfs; i++ )
{
drawSurf_t* drawSurf = drawSurfs[i];
const srfTriangles_t* tri = drawSurf->frontEndGeo;
if( tri->verts == NULL )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
// draw non-shared edges in yellow
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( int j = 0; j < tri->numIndexes; j += 3 )
{
2012-11-26 18:58:24 +00:00
float d0[5], d1[5];
idVec3 temp;
idVec3 tangents[2];
const idDrawVert* a = &tri->verts[tri->indexes[j + 0]];
const idDrawVert* b = &tri->verts[tri->indexes[j + 1]];
const idDrawVert* c = &tri->verts[tri->indexes[j + 2]];
2012-11-26 18:58:24 +00:00
const idPlane plane( a->xyz, b->xyz, c->xyz );
2012-11-26 18:58:24 +00:00
// make the midpoint slightly above the triangle
const idVec3 mid = ( a->xyz + b->xyz + c->xyz ) * ( 1.0f / 3.0f ) + 0.1f * plane.Normal();
2012-11-26 18:58:24 +00:00
// calculate the texture vectors
const idVec2 aST = a->GetTexCoord();
const idVec2 bST = b->GetTexCoord();
const idVec2 cST = c->GetTexCoord();
2012-11-26 18:58:24 +00:00
d0[0] = b->xyz[0] - a->xyz[0];
d0[1] = b->xyz[1] - a->xyz[1];
d0[2] = b->xyz[2] - a->xyz[2];
d0[3] = bST[0] - aST[0];
d0[4] = bST[1] - aST[1];
2012-11-26 18:58:24 +00:00
d1[0] = c->xyz[0] - a->xyz[0];
d1[1] = c->xyz[1] - a->xyz[1];
d1[2] = c->xyz[2] - a->xyz[2];
d1[3] = cST[0] - aST[0];
d1[4] = cST[1] - aST[1];
2012-11-26 18:58:24 +00:00
const float area = d0[3] * d1[4] - d0[4] * d1[3];
if( area == 0 )
{
2012-11-26 18:58:24 +00:00
continue;
}
const float inva = 1.0f / area;
temp[0] = ( d0[0] * d1[4] - d0[4] * d1[0] ) * inva;
temp[1] = ( d0[1] * d1[4] - d0[4] * d1[1] ) * inva;
temp[2] = ( d0[2] * d1[4] - d0[4] * d1[2] ) * inva;
2012-11-26 18:58:24 +00:00
temp.Normalize();
tangents[0] = temp;
temp[0] = ( d0[3] * d1[0] - d0[0] * d1[3] ) * inva;
temp[1] = ( d0[3] * d1[1] - d0[1] * d1[3] ) * inva;
temp[2] = ( d0[3] * d1[2] - d0[2] * d1[3] ) * inva;
2012-11-26 18:58:24 +00:00
temp.Normalize();
tangents[1] = temp;
2012-11-26 18:58:24 +00:00
// draw the tangents
tangents[0] = mid + tangents[0] * r_showTextureVectors.GetFloat();
tangents[1] = mid + tangents[1] * r_showTextureVectors.GetFloat();
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( mid.ToFloatPtr() );
glVertex3fv( tangents[0].ToFloatPtr() );
2012-11-26 18:58:24 +00:00
GL_Color( 0, 1, 0 );
2012-12-17 16:30:59 +00:00
glVertex3fv( mid.ToFloatPtr() );
glVertex3fv( tangents[1].ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
/*
=====================
RB_ShowDominantTris
Draw lines from each vertex to the dominant triangle center
=====================
*/
static void RB_ShowDominantTris( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
if( !r_showDominantTri.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_LESS );
2012-11-26 18:58:24 +00:00
GL_PolygonOffset( -1, -2 );
2012-12-17 16:30:59 +00:00
glEnable( GL_POLYGON_OFFSET_LINE );
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
if( !tri->verts )
{
2012-11-26 18:58:24 +00:00
continue;
}
if( !tri->dominantTris )
{
2012-11-26 18:58:24 +00:00
continue;
}
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 0 );
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( j = 0; j < tri->numVerts; j++ )
{
const idDrawVert* a, *b, *c;
2012-11-26 18:58:24 +00:00
idVec3 mid;
2012-11-26 18:58:24 +00:00
// find the midpoint of the dominant tri
2012-11-26 18:58:24 +00:00
a = &tri->verts[j];
b = &tri->verts[tri->dominantTris[j].v2];
c = &tri->verts[tri->dominantTris[j].v3];
2012-11-26 18:58:24 +00:00
mid = ( a->xyz + b->xyz + c->xyz ) * ( 1.0f / 3.0f );
2012-12-17 16:30:59 +00:00
glVertex3fv( mid.ToFloatPtr() );
glVertex3fv( a->xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glDisable( GL_POLYGON_OFFSET_LINE );
2012-11-26 18:58:24 +00:00
}
/*
=====================
RB_ShowEdges
Debugging tool
=====================
*/
static void RB_ShowEdges( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i, j, k, m, n, o;
drawSurf_t* drawSurf;
const srfTriangles_t* tri;
const silEdge_t* edge;
2012-11-26 18:58:24 +00:00
int danglePlane;
if( !r_showEdges.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
drawSurf = drawSurfs[i];
2012-11-26 18:58:24 +00:00
tri = drawSurf->frontEndGeo;
idDrawVert* ac = ( idDrawVert* )tri->verts;
if( !ac )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
RB_SimpleSurfaceSetup( drawSurf );
2012-11-26 18:58:24 +00:00
// draw non-shared edges in yellow
GL_Color( 1, 1, 0 );
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( j = 0; j < tri->numIndexes; j += 3 )
{
for( k = 0; k < 3; k++ )
{
2012-11-26 18:58:24 +00:00
int l, i1, i2;
l = ( k == 2 ) ? 0 : k + 1;
i1 = tri->indexes[j + k];
i2 = tri->indexes[j + l];
2012-11-26 18:58:24 +00:00
// if these are used backwards, the edge is shared
for( m = 0; m < tri->numIndexes; m += 3 )
{
for( n = 0; n < 3; n++ )
{
2012-11-26 18:58:24 +00:00
o = ( n == 2 ) ? 0 : n + 1;
if( tri->indexes[m + n] == i2 && tri->indexes[m + o] == i1 )
{
2012-11-26 18:58:24 +00:00
break;
}
}
if( n != 3 )
{
2012-11-26 18:58:24 +00:00
break;
}
}
2012-11-26 18:58:24 +00:00
// if we didn't find a backwards listing, draw it in yellow
if( m == tri->numIndexes )
{
2012-12-17 16:30:59 +00:00
glVertex3fv( ac[ i1 ].xyz.ToFloatPtr() );
glVertex3fv( ac[ i2 ].xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
}
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
// draw dangling sil edges in red
if( !tri->silEdges )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
// the plane number after all real planes
// is the dangling edge
danglePlane = tri->numIndexes / 3;
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0 );
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
for( j = 0; j < tri->numSilEdges; j++ )
{
2012-11-26 18:58:24 +00:00
edge = tri->silEdges + j;
if( edge->p1 != danglePlane && edge->p2 != danglePlane )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-12-17 16:30:59 +00:00
glVertex3fv( ac[ edge->v1 ].xyz.ToFloatPtr() );
glVertex3fv( ac[ edge->v2 ].xyz.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
/*
==============
RB_ShowLights
Visualize all light volumes used in the current scene
r_showLights 1 : just print volumes numbers, highlighting ones covering the view
r_showLights 2 : also draw planes of each volume
r_showLights 3 : also draw edges of each volume
==============
*/
static void RB_ShowLights()
{
if( !r_showLights.GetInteger() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
2012-11-26 18:58:24 +00:00
// we use the 'vLight->invProjectMVPMatrix'
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
renderProgManager.BindShader_Color();
2012-11-26 18:58:24 +00:00
GL_Cull( CT_TWO_SIDED );
2012-11-26 18:58:24 +00:00
common->Printf( "volumes: " ); // FIXME: not in back end!
2012-11-26 18:58:24 +00:00
int count = 0;
for( viewLight_t* vLight = backEnd.viewDef->viewLights; vLight != NULL; vLight = vLight->next )
{
2012-11-26 18:58:24 +00:00
count++;
2012-11-26 18:58:24 +00:00
// depth buffered planes
if( r_showLights.GetInteger() >= 2 )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHMASK );
GL_Color( 0.0f, 0.0f, 1.0f, 0.25f );
idRenderMatrix invProjectMVPMatrix;
idRenderMatrix::Multiply( backEnd.viewDef->worldSpace.mvp, vLight->inverseBaseLightProject, invProjectMVPMatrix );
RB_SetMVP( invProjectMVPMatrix );
RB_DrawElementsWithCounters( &backEnd.zeroOneCubeSurface );
}
2012-11-26 18:58:24 +00:00
// non-hidden lines
if( r_showLights.GetInteger() >= 3 )
{
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_POLYMODE_LINE | GLS_DEPTHMASK );
2012-11-26 18:58:24 +00:00
GL_Color( 1.0f, 1.0f, 1.0f );
idRenderMatrix invProjectMVPMatrix;
idRenderMatrix::Multiply( backEnd.viewDef->worldSpace.mvp, vLight->inverseBaseLightProject, invProjectMVPMatrix );
RB_SetMVP( invProjectMVPMatrix );
RB_DrawElementsWithCounters( &backEnd.zeroOneCubeSurface );
}
2012-11-26 18:58:24 +00:00
common->Printf( "%i ", vLight->lightDef->index );
}
2012-11-26 18:58:24 +00:00
common->Printf( " = %i total\n", count );
2012-11-26 18:58:24 +00:00
// set back the default projection matrix
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( backEnd.viewDef->projectionMatrix );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
2012-11-26 18:58:24 +00:00
}
/*
=====================
RB_ShowPortals
Debugging tool, won't work correctly with SMP or when mirrors are present
=====================
*/
static void RB_ShowPortals()
{
if( !r_showPortals.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// all portals are expressed in world coordinates
RB_SimpleWorldSetup();
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
renderProgManager.BindShader_Color();
GL_State( GLS_DEPTHFUNC_ALWAYS );
( ( idRenderWorldLocal* )backEnd.viewDef->renderWorld )->ShowPortals();
2012-11-26 18:58:24 +00:00
}
/*
================
RB_ClearDebugText
================
*/
void RB_ClearDebugText( int time )
{
2012-11-26 18:58:24 +00:00
int i;
int num;
debugText_t* text;
2012-11-26 18:58:24 +00:00
rb_debugTextTime = time;
if( !time )
{
2012-11-26 18:58:24 +00:00
// free up our strings
text = rb_debugText;
for( i = 0; i < MAX_DEBUG_TEXT; i++, text++ )
{
2012-11-26 18:58:24 +00:00
text->text.Clear();
}
rb_numDebugText = 0;
return;
}
2012-11-26 18:58:24 +00:00
// copy any text that still needs to be drawn
num = 0;
text = rb_debugText;
for( i = 0; i < rb_numDebugText; i++, text++ )
{
if( text->lifeTime > time )
{
if( num != i )
{
2012-11-26 18:58:24 +00:00
rb_debugText[ num ] = *text;
}
num++;
}
}
rb_numDebugText = num;
}
/*
================
RB_AddDebugText
================
*/
void RB_AddDebugText( const char* text, const idVec3& origin, float scale, const idVec4& color, const idMat3& viewAxis, const int align, const int lifetime, const bool depthTest )
{
debugText_t* debugText;
if( rb_numDebugText < MAX_DEBUG_TEXT )
{
2012-11-26 18:58:24 +00:00
debugText = &rb_debugText[ rb_numDebugText++ ];
debugText->text = text;
debugText->origin = origin;
debugText->scale = scale;
debugText->color = color;
debugText->viewAxis = viewAxis;
debugText->align = align;
debugText->lifeTime = rb_debugTextTime + lifetime;
debugText->depthTest = depthTest;
}
}
/*
================
RB_DrawTextLength
returns the length of the given text
================
*/
float RB_DrawTextLength( const char* text, float scale, int len )
{
2012-11-26 18:58:24 +00:00
int i, num, index, charIndex;
float spacing, textLen = 0.0f;
if( text && *text )
{
if( !len )
{
len = strlen( text );
}
for( i = 0; i < len; i++ )
{
2012-11-26 18:58:24 +00:00
charIndex = text[i] - 32;
if( charIndex < 0 || charIndex > NUM_SIMPLEX_CHARS )
{
2012-11-26 18:58:24 +00:00
continue;
}
num = simplex[charIndex][0] * 2;
spacing = simplex[charIndex][1];
index = 2;
while( index - 2 < num )
{
if( simplex[charIndex][index] < 0 )
{
2012-11-26 18:58:24 +00:00
index++;
continue;
}
2012-11-26 18:58:24 +00:00
index += 2;
if( simplex[charIndex][index] < 0 )
{
2012-11-26 18:58:24 +00:00
index++;
continue;
}
}
textLen += spacing * scale;
2012-11-26 18:58:24 +00:00
}
}
return textLen;
}
/*
================
RB_DrawText
oriented on the viewaxis
align can be 0-left, 1-center (default), 2-right
================
*/
static void RB_DrawText( const char* text, const idVec3& origin, float scale, const idVec4& color, const idMat3& viewAxis, const int align )
{
2012-11-26 18:58:24 +00:00
renderProgManager.BindShader_Color();
2012-11-26 18:58:24 +00:00
int i, j, len, num, index, charIndex, line;
float textLen = 1.0f, spacing = 1.0f;
idVec3 org, p1, p2;
if( text && *text )
{
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
glColor3fv( color.ToFloatPtr() );
if( text[0] == '\n' )
{
2012-11-26 18:58:24 +00:00
line = 1;
}
else
{
2012-11-26 18:58:24 +00:00
line = 0;
}
2012-11-26 18:58:24 +00:00
len = strlen( text );
for( i = 0; i < len; i++ )
{
if( i == 0 || text[i] == '\n' )
{
2012-11-26 18:58:24 +00:00
org = origin - viewAxis[2] * ( line * 36.0f * scale );
if( align != 0 )
{
for( j = 1; i + j <= len; j++ )
{
if( i + j == len || text[i + j] == '\n' )
{
textLen = RB_DrawTextLength( text + i, scale, j );
2012-11-26 18:58:24 +00:00
break;
}
}
if( align == 2 )
{
2012-11-26 18:58:24 +00:00
// right
org += viewAxis[1] * textLen;
}
else
{
2012-11-26 18:58:24 +00:00
// center
org += viewAxis[1] * ( textLen * 0.5f );
}
}
line++;
}
2012-11-26 18:58:24 +00:00
charIndex = text[i] - 32;
if( charIndex < 0 || charIndex > NUM_SIMPLEX_CHARS )
{
2012-11-26 18:58:24 +00:00
continue;
}
num = simplex[charIndex][0] * 2;
spacing = simplex[charIndex][1];
index = 2;
while( index - 2 < num )
{
if( simplex[charIndex][index] < 0 )
{
2012-11-26 18:58:24 +00:00
index++;
continue;
2012-11-26 18:58:24 +00:00
}
p1 = org + scale * simplex[charIndex][index] * -viewAxis[1] + scale * simplex[charIndex][index + 1] * viewAxis[2];
2012-11-26 18:58:24 +00:00
index += 2;
if( simplex[charIndex][index] < 0 )
{
2012-11-26 18:58:24 +00:00
index++;
continue;
}
p2 = org + scale * simplex[charIndex][index] * -viewAxis[1] + scale * simplex[charIndex][index + 1] * viewAxis[2];
2012-12-17 16:30:59 +00:00
glVertex3fv( p1.ToFloatPtr() );
glVertex3fv( p2.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
org -= viewAxis[1] * ( spacing * scale );
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
/*
================
RB_ShowDebugText
================
*/
void RB_ShowDebugText()
{
2012-11-26 18:58:24 +00:00
int i;
int width;
debugText_t* text;
if( !rb_numDebugText )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// all lines are expressed in world coordinates
RB_SimpleWorldSetup();
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
width = r_debugLineWidth.GetInteger();
if( width < 1 )
{
2012-11-26 18:58:24 +00:00
width = 1;
}
else if( width > 10 )
{
2012-11-26 18:58:24 +00:00
width = 10;
}
2012-11-26 18:58:24 +00:00
// draw lines
2012-12-17 16:30:59 +00:00
glLineWidth( width );
if( !r_debugLineDepthTest.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE | GLS_DEPTHFUNC_ALWAYS );
}
else
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE );
}
2012-11-26 18:58:24 +00:00
text = rb_debugText;
for( i = 0; i < rb_numDebugText; i++, text++ )
{
if( !text->depthTest )
{
2012-11-26 18:58:24 +00:00
RB_DrawText( text->text, text->origin, text->scale, text->color, text->viewAxis, text->align );
}
}
if( !r_debugLineDepthTest.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE );
}
2012-11-26 18:58:24 +00:00
text = rb_debugText;
for( i = 0; i < rb_numDebugText; i++, text++ )
{
if( text->depthTest )
{
2012-11-26 18:58:24 +00:00
RB_DrawText( text->text, text->origin, text->scale, text->color, text->viewAxis, text->align );
}
}
2012-12-17 16:30:59 +00:00
glLineWidth( 1 );
2012-11-26 18:58:24 +00:00
}
/*
================
RB_ClearDebugLines
================
*/
void RB_ClearDebugLines( int time )
{
2012-11-26 18:58:24 +00:00
int i;
int num;
debugLine_t* line;
2012-11-26 18:58:24 +00:00
rb_debugLineTime = time;
if( !time )
{
2012-11-26 18:58:24 +00:00
rb_numDebugLines = 0;
return;
}
2012-11-26 18:58:24 +00:00
// copy any lines that still need to be drawn
num = 0;
line = rb_debugLines;
for( i = 0; i < rb_numDebugLines; i++, line++ )
{
if( line->lifeTime > time )
{
if( num != i )
{
2012-11-26 18:58:24 +00:00
rb_debugLines[ num ] = *line;
}
num++;
}
}
rb_numDebugLines = num;
}
/*
================
RB_AddDebugLine
================
*/
void RB_AddDebugLine( const idVec4& color, const idVec3& start, const idVec3& end, const int lifeTime, const bool depthTest )
{
debugLine_t* line;
if( rb_numDebugLines < MAX_DEBUG_LINES )
{
2012-11-26 18:58:24 +00:00
line = &rb_debugLines[ rb_numDebugLines++ ];
line->rgb = color;
line->start = start;
line->end = end;
line->depthTest = depthTest;
line->lifeTime = rb_debugLineTime + lifeTime;
}
}
/*
================
RB_ShowDebugLines
================
*/
void RB_ShowDebugLines()
{
2012-11-26 18:58:24 +00:00
int i;
int width;
debugLine_t* line;
if( !rb_numDebugLines )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// all lines are expressed in world coordinates
RB_SimpleWorldSetup();
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-11-26 18:58:24 +00:00
width = r_debugLineWidth.GetInteger();
if( width < 1 )
{
2012-11-26 18:58:24 +00:00
width = 1;
}
else if( width > 10 )
{
2012-11-26 18:58:24 +00:00
width = 10;
}
2012-11-26 18:58:24 +00:00
// draw lines
2012-12-17 16:30:59 +00:00
glLineWidth( width );
if( !r_debugLineDepthTest.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE | GLS_DEPTHFUNC_ALWAYS );
}
else
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE );
}
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
2012-11-26 18:58:24 +00:00
line = rb_debugLines;
for( i = 0; i < rb_numDebugLines; i++, line++ )
{
if( !line->depthTest )
{
2012-12-17 16:30:59 +00:00
glColor3fv( line->rgb.ToFloatPtr() );
glVertex3fv( line->start.ToFloatPtr() );
glVertex3fv( line->end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
}
2012-12-17 16:30:59 +00:00
glEnd();
if( !r_debugLineDepthTest.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYMODE_LINE );
}
2012-12-17 16:30:59 +00:00
glBegin( GL_LINES );
2012-11-26 18:58:24 +00:00
line = rb_debugLines;
for( i = 0; i < rb_numDebugLines; i++, line++ )
{
if( line->depthTest )
{
2012-12-17 16:30:59 +00:00
glColor4fv( line->rgb.ToFloatPtr() );
glVertex3fv( line->start.ToFloatPtr() );
glVertex3fv( line->end.ToFloatPtr() );
2012-11-26 18:58:24 +00:00
}
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-12-17 16:30:59 +00:00
glLineWidth( 1 );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
================
RB_ClearDebugPolygons
================
*/
void RB_ClearDebugPolygons( int time )
{
2012-11-26 18:58:24 +00:00
int i;
int num;
debugPolygon_t* poly;
2012-11-26 18:58:24 +00:00
rb_debugPolygonTime = time;
if( !time )
{
2012-11-26 18:58:24 +00:00
rb_numDebugPolygons = 0;
return;
}
2012-11-26 18:58:24 +00:00
// copy any polygons that still need to be drawn
num = 0;
2012-11-26 18:58:24 +00:00
poly = rb_debugPolygons;
for( i = 0; i < rb_numDebugPolygons; i++, poly++ )
{
if( poly->lifeTime > time )
{
if( num != i )
{
2012-11-26 18:58:24 +00:00
rb_debugPolygons[ num ] = *poly;
}
num++;
}
}
rb_numDebugPolygons = num;
}
/*
================
RB_AddDebugPolygon
================
*/
void RB_AddDebugPolygon( const idVec4& color, const idWinding& winding, const int lifeTime, const bool depthTest )
{
debugPolygon_t* poly;
if( rb_numDebugPolygons < MAX_DEBUG_POLYGONS )
{
2012-11-26 18:58:24 +00:00
poly = &rb_debugPolygons[ rb_numDebugPolygons++ ];
poly->rgb = color;
poly->winding = winding;
poly->depthTest = depthTest;
poly->lifeTime = rb_debugPolygonTime + lifeTime;
}
}
/*
================
RB_ShowDebugPolygons
================
*/
void RB_ShowDebugPolygons()
{
2012-11-26 18:58:24 +00:00
int i, j;
debugPolygon_t* poly;
if( !rb_numDebugPolygons )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
// all lines are expressed in world coordinates
RB_SimpleWorldSetup();
2012-11-26 18:58:24 +00:00
globalImages->BindNull();
2012-12-17 16:30:59 +00:00
glDisable( GL_TEXTURE_2D );
if( r_debugPolygonFilled.GetBool() )
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYGON_OFFSET | GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA | GLS_DEPTHMASK );
GL_PolygonOffset( -1, -2 );
}
else
{
2012-11-26 18:58:24 +00:00
GL_State( GLS_POLYGON_OFFSET | GLS_POLYMODE_LINE );
GL_PolygonOffset( -1, -2 );
}
2012-11-26 18:58:24 +00:00
poly = rb_debugPolygons;
for( i = 0; i < rb_numDebugPolygons; i++, poly++ )
{
2012-11-26 18:58:24 +00:00
// if ( !poly->depthTest ) {
2012-12-17 16:30:59 +00:00
glColor4fv( poly->rgb.ToFloatPtr() );
2012-12-17 16:30:59 +00:00
glBegin( GL_POLYGON );
for( j = 0; j < poly->winding.GetNumPoints(); j++ )
{
2012-12-17 16:30:59 +00:00
glVertex3fv( poly->winding[j].ToFloatPtr() );
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
// }
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
if( r_debugPolygonFilled.GetBool() )
{
2012-12-17 16:30:59 +00:00
glDisable( GL_POLYGON_OFFSET_FILL );
}
else
{
2012-12-17 16:30:59 +00:00
glDisable( GL_POLYGON_OFFSET_LINE );
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
}
/*
================
RB_ShowCenterOfProjection
================
*/
void RB_ShowCenterOfProjection()
{
if( !r_showCenterOfProjection.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
const int w = backEnd.viewDef->scissor.GetWidth();
const int h = backEnd.viewDef->scissor.GetHeight();
2012-12-17 16:30:59 +00:00
glClearColor( 1, 0, 0, 1 );
for( float f = 0.0f ; f <= 1.0f ; f += 0.125f )
{
2012-12-17 16:30:59 +00:00
glScissor( w * f - 1 , 0, 3, h );
glClear( GL_COLOR_BUFFER_BIT );
glScissor( 0, h * f - 1 , w, 3 );
glClear( GL_COLOR_BUFFER_BIT );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glClearColor( 0, 1, 0, 1 );
2012-11-26 18:58:24 +00:00
float f = 0.5f;
2012-12-17 16:30:59 +00:00
glScissor( w * f - 1 , 0, 3, h );
glClear( GL_COLOR_BUFFER_BIT );
glScissor( 0, h * f - 1 , w, 3 );
glClear( GL_COLOR_BUFFER_BIT );
2012-12-17 16:30:59 +00:00
glScissor( 0, 0, w, h );
2012-11-26 18:58:24 +00:00
}
/*
================
RB_ShowLines
Draw exact pixel lines to check pixel center sampling
================
*/
void RB_ShowLines()
{
if( !r_showLines.GetBool() )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
glEnable( GL_SCISSOR_TEST );
if( backEnd.viewDef->renderView.viewEyeBuffer == 0 )
{
2012-11-26 18:58:24 +00:00
glClearColor( 1, 0, 0, 1 );
}
else if( backEnd.viewDef->renderView.viewEyeBuffer == 1 )
{
2012-11-26 18:58:24 +00:00
glClearColor( 0, 1, 0, 1 );
}
else
{
2012-11-26 18:58:24 +00:00
glClearColor( 0, 0, 1, 1 );
}
2012-11-26 18:58:24 +00:00
const int start = ( r_showLines.GetInteger() > 2 ); // 1,3 = horizontal, 2,4 = vertical
if( r_showLines.GetInteger() == 1 || r_showLines.GetInteger() == 3 )
{
for( int i = start ; i < tr.GetHeight() ; i += 2 )
{
2012-11-26 18:58:24 +00:00
glScissor( 0, i, tr.GetWidth(), 1 );
glClear( GL_COLOR_BUFFER_BIT );
}
}
else
{
for( int i = start ; i < tr.GetWidth() ; i += 2 )
{
2012-11-26 18:58:24 +00:00
glScissor( i, 0, 1, tr.GetHeight() );
glClear( GL_COLOR_BUFFER_BIT );
}
}
}
/*
================
RB_TestGamma
================
*/
#define G_WIDTH 512
#define G_HEIGHT 512
#define BAR_HEIGHT 64
void RB_TestGamma()
{
2012-11-26 18:58:24 +00:00
byte image[G_HEIGHT][G_WIDTH][4];
int i, j;
int c, comp;
int v, dither;
int mask, y;
if( r_testGamma.GetInteger() <= 0 )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
v = r_testGamma.GetInteger();
if( v <= 1 || v >= 196 )
{
2012-11-26 18:58:24 +00:00
v = 128;
}
2012-11-26 18:58:24 +00:00
memset( image, 0, sizeof( image ) );
for( mask = 0; mask < 8; mask++ )
{
2012-11-26 18:58:24 +00:00
y = mask * BAR_HEIGHT;
for( c = 0; c < 4; c++ )
{
2012-11-26 18:58:24 +00:00
v = c * 64 + 32;
// solid color
for( i = 0; i < BAR_HEIGHT / 2; i++ )
{
for( j = 0; j < G_WIDTH / 4; j++ )
{
for( comp = 0; comp < 3; comp++ )
{
if( mask & ( 1 << comp ) )
{
image[y + i][c * G_WIDTH / 4 + j][comp] = v;
2012-11-26 18:58:24 +00:00
}
}
}
// dithered color
for( j = 0; j < G_WIDTH / 4; j++ )
{
if( ( i ^ j ) & 1 )
{
2012-11-26 18:58:24 +00:00
dither = c * 64;
}
else
{
2012-11-26 18:58:24 +00:00
dither = c * 64 + 63;
}
for( comp = 0; comp < 3; comp++ )
{
if( mask & ( 1 << comp ) )
{
image[y + BAR_HEIGHT / 2 + i][c * G_WIDTH / 4 + j][comp] = dither;
2012-11-26 18:58:24 +00:00
}
}
}
}
}
}
2012-11-26 18:58:24 +00:00
// draw geometrically increasing steps in the bottom row
y = 0 * BAR_HEIGHT;
float scale = 1;
for( c = 0; c < 4; c++ )
{
v = ( int )( 64 * scale );
if( v < 0 )
{
2012-11-26 18:58:24 +00:00
v = 0;
}
else if( v > 255 )
{
2012-11-26 18:58:24 +00:00
v = 255;
}
scale = scale * 1.5;
for( i = 0; i < BAR_HEIGHT; i++ )
{
for( j = 0; j < G_WIDTH / 4; j++ )
{
image[y + i][c * G_WIDTH / 4 + j][0] = v;
image[y + i][c * G_WIDTH / 4 + j][1] = v;
image[y + i][c * G_WIDTH / 4 + j][2] = v;
2012-11-26 18:58:24 +00:00
}
}
}
2012-12-17 16:30:59 +00:00
glLoadIdentity();
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
GL_Color( 1, 1, 1 );
2012-12-17 16:30:59 +00:00
glPushMatrix();
glLoadIdentity();
glDisable( GL_TEXTURE_2D );
glOrtho( 0, 1, 0, 1, -1, 1 );
glRasterPos2f( 0.01f, 0.01f );
glDrawPixels( G_WIDTH, G_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, image );
glPopMatrix();
glEnable( GL_TEXTURE_2D );
glMatrixMode( GL_MODELVIEW );
2012-11-26 18:58:24 +00:00
}
/*
==================
RB_TestGammaBias
==================
*/
static void RB_TestGammaBias()
{
2012-11-26 18:58:24 +00:00
byte image[G_HEIGHT][G_WIDTH][4];
if( r_testGammaBias.GetInteger() <= 0 )
{
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
int y = 0;
for( int bias = -40; bias < 40; bias += 10, y += BAR_HEIGHT )
{
2012-11-26 18:58:24 +00:00
float scale = 1;
for( int c = 0; c < 4; c++ )
{
int v = ( int )( 64 * scale + bias );
2012-11-26 18:58:24 +00:00
scale = scale * 1.5;
if( v < 0 )
{
2012-11-26 18:58:24 +00:00
v = 0;
}
else if( v > 255 )
{
2012-11-26 18:58:24 +00:00
v = 255;
}
for( int i = 0; i < BAR_HEIGHT; i++ )
{
for( int j = 0; j < G_WIDTH / 4; j++ )
{
image[y + i][c * G_WIDTH / 4 + j][0] = v;
image[y + i][c * G_WIDTH / 4 + j][1] = v;
image[y + i][c * G_WIDTH / 4 + j][2] = v;
2012-11-26 18:58:24 +00:00
}
}
}
}
2012-12-17 16:30:59 +00:00
glLoadIdentity();
glMatrixMode( GL_PROJECTION );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEPTHFUNC_ALWAYS );
GL_Color( 1, 1, 1 );
2012-12-17 16:30:59 +00:00
glPushMatrix();
glLoadIdentity();
glDisable( GL_TEXTURE_2D );
glOrtho( 0, 1, 0, 1, -1, 1 );
glRasterPos2f( 0.01f, 0.01f );
glDrawPixels( G_WIDTH, G_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, image );
glPopMatrix();
glEnable( GL_TEXTURE_2D );
glMatrixMode( GL_MODELVIEW );
2012-11-26 18:58:24 +00:00
}
/*
================
RB_TestImage
Display a single image over most of the screen
================
*/
void RB_TestImage()
{
idImage* image = NULL;
idImage* imageCr = NULL;
idImage* imageCb = NULL;
2012-11-26 18:58:24 +00:00
int max;
float w, h;
2012-11-26 18:58:24 +00:00
image = tr.testImage;
if( !image )
{
2012-11-26 18:58:24 +00:00
return;
}
if( tr.testVideo )
{
2012-11-26 18:58:24 +00:00
cinData_t cin;
2012-11-26 18:58:24 +00:00
cin = tr.testVideo->ImageForTime( backEnd.viewDef->renderView.time[1] - tr.testVideoStartTime );
if( cin.imageY != NULL )
{
2012-11-26 18:58:24 +00:00
image = cin.imageY;
imageCr = cin.imageCr;
imageCb = cin.imageCb;
}
else
{
2012-11-26 18:58:24 +00:00
tr.testImage = NULL;
return;
}
w = 0.25;
h = 0.25;
}
else
{
2012-11-26 18:58:24 +00:00
max = image->GetUploadWidth() > image->GetUploadHeight() ? image->GetUploadWidth() : image->GetUploadHeight();
2012-11-26 18:58:24 +00:00
w = 0.25 * image->GetUploadWidth() / max;
h = 0.25 * image->GetUploadHeight() / max;
w *= ( float )renderSystem->GetHeight() / renderSystem->GetWidth();
2012-11-26 18:58:24 +00:00
}
2012-11-26 18:58:24 +00:00
// Set State
GL_State( GLS_DEPTHFUNC_ALWAYS | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
2012-11-26 18:58:24 +00:00
// Set Parms
float texS[4] = { 1.0f, 0.0f, 0.0f, 0.0f };
float texT[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
renderProgManager.SetRenderParm( RENDERPARM_TEXTUREMATRIX_S, texS );
renderProgManager.SetRenderParm( RENDERPARM_TEXTUREMATRIX_T, texT );
2012-11-26 18:58:24 +00:00
float texGenEnabled[4] = { 0, 0, 0, 0 };
renderProgManager.SetRenderParm( RENDERPARM_TEXGEN_0_ENABLED, texGenEnabled );
2012-11-26 18:58:24 +00:00
// not really necessary but just for clarity
const float screenWidth = 1.0f;
const float screenHeight = 1.0f;
const float halfScreenWidth = screenWidth * 0.5f;
const float halfScreenHeight = screenHeight * 0.5f;
2012-11-26 18:58:24 +00:00
float scale[16] = { 0 };
scale[0] = w; // scale
scale[5] = h; // scale
scale[12] = halfScreenWidth - ( halfScreenWidth * w ); // translate
scale[13] = halfScreenHeight - ( halfScreenHeight * h ); // translate
scale[10] = 1.0f;
scale[15] = 1.0f;
2012-11-26 18:58:24 +00:00
float ortho[16] = { 0 };
ortho[0] = 2.0f / screenWidth;
ortho[5] = -2.0f / screenHeight;
ortho[10] = -2.0f;
ortho[12] = -1.0f;
ortho[13] = 1.0f;
ortho[14] = -1.0f;
ortho[15] = 1.0f;
2012-11-26 18:58:24 +00:00
float finalOrtho[16];
R_MatrixMultiply( scale, ortho, finalOrtho );
2012-11-26 18:58:24 +00:00
float projMatrixTranspose[16];
R_MatrixTranspose( finalOrtho, projMatrixTranspose );
renderProgManager.SetRenderParms( RENDERPARM_MVPMATRIX_X, projMatrixTranspose, 4 );
2012-12-17 16:30:59 +00:00
glMatrixMode( GL_PROJECTION );
glLoadMatrixf( finalOrtho );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
2012-11-26 18:58:24 +00:00
// Set Color
GL_Color( 1, 1, 1, 1 );
2012-11-26 18:58:24 +00:00
// Bind the Texture
if( ( imageCr != NULL ) && ( imageCb != NULL ) )
{
2012-11-26 18:58:24 +00:00
GL_SelectTexture( 0 );
image->Bind();
GL_SelectTexture( 1 );
imageCr->Bind();
GL_SelectTexture( 2 );
imageCb->Bind();
renderProgManager.BindShader_Bink();
}
else
{
2012-11-26 18:58:24 +00:00
GL_SelectTexture( 0 );
image->Bind();
// Set Shader
renderProgManager.BindShader_Texture();
}
// Draw!
RB_DrawElementsWithCounters( &backEnd.testImageSurface );
}
/*
=================
RB_DrawExpandedTriangles
=================
*/
void RB_DrawExpandedTriangles( const srfTriangles_t* tri, const float radius, const idVec3& vieworg )
{
2012-11-26 18:58:24 +00:00
int i, j, k;
idVec3 dir[6], normal, point;
for( i = 0; i < tri->numIndexes; i += 3 )
{
2012-11-26 18:58:24 +00:00
idVec3 p[3] = { tri->verts[ tri->indexes[ i + 0 ] ].xyz, tri->verts[ tri->indexes[ i + 1 ] ].xyz, tri->verts[ tri->indexes[ i + 2 ] ].xyz };
2012-11-26 18:58:24 +00:00
dir[0] = p[0] - p[1];
dir[1] = p[1] - p[2];
dir[2] = p[2] - p[0];
2012-11-26 18:58:24 +00:00
normal = dir[0].Cross( dir[1] );
if( normal * p[0] < normal * vieworg )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
dir[0] = normal.Cross( dir[0] );
dir[1] = normal.Cross( dir[1] );
dir[2] = normal.Cross( dir[2] );
2012-11-26 18:58:24 +00:00
dir[0].Normalize();
dir[1].Normalize();
dir[2].Normalize();
2012-12-17 16:30:59 +00:00
glBegin( GL_LINE_LOOP );
for( j = 0; j < 3; j++ )
{
2012-11-26 18:58:24 +00:00
k = ( j + 1 ) % 3;
2012-11-26 18:58:24 +00:00
dir[4] = ( dir[j] + dir[k] ) * 0.5f;
dir[4].Normalize();
2012-11-26 18:58:24 +00:00
dir[3] = ( dir[j] + dir[4] ) * 0.5f;
dir[3].Normalize();
2012-11-26 18:58:24 +00:00
dir[5] = ( dir[4] + dir[k] ) * 0.5f;
dir[5].Normalize();
2012-11-26 18:58:24 +00:00
point = p[k] + dir[j] * radius;
2012-12-17 16:30:59 +00:00
glVertex3f( point[0], point[1], point[2] );
2012-11-26 18:58:24 +00:00
point = p[k] + dir[3] * radius;
2012-12-17 16:30:59 +00:00
glVertex3f( point[0], point[1], point[2] );
2012-11-26 18:58:24 +00:00
point = p[k] + dir[4] * radius;
2012-12-17 16:30:59 +00:00
glVertex3f( point[0], point[1], point[2] );
2012-11-26 18:58:24 +00:00
point = p[k] + dir[5] * radius;
2012-12-17 16:30:59 +00:00
glVertex3f( point[0], point[1], point[2] );
2012-11-26 18:58:24 +00:00
point = p[k] + dir[k] * radius;
2012-12-17 16:30:59 +00:00
glVertex3f( point[0], point[1], point[2] );
2012-11-26 18:58:24 +00:00
}
2012-12-17 16:30:59 +00:00
glEnd();
2012-11-26 18:58:24 +00:00
}
}
/*
================
RB_ShowTrace
Debug visualization
FIXME: not thread safe!
================
*/
void RB_ShowTrace( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
int i;
const srfTriangles_t* tri;
const drawSurf_t* surf;
2012-11-26 18:58:24 +00:00
idVec3 start, end;
idVec3 localStart, localEnd;
localTrace_t hit;
float radius;
if( r_showTrace.GetInteger() == 0 )
{
2012-11-26 18:58:24 +00:00
return;
}
if( r_showTrace.GetInteger() == 2 )
{
2012-11-26 18:58:24 +00:00
radius = 5.0f;
}
else
{
2012-11-26 18:58:24 +00:00
radius = 0.0f;
}
2012-11-26 18:58:24 +00:00
// determine the points of the trace
start = backEnd.viewDef->renderView.vieworg;
end = start + 4000 * backEnd.viewDef->renderView.viewaxis[0];
2012-11-26 18:58:24 +00:00
// check and draw the surfaces
globalImages->whiteImage->Bind();
2012-11-26 18:58:24 +00:00
// find how many are ambient
for( i = 0; i < numDrawSurfs; i++ )
{
2012-11-26 18:58:24 +00:00
surf = drawSurfs[i];
tri = surf->frontEndGeo;
if( tri == NULL || tri->verts == NULL )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-11-26 18:58:24 +00:00
// transform the points into local space
R_GlobalPointToLocal( surf->space->modelMatrix, start, localStart );
R_GlobalPointToLocal( surf->space->modelMatrix, end, localEnd );
2012-11-26 18:58:24 +00:00
// check the bounding box
if( !tri->bounds.Expand( radius ).LineIntersection( localStart, localEnd ) )
{
2012-11-26 18:58:24 +00:00
continue;
}
2012-12-17 16:30:59 +00:00
glLoadMatrixf( surf->space->modelViewMatrix );
2012-11-26 18:58:24 +00:00
// highlight the surface
GL_State( GLS_SRCBLEND_SRC_ALPHA | GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 0, 0, 0.25 );
RB_DrawElementsWithCounters( surf );
2012-11-26 18:58:24 +00:00
// draw the bounding box
GL_State( GLS_DEPTHFUNC_ALWAYS );
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1, 1 );
RB_DrawBounds( tri->bounds );
if( radius != 0.0f )
{
2012-11-26 18:58:24 +00:00
// draw the expanded triangles
GL_Color( 0.5f, 0.5f, 1.0f, 1.0f );
RB_DrawExpandedTriangles( tri, radius, localStart );
}
2012-11-26 18:58:24 +00:00
// check the exact surfaces
hit = R_LocalTrace( localStart, localEnd, radius, tri );
if( hit.fraction < 1.0 )
{
2012-11-26 18:58:24 +00:00
GL_Color( 1, 1, 1, 1 );
RB_DrawBounds( idBounds( hit.point ).Expand( 1 ) );
}
}
}
/*
=================
RB_RenderDebugTools
=================
*/
void RB_RenderDebugTools( drawSurf_t** drawSurfs, int numDrawSurfs )
{
2012-11-26 18:58:24 +00:00
// don't do much if this was a 2D rendering
if( !backEnd.viewDef->viewEntitys )
{
2012-11-26 18:58:24 +00:00
RB_TestImage();
RB_ShowLines();
return;
}
2012-11-26 18:58:24 +00:00
renderLog.OpenMainBlock( MRB_DRAW_DEBUG_TOOLS );
RENDERLOG_PRINTF( "---------- RB_RenderDebugTools ----------\n" );
2012-11-26 18:58:24 +00:00
GL_State( GLS_DEFAULT );
2012-11-26 18:58:24 +00:00
GL_Scissor( backEnd.viewDef->viewport.x1 + backEnd.viewDef->scissor.x1,
backEnd.viewDef->viewport.y1 + backEnd.viewDef->scissor.y1,
backEnd.viewDef->scissor.x2 + 1 - backEnd.viewDef->scissor.x1,
backEnd.viewDef->scissor.y2 + 1 - backEnd.viewDef->scissor.y1 );
backEnd.currentScissor = backEnd.viewDef->scissor;
2012-11-26 18:58:24 +00:00
RB_ShowLightCount();
RB_ShowTexturePolarity( drawSurfs, numDrawSurfs );
RB_ShowTangentSpace( drawSurfs, numDrawSurfs );
RB_ShowVertexColor( drawSurfs, numDrawSurfs );
RB_ShowTris( drawSurfs, numDrawSurfs );
RB_ShowUnsmoothedTangents( drawSurfs, numDrawSurfs );
RB_ShowSurfaceInfo( drawSurfs, numDrawSurfs );
RB_ShowEdges( drawSurfs, numDrawSurfs );
RB_ShowNormals( drawSurfs, numDrawSurfs );
RB_ShowViewEntitys( backEnd.viewDef->viewEntitys );
RB_ShowLights();
RB_ShowTextureVectors( drawSurfs, numDrawSurfs );
RB_ShowDominantTris( drawSurfs, numDrawSurfs );
if( r_testGamma.GetInteger() > 0 ) // test here so stack check isn't so damn slow on debug builds
{
2012-11-26 18:58:24 +00:00
RB_TestGamma();
}
if( r_testGammaBias.GetInteger() > 0 )
{
2012-11-26 18:58:24 +00:00
RB_TestGammaBias();
}
RB_TestImage();
RB_ShowPortals();
RB_ShowSilhouette();
RB_ShowDepthBuffer();
RB_ShowIntensity();
RB_ShowCenterOfProjection();
RB_ShowLines();
RB_ShowDebugLines();
RB_ShowDebugText();
RB_ShowDebugPolygons();
RB_ShowTrace( drawSurfs, numDrawSurfs );
2012-11-26 18:58:24 +00:00
renderLog.CloseMainBlock();
}
/*
=================
RB_ShutdownDebugTools
=================
*/
void RB_ShutdownDebugTools()
{
for( int i = 0; i < MAX_DEBUG_POLYGONS; i++ )
{
2012-11-26 18:58:24 +00:00
rb_debugPolygons[i].winding.Clear();
}
}