mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Terrain baseTex support multiple formats
DDS, PNG, JPG or NONE
This commit is contained in:
parent
f2a3a1e2a6
commit
431d8a9b66
3 changed files with 44 additions and 8 deletions
|
|
@ -186,6 +186,7 @@ TerrainBlock::TerrainBlock()
|
||||||
mCell( NULL ),
|
mCell( NULL ),
|
||||||
mCRC( 0 ),
|
mCRC( 0 ),
|
||||||
mBaseTexSize( 1024 ),
|
mBaseTexSize( 1024 ),
|
||||||
|
mBaseTexFormat( TerrainBlock::JPG ),
|
||||||
mBaseMaterial( NULL ),
|
mBaseMaterial( NULL ),
|
||||||
mDefaultMatInst( NULL ),
|
mDefaultMatInst( NULL ),
|
||||||
mBaseTexScaleConst( NULL ),
|
mBaseTexScaleConst( NULL ),
|
||||||
|
|
@ -961,7 +962,7 @@ String TerrainBlock::_getBaseTexCacheFileName() const
|
||||||
{
|
{
|
||||||
Torque::Path basePath( mTerrFileName );
|
Torque::Path basePath( mTerrFileName );
|
||||||
basePath.setFileName( basePath.getFileName() + "_basetex" );
|
basePath.setFileName( basePath.getFileName() + "_basetex" );
|
||||||
basePath.setExtension( "dds" );
|
basePath.setExtension( formatToExtension(mBaseTexFormat) );
|
||||||
return basePath.getFullPath();
|
return basePath.getFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1200,7 +1201,7 @@ void TerrainBlock::unpackUpdate(NetConnection* con, BitStream *stream)
|
||||||
{
|
{
|
||||||
mBaseTexSize = baseTexSize;
|
mBaseTexSize = baseTexSize;
|
||||||
if ( isProperlyAdded() )
|
if ( isProperlyAdded() )
|
||||||
_updateBaseTexture( false );
|
_updateBaseTexture( NONE );
|
||||||
}
|
}
|
||||||
|
|
||||||
U32 lightMapSize;
|
U32 lightMapSize;
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,26 @@ protected:
|
||||||
NextFreeMask = Parent::NextFreeMask << 6,
|
NextFreeMask = Parent::NextFreeMask << 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum BaseTexFormat
|
||||||
|
{
|
||||||
|
NONE, DDS, PNG, JPG
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* formatToExtension(BaseTexFormat format)
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case DDS:
|
||||||
|
return "dds";
|
||||||
|
case PNG:
|
||||||
|
return "png";
|
||||||
|
case JPG:
|
||||||
|
return "jpg";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Box3F mBounds;
|
Box3F mBounds;
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
@ -132,6 +152,8 @@ protected:
|
||||||
/// The desired size for the base texture.
|
/// The desired size for the base texture.
|
||||||
U32 mBaseTexSize;
|
U32 mBaseTexSize;
|
||||||
|
|
||||||
|
BaseTexFormat mBaseTexFormat;
|
||||||
|
|
||||||
///
|
///
|
||||||
TerrCell *mCell;
|
TerrCell *mCell;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ bool TerrainBlock::_initBaseShader()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerrainBlock::_updateBaseTexture( bool writeToCache )
|
void TerrainBlock::_updateBaseTexture(bool writeToCache)
|
||||||
{
|
{
|
||||||
if ( !mBaseShader && !_initBaseShader() )
|
if ( !mBaseShader && !_initBaseShader() )
|
||||||
return;
|
return;
|
||||||
|
|
@ -290,7 +290,14 @@ void TerrainBlock::_updateBaseTexture( bool writeToCache )
|
||||||
GFX->endScene();
|
GFX->endScene();
|
||||||
|
|
||||||
/// Do we cache this sucker?
|
/// Do we cache this sucker?
|
||||||
if ( writeToCache )
|
if (mBaseTexFormat == NONE || !writeToCache)
|
||||||
|
{
|
||||||
|
// We didn't cache the result, so set the base texture
|
||||||
|
// to the render target we updated. This should be good
|
||||||
|
// for realtime painting cases.
|
||||||
|
mBaseTex = blendTex;
|
||||||
|
}
|
||||||
|
else if (mBaseTexFormat == DDS)
|
||||||
{
|
{
|
||||||
String cachePath = _getBaseTexCacheFileName();
|
String cachePath = _getBaseTexCacheFileName();
|
||||||
|
|
||||||
|
|
@ -327,10 +334,16 @@ void TerrainBlock::_updateBaseTexture( bool writeToCache )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We didn't cache the result, so set the base texture
|
FileStream stream;
|
||||||
// to the render target we updated. This should be good
|
if (!stream.open(_getBaseTexCacheFileName(), Torque::FS::File::Write))
|
||||||
// for realtime painting cases.
|
{
|
||||||
mBaseTex = blendTex;
|
mBaseTex = blendTex;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8);
|
||||||
|
blendTex->copyToBmp(&bitmap);
|
||||||
|
bitmap.writeBitmap(formatToExtension(mBaseTexFormat), stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue