| 266 | } |
| 267 | |
| 268 | bool Tr2HostBitmap::CopyFromTextureRes( TriTextureRes& res, Tr2RenderContext& renderContext ) |
| 269 | { |
| 270 | if( !res.GetTexture() ) |
| 271 | { |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | if( res.GetType() != TEX_TYPE_2D && res.GetType() != TEX_TYPE_CUBE ) |
| 276 | { |
| 277 | CCP_LOGERR( "Tr2HostBitmap::CopyFromTextureRes, only 2D and CUBE textures supported" ); |
| 278 | return false; |
| 279 | } |
| 280 | |
| 281 | if( !res.GetTexture() && res.GetType() == TEX_TYPE_CUBE ) |
| 282 | { |
| 283 | CCP_LOGERR( "Tr2HostBitmap::CopyFromTextureRes, legacy CUBE textures are not supported" ); |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | bool alphaConvert = false; |
| 288 | |
| 289 | if( res.GetTexture() ) |
| 290 | { |
| 291 | if( !res.GetTexture()->IsValid() || GetType() != res.GetTexture()->GetType() || !CheckForMatch( res.GetTexture()->GetDesc(), true, alphaConvert, "CopyFromTextureRes" ) ) |
| 292 | { |
| 293 | return false; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | const uint32_t mipCount = std::min( GetTrueMipCount(), res.GetTrueMipCount() ); |
| 298 | const uint32_t faceCount = GetArraySize(); |
| 299 | |
| 300 | |
| 301 | for( uint32_t face = 0; face != faceCount; ++face ) |
| 302 | { |
| 303 | for( uint32_t mipLevel = 0; mipLevel != mipCount; ++mipLevel ) |
| 304 | { |
| 305 | const void* srcData = nullptr; |
| 306 | uint32_t srcPitch = 0; |
| 307 | |
| 308 | HRESULT hr = E_FAIL; |
| 309 | |
| 310 | if( res.m_wrappedRenderTarget ) |
| 311 | { |
| 312 | hr = res.m_wrappedRenderTarget->GetRenderTarget().MapForReading( Tr2TextureSubresource( face, mipLevel ), srcData, srcPitch, renderContext ); |
| 313 | } |
| 314 | else if( res.GetTexture() ) |
| 315 | { |
| 316 | hr = res.GetTexture()->MapForReading( Tr2TextureSubresource( face, mipLevel ), srcData, srcPitch, renderContext ); |
| 317 | } |
| 318 | if( FAILED( hr ) || srcData == nullptr ) |
| 319 | { |
| 320 | CCP_LOGERR( "Tr2HostBitmap::CopyFromTextureRes, error locking surface" ); |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | uint8_t* dst = (uint8_t*)GetMipRawData( mipLevel, face ); |
no test coverage detected