| 471 | } |
| 472 | |
| 473 | ALResult Tr2TextureAL::OpenShared( uintptr_t handle, Tr2GpuUsage::Type gpuUsage, Tr2PrimaryRenderContextAL& renderContext ) |
| 474 | { |
| 475 | Destroy(); |
| 476 | |
| 477 | if( !renderContext.IsValid() ) |
| 478 | { |
| 479 | return E_FAIL; |
| 480 | } |
| 481 | |
| 482 | CCP_AL_LOG( "Opening shared texture %lld", uint64_t( handle ) ); |
| 483 | |
| 484 | CComPtr<ID3D11Texture2D> resource; |
| 485 | auto hr = renderContext.m_d3dDevice11->OpenSharedResource( reinterpret_cast<HANDLE>( handle ), __uuidof( ID3D11Texture2D ), reinterpret_cast<void**>( &resource.p ) ); |
| 486 | if( FAILED( hr ) ) |
| 487 | { |
| 488 | CCP_AL_LOG( "Failed to open shared texture %lld", uint64_t( handle ) ); |
| 489 | } |
| 490 | |
| 491 | FORWARD_HR( hr ); |
| 492 | |
| 493 | if( !resource ) |
| 494 | { |
| 495 | return E_FAIL; |
| 496 | } |
| 497 | |
| 498 | D3D11_TEXTURE2D_DESC dxDesc; |
| 499 | resource->GetDesc( &dxDesc ); |
| 500 | Tr2RenderContextEnum::PixelFormat fmt; |
| 501 | bool createSrgb = true; |
| 502 | if( IsTypeless( Tr2RenderContextEnum::PixelFormat( dxDesc.Format ) ) ) |
| 503 | { |
| 504 | fmt = FromTypeless( Tr2RenderContextEnum::PixelFormat( dxDesc.Format ) ); |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | fmt = Tr2RenderContextEnum::PixelFormat( dxDesc.Format ); |
| 509 | createSrgb = false; |
| 510 | } |
| 511 | Tr2BitmapDimensions desc( Tr2RenderContextEnum::TEX_TYPE_2D, fmt, dxDesc.Width, dxDesc.Height, 1, dxDesc.MipLevels ); |
| 512 | |
| 513 | CCP_AL_LOG( "Creating views for the shared texture %lld, GPU usage is %d", uint64_t( handle ), int( gpuUsage ) ); |
| 514 | |
| 515 | hr = CreateViews( resource, desc, Tr2MsaaDesc(), gpuUsage, Tr2CpuUsage::NONE, createSrgb, renderContext ); |
| 516 | if( FAILED( hr ) ) |
| 517 | { |
| 518 | CCP_AL_LOG( "Failed to create views for the shared texture %lld, GPU usage is %d", uint64_t( handle ), int( gpuUsage ) ); |
| 519 | } |
| 520 | FORWARD_HR( hr ); |
| 521 | |
| 522 | m_desc = desc; |
| 523 | m_msaa = Tr2MsaaDesc(); |
| 524 | m_gpuUsage = gpuUsage; |
| 525 | m_cpuUsage = Tr2CpuUsage::NONE; |
| 526 | m_texture = resource; |
| 527 | return S_OK; |
| 528 | } |
| 529 | |
| 530 | ALResult Tr2TextureAL::CreateViews( |
nothing calls this directly
no test coverage detected