@@ -54,11 +54,16 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
54
54
std::vector < RwTexture* > textureList;
55
55
pGame->GetRenderWareSA ()->GetTxdTextures ( textureList, pTxd );
56
56
57
+ // Double size limit if only one texture in txd
58
+ if ( textureList.size () == 1 )
59
+ uiSizeLimit *= 2 ;
60
+
61
+ SString strError;
57
62
bool bChanged = false ;
58
63
for ( std::vector < RwTexture* > ::iterator iter = textureList.begin () ; iter != textureList.end () ; iter++ )
59
64
{
60
65
RwTexture* pTexture = *iter;
61
- RwTexture* pNewRwTexture = RightSizeTexture ( pTexture, uiSizeLimit );
66
+ RwTexture* pNewRwTexture = RightSizeTexture ( pTexture, uiSizeLimit, strError );
62
67
if ( pNewRwTexture && pNewRwTexture != pTexture )
63
68
{
64
69
// Replace texture in txd if changed
@@ -74,6 +79,11 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
74
79
}
75
80
}
76
81
82
+ // Log last error
83
+ if ( !strError.empty () )
84
+ {
85
+ AddReportLog ( 8430 , SString ( " RightSizeTxd problem %s with '%s'" , *strError, *strInTxdFilename ), 10 );
86
+ }
77
87
78
88
//
79
89
// Save shrunked txd if changed
@@ -103,16 +113,32 @@ bool CRenderWareSA::RightSizeTxd( const SString& strInTxdFilename, const SString
103
113
// Returns new texture if did shrink
104
114
//
105
115
// ///////////////////////////////////////////////////////////////////////////
106
- RwTexture* CRenderWareSA::RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit )
116
+ RwTexture* CRenderWareSA::RightSizeTexture ( RwTexture* pTexture, uint uiSizeLimit, SString& strError )
107
117
{
108
118
// Validate
109
119
RwRaster* pRaster = pTexture->raster ;
110
120
if ( !pRaster )
121
+ {
122
+ strError = " pRaster == NULL" ;
111
123
return NULL ;
124
+ }
112
125
113
126
RwD3D9Raster* pD3DRaster = (RwD3D9Raster*)( &pRaster->renderResource );
114
- if ( !pD3DRaster->texture || !pD3DRaster->lockedSurface || !pD3DRaster->lockedRect .pBits )
127
+ if ( !pD3DRaster->texture )
128
+ {
129
+ strError = " pD3DRaster->texture == NULL" ;
130
+ return NULL ;
131
+ }
132
+ if ( !pD3DRaster->lockedSurface )
133
+ {
134
+ strError = " pD3DRaster->lockedSurface == NULL" ;
135
+ return NULL ;
136
+ }
137
+ if ( !pD3DRaster->lockedRect .pBits )
138
+ {
139
+ strError = " pD3DRaster->lockedRect.pBits == NULL" ;
115
140
return NULL ;
141
+ }
116
142
117
143
// Get texture info
118
144
uint uiWidth = pRaster->width ;
@@ -131,6 +157,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
131
157
if ( d3dFormat != D3DFMT_DXT1 && d3dFormat != D3DFMT_DXT3 && d3dFormat != D3DFMT_DXT5 )
132
158
return NULL ;
133
159
160
+ // Double size limit if DXT1
161
+ if ( d3dFormat == D3DFMT_DXT1 )
162
+ uiSizeLimit *= 2 ;
163
+
134
164
// Change size
135
165
uint uiReqWidth = Min ( uiSizeLimit, uiWidth );
136
166
uint uiReqHeight = Min ( uiSizeLimit, uiHeight );
@@ -142,7 +172,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
142
172
bool bNeedOwnLock = ( pD3DRaster->lockedLevel != 0 ) || !pD3DRaster->lockedSurface ;
143
173
if ( bNeedOwnLock )
144
174
if ( FAILED ( pD3DRaster->texture ->LockRect ( 0 , &lockedRect, NULL , D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY ) ) )
175
+ {
176
+ strError = " pD3DRaster->texture->LockRect failed" ;
145
177
return NULL ;
178
+ }
146
179
147
180
// Try resize
148
181
CBuffer newPixelBuffer;
@@ -152,7 +185,10 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
152
185
pD3DRaster->texture ->UnlockRect ( 0 );
153
186
154
187
if ( !bDidResize )
188
+ {
189
+ strError = " ResizeTextureData failed" ;
155
190
return NULL ;
191
+ }
156
192
157
193
// Make new RwTexture from pixels
158
194
NativeTexturePC_Header header;
@@ -190,12 +226,21 @@ RwTexture* CRenderWareSA::RightSizeTexture( RwTexture* pTexture, uint uiSizeLimi
190
226
buffer.size = nativeData.GetSize ();
191
227
RwStream * rwStream = RwStreamOpen ( STREAM_TYPE_BUFFER, STREAM_MODE_READ, &buffer );
192
228
if ( !rwStream )
229
+ {
230
+ strError = " RwStreamOpen failed" ;
193
231
return NULL ;
232
+ }
194
233
195
234
// Read new texture
196
235
RwTexture* pNewRwTexture = NULL ;
197
236
rwD3D9NativeTextureRead ( rwStream, &pNewRwTexture );
198
237
RwStreamClose ( rwStream, NULL );
199
238
239
+ if ( !pNewRwTexture )
240
+ {
241
+ strError = " rwD3D9NativeTextureRead failed" ;
242
+ return NULL ;
243
+ }
244
+
200
245
return pNewRwTexture;
201
246
}
0 commit comments