From b0f0376a4fd5609f55f91dbf4838188515a7a58a Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Mon, 6 May 2013 18:01:44 -0700 Subject: [PATCH] Misc fixes to IBO code to correctly use sizeof(glIndex_t) --- code/renderergl2/tr_shade.c | 4 ++-- code/renderergl2/tr_sky.c | 2 +- code/renderergl2/tr_surface.c | 4 ++-- code/renderergl2/tr_vbo.c | 13 +++++-------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/code/renderergl2/tr_shade.c b/code/renderergl2/tr_shade.c index 633b3f43..adb164e5 100644 --- a/code/renderergl2/tr_shade.c +++ b/code/renderergl2/tr_shade.c @@ -44,9 +44,9 @@ R_DrawElements void R_DrawElementsVBO( int numIndexes, glIndex_t firstIndex, glIndex_t minIndex, glIndex_t maxIndex ) { if (glRefConfig.drawRangeElements) - qglDrawRangeElementsEXT(GL_TRIANGLES, minIndex, maxIndex, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE))); + qglDrawRangeElementsEXT(GL_TRIANGLES, minIndex, maxIndex, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(glIndex_t))); else - qglDrawElements(GL_TRIANGLES, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE))); + qglDrawElements(GL_TRIANGLES, numIndexes, GL_INDEX_TYPE, BUFFER_OFFSET(firstIndex * sizeof(glIndex_t))); } diff --git a/code/renderergl2/tr_sky.c b/code/renderergl2/tr_sky.c index f1e5249d..75970740 100644 --- a/code/renderergl2/tr_sky.c +++ b/code/renderergl2/tr_sky.c @@ -468,7 +468,7 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max 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))); + //qglDrawElements(GL_TRIANGLES, tess.numIndexes - tess.firstIndex, GL_INDEX_TYPE, BUFFER_OFFSET(tess.firstIndex * sizeof(glIndex_t))); //R_BindNullVBO(); //R_BindNullIBO(); diff --git a/code/renderergl2/tr_surface.c b/code/renderergl2/tr_surface.c index 427d153d..ba1825f4 100644 --- a/code/renderergl2/tr_surface.c +++ b/code/renderergl2/tr_surface.c @@ -437,8 +437,8 @@ static qboolean RB_SurfaceVbo(VBO_t *vbo, IBO_t *ibo, int numVerts, int numIndex // merge this into any existing multidraw primitives mergeForward = -1; mergeBack = -1; - firstIndexOffset = BUFFER_OFFSET(firstIndex * sizeof(GL_INDEX_TYPE)); - lastIndexOffset = BUFFER_OFFSET((firstIndex + numIndexes) * sizeof(GL_INDEX_TYPE)); + firstIndexOffset = BUFFER_OFFSET(firstIndex * sizeof(glIndex_t)); + lastIndexOffset = BUFFER_OFFSET((firstIndex + numIndexes) * sizeof(glIndex_t)); if (r_mergeMultidraws->integer) { diff --git a/code/renderergl2/tr_vbo.c b/code/renderergl2/tr_vbo.c index e9f2598b..09f6104a 100644 --- a/code/renderergl2/tr_vbo.c +++ b/code/renderergl2/tr_vbo.c @@ -506,12 +506,11 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * IBO_t *ibo; int i, j; - byte *indexes; + glIndex_t *indexes; int indexesSize; - int indexesOfs; + int indexesCount; srfTriangle_t *tri; - glIndex_t index; int glUsage; switch (usage) @@ -548,17 +547,15 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * Q_strncpyz(ibo->name, name, sizeof(ibo->name)); - indexesSize = numTriangles * 3 * sizeof(int); + indexesSize = numTriangles * 3 * sizeof(glIndex_t); indexes = ri.Hunk_AllocateTempMemory(indexesSize); - indexesOfs = 0; + indexesCount = 0; for(i = 0, tri = triangles; i < numTriangles; i++, tri++) { for(j = 0; j < 3; j++) { - index = tri->indexes[j]; - memcpy(indexes + indexesOfs, &index, sizeof(glIndex_t)); - indexesOfs += sizeof(glIndex_t); + indexes[indexesCount++] = tri->indexes[j]; } }