| 1285 | } |
| 1286 | |
| 1287 | bool Tr2TextureAtlas::EjectTextureHelper( Tr2AtlasTexture* tex ) |
| 1288 | { |
| 1289 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 1290 | |
| 1291 | CCP_ASSERT( tex ); |
| 1292 | if( !tex ) |
| 1293 | { |
| 1294 | return false; |
| 1295 | } |
| 1296 | CCP_ASSERT( tex->m_textureAtlas == this ); |
| 1297 | CCP_ASSERT( tex->m_atlasArea ); |
| 1298 | |
| 1299 | Tr2TextureAtlasArea* texArea = tex->m_atlasArea; |
| 1300 | |
| 1301 | Tr2Rect copyRect; |
| 1302 | copyRect.left = texArea->rect.left + m_margin; |
| 1303 | copyRect.top = texArea->rect.top + m_margin; |
| 1304 | copyRect.right = copyRect.left + tex->GetWidth(); |
| 1305 | copyRect.bottom = copyRect.top + tex->GetHeight(); |
| 1306 | const int width = tex->GetWidth(); |
| 1307 | const int height = tex->GetHeight(); |
| 1308 | |
| 1309 | |
| 1310 | if( !Tr2Renderer::IsResourceCreationAllowed() ) |
| 1311 | { |
| 1312 | CCP_LOGERR( "EjectTexture: There is no AL device available" ); |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
| 1316 | HRESULT hr = tex->m_texture.Create( Tr2BitmapDimensions( width, height, 1, m_format ), Tr2GpuUsage::SHADER_RESOURCE, Tr2CpuUsage::READ | Tr2CpuUsage::WRITE, renderContext ); |
| 1317 | |
| 1318 | if( FAILED( hr ) ) |
| 1319 | { |
| 1320 | CCP_LOGERR( "Tr2TextureAtlas::EjectTexture - couldn't create D3D texture (%d)", hr ); |
| 1321 | return false; |
| 1322 | } |
| 1323 | |
| 1324 | Tr2TextureSubresource subrect; |
| 1325 | subrect.m_endMipLevel = 1; |
| 1326 | subrect.m_box.left = copyRect.left; |
| 1327 | subrect.m_box.right = copyRect.right; |
| 1328 | subrect.m_box.top = copyRect.top; |
| 1329 | subrect.m_box.bottom = copyRect.bottom; |
| 1330 | if( SUCCEEDED( tex->m_texture.CopySubresourceRegion( Tr2TextureSubresource(), m_texture, subrect, renderContext ) ) ) |
| 1331 | { |
| 1332 | tex->m_x = 0; |
| 1333 | tex->m_y = 0; |
| 1334 | tex->m_width = width; |
| 1335 | tex->m_height = height; |
| 1336 | tex->m_textureWidth = width; |
| 1337 | tex->m_textureHeight = height; |
| 1338 | tex->m_atlasArea = NULL; |
| 1339 | |
| 1340 | tex->FinalizePrepare(); |
| 1341 | |
| 1342 | // Instead of immediately freeing the area, we put it in a pending free list with the current frame number. |
| 1343 | // This is a workaround for a driver bug where the driver may schedule a new texture upload into the same area |
| 1344 | // before the GPU has finished reading from it for copying. |
nothing calls this directly
no test coverage detected