[iortcw] 97/152: All: Rend2: Preallocate grid surfaces like other BSP surfaces

Simon McVittie smcv at debian.org
Fri Sep 8 10:40:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.5a
in repository iortcw.

commit c9d29d4f4072b8805c76b8d4ca93ee3017741392
Author: MAN-AT-ARMS <M4N4T4RMS at gmail.com>
Date:   Mon Aug 15 16:11:10 2016 -0400

    All: Rend2: Preallocate grid surfaces like other BSP surfaces
---
 MP/code/rend2/tr_bsp.c   | 104 ++++++++++++++++++++++-------------------------
 MP/code/rend2/tr_curve.c |  68 ++++++++++++-------------------
 MP/code/rend2/tr_local.h |   8 ++--
 SP/code/rend2/tr_bsp.c   | 104 ++++++++++++++++++++++-------------------------
 SP/code/rend2/tr_curve.c |  68 ++++++++++++-------------------
 SP/code/rend2/tr_local.h |   8 ++--
 6 files changed, 156 insertions(+), 204 deletions(-)

diff --git a/MP/code/rend2/tr_bsp.c b/MP/code/rend2/tr_bsp.c
index eef7f0f..2289bc2 100644
--- a/MP/code/rend2/tr_bsp.c
+++ b/MP/code/rend2/tr_bsp.c
@@ -869,7 +869,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];
@@ -950,8 +950,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
@@ -964,6 +963,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;
 }
 
 /*
@@ -1124,6 +1129,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.type = CULLINFO_NONE;
 }
 
 
@@ -1450,8 +1457,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1506,8 +1513,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1573,8 +1580,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[grid1->width * ( k + 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1629,8 +1636,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[grid1->width * ( k + 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1697,8 +1704,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1753,8 +1760,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					R_GridInsertRow( grid2, l + 1, column,
+								grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
 					if ( !grid2 ) {
 						break;
 					}
@@ -1823,8 +1830,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[grid1->width * ( k - 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1879,8 +1886,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[grid1->width * ( k - 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1981,10 +1988,11 @@ 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
@@ -1992,27 +2000,25 @@ void R_MovePatchSurfacesToHunk( void ) {
 			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 );
-
-		hunkgrid->heightLodError = ri.Hunk_Alloc( grid->height * 4, h_low );
-		Com_Memcpy( hunkgrid->heightLodError, grid->heightLodError, grid->height * 4 );
-
-		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);
-		Com_Memcpy(hunkgrid->verts, grid->verts, grid->numVerts * sizeof(srfVert_t));
-
-		R_FreeSurfaceGridMesh( grid );
-
-		s_worldData.surfaces[i].data = (void *) hunkgrid;
+		copyFrom = grid->widthLodError;
+		grid->widthLodError = ri.Hunk_Alloc( grid->width * 4, h_low );
+		Com_Memcpy(grid->widthLodError, copyFrom, grid->width * 4);
+		ri.Free(copyFrom);
+
+		copyFrom = grid->heightLodError;
+		grid->heightLodError = ri.Hunk_Alloc(grid->height * 4, h_low);
+		Com_Memcpy(grid->heightLodError, copyFrom, grid->height * 4);
+		ri.Free(copyFrom);
+
+		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);
+
+		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);
 	}
 }
 
@@ -2516,7 +2522,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);
@@ -2538,15 +2544,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:
@@ -2559,9 +2556,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/MP/code/rend2/tr_curve.c b/MP/code/rend2/tr_curve.c
index ca7683d..30547ce 100644
--- a/MP/code/rend2/tr_curve.c
+++ b/MP/code/rend2/tr_curve.c
@@ -260,14 +260,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;
@@ -294,16 +291,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;
 }
 
@@ -381,22 +368,18 @@ 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.Z_Malloc( size );
-	Com_Memset( grid, 0, size );
-
 	grid->widthLodError = /*ri.Hunk_Alloc*/ ri.Z_Malloc( width * 4 );
 	memcpy( grid->widthLodError, errorTable[0], width * 4 );
 
@@ -410,9 +393,6 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height,
 	grid->numVerts = (width * height);
 	grid->verts = ri.Z_Malloc(grid->numVerts * sizeof(srfVert_t));
 #else
-	grid = ri.Hunk_Alloc( size, h_low );
-	memset( grid, 0, size );
-
 	grid->widthLodError = ri.Hunk_Alloc( width * 4, h_low );
 	memcpy( grid->widthLodError, errorTable[0], width * 4 );
 
@@ -448,20 +428,18 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height,
 	VectorCopy( grid->cullOrigin, grid->lodOrigin );
 	grid->lodRadius = grid->cullRadius;
 	//
-	return grid;
 }
 
 /*
 =================
-R_FreeSurfaceGridMesh
+R_FreeSurfaceGridMeshData
 =================
 */
-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 );
 }
 
 /*
@@ -469,7 +447,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 );
@@ -635,7 +613,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 );
@@ -643,7 +621,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);
 }
 
 /*
@@ -651,7 +629,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];
@@ -664,7 +642,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++ ) {
@@ -692,20 +670,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;
 }
 
 /*
@@ -713,7 +693,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];
@@ -727,7 +707,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 ) {
@@ -754,18 +734,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/MP/code/rend2/tr_local.h b/MP/code/rend2/tr_local.h
index ecd2fd4..ee25e17 100644
--- a/MP/code/rend2/tr_local.h
+++ b/MP/code/rend2/tr_local.h
@@ -2390,11 +2390,11 @@ 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_FreeSurfaceGridMesh( srfBspSurface_t *grid );
+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_FreeSurfaceGridMeshData( srfBspSurface_t *grid );
 
 /*
 ============================================================
diff --git a/SP/code/rend2/tr_bsp.c b/SP/code/rend2/tr_bsp.c
index 06e4e8e..c609a67 100644
--- a/SP/code/rend2/tr_bsp.c
+++ b/SP/code/rend2/tr_bsp.c
@@ -866,7 +866,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];
@@ -947,8 +947,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
@@ -961,6 +960,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;
 }
 
 /*
@@ -1120,6 +1125,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.type = CULLINFO_NONE;
 }
 
 
@@ -1446,8 +1453,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1502,8 +1509,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[k + 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1569,8 +1576,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[grid1->width * ( k + 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1625,8 +1632,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[grid1->width * ( k + 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1693,8 +1700,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1749,8 +1756,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
+					R_GridInsertRow( grid2, l + 1, column,
+								grid1->verts[k - 1 + offset1].xyz, grid1->widthLodError[k + 1] );
 					if ( !grid2 ) {
 						break;
 					}
@@ -1819,8 +1826,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						row = grid2->height - 1;
 					} else { row = 0;}
-					grid2 = R_GridInsertColumn( grid2, l + 1, row,
-												grid1->verts[grid1->width * ( k - 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1875,8 +1882,8 @@ int R_StitchPatches( int grid1num, int grid2num ) {
 					if ( m ) {
 						column = grid2->width - 1;
 					} else { column = 0;}
-					grid2 = R_GridInsertRow( grid2, l + 1, column,
-											 grid1->verts[grid1->width * ( k - 1 ) + offset1].xyz, grid1->heightLodError[k + 1] );
+					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;
 					return qtrue;
@@ -1977,10 +1984,11 @@ 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
@@ -1988,27 +1996,25 @@ void R_MovePatchSurfacesToHunk( void ) {
 			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 );
-
-		hunkgrid->heightLodError = ri.Hunk_Alloc( grid->height * 4, h_low );
-		Com_Memcpy( hunkgrid->heightLodError, grid->heightLodError, grid->height * 4 );
-
-		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);
-		Com_Memcpy(hunkgrid->verts, grid->verts, grid->numVerts * sizeof(srfVert_t));
-
-		R_FreeSurfaceGridMesh( grid );
-
-		s_worldData.surfaces[i].data = (void *) hunkgrid;
+		copyFrom = grid->widthLodError;
+		grid->widthLodError = ri.Hunk_Alloc( grid->width * 4, h_low );
+		Com_Memcpy(grid->widthLodError, copyFrom, grid->width * 4);
+		ri.Free(copyFrom);
+
+		copyFrom = grid->heightLodError;
+		grid->heightLodError = ri.Hunk_Alloc(grid->height * 4, h_low);
+		Com_Memcpy(grid->heightLodError, copyFrom, grid->height * 4);
+		ri.Free(copyFrom);
+
+		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);
+
+		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);
 	}
 }
 
@@ -2504,7 +2510,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);
@@ -2526,15 +2532,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:
@@ -2547,9 +2544,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/SP/code/rend2/tr_curve.c b/SP/code/rend2/tr_curve.c
index 6886c69..54349cd 100644
--- a/SP/code/rend2/tr_curve.c
+++ b/SP/code/rend2/tr_curve.c
@@ -261,14 +261,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;
@@ -295,16 +292,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;
 }
 
@@ -382,21 +369,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 = malloc( size );
-	Com_Memset( grid, 0, size );
-
 	grid->widthLodError = malloc( width * 4 );
 	memcpy( grid->widthLodError, errorTable[0], width * 4 );
 
@@ -410,9 +393,6 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height,
 	grid->numVerts = (width * height);
 	grid->verts = ri.Z_Malloc(grid->numVerts * sizeof(srfVert_t));
 #else
-	grid = ri.Hunk_Alloc( size, h_low );
-	memset( grid, 0, size );
-
 	grid->widthLodError = ri.Hunk_Alloc( width * 4, h_low );
 	memcpy( grid->widthLodError, errorTable[0], width * 4 );
 
@@ -448,20 +428,18 @@ srfBspSurface_t *R_CreateSurfaceGridMesh(int width, int height,
 	VectorCopy( grid->cullOrigin, grid->lodOrigin );
 	grid->lodRadius = grid->cullRadius;
 	//
-	return grid;
 }
 
 /*
 =================
-R_FreeSurfaceGridMesh
+R_FreeSurfaceGridMeshData
 =================
 */
-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 );
 }
 
 /*
@@ -469,7 +447,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 );
@@ -635,7 +613,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 );
@@ -643,7 +621,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);
 }
 
 /*
@@ -651,7 +629,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];
@@ -664,7 +642,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++ ) {
@@ -692,20 +670,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;
 }
 
 /*
@@ -713,7 +693,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];
@@ -727,7 +707,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 ) {
@@ -754,19 +734,21 @@ 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/SP/code/rend2/tr_local.h b/SP/code/rend2/tr_local.h
index fd31689..01bd9dc 100644
--- a/SP/code/rend2/tr_local.h
+++ b/SP/code/rend2/tr_local.h
@@ -2420,11 +2420,11 @@ 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_FreeSurfaceGridMesh( srfBspSurface_t *grid );
+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_FreeSurfaceGridMeshData( srfBspSurface_t *grid );
 
 /*
 ============================================================

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/iortcw.git



More information about the Pkg-games-commits mailing list