Am Dienstag, 26. Dezember 2006 11:41 schrieb Dennis Schridde:
> Am Dienstag, 26. Dezember 2006 02:53 schrieb Christian Ohm:
> > On Tuesday, 26 December 2006 at  2:37, Dennis Schridde wrote:
> > > I just profiled Warzone using gDEBugger.
> > >
> > > The logs are horrible and attached.
> > > (I monitored ~3 frames)
> > >
> > > Basically it looks like this:
> > > Lots of Matrix popping
> >
> > Which is bad, especially if uses any glGetWhatever functions, those just
> > kill performance (I think the shadow code uses that).
>
> Didn't look like it uses glGetX, only A LOT of glPopMatrix and
> glPushMatrix. ...
> Really a lot.
>
> > > Lots of texture binding
> >
> > Shouldn't be too bad, just uses up memory.
>
> From what I've read in GL3 articles, it sounded like glBindTexture is VERY
> bad and takes a lot of time... But actually it shouldn't use any memory,
> because the texture is only bound, not loaded. (Loading it multiple times
> would be even worse, though.)
>
> And glBindTexture taking long would also explain why the (callgrind)
> profiler reports that WZ spends a lot of time in the terrain rendering
> functions. I think if we would load the tertile texpage entirely (without
> spliting it into 512x512 pieces) and just calculate the tile-id into a UV
> coordinate into the complete tertile texpage, it should remove the need for
> 99% of the texture binds and thus improve the performance a lot.
>
> I tried that a while ago (and still have the patches, if someone wants).
As requested: The Patch.
(I updated it, so it applies to r570.)

I think most of is relatively ok. (Means: It is not a real ugly _hack_, but 
maybe ugly anyways.)

The changes to display3d.c are total crap, of course.
Somehow Warzone send some ints through the pipes, did some Voodoo to them and 
in the end they got used as floats, which seems to work somehow.
I tried to replace that weirdness with floats right from the start, which 
doesn't work. (Yes, I know that code _cant_ work, but to my excuse: It was 
very late in the night when I got mad at the code.)

I think somewhere the code which looks in which texpage the tile is and the 
binds the appropriate textures should be removed, if I didn't do this 
allready.
So this patch does only part of the job, I didn't get that far.

--Dennis
Index: src/display3d.c
===================================================================
--- src/display3d.c	(revision 570)
+++ src/display3d.c	(working copy)
@@ -5144,27 +5144,28 @@
 	*/
 	/* Get the right texture page; it is pre stored and indexed on
 	 * the graphics card */
-	pie_SetTexturePage(tileTexInfo[tileNumber & TILE_NUMMASK].texPage);
+	// FIXME : Seems like pie_DrawPoly allready does this!!
+	// pie_SetTexturePage(tileTexInfo[tileNumber & TILE_NUMMASK].texPage);
 
 	/* set up the texture size info */
 	renderFlag = 0;
-	offset.x = (tileTexInfo[tileNumber & TILE_NUMMASK].xOffset * 64);
-	offset.y = (tileTexInfo[tileNumber & TILE_NUMMASK].yOffset * 64);
+	offset.x = (UWORD)(tileTexInfo[tileNumber & TILE_NUMMASK].u)*(UWORD)(-1); // FIXME HACK to wrap a float into a UWORD
+	offset.y = (UWORD)(tileTexInfo[tileNumber & TILE_NUMMASK].v)*(UWORD)(-1); // FIXME HACK to wrap a float into a UWORD;
 
 	/* Check for rotations and flips - this sets up the coordinates for texturing */
 	flipsAndRots(tileNumber & ~TILE_NUMMASK);
 
-	tileScreenInfo[i+0][j+0].tu = (UWORD)(psP1->x + offset.x);
-	tileScreenInfo[i+0][j+0].tv = (UWORD)(psP1->y + offset.y);
+	tileScreenInfo[i+0][j+0].tu = offset.x;
+	tileScreenInfo[i+0][j+0].tv = offset.y;
 
-	tileScreenInfo[i+0][j+1].tu = (UWORD)(psP2->x + offset.x);
-	tileScreenInfo[i+0][j+1].tv = (UWORD)(psP2->y + offset.y);
+	tileScreenInfo[i+0][j+1].tu = offset.x + (tileTexInfo[tileNumber & TILE_NUMMASK].width)*(UWORD)(-1);
+	tileScreenInfo[i+0][j+1].tv = offset.y;
 
-	tileScreenInfo[i+1][j+1].tu = (UWORD)(psP3->x + offset.x);
-	tileScreenInfo[i+1][j+1].tv = (UWORD)(psP3->y + offset.y);
+	tileScreenInfo[i+1][j+1].tu = offset.x + (tileTexInfo[tileNumber & TILE_NUMMASK].width)*(UWORD)(-1);
+	tileScreenInfo[i+1][j+1].tv = offset.y + (tileTexInfo[tileNumber & TILE_NUMMASK].height)*(UWORD)(-1);
 
-	tileScreenInfo[i+1][j+0].tu = (UWORD)(psP4->x + offset.x);
-	tileScreenInfo[i+1][j+0].tv = (UWORD)(psP4->y + offset.y);
+	tileScreenInfo[i+1][j+0].tu = offset.x;
+	tileScreenInfo[i+1][j+0].tv = offset.y + (tileTexInfo[tileNumber & TILE_NUMMASK].height)*(UWORD)(-1);
 
 	/* The first triangle */
 	if(TRI_FLIPPED(psTile))
@@ -5271,8 +5272,8 @@
 
 	/* set up the texture size info */
 	renderFlag = 0;
-	offset.x = (tileTexInfo[tileNumber & TILE_NUMMASK].xOffset * 64);
-	offset.y = (tileTexInfo[tileNumber & TILE_NUMMASK].yOffset * 64);
+	offset.x = (tileTexInfo[tileNumber & TILE_NUMMASK].u)*sizeof(UWORD); // FIXME HACK to wrap a float into a UWORD
+	offset.y = (tileTexInfo[tileNumber & TILE_NUMMASK].v)*sizeof(UWORD); // FIXME HACK to wrap a float into a UWORD;
 
 	/* Check for rotations and flips - this sets up the coordinates for texturing */
 	flipsAndRots(tileNumber & ~TILE_NUMMASK);
@@ -5397,8 +5398,8 @@
 		/* 3dfx is pre stored and indexed */
 		pie_SetTexturePage(tileTexInfo[tileNumber & TILE_NUMMASK].texPage);
 
-		offset.x = (tileTexInfo[tileNumber & TILE_NUMMASK].xOffset * 64);
-		offset.y = (tileTexInfo[tileNumber & TILE_NUMMASK].yOffset * 64);
+	offset.x = (tileTexInfo[tileNumber & TILE_NUMMASK].u)*sizeof(UWORD); // FIXME HACK to wrap a float into a UWORD
+	offset.y = (tileTexInfo[tileNumber & TILE_NUMMASK].v)*sizeof(UWORD); // FIXME HACK to wrap a float into a UWORD;
 
 		tileScreenInfo[i+0][j+0].tu = (UWORD)(offset.x + 1);
 		tileScreenInfo[i+0][j+0].tv = (UWORD)(offset.y);
Index: src/data.c
===================================================================
--- src/data.c	(revision 570)
+++ src/data.c	(working copy)
@@ -756,6 +756,10 @@
 			debug( LOG_ERROR, "HWTERTILES reload failed" );
 			return FALSE;
 		}
+
+		remakeTileTexturePages(tilesPCX);
+
+		*ppData = NULL;
 	}
 	else
 	{
@@ -765,31 +769,18 @@
 			debug( LOG_ERROR, "HWTERTILES load failed" );
 			return FALSE;
 		}
-	}
 
-	{
-		getTileRadarColours();
 		// make several 256 * 256 pages
-		if (bTilesPCXLoaded)
-		{
-			remakeTileTexturePages(tilesPCX.width,tilesPCX.height,TILE_WIDTH, TILE_HEIGHT, tilesPCX.bmp);
-		}
-		else
-		{
-			makeTileTexturePages(tilesPCX.width,tilesPCX.height,TILE_WIDTH, TILE_HEIGHT, tilesPCX.bmp);
-		}
-	}
+		makeTileTexturePages(tilesPCX);
 
-	if (bTilesPCXLoaded)
-	{
-		*ppData = NULL;
-	}
-	else
-	{
 		bTilesPCXLoaded = TRUE;
 		*ppData = &tilesPCX;
 	}
+
+	getTileRadarColours();
+
 	debug( LOG_TEXTURE, "HW Tiles loaded\n" );
+
 	return TRUE;
 }
 
Index: src/texture.c
===================================================================
--- src/texture.c	(revision 570)
+++ src/texture.c	(working copy)
@@ -18,7 +18,6 @@
 #define PAGE_HEIGHT		512
 // 4 byte depth == 32 bpp
 #define PAGE_DEPTH		4
-#define TEXTURE_PAGE_SIZE	PAGE_WIDTH*PAGE_HEIGHT*PAGE_DEPTH
 
 #define NUM_OTHER_PAGES		19
 
@@ -33,12 +32,6 @@
 /* Texture page and coordinates for each tile */
 TILE_TEX_INFO	tileTexInfo[MAX_TILES];
 
-static UDWORD	getTileXIndex(UDWORD tileNumber);
-static UDWORD	getTileYIndex(UDWORD tileNumber);
-static void getRectFromPage(UDWORD width, UDWORD height, unsigned char *src, UDWORD bufWidth, unsigned char *dest);
-static void putRectIntoPage(UDWORD width, UDWORD height, unsigned char *dest, UDWORD bufWidth, unsigned char *src);
-static void buildTileIndexes(void);
-
 /*
 	Extracts the tile textures into separate texture pages and builds
 	a table of which texture page to find each tile in, as well as which one it is
@@ -57,162 +50,50 @@
 	We must then make sure that we source in that texture page and set the
 	texture coordinate for a complete tile to be its position.
 */
-void	makeTileTexturePages(UDWORD srcWidth, UDWORD srcHeight, UDWORD tileWidth, UDWORD tileHeight, unsigned char *src)
+void makeTileTexturePages(iSprite srcTiles)
 {
-	UDWORD	i,j;
-	UDWORD	pageNumber;
-	UDWORD	tilesAcross,tilesDown;
-	UDWORD	tilesAcrossPage,tilesDownPage,tilesPerPage,tilesPerSource;
-	UDWORD	tilesProcessed;
-	unsigned char	*tileStorage;
-	unsigned char	*presentLoc;
-	iSprite	sprite;
+	int i=0;
 
+	numTexturePages = 0;
+
 	/* This is how many pages are already used on hardware */
 	firstTexturePage = pie_GetLastPageDownloaded() + 1;
 
-	debug(LOG_TEXTURE, "makeTileTexturePages: src(%d,%d) tile(%d,%d) pages used=%d", srcWidth, srcHeight, tileWidth, tileHeight, firstTexturePage);
+	pageId[0] = pie_AddBMPtoTexPages(&srcTiles, "terrain", 0, TRUE, FALSE);
 
-	/* Get enough memory to store one tile */
-	pageNumber = 0;
-	tileStorage = MALLOC(tileWidth * tileHeight * PAGE_DEPTH);
-	sprite.bmp = MALLOC(TEXTURE_PAGE_SIZE);
-	sprite.width = PAGE_WIDTH;
-	sprite.height = PAGE_HEIGHT;
-	tilesProcessed = 0;
-	tilesAcross = srcWidth/tileWidth;
-	tilesDown = srcHeight/tileHeight;
-	tilesPerSource = tilesAcross*tilesDown;
-	tilesAcrossPage = PAGE_WIDTH/tileWidth;
-	tilesDownPage = PAGE_HEIGHT/tileHeight;
-	tilesPerPage = tilesAcrossPage*tilesDownPage;
-	presentLoc = sprite.bmp;
+	#define TILES_IN_A_ROW 9
+	#define TILES_IN_A_COL 10
 
-	for(i=0; i<tilesDown; i++)
+	for(i=0; i<MAX_TILES; i++)
 	{
-		for(j=0; j<tilesAcross; j++)
-		{
-			getRectFromPage(tileWidth,tileHeight,src,srcWidth,tileStorage);
-			putRectIntoPage(tileWidth,tileHeight,presentLoc,PAGE_WIDTH,tileStorage);
-			tilesProcessed++;
-			presentLoc+=tileWidth*PAGE_DEPTH;
-			src+=tileWidth*PAGE_DEPTH;
-			/* Have we got all the tiles from the source!? */
-			if((tilesProcessed == tilesPerSource))
-			{
-				pageId[pageNumber] = pie_AddBMPtoTexPages(&sprite, "terrain", 0, TRUE, FALSE);
-				goto exit;
-			}
-
-			/* Have we run out of texture page? */
-			if(tilesProcessed%tilesPerPage == 0)
-			{
-				debug(LOG_TEXTURE, "makeTileTexturePages: ran out of texture page ...");
-				debug(LOG_TEXTURE, "tilesDown=%d tilesAcross=%d tilesProcessed=%d tilesPerPage=%d",
-				      tilesDown, tilesAcross, tilesProcessed, tilesPerPage);
-				/* If so, download this one and reset to start again */
-				pageId[pageNumber] = pie_AddBMPtoTexPages(&sprite, "terrain", 0, TRUE, FALSE);
-				sprite.bmp = MALLOC(TEXTURE_PAGE_SIZE);
-				pageNumber++;
-				presentLoc = sprite.bmp;
-			}
-			else if(tilesProcessed%tilesAcrossPage == 0)
-			{
-				/* Right hand side of texture page */
-				/* So go to one tile down */
-				presentLoc+= ( (tileHeight-1) * PAGE_WIDTH)*PAGE_DEPTH;
-			}
-		}
-		src+=( (tileHeight-1) * srcWidth)*PAGE_DEPTH;
+		tileTexInfo[i].width = srcTiles.width / TILES_IN_A_ROW;
+		tileTexInfo[i].height = srcTiles.height / TILES_IN_A_COL;
+		tileTexInfo[i].u = 1.0f / ( i % TILES_IN_A_ROW );
+		tileTexInfo[i].v = 1.0f / ( ( i - ( i % TILES_IN_A_COL ) ) / TILES_IN_A_COL );
+		tileTexInfo[i].texPage = pageId[0];
 	}
 
-	numTexturePages = pageNumber;
-
-exit:
-	FREE(tileStorage);
-	buildTileIndexes();
 	return;
 }
 
-void	remakeTileTexturePages(UDWORD srcWidth,UDWORD srcHeight, UDWORD tileWidth, UDWORD tileHeight, unsigned char *src)
+void remakeTileTexturePages(iSprite srcTiles)
 {
-	UDWORD	i,j;
-	UDWORD	pageNumber;
-	UDWORD	tilesAcross,tilesDown;
-	UDWORD	tilesAcrossPage,tilesDownPage,tilesPerPage,tilesPerSource;
-	UDWORD	tilesProcessed;
-	unsigned char	*tileStorage;
-	unsigned char	*presentLoc;
-	iSprite	sprite;
-	//check enough pages are allocated
+	int i=0;
 
-	debug(LOG_TEXTURE, "remakeTileTexturePages: src(%d,%d), tile(%d, %d)", srcWidth,
-	      srcHeight, tileWidth, tileHeight);
+	pie_ChangeTexPage(pageId[0], &srcTiles, 0, TRUE, FALSE);
 
-	/* Get enough memory to store one tile */
-	pageNumber = 0;
-	tileStorage = MALLOC(tileWidth * tileHeight * PAGE_DEPTH);
-//	texturePage = MALLOC(TEXTURE_PAGE_SIZE);
-	sprite.width = PAGE_WIDTH;
-	sprite.height = PAGE_HEIGHT;
-
-	sprite.bmp = MALLOC(TEXTURE_PAGE_SIZE);
-//	memset(sprite.bmp,0,TEXTURE_PAGE_SIZE);
-	tilesProcessed = 0;
-	tilesAcross = srcWidth/tileWidth;
-	tilesDown = srcHeight/tileHeight;
-	tilesPerSource = tilesAcross*tilesDown;
-	tilesAcrossPage = PAGE_WIDTH/tileWidth;
-	tilesDownPage = PAGE_HEIGHT/tileHeight;
-	tilesPerPage = tilesAcrossPage*tilesDownPage;
-	presentLoc = sprite.bmp;
-
-	for(i=0; i<tilesDown; i++)
+	for(i=0; i<MAX_TILES; i++)
 	{
-		for(j=0; j<tilesAcross; j++)
-		{
-			getRectFromPage(tileWidth,tileHeight,src,srcWidth,tileStorage);
-			putRectIntoPage(tileWidth,tileHeight,presentLoc,PAGE_WIDTH,tileStorage);
-			tilesProcessed++;
-			presentLoc+=tileWidth*PAGE_DEPTH;
-			src+=tileWidth*PAGE_DEPTH;
-			/* Have we got all the tiles from the source!? */
-			if((tilesProcessed == tilesPerSource))// || (tileStorage[0] == 0))//hack probably causes too many texture pages to be used
-			{
-				pie_ChangeTexPage(pageId[pageNumber], &sprite, 0, TRUE, FALSE);
-				goto exit;
-			}
-
-			/* Have we run out of texture page? */
-			if(tilesProcessed%tilesPerPage == 0)
-			{
-				debug(LOG_TEXTURE, "remakeTileTexturePages: ran out of texture page ...");
-				debug(LOG_TEXTURE, "tilesDown=%d tilesAcross=%d tilesProcessed=%d tilesPerPage=%d",
-				      tilesDown, tilesAcross, tilesProcessed, tilesPerPage);
-				pie_ChangeTexPage(pageId[pageNumber], &sprite, 0, TRUE, FALSE);
-				pageNumber++;
-				presentLoc = sprite.bmp;
-			}
-			else if(tilesProcessed%tilesAcrossPage == 0)
-			{
-				/* Right hand side of texture page */
-				/* So go to one tile down */
-				presentLoc+= ( (tileHeight-1) * PAGE_WIDTH)*PAGE_DEPTH;
-			}
-		}
-		src+=( (tileHeight-1) * srcWidth)*PAGE_DEPTH;
+		tileTexInfo[i].width = 1.0f / TILES_IN_A_ROW;
+		tileTexInfo[i].height = 1.0f / TILES_IN_A_COL;
+		tileTexInfo[i].u = 1.0f / ( i % TILES_IN_A_ROW );
+		tileTexInfo[i].v = 1.0f / ( ( i - ( i % TILES_IN_A_COL ) ) / TILES_IN_A_COL );
+		tileTexInfo[i].texPage = pageId[0];
 	}
 
-	//check numTexturePages == pageNumber;
-	ASSERT( numTexturePages >= (SDWORD)pageNumber,"New Tertiles too large" );
-
-exit:
-	FREE(tileStorage);
-	buildTileIndexes();
 	return;
 }
 
-
 BOOL getTileRadarColours(void)
 {
 	UDWORD x, y, i, j, w, h, t;
@@ -261,71 +142,3 @@
 		FREE(_TEX_PAGE[(firstTexturePage+i)].tex.bmp);
 	}
 }
-
-static UDWORD	getTileXIndex(UDWORD tileNumber)
-{
-	UDWORD	texPage;
-	UDWORD	tileInPage;
-	UDWORD	xIndex;
-
-	texPage = tileNumber/16;
-	tileInPage = tileNumber - (texPage*16);
-	xIndex = tileInPage%4;
-	return(xIndex);
-}
-
-static UDWORD	getTileYIndex(UDWORD tileNumber)
-{
-	UDWORD	texPage;
-	UDWORD	tileInPage;
-	UDWORD	yIndex;
-
-	texPage = tileNumber/16;
-	tileInPage = tileNumber - (texPage*16);
-	yIndex = tileInPage/4;
-	return(yIndex);
-}
-
-
-/* Extracts a rectangular buffer from a source buffer, storing result in one contiguous
-   chunk	*/
-static void getRectFromPage(UDWORD width, UDWORD height, unsigned char *src, UDWORD bufWidth, unsigned char *dest)
-{
-	UDWORD	i,j;
-
-	for (i=0; i<height; i++)
-	{
-		for(j=0; j<width*PAGE_DEPTH; j++)
-		{
-			*dest++ = *src++;
-		}
-		src+=(bufWidth-width)*PAGE_DEPTH;
-	}
-}
-
-/* Inserts a rectangle into a dest rectangle */
-static void putRectIntoPage(UDWORD width, UDWORD height, unsigned char *dest, UDWORD bufWidth, unsigned char *src)
-{
-UDWORD	i,j;
-
-	for(i=0; i<height; i++)
-	{
-		for(j=0; j<width*PAGE_DEPTH; j++)
-		{
-			*dest++ = *src++;
-		}
-		dest+=(bufWidth-width)*PAGE_DEPTH;
-	}
-}
-
-static void buildTileIndexes(void)
-{
-	UDWORD	i;
-
-	for(i=0; i<MAX_TILES; i++)
-	{
-		tileTexInfo[i].xOffset = getTileXIndex(i);
-		tileTexInfo[i].yOffset = getTileYIndex(i);
-		tileTexInfo[i].texPage = pageId[(i/16)];//(i/16) + firstTexturePage;
-	}
-}
Index: src/texture.h
===================================================================
--- src/texture.h	(revision 570)
+++ src/texture.h	(working copy)
@@ -3,18 +3,15 @@
 
 extern iSprite tilesPCX;
 
-int makeTileTextures(void);
-int remakeTileTextures(void);
-void makeTileTexturePages(UDWORD srcWidth,UDWORD srcHeight, UDWORD tileWidth, UDWORD tileHeight, unsigned char *src);
-void remakeTileTexturePages(UDWORD srcWidth,UDWORD srcHeight, UDWORD tileWidth, UDWORD tileHeight, unsigned char *src);
+void makeTileTexturePages(iSprite srcTiles);
+void remakeTileTexturePages(iSprite srcTiles);
 BOOL	getTileRadarColours(void);
 void	freeTileTextures( void );
 
 typedef struct _tileTexInfo
 {
-UDWORD	xOffset;	// Offset into texture page to left hand edge
-UDWORD	yOffset;	// Offset into texture page to top hand edge
-UDWORD	texPage;	// Which textpage is the tile in? TileNumber/16 basically;
+	float u, v, width, height;
+	UDWORD texPage; // Which textpage is the tile in? TileNumber/16 basically;
 } TILE_TEX_INFO;
 
 #define MAX_TILES 100

Attachment: pgpuGIgsTGgvt.pgp
Description: PGP signature

_______________________________________________
Warzone-dev mailing list
[email protected]
https://mail.gna.org/listinfo/warzone-dev

Reply via email to