From 4968bfca6d51d87de3e473843acf0b86908f2ae4 Mon Sep 17 00:00:00 2001 From: myT Date: Thu, 26 Dec 2019 16:16:30 +0100 Subject: [PATCH] crash and drawing fixes for r_shownormals, r_showtris and r_debugSurface - preventing crashes and drops with r_shownormals - fixed the colors of r_showtris, r_shownormals and r_debugSurface - simplified the overflow macro --- code/renderer/tr_backend.cpp | 4 +++- code/renderer/tr_local.h | 2 +- code/renderer/tr_shade.cpp | 15 ++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/code/renderer/tr_backend.cpp b/code/renderer/tr_backend.cpp index 9965f14..4e24d5c 100644 --- a/code/renderer/tr_backend.cpp +++ b/code/renderer/tr_backend.cpp @@ -516,6 +516,7 @@ static void R_DebugPolygon( int colorMask, int numPoints, const float* points ) stage.constantColor[1] = ((colorMask >> 1) & 1) ? 255 : 0; stage.constantColor[2] = ((colorMask >> 2) & 1) ? 255 : 0; stage.constantColor[3] = 255; + R_ComputeColors( &stage, tess.svars[0], 0, numPoints ); gal.Draw( DT_GENERIC ); // wireframe @@ -527,10 +528,11 @@ static void R_DebugPolygon( int colorMask, int numPoints, const float* points ) tess.numIndexes = numPoints * 3; stage.stateBits |= GLS_POLYMODE_LINE; stage.rgbGen = CGEN_IDENTITY; + R_ComputeColors( &stage, tess.svars[0], 0, numPoints ); gal.SetDepthRange( 0, 0 ); gal.Draw( DT_GENERIC ); - gal.SetDepthRange( 0, 1 ); + RB_PopShader(); tess.numVertexes = 0; tess.numIndexes = 0; diff --git a/code/renderer/tr_local.h b/code/renderer/tr_local.h index 5d1570d..3b21b62 100644 --- a/code/renderer/tr_local.h +++ b/code/renderer/tr_local.h @@ -1251,7 +1251,7 @@ extern shaderCommands_t tess; void RB_BeginSurface( const shader_t* shader, int fogNum ); void RB_EndSurface(); void RB_CheckOverflow( int verts, int indexes ); -#define RB_CHECKOVERFLOW(v,i) if (tess.numVertexes + (v) >= SHADER_MAX_VERTEXES || tess.numIndexes + (i) >= SHADER_MAX_INDEXES ) {RB_CheckOverflow(v,i);} +#define RB_CHECKOVERFLOW(v,i) RB_CheckOverflow(v,i) void R_ComputeColors( const shaderStage_t* pStage, stageVars_t& svars, int firstVertex, int numVertexes ); void R_ComputeTexCoords( const shaderStage_t* pStage, stageVars_t& svars, int firstVertex, int numVertexes, qbool ptrOpt ); diff --git a/code/renderer/tr_shade.cpp b/code/renderer/tr_shade.cpp index e7057af..6b5051f 100644 --- a/code/renderer/tr_shade.cpp +++ b/code/renderer/tr_shade.cpp @@ -190,20 +190,24 @@ void RB_EndSurface() tess.numVertexes > 0) { if (r_showtris->integer) { RB_PushSingleStageShader(GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE, CT_FRONT_SIDED); + R_ComputeColors(tess.shader->stages[0], tess.svars[0], 0, tess.numVertexes); gal.SetDepthRange(0, 0); gal.Draw(DT_GENERIC); gal.SetDepthRange(0, 1); RB_PopShader(); } if (r_shownormals->integer) { - const int nv = tess.numVertexes; + // we only draw the normals for the first (SHADER_MAX_VERTEXES / 2 - 1) vertices + int nv = tess.numVertexes; + if (nv >= SHADER_MAX_VERTEXES / 2) + nv = SHADER_MAX_VERTEXES / 2 - 1; for (int i = 0, j = nv; i < nv; ++i, ++j) { VectorMA(input->xyz[i], 2, input->normal[i], tess.xyz[j]); } - for (int i = 0, j = 0; i < nv; ++i) { - tess.indexes[j++] = i; - tess.indexes[j++] = i; - tess.indexes[j++] = i + nv; + for (int i = 0, j = 0; i < nv; ++i, j += 3) { + tess.indexes[j + 0] = i; + tess.indexes[j + 1] = i; + tess.indexes[j + 2] = i + nv; } tess.numVertexes = nv * 2; tess.numIndexes = nv * 3; @@ -214,6 +218,7 @@ void RB_EndSurface() stage->constantColor[1] = 0; stage->constantColor[2] = 255; stage->constantColor[3] = 255; + R_ComputeColors(tess.shader->stages[0], tess.svars[0], 0, tess.numVertexes); gal.SetDepthRange(0, 0); gal.Draw(DT_GENERIC); gal.SetDepthRange(0, 1);