diff options
author | SmileTheory <SmileTheory@gmail.com> | 2013-11-08 01:46:17 -0800 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2014-06-17 17:43:36 +0100 |
commit | 877ec28e7cab95c190366ae2d3d26955bc6993d7 (patch) | |
tree | 12be964e06132c9e08ab16f60573b94cda301eee | |
parent | 98078a30922ff0da92f7023b18f954f894058a18 (diff) |
OpenGL2: Remove srfTriangle_t, and use glIndex_t instead.
-rw-r--r-- | src/renderergl2/tr_bsp.c | 148 | ||||
-rw-r--r-- | src/renderergl2/tr_curve.c | 124 | ||||
-rw-r--r-- | src/renderergl2/tr_local.h | 18 | ||||
-rw-r--r-- | src/renderergl2/tr_main.c | 6 | ||||
-rw-r--r-- | src/renderergl2/tr_marks.c | 12 | ||||
-rw-r--r-- | src/renderergl2/tr_model.c | 38 | ||||
-rw-r--r-- | src/renderergl2/tr_surface.c | 50 | ||||
-rw-r--r-- | src/renderergl2/tr_vbo.c | 15 |
8 files changed, 176 insertions, 235 deletions
diff --git a/src/renderergl2/tr_bsp.c b/src/renderergl2/tr_bsp.c index 2867d13e..797ac354 100644 --- a/src/renderergl2/tr_bsp.c +++ b/src/renderergl2/tr_bsp.c @@ -654,8 +654,8 @@ ParseFace static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, msurface_t *surf, int *indexes ) { int i, j; srfBspSurface_t *cv; - srfTriangle_t *tri; - int numVerts, numTriangles, badTriangles; + glIndex_t *tri; + int numVerts, numIndexes, badTriangles; int realLightmapNum; realLightmapNum = LittleLong( ds->lightmapNum ); @@ -676,14 +676,14 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, surf->shader = tr.defaultShader; } - numTriangles = LittleLong(ds->numIndexes) / 3; + numIndexes = LittleLong(ds->numIndexes); //cv = ri.Hunk_Alloc(sizeof(*cv), h_low); cv = (void *)surf->data; cv->surfaceType = SF_FACE; - cv->numTriangles = numTriangles; - cv->triangles = ri.Hunk_Alloc(numTriangles * sizeof(cv->triangles[0]), h_low); + cv->numIndexes = numIndexes; + cv->indexes = ri.Hunk_Alloc(numIndexes * sizeof(cv->indexes[0]), h_low); cv->numVerts = numVerts; cv->verts = ri.Hunk_Alloc(numVerts * sizeof(cv->verts[0]), h_low); @@ -741,29 +741,29 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, // copy triangles badTriangles = 0; indexes += LittleLong(ds->firstIndex); - for(i = 0, tri = cv->triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = cv->indexes; i < numIndexes; i += 3, tri += 3) { for(j = 0; j < 3; j++) { - tri->indexes[j] = LittleLong(indexes[i * 3 + j]); + tri[j] = LittleLong(indexes[i + j]); - if(tri->indexes[j] < 0 || tri->indexes[j] >= numVerts) + if(tri[j] < 0 || tri[j] >= numVerts) { ri.Error(ERR_DROP, "Bad index in face surface"); } } - if ((tri->indexes[0] == tri->indexes[1]) || (tri->indexes[1] == tri->indexes[2]) || (tri->indexes[0] == tri->indexes[2])) + if ((tri[0] == tri[1]) || (tri[1] == tri[2]) || (tri[0] == tri[2])) { - tri--; + tri -= 3; badTriangles++; } } if (badTriangles) { - ri.Printf(PRINT_WARNING, "Face has bad triangles, originally shader %s %d tris %d verts, now %d tris\n", surf->shader->name, numTriangles, numVerts, numTriangles - badTriangles); - cv->numTriangles -= badTriangles; + ri.Printf(PRINT_WARNING, "Face has bad triangles, originally shader %s %d tris %d verts, now %d tris\n", surf->shader->name, numIndexes / 3, numVerts, numIndexes / 3 - badTriangles); + cv->numIndexes -= badTriangles * 3; } // take the plane information from the lightmap vector @@ -782,11 +782,11 @@ static void ParseFace( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, { srfVert_t *dv[3]; - for(i = 0, tri = cv->triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = cv->indexes; i < numIndexes; i += 3, tri += 3) { - dv[0] = &cv->verts[tri->indexes[0]]; - dv[1] = &cv->verts[tri->indexes[1]]; - dv[2] = &cv->verts[tri->indexes[2]]; + dv[0] = &cv->verts[tri[0]]; + dv[1] = &cv->verts[tri[1]]; + dv[2] = &cv->verts[tri[2]]; R_CalcTangentVectors(dv); } @@ -905,9 +905,9 @@ ParseTriSurf */ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, msurface_t *surf, int *indexes ) { srfBspSurface_t *cv; - srfTriangle_t *tri; + glIndex_t *tri; int i, j; - int numVerts, numTriangles, badTriangles; + int numVerts, numIndexes, badTriangles; // get fog volume surf->fogIndex = LittleLong( ds->fogNum ) + 1; @@ -919,14 +919,14 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, float *hdrVertColor } numVerts = LittleLong(ds->numVerts); - numTriangles = LittleLong(ds->numIndexes) / 3; + numIndexes = LittleLong(ds->numIndexes); //cv = ri.Hunk_Alloc(sizeof(*cv), h_low); cv = (void *)surf->data; cv->surfaceType = SF_TRIANGLES; - cv->numTriangles = numTriangles; - cv->triangles = ri.Hunk_Alloc(numTriangles * sizeof(cv->triangles[0]), h_low); + cv->numIndexes = numIndexes; + cv->indexes = ri.Hunk_Alloc(numIndexes * sizeof(cv->indexes[0]), h_low); cv->numVerts = numVerts; cv->verts = ri.Hunk_Alloc(numVerts * sizeof(cv->verts[0]), h_low); @@ -985,29 +985,29 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, float *hdrVertColor // copy triangles badTriangles = 0; indexes += LittleLong(ds->firstIndex); - for(i = 0, tri = cv->triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = cv->indexes; i < numIndexes; i += 3, tri += 3) { for(j = 0; j < 3; j++) { - tri->indexes[j] = LittleLong(indexes[i * 3 + j]); + tri[j] = LittleLong(indexes[i + j]); - if(tri->indexes[j] < 0 || tri->indexes[j] >= numVerts) + if(tri[j] < 0 || tri[j] >= numVerts) { ri.Error(ERR_DROP, "Bad index in face surface"); } } - if ((tri->indexes[0] == tri->indexes[1]) || (tri->indexes[1] == tri->indexes[2]) || (tri->indexes[0] == tri->indexes[2])) + if ((tri[0] == tri[1]) || (tri[1] == tri[2]) || (tri[0] == tri[2])) { - tri--; + tri -= 3; badTriangles++; } } if (badTriangles) { - ri.Printf(PRINT_WARNING, "Trisurf has bad triangles, originally shader %s %d tris %d verts, now %d tris\n", surf->shader->name, numTriangles, numVerts, numTriangles - badTriangles); - cv->numTriangles -= badTriangles; + ri.Printf(PRINT_WARNING, "Trisurf has bad triangles, originally shader %s %d tris %d verts, now %d tris\n", surf->shader->name, numIndexes / 3, numVerts, numIndexes / 3 - badTriangles); + cv->numIndexes -= badTriangles * 3; } #ifdef USE_VERT_TANGENT_SPACE @@ -1015,11 +1015,11 @@ static void ParseTriSurf( dsurface_t *ds, drawVert_t *verts, float *hdrVertColor { srfVert_t *dv[3]; - for(i = 0, tri = cv->triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = cv->indexes; i < numIndexes; i += 3, tri += 3) { - dv[0] = &cv->verts[tri->indexes[0]]; - dv[1] = &cv->verts[tri->indexes[1]]; - dv[2] = &cv->verts[tri->indexes[2]]; + dv[0] = &cv->verts[tri[0]]; + dv[1] = &cv->verts[tri[1]]; + dv[2] = &cv->verts[tri[2]]; R_CalcTangentVectors(dv); } @@ -1748,9 +1748,9 @@ void R_MovePatchSurfacesToHunk(void) { hunkgrid->heightLodError = ri.Hunk_Alloc( grid->height * 4, h_low ); Com_Memcpy( hunkgrid->heightLodError, grid->heightLodError, grid->height * 4 ); - hunkgrid->numTriangles = grid->numTriangles; - hunkgrid->triangles = ri.Hunk_Alloc(grid->numTriangles * sizeof(srfTriangle_t), h_low); - Com_Memcpy(hunkgrid->triangles, grid->triangles, grid->numTriangles * sizeof(srfTriangle_t)); + hunkgrid->numIndexes = grid->numIndexes; + hunkgrid->indexes = ri.Hunk_Alloc(grid->numIndexes * sizeof(glIndex_t), h_low); + Com_Memcpy(hunkgrid->indexes, grid->indexes, grid->numIndexes * sizeof(glIndex_t)); hunkgrid->numVerts = grid->numVerts; hunkgrid->verts = ri.Hunk_Alloc(grid->numVerts * sizeof(srfVert_t), h_low); @@ -1842,8 +1842,8 @@ static void R_CreateWorldVBOs(void) int numVerts; srfVert_t *verts; - int numTriangles; - srfTriangle_t *triangles; + int numIndexes; + glIndex_t *indexes; int numSortedSurfaces, numSurfaces; msurface_t *surface, **firstSurf, **lastSurf, **currSurf; @@ -1881,7 +1881,7 @@ static void R_CreateWorldVBOs(void) bspSurf = (srfBspSurface_t *) surface->data; - if (!bspSurf->numTriangles || !bspSurf->numVerts) + if (!bspSurf->numIndexes || !bspSurf->numVerts) continue; numSortedSurfaces++; @@ -1911,7 +1911,7 @@ static void R_CreateWorldVBOs(void) bspSurf = (srfBspSurface_t *) surface->data; - if (!bspSurf->numTriangles || !bspSurf->numVerts) + if (!bspSurf->numIndexes || !bspSurf->numVerts) continue; surfacesSorted[j++] = surface; @@ -1940,7 +1940,7 @@ static void R_CreateWorldVBOs(void) srfBspSurface_t *bspSurf = (srfBspSurface_t *) (*currSurf)->data; addVboSize += bspSurf->numVerts * sizeof(srfVert_t); - addIboSize += bspSurf->numTriangles * 3 * sizeof(glIndex_t); + addIboSize += bspSurf->numIndexes * sizeof(glIndex_t); } if ((currVboSize != 0 && addVboSize + currVboSize > maxVboSize) @@ -1953,56 +1953,50 @@ static void R_CreateWorldVBOs(void) currIboSize += addIboSize; } - // count verts/triangles/surfaces + // count verts/indexes/surfaces numVerts = 0; - numTriangles = 0; + numIndexes = 0; numSurfaces = 0; for (currSurf = firstSurf; currSurf < lastSurf; currSurf++) { srfBspSurface_t *bspSurf = (srfBspSurface_t *) (*currSurf)->data; numVerts += bspSurf->numVerts; - numTriangles += bspSurf->numTriangles; + numIndexes += bspSurf->numIndexes; numSurfaces++; } - ri.Printf(PRINT_ALL, "...calculating world VBO %d ( %i verts %i tris )\n", k, numVerts, numTriangles); + ri.Printf(PRINT_ALL, "...calculating world VBO %d ( %i verts %i tris )\n", k, numVerts, numIndexes / 3); // create arrays verts = ri.Hunk_AllocateTempMemory(numVerts * sizeof(srfVert_t)); - triangles = ri.Hunk_AllocateTempMemory(numTriangles * sizeof(srfTriangle_t)); + indexes = ri.Hunk_AllocateTempMemory(numIndexes * sizeof(glIndex_t)); - // set up triangle indices and copy vertices + // set up indices and copy vertices numVerts = 0; - numTriangles = 0; + numIndexes = 0; for (currSurf = firstSurf; currSurf < lastSurf; currSurf++) { srfBspSurface_t *bspSurf = (srfBspSurface_t *) (*currSurf)->data; - srfTriangle_t *tri; + glIndex_t *surfIndex; - bspSurf->firstIndex = numTriangles * 3; - bspSurf->minIndex = numVerts + bspSurf->triangles->indexes[0]; - bspSurf->maxIndex = numVerts + bspSurf->triangles->indexes[0]; + bspSurf->firstIndex = numIndexes; + bspSurf->minIndex = numVerts + bspSurf->indexes[0]; + bspSurf->maxIndex = numVerts + bspSurf->indexes[0]; - for(i = 0, tri = bspSurf->triangles; i < bspSurf->numTriangles; i++, tri++) + for(i = 0, surfIndex = bspSurf->indexes; i < bspSurf->numIndexes; i++, surfIndex++) { - for(j = 0; j < 3; j++) - { - triangles[numTriangles + i].indexes[j] = numVerts + tri->indexes[j]; - bspSurf->minIndex = MIN(bspSurf->minIndex, numVerts + tri->indexes[j]); - bspSurf->maxIndex = MAX(bspSurf->maxIndex, numVerts + tri->indexes[j]); - } + indexes[numIndexes++] = numVerts + *surfIndex; + bspSurf->minIndex = MIN(bspSurf->minIndex, numVerts + *surfIndex); + bspSurf->maxIndex = MAX(bspSurf->maxIndex, numVerts + *surfIndex); } bspSurf->firstVert = numVerts; for(i = 0; i < bspSurf->numVerts; i++) { - CopyVert(&bspSurf->verts[i], &verts[numVerts + i]); + CopyVert(&bspSurf->verts[i], &verts[numVerts++]); } - - numTriangles += bspSurf->numTriangles; - numVerts += bspSurf->numVerts; } #ifdef USE_VERT_TANGENT_SPACE @@ -2015,9 +2009,9 @@ static void R_CreateWorldVBOs(void) ATTR_NORMAL | ATTR_COLOR | ATTR_LIGHTDIRECTION, VBO_USAGE_STATIC); #endif - ibo = R_CreateIBO2(va("staticBspModel0_IBO %i", k), numTriangles, triangles, VBO_USAGE_STATIC); + ibo = R_CreateIBO2(va("staticBspModel0_IBO %i", k), numIndexes, indexes, VBO_USAGE_STATIC); - // point triangle surfaces to VBO + // point bsp surfaces to VBO for (currSurf = firstSurf; currSurf < lastSurf; currSurf++) { srfBspSurface_t *bspSurf = (srfBspSurface_t *) (*currSurf)->data; @@ -2026,7 +2020,7 @@ static void R_CreateWorldVBOs(void) bspSurf->ibo = ibo; } - ri.Hunk_FreeTempMemory(triangles); + ri.Hunk_FreeTempMemory(indexes); ri.Hunk_FreeTempMemory(verts); k++; @@ -2100,7 +2094,7 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump ) { // Two passes, allocate surfaces first, then load them full of data // This ensures surfaces are close together to reduce L2 cache misses when using VBOs, - // which don't actually use the verts and tris + // which don't actually use the verts and indexes in = (void *)(fileBase + surfs->fileofs); out = s_worldData.surfaces; for ( i = 0 ; i < count ; i++, in++, out++ ) { @@ -3086,7 +3080,7 @@ void R_MergeLeafSurfaces(void) vec3_t bounds[2]; int numSurfsToMerge; - int numTriangles; + int numIndexes; int numVerts; int firstIndex; @@ -3102,7 +3096,7 @@ void R_MergeLeafSurfaces(void) // count verts, indexes, and surfaces numSurfsToMerge = 0; - numTriangles = 0; + numIndexes = 0; numVerts = 0; for (j = i; j < numWorldSurfaces; j++) { @@ -3115,12 +3109,12 @@ void R_MergeLeafSurfaces(void) surf2 = s_worldData.surfaces + j; bspSurf = (srfBspSurface_t *) surf2->data; - numTriangles += bspSurf->numTriangles; + numIndexes += bspSurf->numIndexes; numVerts += bspSurf->numVerts; numSurfsToMerge++; } - if (numVerts == 0 || numTriangles == 0 || numSurfsToMerge < 2) + if (numVerts == 0 || numIndexes == 0 || numSurfsToMerge < 2) { continue; } @@ -3132,7 +3126,7 @@ void R_MergeLeafSurfaces(void) numIboIndexes = 0; // allocate indexes - iboIndexes = outIboIndexes = ri.Malloc(numTriangles * 3 * sizeof(*outIboIndexes)); + iboIndexes = outIboIndexes = ri.Malloc(numIndexes * sizeof(*outIboIndexes)); // Merge surfaces (indexes) and calculate bounds ClearBounds(bounds[0], bounds[1]); @@ -3151,12 +3145,10 @@ void R_MergeLeafSurfaces(void) AddPointToBounds(surf2->cullinfo.bounds[1], bounds[0], bounds[1]); bspSurf = (srfBspSurface_t *) surf2->data; - for (k = 0; k < bspSurf->numTriangles; k++) + for (k = 0; k < bspSurf->numIndexes; k++) { - *outIboIndexes++ = bspSurf->triangles[k].indexes[0] + bspSurf->firstVert; - *outIboIndexes++ = bspSurf->triangles[k].indexes[1] + bspSurf->firstVert; - *outIboIndexes++ = bspSurf->triangles[k].indexes[2] + bspSurf->firstVert; - numIboIndexes += 3; + *outIboIndexes++ = bspSurf->indexes[k] + bspSurf->firstVert; + numIboIndexes++; } break; } @@ -3168,14 +3160,14 @@ void R_MergeLeafSurfaces(void) vboSurf->vbo = vbo; vboSurf->ibo = ibo; - vboSurf->numTriangles = numTriangles; + vboSurf->numIndexes = numIndexes; vboSurf->numVerts = numVerts; vboSurf->firstIndex = firstIndex; vboSurf->minIndex = *(iboIndexes + firstIndex); vboSurf->maxIndex = *(iboIndexes + firstIndex); - for (j = 0; j < numTriangles * 3; j++) + for (j = 0; j < numIndexes; j++) { vboSurf->minIndex = MIN(vboSurf->minIndex, *(iboIndexes + firstIndex + j)); vboSurf->maxIndex = MAX(vboSurf->maxIndex, *(iboIndexes + firstIndex + j)); diff --git a/src/renderergl2/tr_curve.c b/src/renderergl2/tr_curve.c index 104e706a..4c5474b1 100644 --- a/src/renderergl2/tr_curve.c +++ b/src/renderergl2/tr_curve.c @@ -214,13 +214,13 @@ static int neighbors[8][2] = { } #ifdef USE_VERT_TANGENT_SPACE -static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], int numTriangles, - srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]) +static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], int numIndexes, + glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { int i, j; srfVert_t *dv[3]; static srfVert_t ctrl2[MAX_GRID_SIZE * MAX_GRID_SIZE]; - srfTriangle_t *tri; + glIndex_t *tri; // FIXME: use more elegant way for(i = 0; i < width; i++) @@ -232,53 +232,15 @@ static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRI } } - for(i = 0, tri = triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = indexes; i < numIndexes; i += 3, tri += 3) { - dv[0] = &ctrl2[tri->indexes[0]]; - dv[1] = &ctrl2[tri->indexes[1]]; - dv[2] = &ctrl2[tri->indexes[2]]; + dv[0] = &ctrl2[tri[0]]; + dv[1] = &ctrl2[tri[1]]; + dv[2] = &ctrl2[tri[2]]; R_CalcTangentVectors(dv); } -#if 0 - for(i = 0; i < (width * height); i++) - { - dv0 = &ctrl2[i]; - - VectorNormalize(dv0->normal); -#if 0 - VectorNormalize(dv0->tangent); - VectorNormalize(dv0->bitangent); -#else - d = DotProduct(dv0->tangent, dv0->normal); - VectorMA(dv0->tangent, -d, dv0->normal, dv0->tangent); - VectorNormalize(dv0->tangent); - - d = DotProduct(dv0->bitangent, dv0->normal); - VectorMA(dv0->bitangent, -d, dv0->normal, dv0->bitangent); - VectorNormalize(dv0->bitangent); -#endif - } -#endif - - -#if 0 - // do another extra smoothing for normals to avoid flat shading - for(i = 0; i < (width * height); i++) - { - for(j = 0; j < (width * height); j++) - { - if(R_CompareVert(&ctrl2[i], &ctrl2[j], qfalse)) - { - VectorAdd(ctrl2[i].normal, ctrl2[j].normal, ctrl2[i].normal); - } - } - - VectorNormalize(ctrl2[i].normal); - } -#endif - for(i = 0; i < width; i++) { for(j = 0; j < height; j++) @@ -294,18 +256,18 @@ static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRI #endif -static int MakeMeshTriangles(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], - srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]) +static int MakeMeshIndexes(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], + glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { int i, j; - int numTriangles; + int numIndexes; int w, h; srfVert_t *dv; static srfVert_t ctrl2[MAX_GRID_SIZE * MAX_GRID_SIZE]; h = height - 1; w = width - 1; - numTriangles = 0; + numIndexes = 0; for(i = 0; i < h; i++) { for(j = 0; j < w; j++) @@ -318,15 +280,13 @@ static int MakeMeshTriangles(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE v3 = v2 + width; v4 = v3 + 1; - triangles[numTriangles].indexes[0] = v2; - triangles[numTriangles].indexes[1] = v3; - triangles[numTriangles].indexes[2] = v1; - numTriangles++; + indexes[numIndexes++] = v2; + indexes[numIndexes++] = v3; + indexes[numIndexes++] = v1; - triangles[numTriangles].indexes[0] = v1; - triangles[numTriangles].indexes[1] = v3; - triangles[numTriangles].indexes[2] = v4; - numTriangles++; + indexes[numIndexes++] = v1; + indexes[numIndexes++] = v3; + indexes[numIndexes++] = v4; } } @@ -340,7 +300,7 @@ static int MakeMeshTriangles(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE } } - return numTriangles; + return numIndexes; } @@ -419,7 +379,7 @@ R_CreateSurfaceGridMesh */ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], float errorTable[2][MAX_GRID_SIZE], - int numTriangles, srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]) { + int numIndexes, glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { int i, j, size; srfVert_t *vert; vec3_t tmpVec; @@ -438,9 +398,9 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, grid->heightLodError = /*ri.Hunk_Alloc*/ ri.Malloc( height * 4 ); Com_Memcpy( grid->heightLodError, errorTable[1], height * 4 ); - grid->numTriangles = numTriangles; - grid->triangles = ri.Malloc(grid->numTriangles * sizeof(srfTriangle_t)); - Com_Memcpy(grid->triangles, triangles, numTriangles * sizeof(srfTriangle_t)); + grid->numIndexes = numIndexes; + grid->indexes = ri.Malloc(grid->numIndexes * sizeof(glIndex_t)); + Com_Memcpy(grid->indexes, indexes, numIndexes * sizeof(glIndex_t)); grid->numVerts = (width * height); grid->verts = ri.Malloc(grid->numVerts * sizeof(srfVert_t)); @@ -454,9 +414,9 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, grid->heightLodError = ri.Hunk_Alloc( height * 4 ); Com_Memcpy( grid->heightLodError, errorTable[1], height * 4 ); - grid->numTriangles = numTriangles; - grid->triangles = ri.Hunk_Alloc(grid->numTriangles * sizeof(srfTriangle_t), h_low); - Com_Memcpy(grid->triangles, triangles, numTriangles * sizeof(srfTriangle_t)); + grid->numIndexes = numIndexes; + grid->indexes = ri.Hunk_Alloc(grid->numIndexes * sizeof(glIndex_t), h_low); + Com_Memcpy(grid->indexes, indexes, numIndexes * sizeof(glIndex_t)); grid->numVerts = (width * height); grid->verts = ri.Hunk_Alloc(grid->numVerts * sizeof(srfVert_t), h_low); @@ -494,7 +454,7 @@ R_FreeSurfaceGridMesh void R_FreeSurfaceGridMesh( srfBspSurface_t *grid ) { ri.Free(grid->widthLodError); ri.Free(grid->heightLodError); - ri.Free(grid->triangles); + ri.Free(grid->indexes); ri.Free(grid->verts); ri.Free(grid); } @@ -515,8 +475,8 @@ srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, int t; srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; float errorTable[2][MAX_GRID_SIZE]; - int numTriangles; - static srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]; + int numIndexes; + static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; int consecutiveComplete; for ( i = 0 ; i < width ; i++ ) { @@ -670,16 +630,16 @@ srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, } #endif - // calculate triangles - numTriangles = MakeMeshTriangles(width, height, ctrl, triangles); + // calculate indexes + numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); #ifdef USE_VERT_TANGENT_SPACE - MakeMeshTangentVectors(width, height, ctrl, numTriangles, triangles); + MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); #endif - return R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numTriangles, triangles); + return R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); } /* @@ -694,8 +654,8 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, float errorTable[2][MAX_GRID_SIZE]; float lodRadius; vec3_t lodOrigin; - int numTriangles; - static srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]; + int numIndexes; + static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; oldwidth = 0; width = grid->width + 1; @@ -725,8 +685,8 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, // put all the aproximating points on the curve //PutPointsOnCurve( ctrl, width, height ); - // calculate triangles - numTriangles = MakeMeshTriangles(width, height, ctrl, triangles); + // calculate indexes + numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); @@ -736,7 +696,7 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, // free the old grid R_FreeSurfaceGridMesh(grid); // create a new grid - grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numTriangles, triangles); + grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); grid->lodRadius = lodRadius; VectorCopy(lodOrigin, grid->lodOrigin); return grid; @@ -754,8 +714,8 @@ srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, ve float errorTable[2][MAX_GRID_SIZE]; float lodRadius; vec3_t lodOrigin; - int numTriangles; - static srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]; + int numIndexes; + static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; oldheight = 0; width = grid->width; @@ -785,8 +745,8 @@ srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, ve // put all the aproximating points on the curve //PutPointsOnCurve( ctrl, width, height ); - // calculate triangles - numTriangles = MakeMeshTriangles(width, height, ctrl, triangles); + // calculate indexes + numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); @@ -796,7 +756,7 @@ srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, ve // free the old grid R_FreeSurfaceGridMesh(grid); // create a new grid - grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numTriangles, triangles); + grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); grid->lodRadius = lodRadius; VectorCopy(lodOrigin, grid->lodOrigin); return grid; diff --git a/src/renderergl2/tr_local.h b/src/renderergl2/tr_local.h index 6f56f139..b56fdf0d 100644 --- a/src/renderergl2/tr_local.h +++ b/src/renderergl2/tr_local.h @@ -1004,12 +1004,6 @@ typedef struct #define srfVert_t_cleared(x) srfVert_t (x) = {{0, 0, 0}, {0, 0}, {0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0, 0}} #endif -typedef struct -{ - int indexes[3]; - int neighbors[3]; -} srfTriangle_t; - // srfBspSurface_t covers SF_GRID, SF_TRIANGLES, SF_POLY, and SF_VBO_MESH typedef struct srfBspSurface_s { @@ -1025,9 +1019,9 @@ typedef struct srfBspSurface_s float cullRadius; cplane_t cullPlane; - // triangle definitions - int numTriangles; - srfTriangle_t *triangles; + // indexes + int numIndexes; + glIndex_t *indexes; // vertexes int numVerts; @@ -1327,8 +1321,8 @@ typedef struct mdvSurface_s mdvVertex_t *verts; mdvSt_t *st; - int numTriangles; - srfTriangle_t *triangles; + int numIndexes; + glIndex_t *indexes; struct mdvModel_s *model; } mdvSurface_t; @@ -2278,7 +2272,7 @@ VBO_t *R_CreateVBO(const char *name, byte * vertexes, int vertexesSize, VBO_t *R_CreateVBO2(const char *name, int numVertexes, srfVert_t * vertexes, uint32_t stateBits, vboUsage_t usage); IBO_t *R_CreateIBO(const char *name, byte * indexes, int indexesSize, vboUsage_t usage); -IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * triangles, vboUsage_t usage); +IBO_t *R_CreateIBO2(const char *name, int numIndexes, glIndex_t * inIndexes, vboUsage_t usage); void R_BindVBO(VBO_t * vbo); void R_BindNullVBO(void); diff --git a/src/renderergl2/tr_main.c b/src/renderergl2/tr_main.c index b0362a88..ca6bab3c 100644 --- a/src/renderergl2/tr_main.c +++ b/src/renderergl2/tr_main.c @@ -1289,9 +1289,9 @@ void R_PlaneForSurface (surfaceType_t *surfType, cplane_t *plane) { return; case SF_TRIANGLES: tri = (srfBspSurface_t *)surfType; - v1 = tri->verts + tri->triangles[0].indexes[0]; - v2 = tri->verts + tri->triangles[0].indexes[1]; - v3 = tri->verts + tri->triangles[0].indexes[2]; + v1 = tri->verts + tri->indexes[0]; + v2 = tri->verts + tri->indexes[1]; + v3 = tri->verts + tri->indexes[2]; PlaneFromPoints( plane4, v1->xyz, v2->xyz, v3->xyz ); VectorCopy( plane4, plane->normal ); plane->dist = plane4[3]; diff --git a/src/renderergl2/tr_marks.c b/src/renderergl2/tr_marks.c index 3fe41d1c..f698262c 100644 --- a/src/renderergl2/tr_marks.c +++ b/src/renderergl2/tr_marks.c @@ -270,7 +270,7 @@ int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projectio int numClipPoints; float *v; srfBspSurface_t *cv; - srfTriangle_t *tri; + glIndex_t *tri; srfVert_t *dv; vec3_t normal; vec3_t projectionDir; @@ -415,11 +415,11 @@ int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projectio continue; } - for(k = 0, tri = surf->triangles; k < surf->numTriangles; k++, tri++) + for(k = 0, tri = surf->indexes; k < surf->numIndexes; k += 3, tri += 3) { for(j = 0; j < 3; j++) { - v = surf->verts[tri->indexes[j]].xyz; + v = surf->verts[tri[j]].xyz; VectorMA(v, MARKER_OFFSET, surf->cullPlane.normal, clipPoints[0][j]); } @@ -438,12 +438,12 @@ int R_MarkFragments( int numPoints, const vec3_t *points, const vec3_t projectio srfBspSurface_t *surf = (srfBspSurface_t *) surfaces[i]; - for(k = 0, tri = surf->triangles; k < surf->numTriangles; k++, tri++) + for(k = 0, tri = surf->indexes; k < surf->numIndexes; k += 3, tri += 3) { for(j = 0; j < 3; j++) { - v = surf->verts[tri->indexes[j]].xyz; - VectorMA(v, MARKER_OFFSET, surf->verts[tri->indexes[j]].normal, clipPoints[0][j]); + v = surf->verts[tri[j]].xyz; + VectorMA(v, MARKER_OFFSET, surf->verts[tri[j]].normal, clipPoints[0][j]); } // add the fragments of this face diff --git a/src/renderergl2/tr_model.c b/src/renderergl2/tr_model.c index 34aff630..c4c2a247 100644 --- a/src/renderergl2/tr_model.c +++ b/src/renderergl2/tr_model.c @@ -395,7 +395,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, mdvFrame_t *frame; mdvSurface_t *surf;//, *surface; int *shaderIndex; - srfTriangle_t *tri; + glIndex_t *tri; mdvVertex_t *v; mdvSt_t *st; mdvTag_t *tag; @@ -552,15 +552,15 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, } // swap all the triangles - surf->numTriangles = md3Surf->numTriangles; - surf->triangles = tri = ri.Hunk_Alloc(sizeof(*tri) * md3Surf->numTriangles, h_low); + surf->numIndexes = md3Surf->numTriangles * 3; + surf->indexes = tri = ri.Hunk_Alloc(sizeof(*tri) * 3 * md3Surf->numTriangles, h_low); md3Tri = (md3Triangle_t *) ((byte *) md3Surf + md3Surf->ofsTriangles); - for(j = 0; j < md3Surf->numTriangles; j++, tri++, md3Tri++) + for(j = 0; j < md3Surf->numTriangles; j++, tri += 3, md3Tri++) { - tri->indexes[0] = LittleLong(md3Tri->indexes[0]); - tri->indexes[1] = LittleLong(md3Tri->indexes[1]); - tri->indexes[2] = LittleLong(md3Tri->indexes[2]); + tri[0] = LittleLong(md3Tri->indexes[0]); + tri[1] = LittleLong(md3Tri->indexes[1]); + tri[2] = LittleLong(md3Tri->indexes[2]); } // swap all the XyzNormals @@ -624,15 +624,15 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, for(f = 0; f < mdvModel->numFrames; f++) { - for(j = 0, tri = surf->triangles; j < surf->numTriangles; j++, tri++) + for(j = 0, tri = surf->indexes; j < surf->numIndexes; j += 3, tri += 3) { - v0 = surf->verts[surf->numVerts * f + tri->indexes[0]].xyz; - v1 = surf->verts[surf->numVerts * f + tri->indexes[1]].xyz; - v2 = surf->verts[surf->numVerts * f + tri->indexes[2]].xyz; + v0 = surf->verts[surf->numVerts * f + tri[0]].xyz; + v1 = surf->verts[surf->numVerts * f + tri[1]].xyz; + v2 = surf->verts[surf->numVerts * f + tri[2]].xyz; - t0 = surf->st[tri->indexes[0]].st; - t1 = surf->st[tri->indexes[1]].st; - t2 = surf->st[tri->indexes[2]].st; + t0 = surf->st[tri[0]].st; + t1 = surf->st[tri[1]].st; + t2 = surf->st[tri[2]].st; if (!r_recalcMD3Normals->integer) VectorCopy(v->normal, normal); @@ -650,15 +650,15 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, { float *v; - v = surf->verts[surf->numVerts * f + tri->indexes[k]].tangent; + v = surf->verts[surf->numVerts * f + tri[k]].tangent; VectorAdd(v, tangent, v); - v = surf->verts[surf->numVerts * f + tri->indexes[k]].bitangent; + v = surf->verts[surf->numVerts * f + tri[k]].bitangent; VectorAdd(v, bitangent, v); if (r_recalcMD3Normals->integer) { - v = surf->verts[surf->numVerts * f + tri->indexes[k]].normal; + v = surf->verts[surf->numVerts * f + tri[k]].normal; VectorAdd(v, normal, v); } } @@ -754,7 +754,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, vboSurf->surfaceType = SF_VBO_MDVMESH; vboSurf->mdvModel = mdvModel; vboSurf->mdvSurface = surf; - vboSurf->numIndexes = surf->numTriangles * 3; + vboSurf->numIndexes = surf->numIndexes; vboSurf->numVerts = surf->numVerts; vboSurf->minIndex = 0; @@ -783,7 +783,7 @@ static qboolean R_LoadMD3(model_t * mod, int lod, void *buffer, int bufferSize, ri.Free(data); - vboSurf->ibo = R_CreateIBO2(va("staticMD3Mesh_IBO %s", surf->name), surf->numTriangles, surf->triangles, VBO_USAGE_STATIC); + vboSurf->ibo = R_CreateIBO2(va("staticMD3Mesh_IBO %s", surf->name), surf->numIndexes, surf->indexes, VBO_USAGE_STATIC); } } diff --git a/src/renderergl2/tr_surface.c b/src/renderergl2/tr_surface.c index 563c75c1..eff3a257 100644 --- a/src/renderergl2/tr_surface.c +++ b/src/renderergl2/tr_surface.c @@ -312,30 +312,28 @@ static void RB_SurfacePolychain( srfPoly_t *p ) { tess.numVertexes = numv; } -static void RB_SurfaceVertsAndTris( int numVerts, srfVert_t *verts, int numTriangles, srfTriangle_t *triangles, int dlightBits, int pshadowBits) +static void RB_SurfaceVertsAndIndexes( int numVerts, srfVert_t *verts, int numIndexes, glIndex_t *indexes, int dlightBits, int pshadowBits) { int i; - srfTriangle_t *tri; + glIndex_t *inIndex; srfVert_t *dv; float *xyz, *normal, *texCoords, *lightCoords, *lightdir; #ifdef USE_VERT_TANGENT_SPACE float *tangent, *bitangent; #endif - glIndex_t *index; + glIndex_t *outIndex; float *color; RB_CheckVBOandIBO(tess.vbo, tess.ibo); - RB_CHECKOVERFLOW( numVerts, numTriangles * 3 ); + RB_CHECKOVERFLOW( numVerts, numIndexes ); - tri = triangles; - index = &tess.indexes[ tess.numIndexes ]; - for ( i = 0 ; i < numTriangles ; i++, tri++ ) { - *index++ = tess.numVertexes + tri->indexes[0]; - *index++ = tess.numVertexes + tri->indexes[1]; - *index++ = tess.numVertexes + tri->indexes[2]; + inIndex = indexes; + outIndex = &tess.indexes[ tess.numIndexes ]; + for ( i = 0 ; i < numIndexes ; i++ ) { + *outIndex++ = tess.numVertexes + *inIndex++; } - tess.numIndexes += numTriangles * 3; + tess.numIndexes += numIndexes; if ( tess.shader->vertexAttribs & ATTR_POSITION ) { @@ -524,14 +522,14 @@ RB_SurfaceTriangles ============= */ static void RB_SurfaceTriangles( srfBspSurface_t *srf ) { - if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numTriangles * 3, + if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numIndexes, srf->firstIndex, srf->minIndex, srf->maxIndex, srf->dlightBits, srf->pshadowBits, qtrue ) ) { return; } - RB_SurfaceVertsAndTris(srf->numVerts, srf->verts, srf->numTriangles, - srf->triangles, srf->dlightBits, srf->pshadowBits); + RB_SurfaceVertsAndIndexes(srf->numVerts, srf->verts, srf->numIndexes, + srf->indexes, srf->dlightBits, srf->pshadowBits); } @@ -1202,9 +1200,7 @@ RB_SurfaceMesh static void RB_SurfaceMesh(mdvSurface_t *surface) { int j; float backlerp; - srfTriangle_t *triangles; mdvSt_t *texCoords; - int indexes; int Bob, Doug; int numVerts; @@ -1214,20 +1210,16 @@ static void RB_SurfaceMesh(mdvSurface_t *surface) { backlerp = backEnd.currentEntity->e.backlerp; } - RB_CHECKOVERFLOW( surface->numVerts, surface->numTriangles*3 ); + RB_CHECKOVERFLOW( surface->numVerts, surface->numIndexes ); LerpMeshVertexes (surface, backlerp); - triangles = surface->triangles; - indexes = surface->numTriangles * 3; Bob = tess.numIndexes; Doug = tess.numVertexes; - for (j = 0 ; j < surface->numTriangles ; j++) { - tess.indexes[Bob + j*3 + 0] = Doug + triangles[j].indexes[0]; - tess.indexes[Bob + j*3 + 1] = Doug + triangles[j].indexes[1]; - tess.indexes[Bob + j*3 + 2] = Doug + triangles[j].indexes[2]; + for (j = 0 ; j < surface->numIndexes ; j++) { + tess.indexes[Bob + j] = Doug + surface->indexes[j]; } - tess.numIndexes += indexes; + tess.numIndexes += surface->numIndexes; texCoords = surface->st; @@ -1249,14 +1241,14 @@ RB_SurfaceFace ============== */ static void RB_SurfaceFace( srfBspSurface_t *srf ) { - if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numTriangles * 3, + if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numIndexes, srf->firstIndex, srf->minIndex, srf->maxIndex, srf->dlightBits, srf->pshadowBits, qtrue ) ) { return; } - RB_SurfaceVertsAndTris(srf->numVerts, srf->verts, srf->numTriangles, - srf->triangles, srf->dlightBits, srf->pshadowBits); + RB_SurfaceVertsAndIndexes(srf->numVerts, srf->verts, srf->numIndexes, + srf->indexes, srf->dlightBits, srf->pshadowBits); } @@ -1318,7 +1310,7 @@ static void RB_SurfaceGrid( srfBspSurface_t *srf ) { int pshadowBits; //int *vDlightBits; - if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numTriangles * 3, + if( RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numIndexes, srf->firstIndex, srf->minIndex, srf->maxIndex, srf->dlightBits, srf->pshadowBits, qtrue ) ) { return; @@ -1577,7 +1569,7 @@ static void RB_SurfaceFlare(srfFlare_t *surf) static void RB_SurfaceVBOMesh(srfBspSurface_t * srf) { - RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numTriangles * 3, srf->firstIndex, + RB_SurfaceVbo (srf->vbo, srf->ibo, srf->numVerts, srf->numIndexes, srf->firstIndex, srf->minIndex, srf->maxIndex, srf->dlightBits, srf->pshadowBits, qfalse ); } diff --git a/src/renderergl2/tr_vbo.c b/src/renderergl2/tr_vbo.c index 7433b5b1..44c66d01 100644 --- a/src/renderergl2/tr_vbo.c +++ b/src/renderergl2/tr_vbo.c @@ -501,7 +501,7 @@ IBO_t *R_CreateIBO(const char *name, byte * indexes, int indexesSize, v R_CreateIBO2 ============ */ -IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * triangles, vboUsage_t usage) +IBO_t *R_CreateIBO2(const char *name, int numIndexes, glIndex_t * inIndexes, vboUsage_t usage) { IBO_t *ibo; int i, j; @@ -510,7 +510,8 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * int indexesSize; int indexesCount; - srfTriangle_t *tri; + glIndex_t *tri; + glIndex_t index; int glUsage; switch (usage) @@ -528,7 +529,7 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * return NULL; } - if(!numTriangles) + if(!numIndexes) return NULL; if(strlen(name) >= MAX_QPATH) @@ -547,15 +548,17 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t * Q_strncpyz(ibo->name, name, sizeof(ibo->name)); - indexesSize = numTriangles * 3 * sizeof(glIndex_t); + indexesSize = numIndexes * sizeof(glIndex_t); indexes = ri.Hunk_AllocateTempMemory(indexesSize); indexesCount = 0; - for(i = 0, tri = triangles; i < numTriangles; i++, tri++) + for(i = 0, tri = inIndexes; i < numIndexes; i += 3, tri += 3) { for(j = 0; j < 3; j++) { - indexes[indexesCount++] = tri->indexes[j]; + index = tri[j]; + memcpy(indexes + indexesOfs, &index, sizeof(glIndex_t)); + indexesOfs += sizeof(glIndex_t); } } |