//-----------------------------------------------------------------------------
// Does a texture have alpha?
//-----------------------------------------------------------------------------
static bool DoesTextureUseAlpha( const char *pTextureName, const char *pMaterialName )
{
	if ( IsX360() )
	{
		// not supporting
		return false;
	}

	// Special textures start with '_'..
	if ( pTextureName[0] == '_' )
		return false;

	// The texture name doubles as the relative file name
	// It's assumed to have already been set by this point	
	// Compute the cache name
	char pCacheFileName[MATERIAL_MAX_PATH];
	Q_snprintf( pCacheFileName, sizeof( pCacheFileName ), "materials/%s.vtf", pTextureName );

	CUtlBuffer buf;
	FileHandle_t fileHandle = g_pFullFileSystem->Open( pCacheFileName, "rb" );
	if ( fileHandle == FILESYSTEM_INVALID_HANDLE)
	{
		Warning( "Material \"%s\": can't open texture \"%s\"\n", pMaterialName, pCacheFileName );
		return false;
	}

	// Check the .vtf for an alpha channel
	IVTFTexture *pVTFTexture = CreateVTFTexture();

	int nHeaderSize = VTFFileHeaderSize( VTF_MAJOR_VERSION );
	buf.EnsureCapacity( nHeaderSize );

	// read the header first.. it's faster!!
	g_pFullFileSystem->Read( buf.Base(), nHeaderSize, fileHandle );
	buf.SeekPut( CUtlBuffer::SEEK_HEAD, nHeaderSize );

	// Unserialize the header
	bool bUsesAlpha = false;

	if (!pVTFTexture->Unserialize( buf, true ))
	{
		Warning( "Error reading material \"%s\"\n", pCacheFileName );
		g_pFullFileSystem->Close(fileHandle);
	}
	else
	{
		if ( pVTFTexture->Flags() & (TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA) )
		{
			bUsesAlpha = true;
		}
	}

	DestroyVTFTexture( pVTFTexture );
	g_pFullFileSystem->Close( fileHandle );
	return bUsesAlpha;
}
예제 #2
0
//-----------------------------------------------------------------------------
// These are methods to help with optimization of file access
//-----------------------------------------------------------------------------
void CVTFTexture::LowResFileInfo( int *pStartLocation, int *pSizeInBytes) const
{
	// Once the header is read in, they indicate where to start reading
	// other data, and how many bytes to read....
	*pStartLocation = VTFFileHeaderSize();

	if ((m_nLowResImageWidth == 0) || (m_nLowResImageHeight == 0))
	{
		*pSizeInBytes = 0;
	}
	else
	{
		*pSizeInBytes = ImageLoader::GetMemRequired( m_nLowResImageWidth, 
			m_nLowResImageHeight, m_LowResImageFormat, false );
	}
}