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
This commit is contained in:
myT 2019-12-26 16:16:30 +01:00
parent 554d80ba64
commit 4968bfca6d
3 changed files with 14 additions and 7 deletions

View file

@ -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;

View file

@ -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 );

View file

@ -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);