Ejemplo n.º 1
0
//-------------------------------------------------------------------------
//--unused-- int info_printed = 0;
grsBitmap * TexMergeGetCachedBitmap (int tMapBot, int tMapTop, int nOrient)
{
	grsBitmap		*bmTop, *bmBot, *bmP;
	int				i, nLowestFrame, nLRU;
	TEXTURE_CACHE	*cacheP;

nLRU = 0;
nLowestFrame = texCache [0].last_frame_used;
bmTop = BmOverride (gameData.pig.tex.pBitmaps + gameData.pig.tex.pBmIndex [tMapTop].index, -1);
bmBot = BmOverride (gameData.pig.tex.pBitmaps + gameData.pig.tex.pBmIndex [tMapBot].index, -1);

for (i = 0, cacheP = texCache; i < nCacheEntries; i++,cacheP++) {
#if 1//ndef _DEBUG
	if ((cacheP->last_frame_used > -1) && 
		 (cacheP->bmTop == bmTop) && 
		 (cacheP->bmBot == bmBot) && 
		 (cacheP->nOrient == nOrient) &&
		  cacheP->bitmap) {
		nCacheHits++;
		cacheP->last_frame_used = gameData.app.nFrameCount;
		return cacheP->bitmap;
	}	
#endif
	if (cacheP->last_frame_used < nLowestFrame)	{
		nLowestFrame = cacheP->last_frame_used;
		nLRU = i;
		}
	}
//---- Page out the LRU bitmap;
nCacheMisses++;
// Make sure the bitmaps are paged in...
#ifdef PIGGY_USE_PAGING
gameData.pig.tex.bPageFlushed = 0;
PIGGY_PAGE_IN (gameData.pig.tex.pBmIndex [tMapTop], gameStates.app.bD1Mission);
PIGGY_PAGE_IN (gameData.pig.tex.pBmIndex [tMapBot], gameStates.app.bD1Mission);
if (gameData.pig.tex.bPageFlushed)	{	// If cache got flushed, re-read 'em.
	gameData.pig.tex.bPageFlushed = 0;
	PIGGY_PAGE_IN (gameData.pig.tex.pBmIndex [tMapTop], gameStates.app.bD1Mission);
	PIGGY_PAGE_IN (gameData.pig.tex.pBmIndex [tMapBot], gameStates.app.bD1Mission);
	}
Assert (gameData.pig.tex.bPageFlushed == 0);
#endif

bmTop = BmOverride (gameData.pig.tex.pBitmaps + gameData.pig.tex.pBmIndex [tMapTop].index, -1);
bmBot = BmOverride (gameData.pig.tex.pBitmaps + gameData.pig.tex.pBmIndex [tMapBot].index, -1);
if (!bmTop->bmPalette)
	bmTop->bmPalette = gamePalette;
if (!bmBot->bmPalette)
	bmBot->bmPalette = gamePalette;
cacheP = texCache + nLRU;
bmP = cacheP->bitmap;
if (bmP)
	OglFreeBmTexture(bmP);

// if necessary, allocate cache bitmap
// in any case make sure the cache bitmap has the proper size
if (!bmP ||
	(bmP->bmProps.w != bmBot->bmProps.w) || 
	(bmP->bmProps.h != bmBot->bmProps.h)) {
	if (bmP)
		GrFreeBitmap (bmP);
	cacheP->bitmap =
	bmP = GrCreateBitmap (bmBot->bmProps.w, bmBot->bmProps.h, 4);
	if (!bmP)
		return NULL;
	}
else
	bmP->bmProps.flags = (char) BM_FLAG_TGA;
if (!bmP->bmTexBuf)
	return NULL;
bmP->bmPalette = gamePalette;
if (!(gameOpts->ogl.bGlTexMerge && gameStates.render.textures.bGlsTexMergeOk)) {
	if (bmTop->bmProps.flags & BM_FLAG_SUPER_TRANSPARENT) {
//			return bmTop;
		MergeTextures (nOrient, bmBot, bmTop, bmP, 1);
		bmP->bmProps.flags |= BM_FLAG_TRANSPARENT | BM_FLAG_SUPER_TRANSPARENT;
		bmP->bmAvgColor = bmTop->bmAvgColor;
		}
	else {
//			MergeTexturesNormal (nOrient, bmBot, bmTop, bmP->bmTexBuf);
		MergeTextures (nOrient, bmBot, bmTop, bmP, 0);
		bmP->bmProps.flags |= bmBot->bmProps.flags & (~BM_FLAG_RLE);
		bmP->bmAvgColor = bmBot->bmAvgColor;
		}
	}
cacheP->bmTop = bmTop;
cacheP->bmBot = bmBot;
cacheP->last_frame_used = gameData.app.nFrameCount;
cacheP->nOrient = nOrient;
return bmP;
}
Ejemplo n.º 2
0
void MergeTextures (
	int nType, grsBitmap * bmBot, grsBitmap * bmTop, grsBitmap *dest_bmp, int bSuperTransp)
{
	tRGBA		*c;
	int		i, x, y, bw, bh, tw, th, dw, dh;
	int		bTopBPP, bBtmBPP, bST = 0;
	frac		topScale, btmScale;
	tRGBA		*dest_data = (tRGBA *) dest_bmp->bmTexBuf;

	ubyte * top_data, *bottom_data, *top_pal, *btmPalette;

bmBot = BmOverride (bmBot, -1);
bmTop = BmOverride (bmTop, -1);
if (gameOpts->ogl.bGlTexMerge && gameStates.render.textures.bGlsTexMergeOk)
	return;
if (bmTop->bmProps.flags & BM_FLAG_RLE)
	bmTop = rle_expand_texture (bmTop);

if (bmBot->bmProps.flags & BM_FLAG_RLE)
	bmBot = rle_expand_texture (bmBot);

//	Assert(bmBot != bmTop);

top_data = bmTop->bmTexBuf;
bottom_data = bmBot->bmTexBuf;
top_pal = bmTop->bmPalette;
btmPalette = bmBot->bmPalette;

//	Assert(bottom_data != top_data);

//Int3();
bh =
bw = bmBot->bmProps.w;
//h = bmBot->bmProps.h;
th =
tw = bmTop->bmProps.w;
dw =
dh = dest_bmp->bmProps.w;
//th = bmTop->bmProps.h;
#if 1
// square textures assumed here, so no test for h!
if (dw < tw) {
	topScale.c = tw / dw;
	topScale.d = 1;
	}
else  {
	topScale.c = 1;
	topScale.d = dw / tw;
	}
if (dw < bw) {
	btmScale.c = bw / dw;
	btmScale.d = 1;
	}
else {
	btmScale.c = dw / bw;
	btmScale.d = 1;
	}
#else
if (w > bmTop->bmProps.w)
	w = h = bmBot->bmProps.w;
scale.c = scale.d = 1;
#endif
bTopBPP = bmTop->bmBPP;
bBtmBPP = bmBot->bmBPP;
#ifdef _DEBUG
memset (dest_data, 253, dest_bmp->bmProps.w * dest_bmp->bmProps.h * 4);
#endif
switch(nType)	{
	case 0:
		// Normal
		for (i = y = 0; y < dh; y++)
			for (x = 0; x < dw; x++, i++) {
				c = C (top_pal, top_data, tw * TOPSCALE (y) + TOPSCALE (x), bTopBPP, &bST);
				if (!(bST || c->a))
					c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST);
				dest_data [i] = *c;
			}
		break;
	case 1:
		// 
		for (i = y = 0; y < dh; y++)
			for (x = 0; x < dw; x++, i++) {
				c = C (top_pal, top_data, tw * TOPSCALE (x) + th - 1 - TOPSCALE (y), bTopBPP, &bST);
				if (!(bST || c->a))
					c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST);
				dest_data [i] = *c;
			}
		break;
	case 2:
		// Normal
		for (i = y = 0; y < dh; y++)
			for (x = 0; x < dw; x++, i++) {
				c = C (top_pal, top_data, tw * (th - 1 - TOPSCALE (y)) + tw - 1 - TOPSCALE (x), bTopBPP, &bST);
				if (!(bST || c->a))
					c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST);
				dest_data [i] = *c;
			}
		break;
	case 3:
		// Normal
		for (i = y = 0; y < dh; y++)
			for (x = 0; x < dw; x++, i++) {
				c = C (top_pal, top_data, tw * (th - 1 - TOPSCALE (x)) + TOPSCALE (y), bTopBPP, &bST);
				if (!(bST || c->a))
					c = C (btmPalette, bottom_data, BTMIDX, bBtmBPP, &bST);
				dest_data [i] = *c;
			}
		break;
	}
}
Ejemplo n.º 3
0
int PixelTranspType (short nTexture, short nOrient, short nFrame, fix u, fix v)
{
	CBitmap *bmP;
	int bmx, bmy, w, h, offs;
	ubyte	c;
#if 0
	tBitmapIndex *bmiP;

bmiP = gameData.pig.tex.bmIndexP + (nTexture);
LoadBitmap (*bmiP, gameStates.app.bD1Data);
bmP = BmOverride (gameData.pig.tex.bitmapP + bmiP->index);
#else
bmP = LoadFaceBitmap (nTexture, nFrame);
if (!bmP->Buffer ())
	return 0;
#endif
if (bmP->Flags () & BM_FLAG_RLE)
	bmP = rle_expand_texture (bmP);
w = bmP->Width ();
h = ((bmP->Type () == BM_TYPE_ALT) && bmP->Frames ()) ? w : bmP->Height ();
if (nOrient == 0) {
	bmx = ((unsigned) X2I (u * w)) % w;
	bmy = ((unsigned) X2I (v * h)) % h;
	}
else if (nOrient == 1) {
	bmx = ((unsigned) X2I ((I2X (1) - v) * w)) % w;
	bmy = ((unsigned) X2I (u * h)) % h;
	}
else if (nOrient == 2) {
	bmx = ((unsigned) X2I ((I2X (1) - u) * w)) % w;
	bmy = ((unsigned) X2I ((I2X (1) - v) * h)) % h;
	}
else {
	bmx = ((unsigned) X2I (v * w)) % w;
	bmy = ((unsigned) X2I ((I2X (1) - u) * h)) % h;
	}
offs = bmy * w + bmx;
if (bmP->Flags () & BM_FLAG_TGA) {
	ubyte *p;

	if (bmP->BPP () == 3)	//no alpha -> no transparency
		return 0;
	p = bmP->Buffer () + offs * bmP->BPP ();
	// check super transparency color
#if 1
	if ((p [0] == 120) && (p [1] == 88) && (p [2] == 128))
#else
	if ((gameOpts->ogl.bGlTexMerge) ?
	    (p [3] == 1) : ((p [0] == 120) && (p [1] == 88) && (p [2] == 128)))
#endif
		return -1;
	// check alpha
	if (!p [3])
		return 1;
	}
else {
	c = bmP->Buffer () [offs];
	if (c == SUPER_TRANSP_COLOR)
		return -1;
	if (c == TRANSPARENCY_COLOR)
		return 1;
	}
return 0;
}