Skip to content
Permalink
Browse files

Tweaked automatic TXD resizing

  • Loading branch information...
ccw808 committed Jun 25, 2015
1 parent cb69ae5 commit 215d31b158bdb0c00010a231f4a93bdbf922ad62
@@ -2391,6 +2391,11 @@ void CCore::NotifyRenderingGrass( bool bIsRenderingGrass )

bool CCore::GetRightSizeTxdEnabled( void )
{
if ( g_pCore->GetDiagnosticDebug () == EDiagnosticDebug::RESIZE_NEVER_0000 )
return false;
if ( g_pCore->GetDiagnosticDebug () == EDiagnosticDebug::RESIZE_ALWAYS_0000 )
return true;

// 32 bit users get rightsized txds
if ( !Is64BitOS() )
return true;
@@ -2400,9 +2405,5 @@ bool CCore::GetRightSizeTxdEnabled( void )
if ( iSystemRamMB <= 2048 )
return true;

// Debug users get rightsized txds
if ( g_strJingleBells == "rightsize" )
return true;

return false;
}
@@ -1973,9 +1973,9 @@ bool CGraphics::ResizeTextureData( const void* pData, uint uiDataPitch, uint uiW
do
{
// Create surfaces
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SYSTEMMEM, &pCurrentSurface, NULL ) ) )
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiWidth, uiHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pCurrentSurface, NULL ) ) )
break;
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiNewWidth, uiNewHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SYSTEMMEM, &pNewSurface, NULL ) ) )
if ( FAILED( g_pGraphics->GetDevice()->CreateOffscreenPlainSurface( uiNewWidth, uiNewHeight, (D3DFORMAT)d3dFormat, D3DPOOL_SCRATCH, &pNewSurface, NULL ) ) )
break;

// Data in
@@ -1260,6 +1260,8 @@ void CSettings::CreateGUI ( void )
m_pDebugSettingCombo->AddItem ( "#0000 Log timing" )->SetData ( (void*)EDiagnosticDebug::LOG_TIMING_0000 );
m_pDebugSettingCombo->AddItem ( "#0000 Joystick" )->SetData ( (void*)EDiagnosticDebug::JOYSTICK_0000 );
m_pDebugSettingCombo->AddItem ( "#0000 Lua trace" )->SetData ( (void*)EDiagnosticDebug::LUA_TRACE_0000 );
m_pDebugSettingCombo->AddItem ( "#0000 Resize always" )->SetData ( (void*)EDiagnosticDebug::RESIZE_ALWAYS_0000 );
m_pDebugSettingCombo->AddItem ( "#0000 Resize never" )->SetData ( (void*)EDiagnosticDebug::RESIZE_NEVER_0000 );
m_pDebugSettingCombo->SetReadOnly ( true );
vecTemp.fY += fLineHeight;

@@ -54,11 +54,16 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
std::vector < RwTexture* > textureList;
pGame->GetRenderWareSA()->GetTxdTextures( textureList, pTxd );

// Double size limit if only one texture in txd
if ( textureList.size() == 1 )
uiSizeLimit *= 2;

SString strError;
bool bChanged = false;
for ( std::vector < RwTexture* > ::iterator iter = textureList.begin() ; iter != textureList.end() ; iter++ )
{
RwTexture* pTexture = *iter;
RwTexture* pNewRwTexture = RightSizeTexture( pTexture, uiSizeLimit );
RwTexture* pNewRwTexture = RightSizeTexture( pTexture, uiSizeLimit, strError );
if ( pNewRwTexture && pNewRwTexture != pTexture )
{
// Replace texture in txd if changed
@@ -74,6 +79,11 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
}
}

// Log last error
if ( !strError.empty() )
{
AddReportLog( 8430, SString( "RightSizeTxd problem %s with '%s'", *strError, *strInTxdFilename ), 10 );
}

//
// Save shrunked txd if changed
@@ -103,16 +113,32 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
// Returns new texture if did shrink
//
/////////////////////////////////////////////////////////////////////////////
RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimit )
RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimit, SString& strError )
{
// Validate
RwRaster* pRaster = pTexture->raster;
if ( !pRaster )
{
strError = "pRaster == NULL";
return NULL;
}

RwD3D9Raster* pD3DRaster = (RwD3D9Raster*)( &pRaster->renderResource );
if ( !pD3DRaster->texture || !pD3DRaster->lockedSurface || !pD3DRaster->lockedRect.pBits )
if ( !pD3DRaster->texture )
{
strError = "pD3DRaster->texture == NULL";
return NULL;
}
if ( !pD3DRaster->lockedSurface )
{
strError = "pD3DRaster->lockedSurface == NULL";
return NULL;
}
if ( !pD3DRaster->lockedRect.pBits )
{
strError = "pD3DRaster->lockedRect.pBits == NULL";
return NULL;
}

// Get texture info
uint uiWidth = pRaster->width;
@@ -131,6 +157,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
if ( d3dFormat != D3DFMT_DXT1 && d3dFormat != D3DFMT_DXT3 && d3dFormat != D3DFMT_DXT5 )
return NULL;

// Double size limit if DXT1
if ( d3dFormat == D3DFMT_DXT1 )
uiSizeLimit *= 2;

// Change size
uint uiReqWidth = Min( uiSizeLimit, uiWidth );
uint uiReqHeight = Min( uiSizeLimit, uiHeight );
@@ -142,7 +172,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
bool bNeedOwnLock = ( pD3DRaster->lockedLevel != 0 ) || !pD3DRaster->lockedSurface;
if ( bNeedOwnLock )
if ( FAILED( pD3DRaster->texture->LockRect( 0, &lockedRect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) )
{
strError = "pD3DRaster->texture->LockRect failed";
return NULL;
}

// Try resize
CBuffer newPixelBuffer;
@@ -152,7 +185,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
pD3DRaster->texture->UnlockRect( 0 );

if ( !bDidResize )
{
strError = "ResizeTextureData failed";
return NULL;
}

// Make new RwTexture from pixels
NativeTexturePC_Header header;
@@ -190,12 +226,21 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
buffer.size = nativeData.GetSize();
RwStream * rwStream = RwStreamOpen( STREAM_TYPE_BUFFER, STREAM_MODE_READ, &buffer );
if ( !rwStream )
{
strError = "RwStreamOpen failed";
return NULL;
}

// Read new texture
RwTexture* pNewRwTexture = NULL;
rwD3D9NativeTextureRead( rwStream, &pNewRwTexture );
RwStreamClose( rwStream, NULL );

if ( !pNewRwTexture )
{
strError = "rwD3D9NativeTextureRead failed";
return NULL;
}

return pNewRwTexture;
}
@@ -109,7 +109,7 @@ class CRenderWareSA : public CRenderWare
void TxdForceUnload ( ushort usTxdId, bool bDestroyTextures );

// CRenderWareSA methods
RwTexture* RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit );
RwTexture* RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit, SString& strError );
void ResetStats ( void );
void GetShaderReplacementStats ( SShaderReplacementStats& outStats );
CModelTexturesInfo* GetModelTexturesInfo ( ushort usModelId );
@@ -172,7 +172,7 @@ bool CClientTXD::GetFilenameToUse( SString& strOutFilename )
{
// See if previously shrunk result exists
SString strLargeSha256 = GenerateSha256HexStringFromFile( m_strFilename );
SString strShrunkFilename = PathJoin( ExtractPath( m_strFilename ), SString( "_2_%s", *strLargeSha256.Left( 32 ) ) );
SString strShrunkFilename = PathJoin( ExtractPath( m_strFilename ), SString( "_3_%s", *strLargeSha256.Left( 32 ) ) );
uint uiShrunkSize = (uint)FileSize( strShrunkFilename );
if ( uiShrunkSize >= 128 )
{
@@ -100,6 +100,8 @@ namespace SharedUtil
LOG_TIMING_0000,
JOYSTICK_0000,
LUA_TRACE_0000,
RESIZE_ALWAYS_0000,
RESIZE_NEVER_0000,
MAX,
};
};

0 comments on commit 215d31b

Please sign in to comment.
You can’t perform that action at this time.