mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-26 22:11:18 +00:00
OpenGL2: Remove srfTriangle_t, and use glIndex_t instead.
This commit is contained in:
parent
d295db747c
commit
ef9fe17dd5
8 changed files with 173 additions and 235 deletions
|
@ -653,8 +653,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 );
|
||||
|
@ -675,14 +675,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);
|
||||
|
@ -740,29 +740,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
|
||||
|
@ -781,11 +781,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);
|
||||
}
|
||||
|
@ -904,9 +904,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;
|
||||
|
@ -918,14 +918,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);
|
||||
|
@ -984,29 +984,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
|
||||
|
@ -1014,11 +1014,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);
|
||||
}
|
||||
|
@ -1747,9 +1747,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);
|
||||
|
@ -1841,8 +1841,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;
|
||||
|
@ -1880,7 +1880,7 @@ static void R_CreateWorldVBOs(void)
|
|||
|
||||
bspSurf = (srfBspSurface_t *) surface->data;
|
||||
|
||||
if (!bspSurf->numTriangles || !bspSurf->numVerts)
|
||||
if (!bspSurf->numIndexes || !bspSurf->numVerts)
|
||||
continue;
|
||||
|
||||
numSortedSurfaces++;
|
||||
|
@ -1910,7 +1910,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;
|
||||
|
@ -1939,7 +1939,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)
|
||||
|
@ -1952,56 +1952,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
|
||||
|
@ -2014,9 +2008,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;
|
||||
|
@ -2025,7 +2019,7 @@ static void R_CreateWorldVBOs(void)
|
|||
bspSurf->ibo = ibo;
|
||||
}
|
||||
|
||||
ri.Hunk_FreeTempMemory(triangles);
|
||||
ri.Hunk_FreeTempMemory(indexes);
|
||||
ri.Hunk_FreeTempMemory(verts);
|
||||
|
||||
k++;
|
||||
|
@ -2099,7 +2093,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++ ) {
|
||||
|
@ -3085,7 +3079,7 @@ void R_MergeLeafSurfaces(void)
|
|||
vec3_t bounds[2];
|
||||
|
||||
int numSurfsToMerge;
|
||||
int numTriangles;
|
||||
int numIndexes;
|
||||
int numVerts;
|
||||
int firstIndex;
|
||||
|
||||
|
@ -3101,7 +3095,7 @@ void R_MergeLeafSurfaces(void)
|
|||
|
||||
// count verts, indexes, and surfaces
|
||||
numSurfsToMerge = 0;
|
||||
numTriangles = 0;
|
||||
numIndexes = 0;
|
||||
numVerts = 0;
|
||||
for (j = i; j < numWorldSurfaces; j++)
|
||||
{
|
||||
|
@ -3114,12 +3108,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;
|
||||
}
|
||||
|
@ -3131,7 +3125,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]);
|
||||
|
@ -3150,12 +3144,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;
|
||||
}
|
||||
|
@ -3167,14 +3159,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));
|
||||
|
|
|
@ -213,13 +213,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++)
|
||||
|
@ -231,53 +231,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++)
|
||||
|
@ -293,18 +255,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++)
|
||||
|
@ -317,15 +279,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +299,7 @@ static int MakeMeshTriangles(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE
|
|||
}
|
||||
}
|
||||
|
||||
return numTriangles;
|
||||
return numIndexes;
|
||||
}
|
||||
|
||||
|
||||
|
@ -418,7 +378,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;
|
||||
|
@ -437,9 +397,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));
|
||||
|
@ -453,9 +413,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);
|
||||
|
@ -493,7 +453,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);
|
||||
}
|
||||
|
@ -514,8 +474,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++ ) {
|
||||
|
@ -669,16 +629,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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -693,8 +653,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;
|
||||
|
@ -724,8 +684,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 );
|
||||
|
@ -735,7 +695,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;
|
||||
|
@ -753,8 +713,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;
|
||||
|
@ -784,8 +744,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 );
|
||||
|
@ -795,7 +755,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;
|
||||
|
|
|
@ -1003,12 +1003,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
|
||||
{
|
||||
|
@ -1024,9 +1018,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;
|
||||
|
@ -1326,8 +1320,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;
|
||||
|
@ -2275,7 +2269,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);
|
||||
|
|
|
@ -1288,9 +1288,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];
|
||||
|
|
|
@ -269,7 +269,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;
|
||||
|
@ -414,11 +414,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]);
|
||||
}
|
||||
|
||||
|
@ -437,12 +437,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
|
||||
|
|
|
@ -394,7 +394,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;
|
||||
|
@ -551,15 +551,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
|
||||
|
@ -623,15 +623,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);
|
||||
|
@ -649,15 +649,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);
|
||||
}
|
||||
}
|
||||
|
@ -753,7 +753,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;
|
||||
|
@ -782,7 +782,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -311,30 +311,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 )
|
||||
{
|
||||
|
@ -523,14 +521,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1201,9 +1199,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;
|
||||
|
||||
|
@ -1213,20 +1209,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;
|
||||
|
||||
|
@ -1248,14 +1240,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1317,7 +1309,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;
|
||||
|
@ -1576,7 +1568,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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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,7 @@ IBO_t *R_CreateIBO2(const char *name, int numTriangles, srfTriangle_t *
|
|||
int indexesSize;
|
||||
int indexesOfs;
|
||||
|
||||
srfTriangle_t *tri;
|
||||
glIndex_t *tri;
|
||||
glIndex_t index;
|
||||
int glUsage;
|
||||
|
||||
|
@ -529,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)
|
||||
|
@ -548,15 +548,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 = numIndexes * sizeof(glIndex_t);
|
||||
indexes = ri.Hunk_AllocateTempMemory(indexesSize);
|
||||
indexesOfs = 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++)
|
||||
{
|
||||
index = tri->indexes[j];
|
||||
index = tri[j];
|
||||
memcpy(indexes + indexesOfs, &index, sizeof(glIndex_t));
|
||||
indexesOfs += sizeof(glIndex_t);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue