29 #include "../idlib/precompiled.h"
35 #define MAX_DEBUG_LINES 16384
49 #define MAX_DEBUG_TEXT 512
66 #define MAX_DEBUG_POLYGONS 8192
79 static void RB_DrawText(
const char *text,
const idVec3 &origin,
float scale,
const idVec4 &
color,
const idMat3 &viewAxis,
const int align );
92 qglVertex3f( bounds[0][0], bounds[0][1], bounds[0][2] );
93 qglVertex3f( bounds[0][0], bounds[1][1], bounds[0][2] );
94 qglVertex3f( bounds[1][0], bounds[1][1], bounds[0][2] );
95 qglVertex3f( bounds[1][0], bounds[0][1], bounds[0][2] );
98 qglVertex3f( bounds[0][0], bounds[0][1], bounds[1][2] );
99 qglVertex3f( bounds[0][0], bounds[1][1], bounds[1][2] );
100 qglVertex3f( bounds[1][0], bounds[1][1], bounds[1][2] );
101 qglVertex3f( bounds[1][0], bounds[0][1], bounds[1][2] );
105 qglVertex3f( bounds[0][0], bounds[0][1], bounds[0][2] );
106 qglVertex3f( bounds[0][0], bounds[0][1], bounds[1][2] );
108 qglVertex3f( bounds[0][0], bounds[1][1], bounds[0][2] );
109 qglVertex3f( bounds[0][0], bounds[1][1], bounds[1][2] );
111 qglVertex3f( bounds[1][0], bounds[0][1], bounds[0][2] );
112 qglVertex3f( bounds[1][0], bounds[0][1], bounds[1][2] );
114 qglVertex3f( bounds[1][0], bounds[1][1], bounds[0][2] );
115 qglVertex3f( bounds[1][0], bounds[1][1], bounds[1][2] );
207 byte *stencilReadback;
209 memset( counts, 0,
sizeof( counts ) );
215 counts[ stencilReadback[
i] ]++;
222 for ( i = 0 ; i < 255 ; i++ ) {
240 byte *stencilReadback;
248 count += stencilReadback[
i];
266 static void R_ColorByStencilBuffer(
void ) {
268 static float colors[8][3] = {
286 for ( i = 0 ; i < 6 ; i++ ) {
315 if ( material ==
NULL ) {
322 int interactions = 0;
334 for ( i = 0; i < numDrawSurfs; i++ ) {
337 const_cast<drawSurf_t *
>(surf)->material = material;
344 const_cast<drawSurf_t *
>(surf)->material = material;
345 newDrawSurfs[i++] =
const_cast<drawSurf_t *
>(surf);
348 const_cast<drawSurf_t *
>(surf)->material = material;
349 newDrawSurfs[i++] =
const_cast<drawSurf_t *
>(surf);
392 for ( i = 0; i <
c ; i+=4 ) {
393 j = colorReadback[
i];
394 if ( colorReadback[i+1] > j ) {
395 j = colorReadback[i+1];
397 if ( colorReadback[i+2] > j ) {
398 j = colorReadback[i+2];
401 colorReadback[i+0] = 2*(128-
j);
402 colorReadback[i+1] = 2*
j;
403 colorReadback[i+2] = 0;
405 colorReadback[i+0] = 0;
406 colorReadback[i+1] = 2*(255-
j);
407 colorReadback[i+2] = 2*(j-128);
466 ((
byte *)depthReadback)[i*4] =
467 ((
byte *)depthReadback)[i*4+1] =
468 ((
byte *)depthReadback)[i*4+2] = 255 * ((
float *)depthReadback)[
i];
469 ((
byte *)depthReadback)[i*4+3] = 1;
514 for ( i = 0 ; i < 2 ; i++ ) {
529 R_ColorByStencilBuffer();
581 for ( i = 0 ; i < 2 ; i++ ) {
596 if ( (i1 & 1) + (i2 & 1) + (i3 & 1) == 1 ) {
597 if ( (i1 & 1) + (i2 & 1) == 0 ) {
600 }
else if ( (i1 & 1 ) + (i3 & 1) == 0 ) {
629 static void RB_ShowShadowCount(
void ) {
655 for ( i = 0 ; i < 2 ; i++ ) {
685 R_ColorByStencilBuffer();
717 for (
int i = 0 ; i < tri->
numIndexes ; i+= 3 ) {
718 for (
int j = 0 ;
j < 3 ;
j++ ) {
719 int k = (
j + 1 ) % 3;
735 static void RB_ShowTris(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
787 static void RB_ShowSurfaceInfo(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
841 static void RB_ShowViewEntitys(
viewEntity_t *vModels ) {
847 for ( ; vModels ; vModels = vModels->
next ) {
868 for ( ; vModels ; vModels = vModels->
next ) {
909 static void RB_ShowTexturePolarity(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
925 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
926 drawSurf = drawSurfs[
i];
945 d0[3] = b->
st[0] - a->
st[0];
946 d0[4] = b->
st[1] - a->
st[1];
948 d1[3] = c->
st[0] - a->
st[0];
949 d1[4] = c->
st[1] - a->
st[1];
951 area = d0[3] * d1[4] - d0[4] * d1[3];
955 }
else if ( area < 0 ) {
978 static void RB_ShowUnsmoothedTangents(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
994 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
995 drawSurf = drawSurfs[
i];
1003 tri = drawSurf->
geo;
1033 static void RB_ShowTangentSpace(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1047 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1048 drawSurf = drawSurfs[
i];
1052 tri = drawSurf->
geo;
1053 if ( !tri->
verts ) {
1064 0.5 + 0.5 * v->
tangents[0][2], 0.5 );
1067 0.5 + 0.5 * v->
tangents[1][2], 0.5 );
1070 0.5 + 0.5 * v->
normal[2], 0.5 );
1087 static void RB_ShowVertexColor(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1101 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1102 drawSurf = drawSurfs[
i];
1106 tri = drawSurf->
geo;
1107 if ( !tri->
verts ) {
1132 static void RB_ShowNormals(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1157 if ( size < 0.0
f ) {
1161 showNumbers =
false;
1164 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1165 drawSurf = drawSurfs[
i];
1169 tri = drawSurf->
geo;
1170 if ( !tri->
verts ) {
1175 for ( j = 0 ; j < tri->
numVerts ; j++ ) {
1194 if ( showNumbers ) {
1196 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1197 drawSurf = drawSurfs[
i];
1198 tri = drawSurf->
geo;
1199 if ( !tri->
verts ) {
1203 for ( j = 0 ; j < tri->
numVerts ; j++ ) {
1208 for ( j = 0 ; j < tri->
numIndexes; j += 3 ) {
1226 static void RB_AltShowNormals(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1243 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1244 drawSurf = drawSurfs[
i];
1248 tri = drawSurf->
geo;
1250 for ( j = 0 ; j < tri->
numIndexes ; j += 3 ) {
1259 mid = ( v[0]->
xyz + v[1]->
xyz + v[2]->
xyz ) * ( 1.0
f / 3.0
f );
1262 for ( k = 0 ; k < 3 ; k++ ) {
1265 pos = ( mid + v[k]->
xyz * 3.0f ) * 0.25
f;
1303 static void RB_ShowTextureVectors(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1317 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1318 drawSurf = drawSurfs[
i];
1320 tri = drawSurf->
geo;
1322 if ( !tri->
verts ) {
1333 for ( j = 0 ; j < tri->
numIndexes ; j+= 3 ) {
1346 mid = ( a->
xyz + b->
xyz + c->
xyz ) * ( 1.0
f / 3.0
f );
1351 d0[3] = b->
st[0] - a->
st[0];
1352 d0[4] = b->
st[1] - a->
st[1];
1354 d1[3] = c->
st[0] - a->
st[0];
1355 d1[4] = c->
st[1] - a->
st[1];
1357 area = d0[3] * d1[4] - d0[4] * d1[3];
1363 temp[0] = (d0[0] * d1[4] - d0[4] * d1[0]) * inva;
1364 temp[1] = (d0[1] * d1[4] - d0[4] * d1[1]) * inva;
1365 temp[2] = (d0[2] * d1[4] - d0[4] * d1[2]) * inva;
1369 temp[0] = (d0[3] * d1[0] - d0[0] * d1[3]) * inva;
1370 temp[1] = (d0[3] * d1[1] - d0[1] * d1[3]) * inva;
1371 temp[2] = (d0[3] * d1[2] - d0[2] * d1[3]) * inva;
1399 static void RB_ShowDominantTris(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1416 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1417 drawSurf = drawSurfs[
i];
1419 tri = drawSurf->
geo;
1421 if ( !tri->
verts ) {
1432 for ( j = 0 ; j < tri->
numVerts ; j++ ) {
1442 mid = ( a->
xyz + b->
xyz + c->
xyz ) * ( 1.0
f / 3.0
f );
1460 static void RB_ShowEdges(
drawSurf_t **drawSurfs,
int numDrawSurfs ) {
1461 int i,
j, k, m,
n, o;
1477 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1478 drawSurf = drawSurfs[
i];
1480 tri = drawSurf->
geo;
1493 for ( j = 0 ; j < tri->
numIndexes ; j+= 3 ) {
1494 for ( k = 0 ; k < 3 ; k++ ) {
1496 l = ( k == 2 ) ? 0 : k + 1;
1501 for ( m = 0 ; m < tri->
numIndexes ; m += 3 ) {
1502 for ( n = 0 ; n < 3 ; n++ ) {
1503 o = ( n == 2 ) ? 0 : n + 1;
1539 if ( edge->
p1 != danglePlane && edge->
p2 != danglePlane ) {
1683 rb_debugText[
num ] = *text;
1688 rb_numDebugText =
num;
1701 debugText->
text = text;
1702 debugText->
origin = origin;
1706 debugText->
align = align;
1721 float spacing, textLen = 0.0f;
1723 if ( text && *text ) {
1727 for ( i = 0; i <
len; i++ ) {
1728 charIndex = text[
i] - 32;
1732 num = simplex[charIndex][0] * 2;
1733 spacing = simplex[charIndex][1];
1736 while( index - 2 < num ) {
1737 if ( simplex[charIndex][index] < 0) {
1742 if ( simplex[charIndex][index] < 0) {
1747 textLen += spacing *
scale;
1761 static void RB_DrawText(
const char *text,
const idVec3 &origin,
float scale,
const idVec4 &
color,
const idMat3 &viewAxis,
const int align ) {
1763 float textLen, spacing;
1766 if ( text && *text ) {
1770 if ( text[0] ==
'\n' ) {
1776 len = strlen( text );
1777 for ( i = 0; i <
len; i++ ) {
1779 if ( i == 0 || text[i] ==
'\n' ) {
1780 org = origin - viewAxis[2] * ( line * 36.0f *
scale );
1782 for ( j = 1; i+j <=
len; j++ ) {
1783 if ( i+j == len || text[i+j] ==
'\n' ) {
1790 org += viewAxis[1] * textLen;
1793 org += viewAxis[1] * ( textLen * 0.5f );
1799 charIndex = text[
i] - 32;
1803 num = simplex[charIndex][0] * 2;
1804 spacing = simplex[charIndex][1];
1807 while( index - 2 < num ) {
1808 if ( simplex[charIndex][index] < 0) {
1812 p1 = org + scale * simplex[charIndex][
index] * -viewAxis[1] + scale * simplex[charIndex][index+1] * viewAxis[2];
1814 if ( simplex[charIndex][index] < 0) {
1818 p2 = org + scale * simplex[charIndex][
index] * -viewAxis[1] + scale * simplex[charIndex][index+1] * viewAxis[2];
1823 org -= viewAxis[1] * ( spacing *
scale );
1852 }
else if ( width > 10 ) {
1909 rb_debugLines[
num ] = *line;
1914 rb_numDebugLines =
num;
1957 }
else if ( width > 10 ) {
2026 rb_debugPolygons[
num ] = *poly;
2031 rb_numDebugPolygons =
num;
2118 #define G_HEIGHT 512
2119 #define BAR_HEIGHT 64
2137 memset( image, 0,
sizeof( image ) );
2139 for ( mask = 0 ; mask < 8 ; mask++ ) {
2141 for ( c = 0 ; c < 4 ; c++ ) {
2144 for ( i = 0 ; i < BAR_HEIGHT/2 ; i++ ) {
2145 for ( j = 0 ; j <
G_WIDTH/4 ; j++ ) {
2146 for ( comp = 0 ; comp < 3 ; comp++ ) {
2147 if ( mask & ( 1 << comp ) ) {
2153 for ( j = 0 ; j <
G_WIDTH/4 ; j++ ) {
2154 if ( ( i ^ j ) & 1 ) {
2157 dither = c * 64 + 63;
2159 for ( comp = 0 ; comp < 3 ; comp++ ) {
2160 if ( mask & ( 1 << comp ) ) {
2161 image[y+BAR_HEIGHT/2+
i][c*
G_WIDTH/4+
j][comp] = dither;
2172 for ( c = 0 ; c < 4 ; c++ ) {
2173 v = (
int)(64 * scale);
2176 }
else if ( v > 255 ) {
2179 scale = scale * 1.5;
2181 for ( j = 0 ; j <
G_WIDTH/4 ; j++ ) {
2212 static void RB_TestGammaBias(
void ) {
2222 for (
int c = 0 ; c < 4 ; c++ ) {
2223 int v = (
int)(64 * scale +
bias);
2224 scale = scale * 1.5;
2227 }
else if ( v > 255 ) {
2231 for (
int j = 0 ; j <
G_WIDTH/4 ; j++ ) {
2335 RB_LogComment(
"---------- RB_RenderDebugTools ----------\n" );
2346 RB_ShowShadowCount();
2347 RB_ShowTexturePolarity( drawSurfs, numDrawSurfs );
2348 RB_ShowTangentSpace( drawSurfs, numDrawSurfs );
2349 RB_ShowVertexColor( drawSurfs, numDrawSurfs );
2350 RB_ShowTris( drawSurfs, numDrawSurfs );
2351 RB_ShowUnsmoothedTangents( drawSurfs, numDrawSurfs );
2352 RB_ShowSurfaceInfo( drawSurfs, numDrawSurfs );
2353 RB_ShowEdges( drawSurfs, numDrawSurfs );
2354 RB_ShowNormals( drawSurfs, numDrawSurfs );
2357 RB_ShowTextureVectors( drawSurfs, numDrawSurfs );
2358 RB_ShowDominantTris( drawSurfs, numDrawSurfs );
const int GLS_DSTBLEND_ONE
const srfTriangles_t * geo
const int GLS_DEPTHFUNC_LESS
const idVec3 & Normal(void) const
#define qglDisableClientState
const int GLS_SRCBLEND_SRC_ALPHA
const int GLS_POLYMODE_LINE
float GetFloat(void) const
idCVar r_showPortals("r_showPortals","0", CVAR_RENDERER|CVAR_BOOL,"draw portal outlines in color based on passed / not passed")
const float * ToFloatPtr(void) const
idRenderModel * R_EntityDefDynamicModel(idRenderEntityLocal *def)
#define VectorSubtract(a, b, c)
GLenum GLenum GLenum GLenum GLenum scale
idCVar r_showTris("r_showTris","0", CVAR_RENDERER|CVAR_INTEGER,"enables wireframe rendering of the world, 1 = only draw visible ones, 2 = draw all front facing, 3 = draw all", 0, 3, idCmdSystem::ArgCompletion_Integer< 0, 3 >)
idCVar r_showTextureVectors("r_showTextureVectors","0", CVAR_RENDERER|CVAR_FLOAT," if > 0 draw each triangles texture (tangent) vectors")
const idMaterial * material
idCVar r_showSilhouette("r_showSilhouette","0", CVAR_RENDERER|CVAR_BOOL,"highlight edges that are casting shadow planes")
idCVar r_showVertexColor("r_showVertexColor","0", CVAR_RENDERER|CVAR_BOOL,"draws all triangles with the solid vertex color")
const struct drawSurf_s * localShadows
const char * GetName(void) const
GLenum GLsizei GLenum GLenum const GLvoid * image
const int GLS_DEPTHFUNC_ALWAYS
const struct drawSurf_s * globalInteractions
idRenderWorldLocal * primaryWorld
virtual const char * Name() const =0
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
idRenderLightLocal * lightDef
const struct viewEntity_s * space
idCVar r_showOverDraw("r_showOverDraw","0", CVAR_RENDERER|CVAR_INTEGER,"1 = geometry overdraw, 2 = light interaction overdraw, 3 = geometry and light interaction overdraw", 0, 3, idCmdSystem::ArgCompletion_Integer< 0, 3 >)
struct vertCache_s * ambientCache
virtual bool Trace(modelTrace_t &trace, const idVec3 &start, const idVec3 &end, const float radius, bool skipDynamic=true, bool skipPlayer=false) const
const idMaterial * material
const viewEntity_t * currentSpace
idCVar r_showUnsmoothedTangents("r_showUnsmoothedTangents","0", CVAR_RENDERER|CVAR_BOOL,"if 1, put all nvidia register combiner programming in display lists")
idCVar r_showSurfaceInfo("r_showSurfaceInfo","0", CVAR_RENDERER|CVAR_BOOL,"show surface material name under crosshair")
idCVar r_showShadowCount("r_showShadowCount","0", CVAR_RENDERER|CVAR_INTEGER,"colors screen based on shadow volume depth complexity, >= 2 = print overdraw count based on stencil index values, 3 = only show turboshadows, 4 = only show static shadows", 0, 4, idCmdSystem::ArgCompletion_Integer< 0, 4 >)
idList< idRenderLightLocal * > lightDefs
void GL_Cull(int cullType)
const int GLS_DEPTHFUNC_EQUAL
struct viewLight_s * next
void RB_RenderDrawSurfListWithFunction(drawSurf_t **drawSurfs, int numDrawSurfs, void(*triFunc_)(const drawSurf_t *))
struct viewLight_s * viewLights
idCVar r_showLights("r_showLights","0", CVAR_RENDERER|CVAR_INTEGER,"1 = just print volumes numbers, highlighting ones covering the view, 2 = also draw planes of each volume, 3 = also draw edges of each volume", 0, 3, idCmdSystem::ArgCompletion_Integer< 0, 3 >)
virtual void DrawText(const char *text, const idVec3 &origin, float scale, const idVec4 &color, const idMat3 &viewAxis, const int align=1, const int lifetime=0, bool depthTest=false)
GLuint GLuint GLsizei count
int GetNumPoints(void) const
GLubyte GLubyte GLubyte GLubyte w
struct viewEntity_s * next
void UploadScratch(const byte *pic, int width, int height)
static float Fabs(float f)
idCVar r_showNormals("r_showNormals","0", CVAR_RENDERER|CVAR_FLOAT,"draws wireframe normals")
idCVar r_testGammaBias("r_testGammaBias","0", CVAR_RENDERER|CVAR_FLOAT,"if > 0 draw a grid pattern to test gamma levels")
idCVar r_showViewEntitys("r_showViewEntitys","0", CVAR_RENDERER|CVAR_INTEGER,"1 = displays the bounding boxes of all view models, 2 = print index numbers")
idCVar r_debugLineDepthTest("r_debugLineDepthTest","0", CVAR_RENDERER|CVAR_ARCHIVE|CVAR_BOOL,"perform depth test on debug lines")
idCVar r_showTangentSpace("r_showTangentSpace","0", CVAR_RENDERER|CVAR_INTEGER,"shade triangles by tangent space, 1 = use 1st tangent vector, 2 = use 2nd tangent vector, 3 = use normal vector", 0, 3, idCmdSystem::ArgCompletion_Integer< 0, 3 >)
int GetInteger(void) const
const int GLS_SRCBLEND_ONE
idCVar r_debugPolygonFilled("r_debugPolygonFilled","1", CVAR_RENDERER|CVAR_BOOL,"draw a filled polygon")
idImageManager * globalImages
void RB_T_RenderTriangleSurface(const drawSurf_t *surf)
idRenderEntityLocal * entityDef
struct vertCache_s * shadowCache
GLubyte GLubyte GLubyte a
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual idBounds Bounds(const struct renderEntity_s *ent=NULL) const =0
void RB_DrawElementsWithCounters(const srfTriangles_t *tri)
const float * ToFloatPtr(void) const
bool UseUnsmoothedTangents(void) const
const int GLS_SRCBLEND_DST_ALPHA
const int GLS_DSTBLEND_ZERO
idDeclManager * declManager
srfTriangles_t * frustumTris
idCVar r_testGamma("r_testGamma","0", CVAR_RENDERER|CVAR_FLOAT,"if > 0 draw a grid pattern to test gamma levels", 0, 195)
int numShadowIndexesNoCaps
idCVar r_showDominantTri("r_showDominantTri","0", CVAR_RENDERER|CVAR_BOOL,"draw lines from vertexes to center of dominant triangles")
void RB_LogComment(const char *comment,...)
const int GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA
struct viewEntity_s * viewEntitys
const struct drawSurf_s * globalShadows
idCVar r_showLightCount("r_showLightCount","0", CVAR_RENDERER|CVAR_INTEGER,"1 = colors surfaces based on light count, 2 = also count everything through walls, 3 = also print overdraw", 0, 3, idCmdSystem::ArgCompletion_Integer< 0, 3 >)
bool IsCleared(void) const
idCVar r_showIntensity("r_showIntensity","0", CVAR_RENDERER|CVAR_BOOL,"draw the screen colors based on intensity, red = 0, green = 128, blue = 255")
const struct drawSurf_s * localInteractions
void * R_StaticAlloc(int bytes)
void RB_ShowTrace(drawSurf_t **drawSurfs, int numDrawSurfs)
void * Position(vertCache_t *buffer)
const struct drawSurf_s * nextOnLight
float modelViewMatrix[16]
const int NUM_SIMPLEX_CHARS
void * R_FrameAlloc(int bytes)
idVertexCache vertexCache
int FindIndex(const type &obj) const
idCVar r_showDepth("r_showDepth","0", CVAR_RENDERER|CVAR_BOOL,"display the contents of the depth buffer and the depth range")
idCVar r_showTexturePolarity("r_showTexturePolarity","0", CVAR_RENDERER|CVAR_BOOL,"shade triangles by texture area polarity")
void GL_State(int stateBits)
const renderEntity_t * entity
idCVar r_debugLineWidth("r_debugLineWidth","1", CVAR_RENDERER|CVAR_ARCHIVE|CVAR_BOOL,"width of debug lines")
idCVar r_showEdges("r_showEdges","0", CVAR_RENDERER|CVAR_BOOL,"draw the sil edges")
#define VectorMA(v, s, b, o)
idCVar r_useScissor("r_useScissor","1", CVAR_RENDERER|CVAR_BOOL,"scissor clip as portals and lights are processed")
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
idRenderWorldLocal * renderWorld
char * va(const char *fmt,...)
virtual cinData_t ImageForTime(int milliseconds)
void R_StaticFree(void *data)
void R_LocalPointToGlobal(const float modelMatrix[16], const idVec3 &in, idVec3 &out)
void RB_RenderTriangleSurface(const srfTriangles_t *tri)
void R_AxisToModelMatrix(const idMat3 &axis, const idVec3 &origin, float modelMatrix[16])
idScreenRect currentScissor
bool Equals(const idScreenRect &rect) const
const viewDef_t * viewDef
dominantTri_t * dominantTris