/* Texture stuff. Alex McLean, Pumpkin Studios, EIDOS Interactive, 1997 */ #include "lib/framework/frame.h" #include "lib/ivis_common/pietypes.h" #include "lib/ivis_common/piestate.h" #include "lib/ivis_common/tex.h" #include "lib/ivis_common/piepalette.h" #include "lib/ivis_opengl/pietexture.h" #include "display3ddef.h" #include "texture.h" #include "radar.h" /* Can fit at most 32 texture pages into a 2meg texture memory */ #define MAX_TEXTURE_PAGES 32 #define MAX_TERRAIN_PAGES 20 #define PAGE_WIDTH 512 #define PAGE_HEIGHT 512 #define PAGE_DEPTH 4 #define TEXTURE_PAGE_SIZE PAGE_WIDTH*PAGE_HEIGHT*PAGE_DEPTH #define NUM_OTHER_PAGES 19 /* Stores the graphics data for the terrain tiles textures (in src/data.c) */ iSprite tilesPCX; /* How many pages have we loaded */ SDWORD firstTexturePage; SDWORD numTexturePages; int pageId[MAX_TERRAIN_PAGES]; /* 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 within that page. 0123 4567 89AB CDEF The above shows the different possible locations for a tile in the page. So we have a table of MAX_TILES showing pageNumber and [0..15] 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) { UDWORD i,j; UDWORD pageNumber; UDWORD tilesAcross,tilesDown; UDWORD tilesAcrossPage,tilesDownPage,tilesPerPage,tilesPerSource; UDWORD tilesProcessed; unsigned char *tileStorage; unsigned char *presentLoc; iSprite sprite; /* 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); /* 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; // 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= (SDWORD)pageNumber,"New Tertiles too large" ); exit: FREE(tileStorage); buildTileIndexes(); return; } BOOL getTileRadarColours(void) { UDWORD x, y, i, j, w, h, t; iBitmap *b, *s; UBYTE tempBMP[TILE_WIDTH * TILE_HEIGHT]; w = tilesPCX.width / TILE_WIDTH; h = tilesPCX.height / TILE_HEIGHT; t = 0; for (i=0; i