Skip to content

Commit

Permalink
When calling qglDrawRangeElementsEXT(), use proper start and end para…
Browse files Browse the repository at this point in the history
…meters.
  • Loading branch information
SmileTheory committed Nov 7, 2012
1 parent 8234225 commit 86984eb
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 36 deletions.
8 changes: 7 additions & 1 deletion code/rend2/tr_backend.c
Expand Up @@ -974,6 +974,8 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
tess.numIndexes = 0;
tess.numVertexes = 0;
tess.firstIndex = 0;
tess.minIndex = 0;
tess.maxIndex = 0;

tess.xyz[tess.numVertexes][0] = x;
tess.xyz[tess.numVertexes][1] = y;
Expand Down Expand Up @@ -1021,6 +1023,8 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
tess.indexes[tess.numIndexes++] = 0;
tess.indexes[tess.numIndexes++] = 2;
tess.indexes[tess.numIndexes++] = 3;
tess.minIndex = 0;
tess.maxIndex = 3;

// FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function
RB_UpdateVBOs(ATTR_POSITION | ATTR_TEXCOORD);
Expand All @@ -1035,14 +1039,16 @@ void RE_StretchRaw (int x, int y, int w, int h, int cols, int rows, const byte *
VectorSet4(color, 1, 1, 1, 1);
GLSL_SetUniformVec4(sp, TEXTURECOLOR_UNIFORM_COLOR, color);

R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex);

//R_BindNullVBO();
//R_BindNullIBO();

tess.numIndexes = 0;
tess.numVertexes = 0;
tess.firstIndex = 0;
tess.minIndex = 0;
tess.maxIndex = 0;
}

void RE_UploadCinematic (int w, int h, int cols, int rows, const byte *data, int client, qboolean dirty) {
Expand Down
24 changes: 24 additions & 0 deletions code/rend2/tr_bsp.c
Expand Up @@ -1939,11 +1939,16 @@ static void R_CreateWorldVBO(void)
{
srfTriangle_t *tri;

srf->minIndex = numVerts + srf->triangles->indexes[0];
srf->maxIndex = numVerts + srf->triangles->indexes[0];

for(i = 0, tri = srf->triangles; i < srf->numTriangles; i++, tri++)
{
for(j = 0; j < 3; j++)
{
triangles[numTriangles + i].indexes[j] = numVerts + tri->indexes[j];
srf->minIndex = MIN(srf->minIndex, numVerts + tri->indexes[j]);
srf->maxIndex = MAX(srf->maxIndex, numVerts + tri->indexes[j]);
}
}

Expand All @@ -1963,11 +1968,16 @@ static void R_CreateWorldVBO(void)
{
srfTriangle_t *tri;

srf->minIndex = numVerts + srf->triangles->indexes[0];
srf->maxIndex = numVerts + srf->triangles->indexes[0];

for(i = 0, tri = srf->triangles; i < srf->numTriangles; i++, tri++)
{
for(j = 0; j < 3; j++)
{
triangles[numTriangles + i].indexes[j] = numVerts + tri->indexes[j];
srf->minIndex = MIN(srf->minIndex, numVerts + tri->indexes[j]);
srf->maxIndex = MAX(srf->maxIndex, numVerts + tri->indexes[j]);
}
}

Expand All @@ -1987,11 +1997,16 @@ static void R_CreateWorldVBO(void)
{
srfTriangle_t *tri;

srf->minIndex = numVerts + srf->triangles->indexes[0];
srf->maxIndex = numVerts + srf->triangles->indexes[0];

for(i = 0, tri = srf->triangles; i < srf->numTriangles; i++, tri++)
{
for(j = 0; j < 3; j++)
{
triangles[numTriangles + i].indexes[j] = numVerts + tri->indexes[j];
srf->minIndex = MIN(srf->minIndex, numVerts + tri->indexes[j]);
srf->maxIndex = MAX(srf->maxIndex, numVerts + tri->indexes[j]);
}
}

Expand Down Expand Up @@ -3101,6 +3116,15 @@ void R_MergeLeafSurfaces(void)
vboSurf->numVerts = numVerts;
vboSurf->firstIndex = firstIndex;

vboSurf->minIndex = *(iboIndexes + firstIndex);
vboSurf->maxIndex = *(iboIndexes + firstIndex);

for (j = 1; j < numTriangles * 3; j++)
{
vboSurf->minIndex = MIN(vboSurf->minIndex, *(iboIndexes + firstIndex + j));
vboSurf->maxIndex = MAX(vboSurf->maxIndex, *(iboIndexes + firstIndex + j));
}

vboSurf->shader = surf1->shader;
vboSurf->fogIndex = surf1->fogIndex;

Expand Down
20 changes: 17 additions & 3 deletions code/rend2/tr_local.h
Expand Up @@ -1151,6 +1151,8 @@ typedef struct srfGridMesh_s
// BSP VBO offsets
int firstVert;
int firstIndex;
glIndex_t minIndex;
glIndex_t maxIndex;

// static render data
VBO_t *vbo; // points to bsp model VBO
Expand Down Expand Up @@ -1180,6 +1182,8 @@ typedef struct
// BSP VBO offsets
int firstVert;
int firstIndex;
glIndex_t minIndex;
glIndex_t maxIndex;

// static render data
VBO_t *vbo; // points to bsp model VBO
Expand Down Expand Up @@ -1209,6 +1213,8 @@ typedef struct
// BSP VBO offsets
int firstVert;
int firstIndex;
glIndex_t minIndex;
glIndex_t maxIndex;

// static render data
VBO_t *vbo; // points to bsp model VBO
Expand Down Expand Up @@ -1267,6 +1273,8 @@ typedef struct srfVBOMesh_s
int numIndexes;
int numVerts;
int firstIndex;
glIndex_t minIndex;
glIndex_t maxIndex;

// static render data
VBO_t *vbo;
Expand All @@ -1283,6 +1291,8 @@ typedef struct srfVBOMDVMesh_s
// backEnd stats
int numIndexes;
int numVerts;
glIndex_t minIndex;
glIndex_t maxIndex;

// static render data
VBO_t *vbo;
Expand Down Expand Up @@ -2363,11 +2373,15 @@ typedef struct shaderCommands_s
int firstIndex;
int numIndexes;
int numVertexes;
glIndex_t minIndex;
glIndex_t maxIndex;

int multiDrawPrimitives;
GLsizei multiDrawNumIndexes[MAX_MULTIDRAW_PRIMITIVES];
GLvoid * multiDrawFirstIndex[MAX_MULTIDRAW_PRIMITIVES];
GLvoid * multiDrawLastIndex[MAX_MULTIDRAW_PRIMITIVES];
glIndex_t *multiDrawFirstIndex[MAX_MULTIDRAW_PRIMITIVES];
glIndex_t *multiDrawLastIndex[MAX_MULTIDRAW_PRIMITIVES];
glIndex_t multiDrawMinIndex[MAX_MULTIDRAW_PRIMITIVES];
glIndex_t multiDrawMaxIndex[MAX_MULTIDRAW_PRIMITIVES];

// info extracted from current shader
int numPasses;
Expand All @@ -2382,7 +2396,7 @@ void RB_EndSurface(void);
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);}

void R_DrawElementsVBO( int numIndexes, int firstIndex );
void R_DrawElementsVBO( int numIndexes, glIndex_t firstIndex, glIndex_t minIndex, glIndex_t maxIndex );
void RB_StageIteratorGeneric( void );
void RB_StageIteratorSky( void );
void RB_StageIteratorVertexLitTexture( void );
Expand Down
4 changes: 4 additions & 0 deletions code/rend2/tr_model.c
Expand Up @@ -762,6 +762,10 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize,
vboSurf->mdvSurface = surf;
vboSurf->numIndexes = surf->numTriangles * 3;
vboSurf->numVerts = surf->numVerts;

vboSurf->minIndex = 0;
vboSurf->maxIndex = surf->numVerts;

vboSurf->vbo = R_CreateVBO(va("staticMD3Mesh_VBO '%s'", surf->name), data, dataSize, VBO_USAGE_STATIC);

vboSurf->vbo->ofs_xyz = ofs_xyz;
Expand Down
45 changes: 24 additions & 21 deletions code/rend2/tr_shade.c
Expand Up @@ -41,21 +41,22 @@ R_DrawElements
==================
*/

void R_DrawElementsVBO( int numIndexes, int firstIndex )
void R_DrawElementsVBO( int numIndexes, glIndex_t firstIndex, glIndex_t minIndex, glIndex_t maxIndex )
{
if (glRefConfig.drawRangeElements)
qglDrawRangeElementsEXT(GL_TRIANGLES, 0, numIndexes, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)));
qglDrawRangeElementsEXT(GL_TRIANGLES, minIndex, maxIndex, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)));
else
qglDrawElements(GL_TRIANGLES, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)));

}


static void R_DrawMultiElementsVBO( int multiDrawPrimitives, const GLvoid **multiDrawFirstIndex, GLsizei *multiDrawNumIndexes )
static void R_DrawMultiElementsVBO( int multiDrawPrimitives, glIndex_t *multiDrawMinIndex, glIndex_t *multiDrawMaxIndex,
GLsizei *multiDrawNumIndexes, glIndex_t **multiDrawFirstIndex)
{
if (glRefConfig.multiDrawArrays)
{
qglMultiDrawElementsEXT(GL_TRIANGLES, multiDrawNumIndexes, GL_INDEX_TYPE, multiDrawFirstIndex, multiDrawPrimitives);
qglMultiDrawElementsEXT(GL_TRIANGLES, multiDrawNumIndexes, GL_INDEX_TYPE, (const GLvoid **)multiDrawFirstIndex, multiDrawPrimitives);
}
else
{
Expand All @@ -65,7 +66,7 @@ static void R_DrawMultiElementsVBO( int multiDrawPrimitives, const GLvoid **mult
{
for (i = 0; i < multiDrawPrimitives; i++)
{
qglDrawRangeElementsEXT(GL_TRIANGLES, 0, multiDrawNumIndexes[i], multiDrawNumIndexes[i], GL_INDEX_TYPE, multiDrawFirstIndex[i]);
qglDrawRangeElementsEXT(GL_TRIANGLES, multiDrawMinIndex[i], multiDrawMaxIndex[i], multiDrawNumIndexes[i], GL_INDEX_TYPE, multiDrawFirstIndex[i]);
}
}
else
Expand Down Expand Up @@ -153,11 +154,11 @@ static void DrawTris (shaderCommands_t *input) {

if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}
}

Expand Down Expand Up @@ -404,11 +405,12 @@ static void ProjectDlightTexture( void ) {

if (tess.multiDrawPrimitives)
{
R_DrawMultiElementsVBO(tess.multiDrawPrimitives, (const GLvoid **)tess.multiDrawFirstIndex, tess.multiDrawNumIndexes);
shaderCommands_t *input = &tess;
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex);
}

backEnd.pc.c_totalIndexes += tess.numIndexes;
Expand Down Expand Up @@ -856,11 +858,11 @@ static void ForwardDlight( void ) {

if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}

backEnd.pc.c_totalIndexes += tess.numIndexes;
Expand Down Expand Up @@ -1052,11 +1054,11 @@ static void ForwardSunlight( void ) {

if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}

backEnd.pc.c_totalIndexes += tess.numIndexes;
Expand Down Expand Up @@ -1127,11 +1129,11 @@ static void ProjectPshadowVBOGLSL( void ) {

if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}

backEnd.pc.c_totalIndexes += tess.numIndexes;
Expand Down Expand Up @@ -1197,11 +1199,12 @@ static void RB_FogPass( void ) {

if (tess.multiDrawPrimitives)
{
R_DrawMultiElementsVBO(tess.multiDrawPrimitives, (const GLvoid **)tess.multiDrawFirstIndex, tess.multiDrawNumIndexes);
shaderCommands_t *input = &tess;
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex, tess.minIndex, tess.maxIndex);
}
}

Expand Down Expand Up @@ -1519,11 +1522,11 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
//
if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}

// allow skipping out to show just lightmaps during development
Expand Down Expand Up @@ -1583,11 +1586,11 @@ static void RB_RenderShadowmap( shaderCommands_t *input )

if (input->multiDrawPrimitives)
{
R_DrawMultiElementsVBO(input->multiDrawPrimitives, (const GLvoid **)input->multiDrawFirstIndex, input->multiDrawNumIndexes);
R_DrawMultiElementsVBO(input->multiDrawPrimitives, input->multiDrawMinIndex, input->multiDrawMaxIndex, input->multiDrawNumIndexes, input->multiDrawFirstIndex);
}
else
{
R_DrawElementsVBO(input->numIndexes, input->firstIndex);
R_DrawElementsVBO(input->numIndexes, input->firstIndex, input->minIndex, input->maxIndex);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion code/rend2/tr_sky.c
Expand Up @@ -366,6 +366,8 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
int s, t;
int firstVertex = tess.numVertexes;
//int firstIndex = tess.numIndexes;
int minIndex = tess.minIndex;
int maxIndex = tess.maxIndex;
vec4_t color;

//tess.numVertexes = 0;
Expand Down Expand Up @@ -415,6 +417,9 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
}
}

tess.minIndex = firstVertex;
tess.maxIndex = tess.numVertexes;

// FIXME: A lot of this can probably be removed for speed, and refactored into a more convenient function
RB_UpdateVBOs(ATTR_POSITION | ATTR_TEXCOORD);
/*
Expand Down Expand Up @@ -458,7 +463,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
}

R_DrawElementsVBO(tess.numIndexes - tess.firstIndex, tess.firstIndex);
R_DrawElementsVBO(tess.numIndexes - tess.firstIndex, tess.firstIndex, tess.minIndex, tess.maxIndex);

//qglDrawElements(GL_TRIANGLES, tess.numIndexes - tess.firstIndex, GL_INDEX_TYPE, BUFFER_OFFSET(tess.firstIndex * sizeof(GL_INDEX_TYPE)));

Expand All @@ -468,6 +473,8 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
tess.numIndexes = tess.firstIndex;
tess.numVertexes = firstVertex;
tess.firstIndex = 0;
tess.minIndex = minIndex;
tess.maxIndex = maxIndex;
}

static void DrawSkyBox( shader_t *shader )
Expand Down

0 comments on commit 86984eb

Please sign in to comment.