示例#1
0
//---------------------------------------------------------------------------
long VFXShapeElement::getTextureHandle (long height)
{
	DWORD textureResult = 0;

	if (height == -1)
	{
		//-----------------------------------------------
		// We need to take the shape bounds and find the
		// smallest texture buffer that will hold it.
		// Create an empty Keyed buffer for now.
		long textureSize = VFX_shape_bounds(shapeTable[0],frameNum[0]);

		long xRes = textureSize >> 16;
		long yRes = textureSize & 0x0000ffff;

		if ((xRes < 16) && (yRes < 16))
		{
			textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",16,gosHint_DisableMipmap);
		}
		else if ((xRes < 32) && (yRes < 32))
		{
			textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",32,gosHint_DisableMipmap);
		}
		else if ((xRes < 64) && (yRes < 64))
		{
			textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",64,gosHint_DisableMipmap);
		}
		else if ((xRes < 128) && (yRes < 128))
		{
			textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",128,gosHint_DisableMipmap);
		}
		else if ((xRes < 256) && (yRes < 256))
		{
			textureResult = gos_NewEmptyTexture(gos_Texture_Keyed,"ShapeTable",256,gosHint_DisableMipmap);
		}
	}
示例#2
0
//----------------------------------------------------------------------
// MC_TextureNode
DWORD MC_TextureNode::get_gosTextureHandle (void)	//If texture is not in VidRAM, cache a texture out and cache this one in.
{
	if (gosTextureHandle == 0xffffffff)
	{
		//Somehow this texture is bad.  Probably we are using a handle which got purged between missions.
		// Just send back, NO TEXTURE and we should be able to debug from there because the tri will have no texture!!
		return 0x0;
	}
	
	if (gosTextureHandle != CACHED_OUT_HANDLE)
	{
		lastUsed = turn;
		return gosTextureHandle;
	}
	else
	{
		if ((mcTextureManager->currentUsedTextures >= MAX_MC2_GOS_TEXTURES) && !mcTextureManager->flushCache())
			return 0x0;		//No texture!
	   
		if (width == 0)
			return 0;		//These faces have no texture!!

		if (!textureData)
			return 0x0;		//No Texture.  Cache is out of RAM!!

		if (width > 0xf0000000)
		{
			//------------------------------------------
			// Cache this badboy IN.
			// Badboys are now LZ Compressed in texture cache.
			// Uncompress, then memcpy.
			long origSize = LZDecomp(MC_TextureManager::lzBuffer2,(MemoryPtr)textureData,lzCompSize);
			if (origSize != (long)(width & 0x0fffffff))
				STOP(("Decompressed to different size from original!  Txm:%s  Width:%d  DecompSize:%d",nodeName,(width & 0x0fffffff),origSize));

			if (origSize >= MAX_LZ_BUFFER_SIZE)
				STOP(("Texture TOO large: %s",nodeName));
			
			gosTextureHandle = gos_NewTextureFromMemory(key,nodeName,MC_TextureManager::lzBuffer2,(width & 0x0fffffff),hints);
			mcTextureManager->currentUsedTextures++;
			lastUsed = turn;
			
			return gosTextureHandle;
		}
		else
		{
			gosTextureHandle = gos_NewEmptyTexture(key,nodeName,width,hints);
			mcTextureManager->currentUsedTextures++;
			
			//------------------------------------------
			// Cache this badboy IN.
			TEXTUREPTR pTextureData;
			gos_LockTexture(gosTextureHandle, 0, 0, &pTextureData);
		 
			//-------------------------------------------------------
			// Create a block of cache memory to hold this texture.
			DWORD txmSize = pTextureData.Height * pTextureData.Height * sizeof(DWORD);
			gosASSERT(textureData);
			
			LZDecomp(MC_TextureManager::lzBuffer2,(MemoryPtr)textureData,lzCompSize);
			memcpy(pTextureData.pTexture,MC_TextureManager::lzBuffer2,txmSize);
			 
			//------------------------
			// Unlock the texture
			gos_UnLockTexture(gosTextureHandle);
			 
			lastUsed = turn;
			return gosTextureHandle;
		}
	}
}