diff --git a/code/renderergl2/tr_bsp.c b/code/renderergl2/tr_bsp.c index 2feeddb7..47333b2c 100644 --- a/code/renderergl2/tr_bsp.c +++ b/code/renderergl2/tr_bsp.c @@ -822,7 +822,7 @@ ParseMesh =============== */ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, msurface_t *surf ) { - srfBspSurface_t *grid; + srfBspSurface_t *grid = (srfBspSurface_t *)surf->data; int i, j; int width, height, numPoints; srfVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE]; @@ -903,8 +903,7 @@ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, } // pre-tesseleate - grid = R_SubdividePatchToGrid( width, height, points ); - surf->data = (surfaceType_t *)grid; + R_SubdividePatchToGrid( grid, width, height, points ); // copy the level of detail origin, which is the center // of the group of all curves that must subdivide the same @@ -917,6 +916,12 @@ static void ParseMesh ( dsurface_t *ds, drawVert_t *verts, float *hdrVertColors, VectorScale( bounds[1], 0.5f, grid->lodOrigin ); VectorSubtract( bounds[0], grid->lodOrigin, tmpVec ); grid->lodRadius = VectorLength( tmpVec ); + + surf->cullinfo.type = CULLINFO_BOX | CULLINFO_SPHERE; + VectorCopy(grid->cullBounds[0], surf->cullinfo.bounds[0]); + VectorCopy(grid->cullBounds[1], surf->cullinfo.bounds[1]); + VectorCopy(grid->cullOrigin, surf->cullinfo.localOrigin); + surf->cullinfo.radius = grid->cullRadius; } /* @@ -1077,6 +1082,8 @@ static void ParseFlare( dsurface_t *ds, drawVert_t *verts, msurface_t *surf, int flare->color[i] = LittleFloat( ds->lightmapVecs[0][i] ); flare->normal[i] = LittleFloat( ds->lightmapVecs[2][i] ); } + + surf->cullinfo = CULLINFO_NONE; } @@ -1321,7 +1328,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert column into grid2 right after after column l if (m) row = grid2->height-1; else row = 0; - grid2 = R_GridInsertColumn( grid2, l+1, row, + R_GridInsertColumn( grid2, l+1, row, grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1365,7 +1372,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert row into grid2 right after after row l if (m) column = grid2->width-1; else column = 0; - grid2 = R_GridInsertRow( grid2, l+1, column, + R_GridInsertRow( grid2, l+1, column, grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1418,7 +1425,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert column into grid2 right after after column l if (m) row = grid2->height-1; else row = 0; - grid2 = R_GridInsertColumn( grid2, l+1, row, + R_GridInsertColumn( grid2, l+1, row, grid1->verts[grid1->width * (k + 1) + offset1].xyz, grid1->heightLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1462,7 +1469,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert row into grid2 right after after row l if (m) column = grid2->width-1; else column = 0; - grid2 = R_GridInsertRow( grid2, l+1, column, + R_GridInsertRow( grid2, l+1, column, grid1->verts[grid1->width * (k + 1) + offset1].xyz, grid1->heightLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1516,7 +1523,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert column into grid2 right after after column l if (m) row = grid2->height-1; else row = 0; - grid2 = R_GridInsertColumn( grid2, l+1, row, + R_GridInsertColumn( grid2, l+1, row, grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1560,7 +1567,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert row into grid2 right after after row l if (m) column = grid2->width-1; else column = 0; - grid2 = R_GridInsertRow( grid2, l+1, column, + R_GridInsertRow( grid2, l+1, column, grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k+1]); if (!grid2) break; @@ -1615,7 +1622,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert column into grid2 right after after column l if (m) row = grid2->height-1; else row = 0; - grid2 = R_GridInsertColumn( grid2, l+1, row, + R_GridInsertColumn( grid2, l+1, row, grid1->verts[grid1->width * (k - 1) + offset1].xyz, grid1->heightLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1659,7 +1666,7 @@ int R_StitchPatches( int grid1num, int grid2num ) { // insert row into grid2 right after after row l if (m) column = grid2->width-1; else column = 0; - grid2 = R_GridInsertRow( grid2, l+1, column, + R_GridInsertRow( grid2, l+1, column, grid1->verts[grid1->width * (k - 1) + offset1].xyz, grid1->heightLodError[k+1]); grid2->lodStitched = qfalse; s_worldData.surfaces[grid2num].data = (void *) grid2; @@ -1749,37 +1756,37 @@ R_MovePatchSurfacesToHunk =============== */ void R_MovePatchSurfacesToHunk(void) { - int i, size; - srfBspSurface_t *grid, *hunkgrid; + int i; + srfBspSurface_t *grid; for ( i = 0; i < s_worldData.numsurfaces; i++ ) { + void *copyFrom; // grid = (srfBspSurface_t *) s_worldData.surfaces[i].data; // if this surface is not a grid if ( grid->surfaceType != SF_GRID ) continue; // - size = sizeof(*grid); - hunkgrid = ri.Hunk_Alloc(size, h_low); - Com_Memcpy(hunkgrid, grid, size); - hunkgrid->widthLodError = ri.Hunk_Alloc( grid->width * 4, h_low ); - Com_Memcpy( hunkgrid->widthLodError, grid->widthLodError, grid->width * 4 ); + copyFrom = grid->widthLodError; + grid->widthLodError = ri.Hunk_Alloc( grid->width * 4, h_low ); + Com_Memcpy(grid->widthLodError, copyFrom, grid->width * 4); + ri.Free(copyFrom); - hunkgrid->heightLodError = ri.Hunk_Alloc( grid->height * 4, h_low ); - Com_Memcpy( hunkgrid->heightLodError, grid->heightLodError, grid->height * 4 ); + copyFrom = grid->heightLodError; + grid->heightLodError = ri.Hunk_Alloc(grid->height * 4, h_low); + Com_Memcpy(grid->heightLodError, copyFrom, grid->height * 4); + ri.Free(copyFrom); - 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)); + copyFrom = grid->indexes; + grid->indexes = ri.Hunk_Alloc(grid->numIndexes * sizeof(glIndex_t), h_low); + Com_Memcpy(grid->indexes, copyFrom, grid->numIndexes * sizeof(glIndex_t)); + ri.Free(copyFrom); - hunkgrid->numVerts = grid->numVerts; - hunkgrid->verts = ri.Hunk_Alloc(grid->numVerts * sizeof(srfVert_t), h_low); - Com_Memcpy(hunkgrid->verts, grid->verts, grid->numVerts * sizeof(srfVert_t)); - - R_FreeSurfaceGridMesh( grid ); - - s_worldData.surfaces[i].data = (void *) hunkgrid; + copyFrom = grid->verts; + grid->verts = ri.Hunk_Alloc(grid->numVerts * sizeof(srfVert_t), h_low); + Com_Memcpy(grid->verts, copyFrom, grid->numVerts * sizeof(srfVert_t)); + ri.Free(copyFrom); } } @@ -2276,7 +2283,7 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump ) { for ( i = 0 ; i < count ; i++, in++, out++ ) { switch ( LittleLong( in->surfaceType ) ) { case MST_PATCH: - // FIXME: do this + out->data = ri.Hunk_Alloc( sizeof(srfBspSurface_t), h_low); break; case MST_TRIANGLE_SOUP: out->data = ri.Hunk_Alloc( sizeof(srfBspSurface_t), h_low); @@ -2298,15 +2305,6 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump ) { switch ( LittleLong( in->surfaceType ) ) { case MST_PATCH: ParseMesh ( in, dv, hdrVertColors, out ); - { - srfBspSurface_t *surface = (srfBspSurface_t *)out->data; - - out->cullinfo.type = CULLINFO_BOX | CULLINFO_SPHERE; - VectorCopy(surface->cullBounds[0], out->cullinfo.bounds[0]); - VectorCopy(surface->cullBounds[1], out->cullinfo.bounds[1]); - VectorCopy(surface->cullOrigin, out->cullinfo.localOrigin); - out->cullinfo.radius = surface->cullRadius; - } numMeshes++; break; case MST_TRIANGLE_SOUP: @@ -2319,9 +2317,6 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump ) { break; case MST_FLARE: ParseFlare( in, dv, out, indexes ); - { - out->cullinfo.type = CULLINFO_NONE; - } numFlares++; break; default: diff --git a/code/renderergl2/tr_curve.c b/code/renderergl2/tr_curve.c index 91c80a4d..f9e17cd4 100644 --- a/code/renderergl2/tr_curve.c +++ b/code/renderergl2/tr_curve.c @@ -254,14 +254,11 @@ static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRI #endif -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]) +static int MakeMeshIndexes(int width, int height, glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { int i, j; int numIndexes; int w, h; - srfVert_t *dv; - static srfVert_t ctrl2[MAX_GRID_SIZE * MAX_GRID_SIZE]; h = height - 1; w = width - 1; @@ -288,16 +285,6 @@ static int MakeMeshIndexes(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][ } } - // FIXME: use more elegant way - for(i = 0; i < width; i++) - { - for(j = 0; j < height; j++) - { - dv = &ctrl2[j * width + i]; - *dv = ctrl[j][i]; - } - } - return numIndexes; } @@ -375,21 +362,17 @@ static void PutPointsOnCurve( srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], R_CreateSurfaceGridMesh ================= */ -srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, +void R_CreateSurfaceGridMesh(srfBspSurface_t *grid, int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], float errorTable[2][MAX_GRID_SIZE], int numIndexes, glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { - int i, j, size; + int i, j; srfVert_t *vert; vec3_t tmpVec; - srfBspSurface_t *grid; // copy the results out to a grid - size = (width * height - 1) * sizeof( srfVert_t ) + sizeof( *grid ); + Com_Memset(grid, 0, sizeof(*grid)); #ifdef PATCH_STITCHING - grid = /*ri.Hunk_Alloc*/ ri.Malloc( size ); - Com_Memset(grid, 0, size); - grid->widthLodError = /*ri.Hunk_Alloc*/ ri.Malloc( width * 4 ); Com_Memcpy( grid->widthLodError, errorTable[0], width * 4 ); @@ -403,9 +386,6 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, grid->numVerts = (width * height); grid->verts = ri.Malloc(grid->numVerts * sizeof(srfVert_t)); #else - grid = ri.Hunk_Alloc( size ); - Com_Memset(grid, 0, size); - grid->widthLodError = ri.Hunk_Alloc( width * 4 ); Com_Memcpy( grid->widthLodError, errorTable[0], width * 4 ); @@ -441,7 +421,6 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, VectorCopy( grid->cullOrigin, grid->lodOrigin ); grid->lodRadius = grid->cullRadius; // - return grid; } /* @@ -449,12 +428,11 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height, R_FreeSurfaceGridMesh ================= */ -void R_FreeSurfaceGridMesh( srfBspSurface_t *grid ) { +void R_FreeSurfaceGridMeshData( srfBspSurface_t *grid ) { ri.Free(grid->widthLodError); ri.Free(grid->heightLodError); ri.Free(grid->indexes); ri.Free(grid->verts); - ri.Free(grid); } /* @@ -462,7 +440,7 @@ void R_FreeSurfaceGridMesh( srfBspSurface_t *grid ) { R_SubdividePatchToGrid ================= */ -srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, +void R_SubdividePatchToGrid( srfBspSurface_t *grid, int width, int height, srfVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] ) { int i, j, k, l; srfVert_t_cleared( prev ); @@ -629,7 +607,7 @@ srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, #endif // calculate indexes - numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); + numIndexes = MakeMeshIndexes(width, height, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); @@ -637,7 +615,7 @@ srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); #endif - return R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); + R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); } /* @@ -645,7 +623,7 @@ srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, R_GridInsertColumn =============== */ -srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, vec3_t point, float loderror ) { +void R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, vec3_t point, float loderror ) { int i, j; int width, height, oldwidth; srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; @@ -658,7 +636,7 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, oldwidth = 0; width = grid->width + 1; if (width > MAX_GRID_SIZE) - return NULL; + return; height = grid->height; for (i = 0; i < width; i++) { if (i == column) { @@ -684,20 +662,22 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, //PutPointsOnCurve( ctrl, width, height ); // calculate indexes - numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); + numIndexes = MakeMeshIndexes(width, height, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); +#ifdef USE_VERT_TANGENT_SPACE + MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); +#endif VectorCopy(grid->lodOrigin, lodOrigin); lodRadius = grid->lodRadius; // free the old grid - R_FreeSurfaceGridMesh(grid); + R_FreeSurfaceGridMeshData(grid); // create a new grid - grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); + R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); grid->lodRadius = lodRadius; VectorCopy(lodOrigin, grid->lodOrigin); - return grid; } /* @@ -705,7 +685,7 @@ srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, R_GridInsertRow =============== */ -srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, vec3_t point, float loderror ) { +void R_GridInsertRow( srfBspSurface_t *grid, int row, int column, vec3_t point, float loderror ) { int i, j; int width, height, oldheight; srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; @@ -719,7 +699,7 @@ srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, ve width = grid->width; height = grid->height + 1; if (height > MAX_GRID_SIZE) - return NULL; + return; for (i = 0; i < height; i++) { if (i == row) { //insert new row @@ -744,18 +724,20 @@ srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, ve //PutPointsOnCurve( ctrl, width, height ); // calculate indexes - numIndexes = MakeMeshIndexes(width, height, ctrl, indexes); + numIndexes = MakeMeshIndexes(width, height, indexes); // calculate normals MakeMeshNormals( width, height, ctrl ); +#ifdef USE_VERT_TANGENT_SPACE + MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); +#endif VectorCopy(grid->lodOrigin, lodOrigin); lodRadius = grid->lodRadius; // free the old grid - R_FreeSurfaceGridMesh(grid); + R_FreeSurfaceGridMeshData(grid); // create a new grid - grid = R_CreateSurfaceGridMesh(width, height, ctrl, errorTable, numIndexes, indexes); + R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); grid->lodRadius = lodRadius; VectorCopy(lodOrigin, grid->lodOrigin); - return grid; } diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h index e81f854b..553fcc08 100644 --- a/code/renderergl2/tr_local.h +++ b/code/renderergl2/tr_local.h @@ -2152,10 +2152,10 @@ CURVE TESSELATION #define PATCH_STITCHING -srfBspSurface_t *R_SubdividePatchToGrid( int width, int height, +void R_SubdividePatchToGrid( srfBspSurface_t *grid, int width, int height, srfVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] ); -srfBspSurface_t *R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, vec3_t point, float loderror ); -srfBspSurface_t *R_GridInsertRow( srfBspSurface_t *grid, int row, int column, vec3_t point, float loderror ); +void R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, vec3_t point, float loderror ); +void R_GridInsertRow( srfBspSurface_t *grid, int row, int column, vec3_t point, float loderror ); void R_FreeSurfaceGridMesh( srfBspSurface_t *grid ); /*