uid issue
This commit is contained in:
@ -0,0 +1,46 @@
|
||||
// ----------------------------------------- //
|
||||
// File generated by VPC //
|
||||
// ----------------------------------------- //
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\studio.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\studio.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\studio.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_lib_check.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_lib_check.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_lib_check.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeamalgtexture.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeamalgtexture.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeamalgtexture.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeimage.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeimage.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeimage.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeprecompiledtexture.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeprecompiledtexture.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmeprecompiledtexture.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmesheetsequence.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmesheetsequence.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmesheetsequence.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmetexture.cpp
|
||||
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmetexture.cpp
|
||||
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\materialobjects\dmetexture.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
938
materialobjects/dmeamalgtexture.cpp
Normal file
938
materialobjects/dmeamalgtexture.cpp
Normal file
@ -0,0 +1,938 @@
|
||||
//===== Copyright <20> 2005-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: build a sheet data file and a large image out of multiple images
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialobjects/dmeamalgtexture.h"
|
||||
#include "bitmap/floatbitmap.h"
|
||||
#include "tier2/fileutils.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "materialobjects/dmesheetsequence.h"
|
||||
#include "resourcefile/schema/sheet.g.h"
|
||||
#include "resourcefile/resourcestream.h"
|
||||
#include "materialobjects/dmeimage.h"
|
||||
#include "bitmap/psheet.h"
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper functions
|
||||
//-----------------------------------------------------------------------------
|
||||
static int GetChannelIndexFromChar( char c )
|
||||
{
|
||||
// r->0 b->1 g->2 a->3 else -1
|
||||
|
||||
static char s_ChannelIDs[] = "rgba";
|
||||
|
||||
char const *pChanChar = strchr( s_ChannelIDs, c );
|
||||
if ( ! pChanChar )
|
||||
{
|
||||
Warning( " bad channel name '%c'\n", c );
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return pChanChar - s_ChannelIDs;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clear the contents of the channel
|
||||
//-----------------------------------------------------------------------------
|
||||
static void ZeroChannel( FloatBitMap_t *newBitmap, FloatBitMap_t *pBitmap, int nDestChannel )
|
||||
{
|
||||
for ( int y = 0; y < newBitmap->NumRows(); y++ )
|
||||
{
|
||||
for ( int x = 0; x < newBitmap->NumCols(); x++ )
|
||||
{
|
||||
pBitmap->Pixel( x, y, 0, nDestChannel ) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static void CopyChannel( FloatBitMap_t *newBitmap, FloatBitMap_t *pBitmap, int nSrcChannel, int nDestChannel )
|
||||
{
|
||||
for ( int y = 0; y < newBitmap->NumRows(); y++ )
|
||||
{
|
||||
for ( int x = 0; x < newBitmap->NumCols(); x++ )
|
||||
{
|
||||
pBitmap->Pixel( x, y, 0, nDestChannel ) = newBitmap->Pixel( x, y, 0, nSrcChannel );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get a full path to fname that is under mod/content/materialsrc
|
||||
// This is where all tgas live.
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetFullPathUsingMaterialsrcContent( const char * fname, char *pFullTGAFileNameDest, int fullPathBufferSize )
|
||||
{
|
||||
char localTexturePath[MAX_PATH];
|
||||
Q_snprintf( localTexturePath, sizeof(localTexturePath), "materialsrc\\%s", fname );
|
||||
const char *result = g_pFullFileSystem->RelativePathToFullPath( localTexturePath, "CONTENT", pFullTGAFileNameDest, fullPathBufferSize );
|
||||
if ( result == NULL )
|
||||
{
|
||||
Warning( "CDataModel: Unable to generate full path for file %s\n", fname );
|
||||
pFullTGAFileNameDest = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Get a full path to fname that is under the current directory.
|
||||
// mksheet is meant to be run from a dir that contains all the tga files
|
||||
// referred to by the .mks file. This fxn lets it find the local files.
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetFullPathUsingCurrentDir( const char * fname, char *pFullTGAFileNameDest, int fullPathBufferSize )
|
||||
{
|
||||
char pDir[MAX_PATH];
|
||||
if ( g_pFullFileSystem->GetCurrentDirectory( pDir, sizeof(pDir) ) )
|
||||
{
|
||||
CUtlString fullPathName = pDir;
|
||||
fullPathName += "\\";
|
||||
fullPathName += fname;
|
||||
Q_strncpy( pFullTGAFileNameDest, fullPathName.Get(), fullPathBufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning( "CDataModel: Unable to generate full path for file %s\n", fname );
|
||||
pFullTGAFileNameDest = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
static FloatBitMap_t *CreateFloatBitmap( const char *pFilename, bool bUseCurrentDir = false )
|
||||
{
|
||||
if ( strchr( pFilename, ',' ) == NULL )
|
||||
{
|
||||
char fullTGAFileName[ MAX_PATH ];
|
||||
if ( Q_IsAbsolutePath( pFilename ) )
|
||||
{
|
||||
Q_strncpy( fullTGAFileName, pFilename, sizeof( fullTGAFileName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( bUseCurrentDir )
|
||||
{
|
||||
GetFullPathUsingCurrentDir( pFilename, fullTGAFileName, sizeof(fullTGAFileName) );
|
||||
}
|
||||
else
|
||||
{
|
||||
GetFullPathUsingMaterialsrcContent( pFilename, fullTGAFileName, sizeof(fullTGAFileName) );
|
||||
}
|
||||
}
|
||||
if ( fullTGAFileName == NULL )
|
||||
{
|
||||
Warning( "CDataModel: Unable to generate full path for file %s\n", pFilename );
|
||||
}
|
||||
return new FloatBitMap_t( fullTGAFileName );
|
||||
}
|
||||
|
||||
// Warning this is Untested not in use currently.
|
||||
|
||||
// parse extended specifications
|
||||
CUtlVector<char *> Images;
|
||||
V_SplitString( pFilename, ",", Images );
|
||||
FloatBitMap_t *pBitmap = NULL;
|
||||
// now, process bitmaps, performing copy operations specified by {} syntax
|
||||
for( int i = 0; i < Images.Count(); i++ )
|
||||
{
|
||||
char fnamebuf[MAX_PATH];
|
||||
strcpy( fnamebuf, Images[i] );
|
||||
char * pBrace = strchr( fnamebuf, '{' );
|
||||
if ( pBrace )
|
||||
{
|
||||
*pBrace = 0; // null it
|
||||
pBrace++; // point at control specifier
|
||||
char *pEndBrace = strchr( pBrace, '}' );
|
||||
if ( ! pEndBrace )
|
||||
{
|
||||
Msg( "bad extended bitmap synax (no close brace) - %s \n", Images[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FloatBitMap_t newBitmap( fnamebuf );
|
||||
if ( !pBitmap )
|
||||
{
|
||||
// first image sets size
|
||||
pBitmap = new FloatBitMap_t( &newBitmap );
|
||||
}
|
||||
|
||||
// now, process operation specifiers of the form "{chan=chan}" or "{chan=0}"
|
||||
if ( pBrace && ( pBrace[1] == '=' ) )
|
||||
{
|
||||
int nDstChan = GetChannelIndexFromChar( pBrace[0] );
|
||||
if ( nDstChan != -1 )
|
||||
{
|
||||
if ( pBrace[2] == '0' )
|
||||
{
|
||||
// zero the channel
|
||||
ZeroChannel( &newBitmap, pBitmap, nDstChan );
|
||||
}
|
||||
else
|
||||
{
|
||||
int nSrcChan = GetChannelIndexFromChar( pBrace[2] );
|
||||
if ( nSrcChan != -1 )
|
||||
{
|
||||
// perform the channel copy
|
||||
CopyChannel( &newBitmap, pBitmap, nSrcChan, nDstChan );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pBitmap;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeAmalgamatedTexture, CDmeAmalgamatedTexture );
|
||||
|
||||
void CDmeAmalgamatedTexture::OnConstruction()
|
||||
{
|
||||
m_ImageList.Init( this, "images" );
|
||||
m_ePackingMode.InitAndSet( this, "packmode", PCKM_FLAT );
|
||||
m_Sequences.Init( this, "sequences" );
|
||||
m_nWidth.Init( this, "width" );
|
||||
m_nHeight.Init( this, "height" );
|
||||
m_pPackedImage.Init( this, "packedImage" );
|
||||
|
||||
m_SequenceCount = 0;
|
||||
}
|
||||
|
||||
void CDmeAmalgamatedTexture::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::Init( const char *pShtFileName, bool bUseCurrentDir )
|
||||
{
|
||||
CDisableUndoScopeGuard sg;
|
||||
m_pCurSequence = NULL;
|
||||
|
||||
// Load up the image bitmaps.
|
||||
char pFullDir[MAX_PATH];
|
||||
Q_strncpy( pFullDir, pShtFileName, sizeof(pFullDir) );
|
||||
Q_StripFilename( pFullDir );
|
||||
|
||||
char pFullPath[MAX_PATH];
|
||||
for( int i = 0; i < m_ImageList.Count(); i++ )
|
||||
{
|
||||
// FIXME: Ugh!
|
||||
const char *pImageName = m_ImageList[i]->GetName();
|
||||
if ( bUseCurrentDir && Q_IsAbsolutePath( pShtFileName ) )
|
||||
{
|
||||
Q_ComposeFileName( pFullDir, pImageName, pFullPath, sizeof(pFullPath) );
|
||||
pImageName = pFullPath;
|
||||
}
|
||||
|
||||
m_ImageList[i]->m_pImage = CreateFloatBitmap( pImageName, bUseCurrentDir );
|
||||
}
|
||||
|
||||
m_SequenceCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Whether the frames loop or not
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::SetCurrentSequenceClamp( bool bState )
|
||||
{
|
||||
if ( m_pCurSequence )
|
||||
{
|
||||
m_pCurSequence->m_Clamp = bState;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeAmalgamatedTexture::GetPackingMode()
|
||||
{
|
||||
return m_ePackingMode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::SetPackingMode( int eMode )
|
||||
{
|
||||
// Assign the packing mode read in to member var.
|
||||
if ( !m_Sequences.Count() )
|
||||
{
|
||||
m_ePackingMode = eMode;
|
||||
}
|
||||
else if ( m_ePackingMode != eMode )
|
||||
{
|
||||
// Allow special changes:
|
||||
// flat -> rgb+a
|
||||
if ( m_ePackingMode == PCKM_FLAT && eMode == PCKM_RGB_A )
|
||||
{
|
||||
m_ePackingMode = eMode;
|
||||
}
|
||||
// everything else
|
||||
else
|
||||
{
|
||||
Warning( "*** line error: incompatible packmode change when %d sequences already defined!\n", m_Sequences.Count() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::CreateNewSequence( int mode )
|
||||
{
|
||||
m_pCurSequence = CreateElement<CDmeSheetSequence>( "", GetFileId() );
|
||||
m_pCurSequence->m_nSequenceNumber = m_SequenceCount;
|
||||
m_SequenceCount++;
|
||||
SetSequenceType( mode );
|
||||
|
||||
m_Sequences.AddToTail( m_pCurSequence );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeAmalgamatedTexture::GetSequenceType()
|
||||
{
|
||||
return m_pCurSequence->m_eMode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::SetSequenceType( int eMode )
|
||||
{
|
||||
m_pCurSequence->m_eMode = eMode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::CurrentSequenceExists()
|
||||
{
|
||||
return m_pCurSequence != NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Validate that image packing is correct
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::ValidateImagePacking( CDmeSheetImage *pBitmap, char *pImageName )
|
||||
{
|
||||
if ( m_ePackingMode == PCKM_RGB_A )
|
||||
{
|
||||
for ( uint16 idx = 0; idx < pBitmap->m_mapSequences.Count(); ++idx )
|
||||
{
|
||||
CDmeSheetSequence *pSeq = pBitmap->FindSequence( idx );
|
||||
Assert( pSeq );
|
||||
|
||||
if ( pSeq->m_eMode != SQM_RGBA &&
|
||||
pSeq->m_eMode != m_pCurSequence->m_eMode )
|
||||
{
|
||||
Warning( "*** line error: 'rgb+a' packing cannot pack image '%s' belonging to sequences %d and %d!\n",
|
||||
pImageName,
|
||||
pSeq->m_nSequenceNumber,
|
||||
m_pCurSequence->m_nSequenceNumber );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::CreateFrame( CUtlVector<char *> &imageNames, float ftime )
|
||||
{
|
||||
CDmeSheetSequenceFrame *pNewFrame = CreateElement<CDmeSheetSequenceFrame>( "", GetFileId() );
|
||||
pNewFrame->m_fDisplayTime = ftime;
|
||||
|
||||
for ( int i = 0; i < imageNames.Count(); i++ )
|
||||
{
|
||||
Assert( imageNames.Count() <= MAX_IMAGES_PER_FRAME );
|
||||
AddImage( pNewFrame, imageNames[i] );
|
||||
}
|
||||
|
||||
m_pCurSequence->m_Frames.AddToTail( pNewFrame->GetHandle() );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::AddImage( CDmeSheetSequenceFrame *pNewSequenceFrame, char *pImageName )
|
||||
{
|
||||
// Store the image in the image list, this is a string - bitmap mapping.
|
||||
CDmeSheetImage *pBitmap = FindImage( pImageName );
|
||||
if ( !pBitmap )
|
||||
{
|
||||
CDmeSheetImage *pBitmap = CreateElement<CDmeSheetImage>( pImageName, GetFileId() );
|
||||
pBitmap->m_pImage = CreateFloatBitmap( pImageName );
|
||||
m_ImageList.AddToTail( pBitmap );
|
||||
}
|
||||
|
||||
pBitmap = FindImage( pImageName );
|
||||
Assert( pBitmap );
|
||||
|
||||
pNewSequenceFrame->m_pSheetImages.AddToTail( pBitmap );
|
||||
|
||||
ValidateImagePacking( pBitmap, pImageName );
|
||||
|
||||
pBitmap->m_mapSequences.AddToTail( m_pCurSequence);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Calls packimages with different widths to find the best size.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::DetermineBestPacking()
|
||||
{
|
||||
int nBestWidth = -1;
|
||||
int nBestSize = (1 << 30 );
|
||||
int nBestSquareness = ( 1 << 30 ); // how square the texture is
|
||||
for( int nTryWidth = 2048; nTryWidth >= 64; nTryWidth >>= 1 )
|
||||
{
|
||||
bool bSuccess = PackImages( false, nTryWidth );
|
||||
if ( !bSuccess )
|
||||
break;
|
||||
|
||||
// Msg( "Packing option: %d x %d (%d pixels)\n", m_nWidth.Get(), m_nHeight.Get(), m_nWidth.Get() * m_nHeight.Get() );
|
||||
|
||||
bool bPreferThisPack = false;
|
||||
|
||||
int thisSize = m_nHeight * m_nWidth;
|
||||
int thisSquareness = ( m_nWidth.Get() == m_nHeight.Get() ) ? 1 : ( m_nHeight / m_nWidth + m_nWidth / m_nHeight );
|
||||
|
||||
if ( thisSize < nBestSize )
|
||||
{
|
||||
while ( (nTryWidth >> 1) >= m_nWidth )
|
||||
nTryWidth >>= 1;
|
||||
|
||||
bPreferThisPack = true;
|
||||
}
|
||||
else if ( thisSize == nBestSize && thisSquareness < nBestSquareness )
|
||||
{
|
||||
bPreferThisPack = true;
|
||||
}
|
||||
|
||||
if ( bPreferThisPack )
|
||||
{
|
||||
nBestWidth = nTryWidth;
|
||||
nBestSize = thisSize;
|
||||
nBestSquareness = thisSquareness;
|
||||
}
|
||||
}
|
||||
|
||||
if ( nBestWidth < 0 )
|
||||
{
|
||||
Warning( "Packing error: failed to pack images!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_nWidth = nBestWidth;
|
||||
m_nHeight = nBestSize / nBestWidth;
|
||||
|
||||
// Msg( "Best option: %d x %d (%d pixels)%s\n", m_nWidth.Get(), m_nHeight.Get(), m_nWidth.Get() * m_nHeight.Get(), ( m_nWidth.Get() == m_nHeight.Get() ) ? " : square texture" : "" );
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::PackImages( bool bGenerateImage, int nWidth )
|
||||
{
|
||||
if ( !m_pPackedImage )
|
||||
{
|
||||
m_pPackedImage = CreateElement< CDmeImage >( GetName(), GetFileId() );
|
||||
}
|
||||
|
||||
switch ( m_ePackingMode )
|
||||
{
|
||||
case PCKM_FLAT:
|
||||
return PackImagesFlat( bGenerateImage, nWidth );
|
||||
case PCKM_RGB_A:
|
||||
return PackImagesRGBA( bGenerateImage, nWidth );
|
||||
case PCKM_INVALID:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::PackImagesFlat( bool bGenerateImage, int nWidth )
|
||||
{
|
||||
int nMaxWidth = nWidth;
|
||||
int nMaxHeight = 2048;
|
||||
|
||||
// !! bug !! packing algorithm is dumb and no error checking is done!
|
||||
FloatBitMap_t &output = m_pPackedImage->BeginFloatBitmapModification();
|
||||
if ( bGenerateImage )
|
||||
{
|
||||
output.Init( nMaxWidth, nMaxHeight );
|
||||
}
|
||||
|
||||
int cur_line = 0;
|
||||
int cur_column = 0;
|
||||
int next_line = 0;
|
||||
int max_column_written = 0;
|
||||
|
||||
for ( int i = 0; i < m_ImageList.Count(); i++ )
|
||||
{
|
||||
CDmeSheetImage &sheetImage = *(m_ImageList[i]);
|
||||
if ( sheetImage.m_pImage == NULL )
|
||||
{
|
||||
Warning( "CDataModel: Image %s was not loaded! Unable to pack.\n", sheetImage.GetName() );
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( cur_column + sheetImage.m_pImage->NumCols() > nMaxWidth )
|
||||
{
|
||||
// no room!
|
||||
cur_column = 0;
|
||||
cur_line = next_line;
|
||||
next_line = cur_line;
|
||||
}
|
||||
// now, pack
|
||||
if ( ( cur_column + sheetImage.m_pImage->NumCols() > nMaxWidth ) ||
|
||||
( cur_line + sheetImage.m_pImage->NumRows() > nMaxHeight ) )
|
||||
{
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return false; // didn't fit! doh
|
||||
}
|
||||
|
||||
sheetImage.m_XCoord = cur_column;
|
||||
sheetImage.m_YCoord = cur_line;
|
||||
|
||||
if ( bGenerateImage ) // don't actually pack the pixel if we're not keeping them
|
||||
{
|
||||
int ic[4];
|
||||
int nc = sheetImage.m_pImage->ComputeValidAttributeList( ic );
|
||||
for ( int y = 0; y < sheetImage.m_pImage->NumRows(); y++ )
|
||||
{
|
||||
for ( int x = 0; x < sheetImage.m_pImage->NumCols(); x++ )
|
||||
{
|
||||
for ( int c = 0; c < nc; c++ )
|
||||
{
|
||||
output.Pixel( x + cur_column, y + cur_line, 0, ic[c] ) = sheetImage.m_pImage->Pixel( x, y, 0, ic[c] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next_line = MAX( next_line, cur_line + sheetImage.m_pImage->NumRows() );
|
||||
cur_column += sheetImage.m_pImage->NumCols();
|
||||
max_column_written = MAX( max_column_written, cur_column );
|
||||
}
|
||||
|
||||
// now, truncate height
|
||||
int h = 1;
|
||||
for( h; h < next_line; h *= 2 )
|
||||
;
|
||||
// truncate width;
|
||||
int w = 1;
|
||||
for( 1; w < max_column_written; w *= 2 )
|
||||
;
|
||||
|
||||
if ( bGenerateImage )
|
||||
{
|
||||
output.Crop( 0, 0, 0, w, h, 1 );
|
||||
}
|
||||
|
||||
// Store these for UV calculation later on
|
||||
m_nHeight = h;
|
||||
m_nWidth = w;
|
||||
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::PackImagesRGBA( bool bGenerateImage, int nWidth )
|
||||
{
|
||||
int nMaxWidth = nWidth;
|
||||
int nMaxHeight = 2048;
|
||||
|
||||
// !! bug !! packing algorithm is dumb and no error checking is done!
|
||||
FloatBitMap_t &output = m_pPackedImage->BeginFloatBitmapModification();
|
||||
if ( bGenerateImage )
|
||||
{
|
||||
output.Init( nMaxWidth, nMaxHeight );
|
||||
}
|
||||
|
||||
int cur_line[2] = {0};
|
||||
int cur_column[2] = {0};
|
||||
int next_line[2] = {0};
|
||||
int max_column_written[2] = {0};
|
||||
|
||||
bool bPackingRGBA = true;
|
||||
|
||||
for ( int i = 0; i < m_ImageList.Count(); i++ )
|
||||
{
|
||||
CDmeSheetImage &sheetImage = *( m_ImageList[i] );
|
||||
if ( sheetImage.m_pImage == NULL )
|
||||
{
|
||||
Warning( "CDataModel: Image %s was not loaded! Unable to pack.\n", sheetImage.GetName() );
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return false;
|
||||
}
|
||||
|
||||
int idxfrm;
|
||||
CDmeSheetSequence *pSequence = sheetImage.FindSequence( 0 );
|
||||
Assert( pSequence );
|
||||
int eMode = pSequence->m_eMode;
|
||||
switch ( eMode )
|
||||
{
|
||||
case SQM_RGB:
|
||||
idxfrm = 0;
|
||||
bPackingRGBA = false;
|
||||
break;
|
||||
case SQM_ALPHA:
|
||||
idxfrm = 1;
|
||||
bPackingRGBA = false;
|
||||
break;
|
||||
case SQM_RGBA:
|
||||
if ( !bPackingRGBA )
|
||||
{
|
||||
Msg( "*** error when packing 'rgb+a', bad sequence %d encountered for image '%s' after all rgba frames packed!\n",
|
||||
pSequence->m_nSequenceNumber,
|
||||
m_ImageList[i]->GetName() );
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return false;
|
||||
}
|
||||
idxfrm = 0;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
Msg( "*** error when packing 'rgb+a', bad sequence %d encountered for image '%s'!\n",
|
||||
pSequence->m_nSequenceNumber,
|
||||
m_ImageList[i]->GetName() );
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( cur_column[idxfrm] + sheetImage.m_pImage->NumCols() > nMaxWidth )
|
||||
{
|
||||
// no room!
|
||||
cur_column[idxfrm] = 0;
|
||||
cur_line[idxfrm] = next_line[idxfrm];
|
||||
next_line[idxfrm] = cur_line[idxfrm];
|
||||
}
|
||||
|
||||
// now, pack
|
||||
if ( ( cur_column[idxfrm] + sheetImage.m_pImage->NumCols() > nMaxWidth ) ||
|
||||
( cur_line[idxfrm] + sheetImage.m_pImage->NumRows() > nMaxHeight ) )
|
||||
{
|
||||
return false; // didn't fit! doh
|
||||
}
|
||||
|
||||
sheetImage.m_XCoord = cur_column[idxfrm];
|
||||
sheetImage.m_YCoord = cur_line[idxfrm];
|
||||
|
||||
if ( bGenerateImage ) // don't actually pack the pixel if we're not keeping them
|
||||
{
|
||||
for ( int y = 0; y < sheetImage.m_pImage->NumRows(); y++ )
|
||||
{
|
||||
for ( int x = 0; x < sheetImage.m_pImage->NumCols(); x++ )
|
||||
{
|
||||
for ( int c = 0; c < 4; c++ )
|
||||
{
|
||||
switch ( eMode )
|
||||
{
|
||||
case SQM_RGB:
|
||||
if ( c < 3 )
|
||||
goto setpx;
|
||||
break;
|
||||
case SQM_ALPHA:
|
||||
if ( c == 3 )
|
||||
goto setpx;
|
||||
break;
|
||||
case SQM_RGBA:
|
||||
if ( c < 4 )
|
||||
goto setpx;
|
||||
break;
|
||||
setpx:
|
||||
output.Pixel( x + cur_column[idxfrm], y + cur_line[idxfrm], 0, c ) = sheetImage.m_pImage->Pixel(x, y, 0, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next_line[idxfrm] = MAX( next_line[idxfrm], cur_line[idxfrm] + sheetImage.m_pImage->NumRows() );
|
||||
cur_column[idxfrm] += sheetImage.m_pImage->NumCols();
|
||||
max_column_written[idxfrm] = MAX( max_column_written[idxfrm], cur_column[idxfrm] );
|
||||
|
||||
if ( bPackingRGBA )
|
||||
{
|
||||
cur_line[1] = cur_line[0];
|
||||
cur_column[1] = cur_column[0];
|
||||
next_line[1] = next_line[0];
|
||||
max_column_written[1] = max_column_written[0];
|
||||
}
|
||||
}
|
||||
|
||||
// now, truncate height
|
||||
int h = 1;
|
||||
for ( int idxfrm = 0; idxfrm < 2; ++idxfrm )
|
||||
{
|
||||
for ( h; h < next_line[idxfrm]; h *= 2 )
|
||||
continue;
|
||||
}
|
||||
// truncate width;
|
||||
int w = 1;
|
||||
for ( int idxfrm = 0; idxfrm < 2; ++idxfrm )
|
||||
{
|
||||
for ( w; w < max_column_written[idxfrm]; w *= 2 )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( bGenerateImage )
|
||||
{
|
||||
output.Crop( 0, 0, 0, w, h, 1 );
|
||||
}
|
||||
|
||||
// Store these for UV calculation later on
|
||||
m_nHeight = h;
|
||||
m_nWidth = w;
|
||||
m_pPackedImage->EndFloatBitmapModification();
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Write out .sht file.
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeAmalgamatedTexture::WriteTGA( const char *pFileName )
|
||||
{
|
||||
if ( !pFileName )
|
||||
goto tgaWriteFailed;
|
||||
|
||||
if ( !m_pPackedImage )
|
||||
goto tgaWriteFailed;
|
||||
|
||||
if ( !m_pPackedImage->FloatBitmap()->WriteTGAFile( pFileName ) )
|
||||
goto tgaWriteFailed;
|
||||
|
||||
Msg( "Ok: successfully saved TGA \"%s\"\n", pFileName );
|
||||
return true;
|
||||
|
||||
tgaWriteFailed:
|
||||
Msg( "Error: failed to save TGA \"%s\"!\n", pFileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Write out .sht file.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeAmalgamatedTexture::WriteFile( const char *pFileName, bool bVerbose )
|
||||
{
|
||||
if ( !pFileName )
|
||||
{
|
||||
Msg( "Error: No output filename set!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
COutputFile Outfile( pFileName );
|
||||
if ( !Outfile.IsOk() )
|
||||
{
|
||||
Msg( "Error: failed to write SHT \"%s\"!\n", pFileName );
|
||||
return;
|
||||
}
|
||||
|
||||
Outfile.PutInt( 1 ); // version #
|
||||
Outfile.PutInt( m_Sequences.Count() );
|
||||
|
||||
// Debugging.
|
||||
if ( bVerbose )
|
||||
{
|
||||
Msg( "1\n");
|
||||
Msg( "m_Sequences.Count() %d\n", m_Sequences.Count());
|
||||
}
|
||||
|
||||
for ( int i = 0; i < m_Sequences.Count(); i++ )
|
||||
{
|
||||
Outfile.PutInt( m_Sequences[i]->m_nSequenceNumber );
|
||||
|
||||
int nSeqFlags = 0;
|
||||
|
||||
if ( m_Sequences[i]->m_Clamp )
|
||||
{
|
||||
nSeqFlags |= SEQ_FLAG_CLAMP;
|
||||
}
|
||||
|
||||
if ( m_Sequences[i]->m_eMode == SQM_RGB )
|
||||
{
|
||||
nSeqFlags |= SEQ_FLAG_NO_ALPHA;
|
||||
}
|
||||
else if ( m_Sequences[i]->m_eMode == SQM_ALPHA )
|
||||
{
|
||||
nSeqFlags |= SEQ_FLAG_NO_COLOR;
|
||||
}
|
||||
|
||||
Outfile.PutInt( nSeqFlags );
|
||||
|
||||
Outfile.PutInt( m_Sequences[i]->m_Frames.Count() );
|
||||
|
||||
// write total sequence length
|
||||
float fTotal = 0.0;
|
||||
for ( int j = 0; j < m_Sequences[i]->m_Frames.Count(); j++ )
|
||||
{
|
||||
fTotal += m_Sequences[i]->m_Frames[j]->m_fDisplayTime;
|
||||
}
|
||||
Outfile.PutFloat( fTotal );
|
||||
|
||||
// Debugging.
|
||||
if ( bVerbose )
|
||||
{
|
||||
Msg( "m_Sequences[%d]->m_nSequenceNumber %d\n", i, m_Sequences[i]->m_nSequenceNumber.Get() );
|
||||
Msg( "m_Sequences[%d]->m_Clamp %d\n", i, m_Sequences[i]->m_Clamp?1:0 );
|
||||
Msg( "m_Sequences[%d] flags %d\n", i, nSeqFlags );
|
||||
Msg( "m_Sequences[%d]->m_Frames.Count() %d\n", i, m_Sequences[i]->m_Frames.Count());
|
||||
Msg( "fTotal %f\n", fTotal );
|
||||
}
|
||||
|
||||
for( int j = 0; j < m_Sequences[i]->m_Frames.Count(); j++ )
|
||||
{
|
||||
Outfile.PutFloat( m_Sequences[i]->m_Frames[j]->m_fDisplayTime );
|
||||
if ( bVerbose )
|
||||
{
|
||||
Msg( "m_Sequences[%d]->m_Frames[%d]->m_fDisplayTime %f\n", i, j, m_Sequences[i]->m_Frames[j]->m_fDisplayTime.Get() );
|
||||
}
|
||||
// output texture coordinates
|
||||
Assert( m_Sequences[i]->m_Frames[j]->m_pSheetImages.Count() > 0 );
|
||||
for( int t = 0; t < m_Sequences[i]->m_Frames[j]->m_pSheetImages.Count(); t++ )
|
||||
{
|
||||
//xmin
|
||||
Outfile.PutFloat( UCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_XCoord ) );
|
||||
|
||||
//ymin
|
||||
Outfile.PutFloat( VCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_YCoord ) );
|
||||
|
||||
//xmax
|
||||
Outfile.PutFloat(
|
||||
UCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_XCoord +
|
||||
m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_pImage->NumCols() - 1 ));
|
||||
|
||||
//ymax
|
||||
Outfile.PutFloat(
|
||||
VCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_YCoord +
|
||||
m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_pImage->NumRows() - 1 ));
|
||||
|
||||
// Debugging.
|
||||
if ( bVerbose )
|
||||
{
|
||||
Msg( "xmin %f\n", UCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_XCoord ) );
|
||||
Msg( "ymin %f\n", VCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_YCoord ) );
|
||||
Msg( "xmax %f\n", UCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_XCoord +
|
||||
m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_pImage->NumCols() - 1 ) );
|
||||
Msg( "ymax %f\n", VCoord( m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_YCoord +
|
||||
m_Sequences[i]->m_Frames[j]->m_pSheetImages[t]->m_pImage->NumRows() - 1 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Sequenceframes must have 4 entries in the .sht file.
|
||||
// We store up to 4 in the dme elements
|
||||
// Add in the missing entries as dummy data.
|
||||
for( int t = m_Sequences[i]->m_Frames[j]->m_pSheetImages.Count(); t < MAX_IMAGES_PER_FRAME; t++ )
|
||||
{
|
||||
Outfile.PutFloat(0.0);
|
||||
Outfile.PutFloat(0.0);
|
||||
Outfile.PutFloat(0.0);
|
||||
Outfile.PutFloat(0.0);
|
||||
|
||||
// Debugging.
|
||||
if ( bVerbose )
|
||||
{
|
||||
Msg( "xmin %f\nymin %f\nxmax %f\nymax %f\n", 0.0, 0.0, 0.0 ,0.0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Msg( "Ok: successfully saved SHT \"%s\"\n", pFileName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Write out .sht file.
|
||||
//-----------------------------------------------------------------------------
|
||||
void *CDmeAmalgamatedTexture::WriteFile( CResourceStream *pStream, ResourceId_t nTextureResourceId )
|
||||
{
|
||||
Sheet_t *pSheet = pStream->Allocate< Sheet_t >( 1 );
|
||||
pSheet->m_hTexture.WriteReference( nTextureResourceId );
|
||||
|
||||
int nCount = m_Sequences.Count();
|
||||
pSheet->m_Sequences = pStream->Allocate< SheetSequence_t >( nCount );
|
||||
|
||||
for ( int i = 0; i < nCount; i++ )
|
||||
{
|
||||
CDmeSheetSequence *pDmeSeq = m_Sequences[i];
|
||||
SheetSequence_t &seq = pSheet->m_Sequences[i];
|
||||
|
||||
seq.m_nId = pDmeSeq->m_nSequenceNumber;
|
||||
seq.m_bClamp = pDmeSeq->m_Clamp;
|
||||
|
||||
int nFrameCount = pDmeSeq->m_Frames.Count();
|
||||
seq.m_Frames = pStream->Allocate< SheetSequenceFrame_t >( nFrameCount );
|
||||
|
||||
seq.m_flTotalTime = 0.0;
|
||||
for( int j = 0; j < nFrameCount; j++ )
|
||||
{
|
||||
CDmeSheetSequenceFrame *pDmeFrame = pDmeSeq->m_Frames[j];
|
||||
SheetSequenceFrame_t &frame = seq.m_Frames[i];
|
||||
|
||||
// Compute total sequence length
|
||||
seq.m_flTotalTime += pDmeFrame->m_fDisplayTime;
|
||||
|
||||
frame.m_flDisplayTime = pDmeFrame->m_fDisplayTime;
|
||||
|
||||
int nImageCount = pDmeFrame->m_pSheetImages.Count();
|
||||
frame.m_Images = pStream->Allocate< SheetFrameImage_t >( nImageCount );
|
||||
|
||||
// output texture coordinates
|
||||
Assert( nImageCount > 0 );
|
||||
for( int t = 0; t < nImageCount; t++ )
|
||||
{
|
||||
CDmeSheetImage *pDmeImage = pDmeFrame->m_pSheetImages[t];
|
||||
SheetFrameImage_t &image = frame.m_Images[t];
|
||||
|
||||
image.uv[0].x = UCoord( pDmeImage->m_XCoord );
|
||||
image.uv[0].y = VCoord( pDmeImage->m_YCoord );
|
||||
image.uv[1].x = UCoord( pDmeImage->m_XCoord + pDmeImage->m_pImage->NumCols() - 1 );
|
||||
image.uv[1].y = VCoord( pDmeImage->m_YCoord + pDmeImage->m_pImage->NumRows() - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pSheet;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeSheetImage *CDmeAmalgamatedTexture::FindImage( const char *pImageName )
|
||||
{
|
||||
int nCount = m_ImageList.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeSheetImage *pImage = m_ImageList[i];
|
||||
if ( !Q_stricmp( pImageName, pImage->GetName() ) )
|
||||
return pImage;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
234
materialobjects/dmedemo2.cpp
Normal file
234
materialobjects/dmedemo2.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
//===== Copyright <20> 2005-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: build a sheet data file and a large image out of multiple images
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialobjects/dmedemo2.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a quad
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadV2, CDmeQuadV2 );
|
||||
|
||||
void CDmeQuadV2::OnConstruction()
|
||||
{
|
||||
m_X0.Init( this, "x0" );
|
||||
m_Y0.Init( this, "y0" );
|
||||
m_X1.Init( this, "x1" );
|
||||
m_Y1.Init( this, "y1" );
|
||||
m_Color.InitAndSet( this, "color", Color( 255, 255, 255, 255 ) );
|
||||
}
|
||||
|
||||
void CDmeQuadV2::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a list of quads
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadListV2, CDmeQuadListV2 );
|
||||
void CDmeQuadListV2::OnConstruction()
|
||||
{
|
||||
m_Quads.Init( this, "quads" );
|
||||
}
|
||||
|
||||
void CDmeQuadListV2::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// List management
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadListV2::AddQuad( CDmeQuadV2 *pQuad )
|
||||
{
|
||||
m_Quads.InsertBefore( 0, pQuad );
|
||||
}
|
||||
|
||||
CDmeQuadV2 *CDmeQuadListV2::FindQuadByName( const char *pName )
|
||||
{
|
||||
for ( int i = 0; i < m_Quads.Count(); ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pName, m_Quads[i]->GetName() ) )
|
||||
return m_Quads[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CDmeQuadListV2::RemoveQuad( CDmeQuadV2 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeQuadListV2::RemoveAllQuads()
|
||||
{
|
||||
m_Quads.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Render order management
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadListV2::MoveToFront( CDmeQuadV2 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
m_Quads.AddToTail( pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeQuadListV2::MoveToBack( CDmeQuadV2 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
m_Quads.InsertBefore( 0, pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a the editor 'document'
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadDocV2, CDmeQuadDocV2 );
|
||||
void CDmeQuadDocV2::OnConstruction()
|
||||
{
|
||||
m_Quads.InitAndCreate( this, "quadList" );
|
||||
m_SelectedQuads.Init( this, "selectedQuads", FATTRIB_DONTSAVE );
|
||||
}
|
||||
|
||||
void CDmeQuadDocV2::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds quad, resets selection to new quad
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::AddQuad( const char *pName, int x0, int y0, int x1, int y1 )
|
||||
{
|
||||
CDmeQuadV2 *pQuadV2 = CreateElement< CDmeQuadV2 >( pName, GetFileId() );
|
||||
pQuadV2->m_X0 = x0;
|
||||
pQuadV2->m_X1 = x1;
|
||||
pQuadV2->m_Y0 = y0;
|
||||
pQuadV2->m_Y1 = y1;
|
||||
m_Quads->AddQuad( pQuadV2 );
|
||||
|
||||
ClearSelection();
|
||||
AddQuadToSelection( pName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears selection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::ClearSelection()
|
||||
{
|
||||
m_SelectedQuads.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds quad to selection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::AddQuadToSelection( const char *pName )
|
||||
{
|
||||
CDmeQuadV2 *pQuad = m_Quads->FindQuadByName( pName );
|
||||
if ( pQuad )
|
||||
{
|
||||
m_SelectedQuads.AddToTail( pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deletes selected quads
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::DeleteSelectedQuads()
|
||||
{
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
DestroyElement( m_SelectedQuads[i] );
|
||||
}
|
||||
ClearSelection();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Changes quad color
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::SetSelectedQuadColor( int r, int g, int b, int a )
|
||||
{
|
||||
Color c( r, g, b, a );
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV2 *pQuad = m_SelectedQuads[i];
|
||||
pQuad->m_Color.Set( c );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Moves quads
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::MoveSelectedQuads( int dx, int dy )
|
||||
{
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV2 *pQuad = m_SelectedQuads[i];
|
||||
pQuad->m_X0 += dx;
|
||||
pQuad->m_X1 += dx;
|
||||
pQuad->m_Y0 += dy;
|
||||
pQuad->m_Y1 += dy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resizes selected quad (works only when 1 quad is selected)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::ResizeSelectedQuad( int nWidth, int nHeight )
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
CDmeQuadV2 *pQuad = m_SelectedQuads[0];
|
||||
pQuad->m_X1 = pQuad->m_X0 + nWidth;
|
||||
pQuad->m_Y1 = pQuad->m_Y0 + nHeight;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Moves selected quad to front/back (works only when 1 quad is selected)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV2::MoveSelectedToFront()
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
m_Quads->MoveToFront( m_SelectedQuads[0] );
|
||||
}
|
||||
|
||||
void CDmeQuadDocV2::MoveSelectedToBack()
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
m_Quads->MoveToBack( m_SelectedQuads[0] );
|
||||
}
|
322
materialobjects/dmedemo3.cpp
Normal file
322
materialobjects/dmedemo3.cpp
Normal file
@ -0,0 +1,322 @@
|
||||
//===== Copyright <20> 2005-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: build a sheet data file and a large image out of multiple images
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialobjects/dmedemo3.h"
|
||||
#include "tier1/strtools.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a quad
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadV3, CDmeQuadV3 );
|
||||
|
||||
void CDmeQuadV3::OnConstruction()
|
||||
{
|
||||
m_X0.Init( this, "x0" );
|
||||
m_Y0.Init( this, "y0" );
|
||||
m_X1.Init( this, "x1" );
|
||||
m_Y1.Init( this, "y1" );
|
||||
m_Color.InitAndSet( this, "color", Color( 255, 255, 255, 255 ) );
|
||||
}
|
||||
|
||||
void CDmeQuadV3::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a list of quads
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadListV3, CDmeQuadListV3 );
|
||||
void CDmeQuadListV3::OnConstruction()
|
||||
{
|
||||
m_Quads.Init( this, "quads" );
|
||||
}
|
||||
|
||||
void CDmeQuadListV3::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iteration necessary to render
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeQuadListV3::GetQuadCount() const
|
||||
{
|
||||
return m_Quads.Count();
|
||||
}
|
||||
|
||||
CDmeQuadV3 *CDmeQuadListV3::GetQuad( int i )
|
||||
{
|
||||
return m_Quads[ i ];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// List management
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadListV3::AddQuad( CDmeQuadV3 *pQuad )
|
||||
{
|
||||
m_Quads.InsertBefore( 0, pQuad );
|
||||
}
|
||||
|
||||
CDmeQuadV3 *CDmeQuadListV3::FindQuadByName( const char *pName )
|
||||
{
|
||||
for ( int i = 0; i < m_Quads.Count(); ++i )
|
||||
{
|
||||
if ( !Q_stricmp( pName, m_Quads[i]->GetName() ) )
|
||||
return m_Quads[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CDmeQuadListV3::RemoveQuad( CDmeQuadV3 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeQuadListV3::RemoveAllQuads()
|
||||
{
|
||||
m_Quads.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Render order management
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadListV3::MoveToFront( CDmeQuadV3 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
m_Quads.AddToTail( pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeQuadListV3::MoveToBack( CDmeQuadV3 *pQuad )
|
||||
{
|
||||
int nIndex = m_Quads.Find( pQuad );
|
||||
if ( nIndex != m_Quads.InvalidIndex() )
|
||||
{
|
||||
m_Quads.Remove( nIndex );
|
||||
m_Quads.InsertBefore( 0, pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Dme version of a the editor 'document'
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeQuadDocV3, CDmeQuadDocV3 );
|
||||
void CDmeQuadDocV3::OnConstruction()
|
||||
{
|
||||
m_QuadList.InitAndCreate( this, "quadList" );
|
||||
m_SelectedQuads.Init( this, "selectedQuads", FATTRIB_DONTSAVE );
|
||||
}
|
||||
|
||||
void CDmeQuadDocV3::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Iteration necessary to render
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeQuadDocV3::GetQuadCount() const
|
||||
{
|
||||
return m_QuadList->GetQuadCount();
|
||||
}
|
||||
|
||||
CDmeQuadV3 *CDmeQuadDocV3::GetQuad( int i )
|
||||
{
|
||||
return m_QuadList->GetQuad( i );
|
||||
}
|
||||
|
||||
int CDmeQuadDocV3::GetSelectedQuadCount() const
|
||||
{
|
||||
return m_SelectedQuads.Count();
|
||||
}
|
||||
|
||||
CDmeQuadV3 *CDmeQuadDocV3::GetSelectedQuad( int i )
|
||||
{
|
||||
return m_SelectedQuads[i];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds quad, resets selection to new quad
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::AddQuad( const char *pName, int x0, int y0, int x1, int y1 )
|
||||
{
|
||||
CDmeQuadV3 *pQuadV3 = CreateElement< CDmeQuadV3 >( pName, GetFileId() );
|
||||
pQuadV3->m_X0 = x0;
|
||||
pQuadV3->m_X1 = x1;
|
||||
pQuadV3->m_Y0 = y0;
|
||||
pQuadV3->m_Y1 = y1;
|
||||
m_QuadList->AddQuad( pQuadV3 );
|
||||
|
||||
ClearSelection();
|
||||
AddQuadToSelection( pName );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Clears selection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::ClearSelection()
|
||||
{
|
||||
m_SelectedQuads.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds quad to selection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::AddQuadToSelection( const char *pName )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_QuadList->FindQuadByName( pName );
|
||||
if ( pQuad )
|
||||
{
|
||||
if ( m_SelectedQuads.Find( pQuad ) == m_SelectedQuads.InvalidIndex() )
|
||||
{
|
||||
m_SelectedQuads.AddToTail( pQuad );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Add quads in rect to selection
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::AddQuadsInRectToSelection( int x0, int y0, int x1, int y1 )
|
||||
{
|
||||
if ( x0 > x1 )
|
||||
{
|
||||
swap( x0, x1 );
|
||||
}
|
||||
if ( y0 > y1 )
|
||||
{
|
||||
swap( y0, y1 );
|
||||
}
|
||||
|
||||
int nCount = m_QuadList->GetQuadCount();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_QuadList->GetQuad( i );
|
||||
|
||||
if ( x0 < pQuad->MaxX() && x1 > pQuad->MinX() && y0 < pQuad->MaxY() && y1 > pQuad->MinY() )
|
||||
{
|
||||
if ( m_SelectedQuads.Find( pQuad ) == m_SelectedQuads.InvalidIndex() )
|
||||
{
|
||||
m_SelectedQuads.AddToTail( pQuad );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is point in selected quad?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmeQuadDocV3::IsPointInSelectedQuad( int x, int y ) const
|
||||
{
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_SelectedQuads[i];
|
||||
if ( x >= pQuad->MinX() && x <= pQuad->MaxX() && y >= pQuad->MinY() && y <= pQuad->MaxY() )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Deletes selected quads
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::DeleteSelectedQuads()
|
||||
{
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = nCount; --i >= 0; )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_SelectedQuads[i];
|
||||
m_SelectedQuads.FastRemove( i );
|
||||
DestroyElement( pQuad );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Changes quad color
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::SetSelectedQuadColor( int r, int g, int b, int a )
|
||||
{
|
||||
Color c( r, g, b, a );
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_SelectedQuads[i];
|
||||
pQuad->m_Color.Set( c );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Moves quads
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::MoveSelectedQuads( int dx, int dy )
|
||||
{
|
||||
int nCount = m_SelectedQuads.Count();
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CDmeQuadV3 *pQuad = m_SelectedQuads[i];
|
||||
pQuad->m_X0 += dx;
|
||||
pQuad->m_X1 += dx;
|
||||
pQuad->m_Y0 += dy;
|
||||
pQuad->m_Y1 += dy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resizes selected quad (works only when 1 quad is selected)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::ResizeSelectedQuad( int nWidth, int nHeight )
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
CDmeQuadV3 *pQuad = m_SelectedQuads[0];
|
||||
pQuad->m_X1 = pQuad->m_X0 + nWidth;
|
||||
pQuad->m_Y1 = pQuad->m_Y0 + nHeight;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Moves selected quad to front/back (works only when 1 quad is selected)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeQuadDocV3::MoveSelectedToFront()
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
m_QuadList->MoveToFront( m_SelectedQuads[0] );
|
||||
}
|
||||
|
||||
void CDmeQuadDocV3::MoveSelectedToBack()
|
||||
{
|
||||
if ( m_SelectedQuads.Count() != 1 )
|
||||
return;
|
||||
|
||||
m_QuadList->MoveToBack( m_SelectedQuads[0] );
|
||||
}
|
522
materialobjects/dmeimage.cpp
Normal file
522
materialobjects/dmeimage.cpp
Normal file
@ -0,0 +1,522 @@
|
||||
//====== Copyright <20> 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "materialobjects/dmeimage.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "bitmap/imageformat.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeImage, CDmeImage );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::OnConstruction()
|
||||
{
|
||||
m_nWidth.Init( this, "width", FATTRIB_HIDDEN );
|
||||
m_nHeight.Init( this, "height", FATTRIB_HIDDEN );
|
||||
m_nDepth.Init( this, "depth", FATTRIB_HIDDEN );
|
||||
m_nFormat.Init( this, "format", FATTRIB_HIDDEN );
|
||||
m_flGamma.Init( this, "gamma", FATTRIB_HIDDEN );
|
||||
m_Bits.Init( this, "bits", FATTRIB_HIDDEN | FATTRIB_HAS_CALLBACK );
|
||||
m_Mode = DMEIMAGE_STORAGE_NONE;
|
||||
m_bInModification = false;
|
||||
m_bInFloatBitmapModification = false;
|
||||
m_bIgnoreChangedBitsAttribute = false;
|
||||
m_hModify = NULL;
|
||||
}
|
||||
|
||||
void CDmeImage::OnDestruction()
|
||||
{
|
||||
Assert( !m_bInModification && !m_bInFloatBitmapModification );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used to make sure the attribute is well-behaved
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::OnAttributeChanged( CDmAttribute *pAttribute )
|
||||
{
|
||||
BaseClass::OnAttributeChanged( pAttribute );
|
||||
if ( pAttribute == m_Bits.GetAttribute() )
|
||||
{
|
||||
if ( !m_bIgnoreChangedBitsAttribute )
|
||||
{
|
||||
// If the attribute changed (undo), the attribute contains the bits;
|
||||
// discard the float bitmap state
|
||||
if ( m_Mode == DMEIMAGE_STORAGE_FLOAT_BITMAP )
|
||||
{
|
||||
SetFloatBitmapStorageMode( false, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeImage::OnElementUnserialized()
|
||||
{
|
||||
BaseClass::OnElementUnserialized();
|
||||
|
||||
// After reading, the attribute contains the bits; discard anything else
|
||||
if ( m_Mode != DMEIMAGE_STORAGE_ATTRIBUTE )
|
||||
{
|
||||
SetFloatBitmapStorageMode( false, true );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeImage::OnElementSerialized()
|
||||
{
|
||||
BaseClass::OnElementSerialized();
|
||||
|
||||
// Prior to serialization, make sure the bits attribute is holding the current bits
|
||||
if ( m_Mode == DMEIMAGE_STORAGE_FLOAT_BITMAP )
|
||||
{
|
||||
SetFloatBitmapStorageMode( false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Initializes the buffer, doesn't allocate space
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::Init( int nWidth, int nHeight, int nDepth, ImageFormat fmt, float flGamma )
|
||||
{
|
||||
if ( IsUsingFloatBitmapStorageMode() )
|
||||
{
|
||||
m_ComputeBits.Shutdown();
|
||||
}
|
||||
m_Bits.Set( NULL, 0 );
|
||||
|
||||
m_nWidth = nWidth;
|
||||
m_nHeight = nHeight;
|
||||
m_nDepth = nDepth;
|
||||
m_nFormat = fmt;
|
||||
m_flGamma = flGamma;
|
||||
m_Mode = DMEIMAGE_STORAGE_NONE;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Image format
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat CDmeImage::Format() const
|
||||
{
|
||||
return (ImageFormat)( m_nFormat.Get() );
|
||||
}
|
||||
|
||||
const char *CDmeImage::FormatName() const
|
||||
{
|
||||
return ImageLoader::GetName( Format() );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns the size of one row
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeImage::RowSizeInBytes( ) const
|
||||
{
|
||||
return ImageLoader::GetMemRequired( m_nWidth, 1, 1, Format(), false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns the size of one z slice
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeImage::ZSliceSizeInBytes( ) const
|
||||
{
|
||||
return ImageLoader::GetMemRequired( m_nWidth, m_nHeight, 1, Format(), false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// returns the total size of the image
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeImage::SizeInBytes( ) const
|
||||
{
|
||||
return ImageLoader::GetMemRequired( m_nWidth, m_nHeight, m_nDepth, Format(), false );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Converts the image into its requested storage mode
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::SetFloatBitmapStorageMode( bool bFloatBitmap, bool bDiscardContents )
|
||||
{
|
||||
Assert( !m_bInModification && !m_bInFloatBitmapModification );
|
||||
|
||||
StorageMode_t nMode = ( bFloatBitmap ) ? DMEIMAGE_STORAGE_FLOAT_BITMAP : DMEIMAGE_STORAGE_ATTRIBUTE;
|
||||
if ( nMode == m_Mode )
|
||||
return;
|
||||
|
||||
// Do this to avoid re-entrancy problems in BeginModification
|
||||
StorageMode_t nOldMode = m_Mode;
|
||||
m_Mode = nMode;
|
||||
|
||||
switch( m_Mode )
|
||||
{
|
||||
case DMEIMAGE_STORAGE_NONE:
|
||||
break;
|
||||
|
||||
case DMEIMAGE_STORAGE_ATTRIBUTE:
|
||||
if ( !bDiscardContents && ( nOldMode == DMEIMAGE_STORAGE_FLOAT_BITMAP ) )
|
||||
{
|
||||
m_nWidth = m_ComputeBits.NumCols();
|
||||
m_nHeight = m_ComputeBits.NumRows();
|
||||
m_nDepth = m_ComputeBits.NumSlices();
|
||||
|
||||
CUtlBinaryBlock &buf = BeginModification();
|
||||
buf.SetLength( SizeInBytes() );
|
||||
m_ComputeBits.WriteToBuffer( buf.Get(), buf.Length(), Format(), Gamma() );
|
||||
EndModification();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Question: If we're in float bitmap mode, but we discard contents,
|
||||
// should we copy back the dimensions?
|
||||
CUtlBinaryBlock &buf = BeginModification();
|
||||
buf.SetLength( SizeInBytes() );
|
||||
EndModification();
|
||||
}
|
||||
m_ComputeBits.Shutdown();
|
||||
break;
|
||||
|
||||
case DMEIMAGE_STORAGE_FLOAT_BITMAP:
|
||||
const ImageFormatInfo_t &info = ImageLoader::ImageFormatInfo( Format() );
|
||||
int nMask = 0;
|
||||
if ( info.m_nNumRedBits > 0 ) nMask |= FBM_ATTR_RED_MASK;
|
||||
if ( info.m_nNumGreenBits > 0 ) nMask |= FBM_ATTR_GREEN_MASK;
|
||||
if ( info.m_nNumBlueBits > 0 ) nMask |= FBM_ATTR_BLUE_MASK;
|
||||
if ( info.m_nNumAlphaBits > 0 ) nMask |= FBM_ATTR_ALPHA_MASK;
|
||||
|
||||
m_ComputeBits.Init( m_nWidth, m_nHeight, m_nDepth, nMask );
|
||||
if ( !bDiscardContents && ( nOldMode == DMEIMAGE_STORAGE_ATTRIBUTE ) )
|
||||
{
|
||||
m_ComputeBits.LoadFromBuffer( m_Bits.Get(), m_Bits.Length(), Format(), Gamma() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copies the bits in whatever form they are currently in
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::CopyFrom( CDmeImage *pSrcImage, ImageFormat fmt )
|
||||
{
|
||||
if ( fmt == IMAGE_FORMAT_UNKNOWN )
|
||||
{
|
||||
fmt = pSrcImage->Format();
|
||||
}
|
||||
|
||||
Init( pSrcImage->Width(), pSrcImage->Height(), pSrcImage->Depth(), fmt, pSrcImage->Gamma() );
|
||||
|
||||
if ( !pSrcImage->HasImageData() )
|
||||
return;
|
||||
|
||||
if ( pSrcImage->IsUsingFloatBitmapStorageMode() )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true, true );
|
||||
m_ComputeBits.LoadFromFloatBitmap( pSrcImage->FloatBitmap() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( pSrcImage->Format() == Format() )
|
||||
{
|
||||
SetImageBits( pSrcImage->ImageBits(), pSrcImage->SizeInBytes() );
|
||||
}
|
||||
else
|
||||
{
|
||||
int nMemory = ImageLoader::GetMemRequired( Width(), Height(), Depth(), 1, Format() );
|
||||
CUtlBinaryBlock &bits = BeginModification();
|
||||
bits.SetLength( nMemory );
|
||||
ImageLoader::ConvertImageFormat( (const uint8*)pSrcImage->ImageBits(), pSrcImage->Format(),
|
||||
(uint8*)bits.Get(), Format(), Width(), Height() * Depth() );
|
||||
EndModification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Color converts the image into the destination format.
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::ConvertFormat( ImageFormat fmt )
|
||||
{
|
||||
if ( fmt == m_nFormat )
|
||||
return;
|
||||
|
||||
if ( ImageLoader::IsCompressed( Format() ) )
|
||||
{
|
||||
// Cannot convert from a compressed format
|
||||
Assert( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ImageLoader::IsCompressed( fmt ) )
|
||||
{
|
||||
// Not supported for compressed textures
|
||||
Assert( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Not super fast, needs to copy the data here even if we use
|
||||
// the faster ImageLoader::ConvertImageFormat calls. And those
|
||||
// don't support volume textures. So, screw it. Doing an easier implementation.
|
||||
// This will convert it to 32323232F, and on return, it will convert
|
||||
// to the desired format.
|
||||
if ( m_Mode == DMEIMAGE_STORAGE_ATTRIBUTE )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true );
|
||||
}
|
||||
|
||||
m_nFormat = fmt;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets the color of every pixel
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::Clear( float r, float g, float b, float a )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true, true );
|
||||
m_ComputeBits.Clear( r, g, b, a );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Compresses an image into this image
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::CompressImage( CDmeImage *pSrcImage, ImageFormat fmt )
|
||||
{
|
||||
if ( ImageLoader::IsCompressed( pSrcImage->Format() ) )
|
||||
{
|
||||
// Cannot convert from a compressed format
|
||||
Assert( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
// Must be a compressed format
|
||||
if ( !ImageLoader::IsCompressed( fmt ) )
|
||||
{
|
||||
Assert( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
Init( pSrcImage->Width(), pSrcImage->Height(), pSrcImage->Depth(), fmt, pSrcImage->Gamma() );
|
||||
|
||||
// We can only convert from a few well-known formats
|
||||
pSrcImage->ConvertFormat( IMAGE_FORMAT_RGBA8888 );
|
||||
|
||||
int nSrcFaceStride = pSrcImage->ZSliceSizeInBytes();
|
||||
int nDstFaceStride = ZSliceSizeInBytes();
|
||||
|
||||
CUtlBinaryBlock &dstBlock = BeginModification();
|
||||
dstBlock.SetLength( SizeInBytes() );
|
||||
|
||||
const uint8* pSrcData = reinterpret_cast< const uint8* >( pSrcImage->ImageBits() );
|
||||
uint8* pDstData = reinterpret_cast< uint8* >( dstBlock.Get() );
|
||||
for ( int z = 0; z < Depth(); ++z, pSrcData += nSrcFaceStride, pDstData += nDstFaceStride )
|
||||
{
|
||||
ImageLoader::ConvertImageFormat( pSrcData, pSrcImage->Format(),
|
||||
pDstData, fmt, pSrcImage->Width(), pSrcImage->Height() );
|
||||
}
|
||||
EndModification();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Reinterprets the image as a new color format; no work is done
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::ReinterpetFormat( ImageFormat fmt )
|
||||
{
|
||||
if ( ImageLoader::SizeInBytes( fmt ) != ImageLoader::SizeInBytes( Format() ) )
|
||||
{
|
||||
// Src + dst format must be the same size for this to work!
|
||||
Assert( 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
m_nFormat = fmt;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copies bits into the image bits buffer
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::SetImageBits( const void *pBits, int nSize )
|
||||
{
|
||||
SetFloatBitmapStorageMode( false, true );
|
||||
m_Bits.Set( pBits, nSize );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used for bit modification
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlBinaryBlock &CDmeImage::BeginModification( )
|
||||
{
|
||||
SetFloatBitmapStorageMode( false );
|
||||
Assert( !m_bInModification && !m_bInFloatBitmapModification );
|
||||
m_bInModification = true;
|
||||
return m_Bits.GetAttribute()->BeginModifyValueInPlace< CUtlBinaryBlock >( &m_hModify );
|
||||
}
|
||||
|
||||
void CDmeImage::EndModification( )
|
||||
{
|
||||
Assert( m_bInModification && !m_bInFloatBitmapModification );
|
||||
m_bInModification = false;
|
||||
m_bIgnoreChangedBitsAttribute = true;
|
||||
m_Bits.GetAttribute()->EndModifyValueInPlace< CUtlBinaryBlock >( m_hModify );
|
||||
m_bIgnoreChangedBitsAttribute = false;
|
||||
m_hModify = NULL;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Used for float bitmap modification
|
||||
//-----------------------------------------------------------------------------
|
||||
FloatBitMap_t &CDmeImage::BeginFloatBitmapModification( )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true );
|
||||
Assert( !m_bInModification && !m_bInFloatBitmapModification );
|
||||
m_bInFloatBitmapModification = true;
|
||||
return m_ComputeBits;
|
||||
}
|
||||
|
||||
void CDmeImage::EndFloatBitmapModification( )
|
||||
{
|
||||
Assert( m_bInFloatBitmapModification && !m_bInModification );
|
||||
m_bInFloatBitmapModification = false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Image data
|
||||
//-----------------------------------------------------------------------------
|
||||
const FloatBitMap_t *CDmeImage::FloatBitmap()
|
||||
{
|
||||
SetFloatBitmapStorageMode( true );
|
||||
return &m_ComputeBits;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Creates an image 1/4 size of the source using a box filter
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::QuarterSize( CDmeImage *pSrcImage )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true, true );
|
||||
pSrcImage->SetFloatBitmapStorageMode( true );
|
||||
pSrcImage->m_ComputeBits.QuarterSize( &m_ComputeBits );
|
||||
m_nFormat = pSrcImage->Format();
|
||||
m_flGamma = pSrcImage->Gamma();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Downsample using nice filter (NOTE: Dest bitmap needs to have been initialized w/ final size)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImage::DownsampleNiceFiltered( const DownsampleInfo_t& info, CDmeImage *pSrcImage )
|
||||
{
|
||||
SetFloatBitmapStorageMode( true, true );
|
||||
pSrcImage->SetFloatBitmapStorageMode( true );
|
||||
pSrcImage->m_ComputeBits.DownsampleNiceFiltered( info, &m_ComputeBits );
|
||||
m_nFormat = pSrcImage->Format();
|
||||
m_flGamma = pSrcImage->Gamma();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeImageArray, CDmeImageArray );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeImageArray::OnConstruction()
|
||||
{
|
||||
m_Images.Init( this, "images" );
|
||||
}
|
||||
|
||||
void CDmeImageArray::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Image format
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeImageArray::ImageCount() const
|
||||
{
|
||||
return m_Images.Count();
|
||||
}
|
||||
|
||||
CDmeImage *CDmeImageArray::GetImage( int nIndex ) const
|
||||
{
|
||||
return m_Images[nIndex];
|
||||
}
|
||||
|
||||
bool CDmeImageArray::IsConsistent( int nWidth, int nHeight, int nDepth, ImageFormat fmt ) const
|
||||
{
|
||||
if ( ImageCount() == 0 )
|
||||
return true;
|
||||
|
||||
CDmeImage *pFirstImage = m_Images[0];
|
||||
return ( nWidth == pFirstImage->Width() && nHeight == pFirstImage->Height() &&
|
||||
fmt == pFirstImage->Format() && nDepth == pFirstImage->Depth() );
|
||||
}
|
||||
|
||||
void CDmeImageArray::AddImage( CDmeImage *pImage )
|
||||
{
|
||||
if ( !IsConsistent( pImage->Width(), pImage->Height(), pImage->Depth(), pImage->Format() ) )
|
||||
{
|
||||
Warning( "Attempted to add different size/format images to the image array!\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
m_Images.AddToTail( pImage );
|
||||
}
|
||||
|
||||
CDmeImage *CDmeImageArray::AddImage( )
|
||||
{
|
||||
CDmeImage *pImage = CreateElement< CDmeImage >( "image", GetFileId() );
|
||||
if ( ImageCount() > 0 )
|
||||
{
|
||||
CDmeImage *pFirstImage = m_Images[0];
|
||||
pImage->Init( pFirstImage->Width(), pFirstImage->Height(),
|
||||
pFirstImage->Depth(), pFirstImage->Format(), pFirstImage->Gamma() );
|
||||
}
|
||||
|
||||
AddImage( pImage );
|
||||
return pImage;
|
||||
}
|
||||
|
||||
|
||||
// Gets dimensions
|
||||
int CDmeImageArray::Width() const
|
||||
{
|
||||
return ( ImageCount() > 0 ) ? m_Images[0]->Width() : -1;
|
||||
}
|
||||
|
||||
int CDmeImageArray::Height() const
|
||||
{
|
||||
return ( ImageCount() > 0 ) ? m_Images[0]->Height() : -1;
|
||||
}
|
||||
|
||||
int CDmeImageArray::Depth() const
|
||||
{
|
||||
return ( ImageCount() > 0 ) ? m_Images[0]->Depth() : -1;
|
||||
}
|
||||
|
||||
ImageFormat CDmeImageArray::Format() const
|
||||
{
|
||||
return ( ImageCount() > 0 ) ? m_Images[0]->Format() : IMAGE_FORMAT_UNKNOWN;
|
||||
}
|
380
materialobjects/dmeprecompiledtexture.cpp
Normal file
380
materialobjects/dmeprecompiledtexture.cpp
Normal file
@ -0,0 +1,380 @@
|
||||
//====== Copyright <20> 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#include "materialobjects/dmeprecompiledtexture.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "materialobjects/dmetexture.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmePrecompiledTexture, CDmePrecompiledTexture );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmePrecompiledTexture::OnConstruction()
|
||||
{
|
||||
m_ImageFileName.Init( this, "imageFileName" );
|
||||
m_Processors.Init( this, "processors" );
|
||||
m_pSourceTexture.Init( this, "sourceTexture" );
|
||||
m_nStartFrame.InitAndSet( this, "startFrame", -1 );
|
||||
m_nEndFrame.InitAndSet( this, "endFrame", -1 );
|
||||
m_nVolumeTextureDepth.InitAndSet( this, "volumeTextureDepth", 1 );
|
||||
m_nTextureArraySize.InitAndSet( this, "textureArraySize", 1 );
|
||||
m_nTextureType.Init( this, "textureType" );
|
||||
m_flBumpScale.InitAndSet( this, "bumpScale", 1.0f );
|
||||
m_flPFMScale.InitAndSet( this, "pfmScale", 1.0f );
|
||||
m_nFilterType.Init( this, "filterType" );
|
||||
m_bClampS.Init( this, "clamps" );
|
||||
m_bClampT.Init( this, "clampt" );
|
||||
m_bClampU.Init( this, "clampu" );
|
||||
m_bLoadMipLevels.Init( this, "loadMipLevels" );
|
||||
m_bBorder.Init( this, "border" );
|
||||
m_bNormalMap.Init( this, "normalMap" );
|
||||
m_bSSBump.Init( this, "ssBump" );
|
||||
m_bNoMip.Init( this, "noMip" );
|
||||
m_bAllMips.Init( this, "allMips" );
|
||||
m_bNoLod.Init( this, "noLod" );
|
||||
m_bNoDebugOverride.Init( this, "noDebugOverride" );
|
||||
m_bNoCompression.Init( this, "noCompression" );
|
||||
m_bHintDxt5Compression.Init( this, "hintDxt5Compression" );
|
||||
}
|
||||
|
||||
void CDmePrecompiledTexture::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Ensures all settings are internally consistent
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CDmePrecompiledTexture::ValidateValues()
|
||||
{
|
||||
if ( ( m_nTextureType == DMETEXTURE_TYPE_CUBEMAP ) && ( m_nTextureArraySize != 1 ) )
|
||||
{
|
||||
// Cubemaps are packed into a single texture in a cross shape
|
||||
Warning( "Specified a cubemap with a texture array size != 1!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( m_nVolumeTextureDepth > 1 ) && ( m_nTextureArraySize != 1 ) )
|
||||
{
|
||||
Warning( "Specified a volume texture with a texture array size != 1!\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m_bLoadMipLevels )
|
||||
{
|
||||
char pBaseName[MAX_PATH];
|
||||
Q_FileBase( GetName(), pBaseName, sizeof( pBaseName ) );
|
||||
|
||||
char pRight[16];
|
||||
V_StrRight( pBaseName, 5, pRight, sizeof( pRight ) );
|
||||
if ( !Q_stristr( pRight, "_mip0" ) )
|
||||
{
|
||||
Warning( "Invalid texture name (\"%s\") for explicitly loading mip levels - the top mip file should end in '_mip0'\n", GetName() );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT( CDmeTextureProcessor );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTextureProcessor::OnConstruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeTextureProcessor::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_ComputeMipmaps, CDmeTP_ComputeMipmaps );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTP_ComputeMipmaps::OnConstruction()
|
||||
{
|
||||
m_bNoNiceFiltering.Init( this, "noNiceFiltering" );
|
||||
m_bAlphaTestDownsampling.Init( this, "alphaTestDownsampling" );
|
||||
m_flAlphaTestDownsampleThreshhold.Init( this, "alphaTestDownsampleThreshhold" );
|
||||
m_flAlphaTestDownsampleHiFreqThreshhold.Init( this, "alphaTestDownsampleHiFreqThreshhold" );
|
||||
}
|
||||
|
||||
void CDmeTP_ComputeMipmaps::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
void CDmeTP_ComputeMipmaps::ProcessTexture( CDmeTexture *pSrcTexture, CDmeTexture *pDstTexture )
|
||||
{
|
||||
int nWidth = pSrcTexture->Width();
|
||||
int nHeight = pSrcTexture->Height();
|
||||
int nDepth = pSrcTexture->Depth();
|
||||
int nTotalMipCount = ImageLoader::GetNumMipMapLevels( nWidth, nHeight, nDepth );
|
||||
|
||||
pSrcTexture->CopyAttributesTo( pDstTexture, TD_NONE );
|
||||
|
||||
// Copying will copy references to src texture frames. Remove them.
|
||||
pDstTexture->RemoveAllFrames();
|
||||
|
||||
DownsampleInfo_t info;
|
||||
info.m_flAlphaThreshhold = m_flAlphaTestDownsampleThreshhold;
|
||||
info.m_flAlphaHiFreqThreshhold = m_flAlphaTestDownsampleHiFreqThreshhold;
|
||||
info.m_nFlags = 0;
|
||||
if ( pSrcTexture->m_bClampS )
|
||||
{
|
||||
info.m_nFlags |= DOWNSAMPLE_CLAMPS;
|
||||
}
|
||||
if ( pSrcTexture->m_bClampT )
|
||||
{
|
||||
info.m_nFlags |= DOWNSAMPLE_CLAMPT;
|
||||
}
|
||||
if ( pSrcTexture->m_bClampU )
|
||||
{
|
||||
info.m_nFlags |= DOWNSAMPLE_CLAMPU;
|
||||
}
|
||||
if ( m_bAlphaTestDownsampling )
|
||||
{
|
||||
info.m_nFlags |= DOWNSAMPLE_ALPHATEST;
|
||||
}
|
||||
|
||||
int nFrameCount = pSrcTexture->FrameCount();
|
||||
CDmeImage **ppSrcImages = (CDmeImage**)stackalloc( nTotalMipCount * sizeof(CDmeImage*) );
|
||||
CDmeImage **ppDstImages = (CDmeImage**)stackalloc( nTotalMipCount * sizeof(CDmeImage*) );
|
||||
for ( int f = 0; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pSrcFrame = pSrcTexture->GetFrame( f );
|
||||
CDmeTextureFrame *pDstFrame = pDstTexture->AddFrame();
|
||||
|
||||
// Add mip level 0 for this frame
|
||||
CDmeImageArray *pSrcArray = pSrcFrame->GetMipLevel( 0 );
|
||||
if ( !pSrcArray )
|
||||
continue;
|
||||
|
||||
for ( int m = 0; m < nTotalMipCount; ++m )
|
||||
{
|
||||
pDstFrame->AddMipLevel();
|
||||
}
|
||||
|
||||
int nImageCount = pSrcFrame->ImageCount();
|
||||
for ( int i = 0; i < nImageCount; ++i )
|
||||
{
|
||||
pSrcTexture->GetImages( f, i, ppSrcImages, nTotalMipCount );
|
||||
CDmeImage *pSrcImage = ppSrcImages[0];
|
||||
if ( !pSrcImage )
|
||||
continue;
|
||||
|
||||
int nMipWidth = nWidth;
|
||||
int nMipHeight = nHeight;
|
||||
int nMipDepth = nDepth;
|
||||
|
||||
for ( int m = 0; m < nTotalMipCount; ++m )
|
||||
{
|
||||
CDmeImageArray *pDstArray = pDstFrame->GetMipLevel( m );
|
||||
CDmeImage *pSrcImage = ppSrcImages[m];
|
||||
CDmeImage *pDstImage = pDstArray->AddImage();
|
||||
ppDstImages[m] = pDstImage;
|
||||
if ( pSrcImage )
|
||||
{
|
||||
Assert( pSrcImage->Width() == nMipWidth );
|
||||
Assert( pSrcImage->Height() == nMipHeight );
|
||||
Assert( pSrcImage->Depth() == nMipDepth );
|
||||
|
||||
// FIXME: Just assign the src image into the dest texture
|
||||
// and remove it from the src texture
|
||||
|
||||
// For mips where we have data, just copy src -> dest.
|
||||
pDstImage->CopyFrom( pSrcImage );
|
||||
}
|
||||
else
|
||||
{
|
||||
// For mips where don't have data, generate a mip from the src data of the previous level
|
||||
Assert( m != 0 && ppDstImages[m-1] );
|
||||
if ( m_bNoNiceFiltering )
|
||||
{
|
||||
pDstImage->QuarterSize( ppDstImages[m-1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
int nSrcMip = clamp( m-3, 0, nTotalMipCount );
|
||||
pDstImage->Init( nMipWidth, nMipHeight, nMipDepth, ppDstImages[nSrcMip]->Format(), ppDstImages[nSrcMip]->Gamma() );
|
||||
pDstImage->DownsampleNiceFiltered( info, ppDstImages[nSrcMip] );
|
||||
}
|
||||
}
|
||||
|
||||
nMipWidth >>= 1; nMipHeight >>= 1; nMipDepth >>= 1;
|
||||
nMipWidth = MAX( 1, nMipWidth ); nMipHeight = MAX( 1, nMipHeight ); nMipDepth = MAX( 1, nMipDepth );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_ChangeColorChannels, CDmeTP_ChangeColorChannels );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTP_ChangeColorChannels::OnConstruction()
|
||||
{
|
||||
m_nMaxChannels.Init( this, "maxChannels" );
|
||||
}
|
||||
|
||||
void CDmeTP_ChangeColorChannels::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
static ImageFormat ComputeDestFormat( ImageFormat fmt, int nChannelCount )
|
||||
{
|
||||
switch( fmt )
|
||||
{
|
||||
case IMAGE_FORMAT_RGBA8888:
|
||||
case IMAGE_FORMAT_ABGR8888:
|
||||
case IMAGE_FORMAT_ARGB8888:
|
||||
case IMAGE_FORMAT_BGRA8888:
|
||||
Assert( nChannelCount != 2 );
|
||||
return ( nChannelCount == 3 ) ? IMAGE_FORMAT_RGB888 : IMAGE_FORMAT_I8;
|
||||
|
||||
case IMAGE_FORMAT_RGB888:
|
||||
case IMAGE_FORMAT_BGR888:
|
||||
case IMAGE_FORMAT_BGRX8888:
|
||||
case IMAGE_FORMAT_RGBX8888:
|
||||
Assert( nChannelCount == 1 );
|
||||
return IMAGE_FORMAT_I8;
|
||||
|
||||
case IMAGE_FORMAT_IA88:
|
||||
Assert( nChannelCount == 1 );
|
||||
return IMAGE_FORMAT_I8;
|
||||
|
||||
case IMAGE_FORMAT_DXT5:
|
||||
Assert( nChannelCount == 3 );
|
||||
return IMAGE_FORMAT_DXT1;
|
||||
|
||||
case IMAGE_FORMAT_RGBA32323232F:
|
||||
if ( nChannelCount == 3 )
|
||||
return IMAGE_FORMAT_RGB323232F;
|
||||
// fall through
|
||||
case IMAGE_FORMAT_RGB323232F:
|
||||
if ( nChannelCount == 2 )
|
||||
return IMAGE_FORMAT_RG3232F;
|
||||
// fall through
|
||||
case IMAGE_FORMAT_RG3232F:
|
||||
Assert( nChannelCount == 1 );
|
||||
return IMAGE_FORMAT_R32F;
|
||||
|
||||
case IMAGE_FORMAT_RGBA16161616F:
|
||||
Assert( nChannelCount != 3 );
|
||||
if ( nChannelCount == 2 )
|
||||
return IMAGE_FORMAT_RG1616F;
|
||||
// fall through
|
||||
case IMAGE_FORMAT_RG1616F:
|
||||
Assert( nChannelCount == 1 );
|
||||
return IMAGE_FORMAT_R16F;
|
||||
|
||||
default:
|
||||
Assert( 0 );
|
||||
break;
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
void CDmeTP_ChangeColorChannels::ProcessImage( CDmeImage *pDstImage, CDmeImage *pSrcImage )
|
||||
{
|
||||
ImageFormat fmt = pSrcImage->Format();
|
||||
ImageFormat dstFmt = fmt;
|
||||
const ImageFormatInfo_t &info = ImageLoader::ImageFormatInfo( fmt );
|
||||
int nChannelCount = 0;
|
||||
if ( info.m_nNumRedBits > 0 ) ++nChannelCount;
|
||||
if ( info.m_nNumGreenBits > 0 ) ++nChannelCount;
|
||||
if ( info.m_nNumBlueBits > 0 ) ++nChannelCount;
|
||||
if ( info.m_nNumAlphaBits > 0 ) ++nChannelCount;
|
||||
if ( nChannelCount > m_nMaxChannels )
|
||||
{
|
||||
dstFmt = ComputeDestFormat( fmt, m_nMaxChannels );
|
||||
}
|
||||
|
||||
pDstImage->CopyFrom( pSrcImage, dstFmt );
|
||||
}
|
||||
|
||||
void CDmeTP_ChangeColorChannels::ProcessTexture( CDmeTexture *pSrcTexture, CDmeTexture *pDstTexture )
|
||||
{
|
||||
pDstTexture->ProcessTexture( pSrcTexture, this, &CDmeTP_ChangeColorChannels::ProcessImage );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
class CDmeTP_OneOverMipLevelInAlpha : public CDmeTextureProcessor
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeTP_OneOverMipLevelInAlpha, CDmeTextureProcessor );
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_OneOverMipLevelInAlpha, CDmeTP_OneOverMipLevelInAlpha );
|
||||
|
||||
class CDmeTP_PreMultiplyColorByOneOverMipLevel : public CDmeTextureProcessor
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeTP_PreMultiplyColorByOneOverMipLevel, CDmeTextureProcessor );
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_PreMultiplyColorByOneOverMipLevel, CDmeTP_PreMultiplyColorByOneOverMipLevel );
|
||||
|
||||
class CDmeTP_NormalToDuDv : public CDmeTextureProcessor
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeTP_NormalToDuDv, CDmeTextureProcessor );
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_NormalToDuDv, CDmeTP_NormalToDuDv );
|
||||
|
||||
class CDmeTP_CompressTexture : public CDmeTextureProcessor
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeTP_CompressTexture, CDmeTextureProcessor );
|
||||
|
||||
public:
|
||||
CDmaVar< bool > m_bNormalGAMap;
|
||||
CDmaVar< bool > m_bDXT5; // FIXME: Should nocompress/dxt5 be combined?
|
||||
CDmaVar< bool > m_bNoCompress;
|
||||
};
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_CompressTexture, CDmeTP_CompressTexture );
|
||||
|
||||
class CDmeTP_GenerateMipmaps : public CDmeTextureProcessor
|
||||
{
|
||||
DEFINE_ELEMENT( CDmeTP_GenerateMipmaps, CDmeTextureProcessor );
|
||||
|
||||
public:
|
||||
CDmaVar< bool > m_bNoNice;
|
||||
CDmaVar< bool > m_bAlphaTest;
|
||||
CDmaVar< float > m_flAlphaThreshhold;
|
||||
CDmaVar< float > m_flAlphaThreshholdHigh;
|
||||
};
|
||||
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTP_GenerateMipmaps, CDmeTP_GenerateMipmaps );
|
||||
*/
|
77
materialobjects/dmesheetsequence.cpp
Normal file
77
materialobjects/dmesheetsequence.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
//===== Copyright <20> 2005-2006, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose: build a sheet data file and a large image out of multiple images
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "materialobjects/dmesheetsequence.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
|
||||
|
||||
// CDmeSheetImage
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSheetImage, CDmeSheetImage );
|
||||
|
||||
void CDmeSheetImage::OnConstruction()
|
||||
{
|
||||
m_XCoord.Init( this, "xcoord" );
|
||||
m_YCoord.Init( this, "ycoord" );
|
||||
m_mapSequences.Init( this, "mapsequences" );
|
||||
}
|
||||
|
||||
void CDmeSheetImage::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
CDmeSheetSequence *CDmeSheetImage::FindSequence( int index )
|
||||
{
|
||||
if ( index < m_mapSequences.Count() )
|
||||
{
|
||||
return m_mapSequences[index];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CDmeSheetSequenceFrame
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSheetSequenceFrame, CDmeSheetSequenceFrame );
|
||||
void CDmeSheetSequenceFrame::OnConstruction()
|
||||
{
|
||||
m_pSheetImages.Init( this, "sheetimages" );
|
||||
m_fDisplayTime.Init( this, "displaytime" );
|
||||
}
|
||||
|
||||
void CDmeSheetSequenceFrame::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// CDmeSheetSequence
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeSheetSequence, CDmeSheetSequence );
|
||||
void CDmeSheetSequence::OnConstruction()
|
||||
{
|
||||
m_nSequenceNumber.Init( this, "sequencenumber" );
|
||||
m_Clamp.Init( this, "clamp" );
|
||||
m_eMode.Init( this, "mode" );
|
||||
m_Frames.Init( this, "frames" );
|
||||
|
||||
m_Clamp = true;
|
||||
m_eMode = SQM_RGBA;
|
||||
}
|
||||
|
||||
void CDmeSheetSequence::OnDestruction()
|
||||
{
|
||||
}
|
394
materialobjects/dmetexture.cpp
Normal file
394
materialobjects/dmetexture.cpp
Normal file
@ -0,0 +1,394 @@
|
||||
//====== Copyright <20> 1996-2004, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
#include "materialobjects/dmetexture.h"
|
||||
#include "datamodel/dmelementfactoryhelper.h"
|
||||
|
||||
#include "materialsystem/IMaterial.h"
|
||||
#include "materialsystem/IMaterialSystem.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTextureFrame, CDmeTextureFrame );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTextureFrame::OnConstruction()
|
||||
{
|
||||
m_MipLevels.Init( this, "mipLevels" );
|
||||
}
|
||||
|
||||
void CDmeTextureFrame::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// List manipulation
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeTextureFrame::MipLevelCount() const
|
||||
{
|
||||
return m_MipLevels.Count();
|
||||
}
|
||||
|
||||
CDmeImageArray *CDmeTextureFrame::GetMipLevel( int nIndex ) const
|
||||
{
|
||||
return m_MipLevels[ nIndex ];
|
||||
}
|
||||
|
||||
void CDmeTextureFrame::AddMipLevel( CDmeImageArray *pImages )
|
||||
{
|
||||
m_MipLevels.AddToTail( pImages );
|
||||
}
|
||||
|
||||
CDmeImageArray *CDmeTextureFrame::AddMipLevel( )
|
||||
{
|
||||
CDmeImageArray *pImages = CreateElement< CDmeImageArray >( "mip", GetFileId() );
|
||||
AddMipLevel( pImages );
|
||||
return pImages;
|
||||
}
|
||||
|
||||
|
||||
int CDmeTextureFrame::ImageCount() const
|
||||
{
|
||||
int nImageCount = 0;
|
||||
int nMipCount = MipLevelCount();
|
||||
for ( int m = 0; m < nMipCount; ++m )
|
||||
{
|
||||
CDmeImageArray *pMipLevel = GetMipLevel( m );
|
||||
nImageCount = MAX( nImageCount, pMipLevel->ImageCount() );
|
||||
}
|
||||
return nImageCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Expose this class to the scene database
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_ELEMENT_FACTORY( DmeTexture, CDmeTexture );
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTexture::OnConstruction()
|
||||
{
|
||||
// m_pVTFTexture = CreateVTFTexture();
|
||||
|
||||
m_bClampS.Init( this, "clampS" );
|
||||
m_bClampT.Init( this, "clampT" );
|
||||
m_bClampU.Init( this, "clampU" );
|
||||
m_bNoDebugOverride.Init( this, "noDebugOverride" );
|
||||
m_bNoLod.Init( this, "noMipmapLOD" );
|
||||
m_bNiceFiltered.Init( this, "niceFiltered" );
|
||||
m_bNormalMap.Init( this, "normalMap" );
|
||||
m_flBumpScale.Init( this, "bumpScale" );
|
||||
m_nCompressType.Init( this, "compressType" );
|
||||
m_nFilterType.Init( this, "filterType" );
|
||||
m_nMipmapType.Init( this, "mipmapType" );
|
||||
m_nTextureType.Init( this, "textureType" );
|
||||
m_Frames.Init( this, "frames" );
|
||||
}
|
||||
|
||||
void CDmeTexture::OnDestruction()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets dimensions
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeTexture::Width() const
|
||||
{
|
||||
int nFrameCount = m_Frames.Count();
|
||||
int nWidth = nFrameCount ? m_Frames[0]->GetMipLevel( 0 )->Width() : 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
for ( int f = 1; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
Assert( pFrame->GetMipLevel( 0 )->Width() == nWidth );
|
||||
}
|
||||
#endif
|
||||
return nWidth;
|
||||
}
|
||||
|
||||
int CDmeTexture::Height() const
|
||||
{
|
||||
int nFrameCount = m_Frames.Count();
|
||||
int nHeight = nFrameCount ? m_Frames[0]->GetMipLevel( 0 )->Height() : 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
for ( int f = 1; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
Assert( pFrame->GetMipLevel( 0 )->Height() == nHeight );
|
||||
}
|
||||
#endif
|
||||
return nHeight;
|
||||
}
|
||||
|
||||
int CDmeTexture::Depth() const
|
||||
{
|
||||
int nFrameCount = m_Frames.Count();
|
||||
int nDepth = nFrameCount ? m_Frames[0]->GetMipLevel( 0 )->Depth() : 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
for ( int f = 1; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
Assert( pFrame->GetMipLevel( 0 )->Depth() == nDepth );
|
||||
}
|
||||
#endif
|
||||
return nDepth;
|
||||
}
|
||||
|
||||
ImageFormat CDmeTexture::Format() const
|
||||
{
|
||||
int nFrameCount = m_Frames.Count();
|
||||
ImageFormat nFormat = nFrameCount ? m_Frames[0]->GetMipLevel( 0 )->Format() : IMAGE_FORMAT_UNKNOWN;
|
||||
|
||||
#ifdef _DEBUG
|
||||
for ( int f = 0; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
int nMipCount = pFrame->MipLevelCount();
|
||||
for ( int m = 0; m < nMipCount; ++m )
|
||||
{
|
||||
CDmeImageArray *pMipLevel = pFrame->GetMipLevel( m );
|
||||
Assert( pMipLevel->Format() == nFormat );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return nFormat;
|
||||
}
|
||||
|
||||
|
||||
int CDmeTexture::MipLevelCount() const
|
||||
{
|
||||
int nFrameCount = m_Frames.Count();
|
||||
int nMipCount = nFrameCount ? m_Frames[0]->MipLevelCount( ) : 0;
|
||||
|
||||
#ifdef _DEBUG
|
||||
for ( int f = 0; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
Assert( nMipCount == pFrame->MipLevelCount() );
|
||||
}
|
||||
#endif
|
||||
return nMipCount;
|
||||
}
|
||||
|
||||
int CDmeTexture::ImageCount() const
|
||||
{
|
||||
int nImageCount = 0;
|
||||
int nFrameCount = m_Frames.Count();
|
||||
for ( int f = 0; f < nFrameCount; ++f )
|
||||
{
|
||||
CDmeTextureFrame *pFrame = m_Frames[f];
|
||||
nImageCount = MAX( nImageCount, pFrame->ImageCount() );
|
||||
}
|
||||
return nImageCount;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes texture flags
|
||||
//-----------------------------------------------------------------------------
|
||||
int CDmeTexture::CalcTextureFlags( int nDepth ) const
|
||||
{
|
||||
int nFlags = 0;
|
||||
if ( m_bClampS )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_CLAMPS;
|
||||
}
|
||||
if ( m_bClampT )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_CLAMPT;
|
||||
}
|
||||
if ( m_bClampU )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_CLAMPU;
|
||||
}
|
||||
if ( m_bNoLod )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_NOLOD;
|
||||
}
|
||||
if ( m_bNormalMap )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_NORMAL;
|
||||
}
|
||||
if ( m_bNormalMap )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_NORMAL;
|
||||
}
|
||||
if ( m_bNoDebugOverride )
|
||||
{
|
||||
nFlags |= TEXTUREFLAGS_NODEBUGOVERRIDE;
|
||||
}
|
||||
|
||||
switch ( m_nCompressType )
|
||||
{
|
||||
case DMETEXTURE_COMPRESS_DEFAULT:
|
||||
case DMETEXTURE_COMPRESS_DXT1:
|
||||
break;
|
||||
case DMETEXTURE_COMPRESS_DXT5:
|
||||
nFlags |= TEXTUREFLAGS_HINT_DXT5;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( m_nFilterType )
|
||||
{
|
||||
case DMETEXTURE_FILTER_DEFAULT:
|
||||
case DMETEXTURE_FILTER_BILINEAR:
|
||||
break;
|
||||
case DMETEXTURE_FILTER_ANISOTROPIC:
|
||||
nFlags |= TEXTUREFLAGS_ANISOTROPIC;
|
||||
break;
|
||||
case DMETEXTURE_FILTER_TRILINEAR:
|
||||
nFlags |= TEXTUREFLAGS_TRILINEAR;
|
||||
break;
|
||||
case DMETEXTURE_FILTER_POINT:
|
||||
nFlags |= TEXTUREFLAGS_POINTSAMPLE;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ( m_nMipmapType )
|
||||
{
|
||||
case DMETEXTURE_MIPMAP_DEFAULT:
|
||||
case DMETEXTURE_MIPMAP_ALL_LEVELS:
|
||||
break;
|
||||
case DMETEXTURE_MIPMAP_NONE:
|
||||
nFlags |= TEXTUREFLAGS_NOMIP;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( nDepth > 1 )
|
||||
{
|
||||
// FIXME: Volume textures don't currently support DXT compression
|
||||
nFlags &= ~TEXTUREFLAGS_HINT_DXT5;
|
||||
}
|
||||
|
||||
return nFlags;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Computes the desired texture format based on flags
|
||||
//-----------------------------------------------------------------------------
|
||||
ImageFormat CDmeTexture::ComputeDesiredImageFormat( ImageFormat srcFormat, int nWidth, int nHeight, int nDepth, int nFlags )
|
||||
{
|
||||
// HDRFIXME: Need to figure out what format to use here.
|
||||
if ( srcFormat == IMAGE_FORMAT_RGB323232F )
|
||||
return IMAGE_FORMAT_RGBA16161616F;
|
||||
|
||||
/*
|
||||
if( bDUDVTarget)
|
||||
{
|
||||
if ( bCopyAlphaToLuminance && ( nFlags & ( TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA ) ) )
|
||||
return IMAGE_FORMAT_UVLX8888;
|
||||
return IMAGE_FORMAT_UV88;
|
||||
}
|
||||
*/
|
||||
|
||||
// can't compress textures that are smaller than 4x4
|
||||
if ( (nFlags & TEXTUREFLAGS_PROCEDURAL) ||
|
||||
( nWidth < 4 ) || ( nHeight < 4 ) || ( nDepth > 1 ) )
|
||||
{
|
||||
if ( nFlags & ( TEXTUREFLAGS_ONEBITALPHA | TEXTUREFLAGS_EIGHTBITALPHA ) )
|
||||
return IMAGE_FORMAT_BGRA8888;
|
||||
return IMAGE_FORMAT_BGR888;
|
||||
}
|
||||
|
||||
if( nFlags & TEXTUREFLAGS_HINT_DXT5 )
|
||||
return IMAGE_FORMAT_DXT5;
|
||||
|
||||
// compressed with alpha blending
|
||||
if ( nFlags & TEXTUREFLAGS_EIGHTBITALPHA )
|
||||
return IMAGE_FORMAT_DXT5;
|
||||
|
||||
if ( nFlags & TEXTUREFLAGS_ONEBITALPHA )
|
||||
return IMAGE_FORMAT_DXT5; // IMAGE_FORMAT_DXT1_ONEBITALPHA
|
||||
|
||||
return IMAGE_FORMAT_DXT1;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Adds a frame
|
||||
//-----------------------------------------------------------------------------
|
||||
CDmeTextureFrame *CDmeTexture::AddFrame()
|
||||
{
|
||||
CDmeTextureFrame *pImageArray = CreateElement< CDmeTextureFrame >( "frame", GetFileId() );
|
||||
m_Frames.AddToTail( pImageArray );
|
||||
return pImageArray;
|
||||
}
|
||||
|
||||
|
||||
void CDmeTexture::RemoveAllFrames()
|
||||
{
|
||||
m_Frames.RemoveAll();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Returns all images associated with a particular frame + face (mip count amount)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTexture::GetImages( int nFrame, int nImageIndex, CDmeImage **ppImages, int nSize )
|
||||
{
|
||||
memset( ppImages, 0, nSize * sizeof(CDmeImage*) );
|
||||
|
||||
int nFrameCount = FrameCount();
|
||||
if ( nFrame >= nFrameCount )
|
||||
return;
|
||||
|
||||
CDmeTextureFrame *pFrame = GetFrame( nFrame );
|
||||
if ( !pFrame )
|
||||
return;
|
||||
|
||||
int nMipCount = MIN( pFrame->MipLevelCount(), nSize );
|
||||
for ( int m = 0; m < nMipCount; ++m )
|
||||
{
|
||||
CDmeImageArray *pImageArray = pFrame->GetMipLevel( m );
|
||||
if ( !pImageArray )
|
||||
continue;
|
||||
|
||||
int nImageCount = pImageArray->ImageCount();
|
||||
if ( nImageIndex >= nImageCount )
|
||||
continue;
|
||||
|
||||
ppImages[m] = pImageArray->GetImage( nImageIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void CDmeTexture::CompressTexture( CDmeTexture *pSrcTexture, ImageFormat fmt )
|
||||
{
|
||||
class CCompressionFunctor
|
||||
{
|
||||
public:
|
||||
CCompressionFunctor( ImageFormat fmt ) { m_Format = fmt; }
|
||||
void operator()( CDmeImage *pDstImage, CDmeImage *pSrcImage )
|
||||
{
|
||||
pDstImage->CompressImage( pSrcImage, m_Format );
|
||||
}
|
||||
|
||||
ImageFormat m_Format;
|
||||
};
|
||||
|
||||
CCompressionFunctor compress( fmt );
|
||||
ProcessTexture( pSrcTexture, compress );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// resolve
|
||||
//-----------------------------------------------------------------------------
|
||||
void CDmeTexture::Resolve()
|
||||
{
|
||||
}
|
50
materialobjects/materialobjects.vpc
Normal file
50
materialobjects/materialobjects.vpc
Normal file
@ -0,0 +1,50 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// MATERIALOBJECTS.VPC
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
$Macro SRCDIR ".."
|
||||
$Include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$PreprocessorDefinitions "$BASE;MATERIALOBJECTS_LIB"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "Materialobjects"
|
||||
{
|
||||
$Folder "Header Files"
|
||||
{
|
||||
}
|
||||
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "dmeamalgtexture.cpp"
|
||||
$File "dmeimage.cpp"
|
||||
$File "dmeprecompiledtexture.cpp"
|
||||
$File "dmesheetsequence.cpp"
|
||||
$File "dmetexture.cpp"
|
||||
}
|
||||
|
||||
$Folder "Interface"
|
||||
{
|
||||
$File "$SRCDIR\public\materialobjects\amalgtexturevars.h"
|
||||
$File "$SRCDIR\public\materialobjects\dmeamalgtexture.h"
|
||||
$File "$SRCDIR\public\materialobjects\dmeimage.h"
|
||||
$File "$SRCDIR\public\materialobjects\dmeprecompiledtexture.h"
|
||||
$File "$SRCDIR\public\materialobjects\dmesheetsequence.h"
|
||||
$File "$SRCDIR\public\materialobjects\dmetexture.h"
|
||||
$File "$SRCDIR\public\materialobjects\materialobjects.h"
|
||||
}
|
||||
|
||||
$Folder "external"
|
||||
{
|
||||
$File "$SRCDIR\public\mathlib\mathlib.h"
|
||||
$File "$SRCDIR\public\studio.cpp"
|
||||
$File "$SRCDIR\public\mathlib\vector.h"
|
||||
}
|
||||
}
|
13
materialobjects/materialobjects.vpc.vpc_cache
Normal file
13
materialobjects/materialobjects.vpc.vpc_cache
Normal file
@ -0,0 +1,13 @@
|
||||
"vpc_cache"
|
||||
{
|
||||
"CacheVersion" "1"
|
||||
"win32"
|
||||
{
|
||||
"CRCFile" "materialobjects.vcxproj.vpc_crc"
|
||||
"OutputFiles"
|
||||
{
|
||||
"0" "materialobjects.vcxproj"
|
||||
"1" "materialobjects.vcxproj.filters"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user