| 889 | } |
| 890 | |
| 891 | ALResult Tr2TextureAL::MapForWriting( const Tr2TextureSubresource& region, void*& data, uint32_t& pitch, Tr2RenderContextAL& renderContext ) |
| 892 | { |
| 893 | data = nullptr; |
| 894 | |
| 895 | if( !HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE ) ) |
| 896 | { |
| 897 | return E_INVALIDCALL; |
| 898 | } |
| 899 | if( !IsValid() || !renderContext.IsValid() ) |
| 900 | { |
| 901 | return E_FAIL; |
| 902 | } |
| 903 | if( !region.IsValidForBitmap( m_desc ) ) |
| 904 | { |
| 905 | return E_INVALIDARG; |
| 906 | } |
| 907 | if( !region.IsSingleSubresource() ) |
| 908 | { |
| 909 | return E_INVALIDARG; |
| 910 | } |
| 911 | if( region.HasBox() && Tr2RenderContextEnum::IsCompressedFormat( m_desc.GetFormat() ) ) |
| 912 | { |
| 913 | return E_INVALIDARG; |
| 914 | } |
| 915 | |
| 916 | if( HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE_OFTEN ) ) |
| 917 | { |
| 918 | D3D11_MAPPED_SUBRESOURCE ms = { nullptr, 0, 0 }; |
| 919 | HRESULT hr = renderContext.m_context->Map( m_texture, D3D10CalcSubresource( region.m_startMipLevel, region.m_startFace, m_desc.GetTrueMipCount() ), D3D11_MAP_WRITE_DISCARD, 0, &ms ); |
| 920 | if( FAILED( hr ) ) |
| 921 | { |
| 922 | pitch = 0; |
| 923 | return hr; |
| 924 | } |
| 925 | if( !ms.pData ) |
| 926 | { |
| 927 | pitch = 0; |
| 928 | return E_FAIL; |
| 929 | } |
| 930 | if( region.HasBox() ) |
| 931 | { |
| 932 | ms.pData = static_cast<uint8_t*>( ms.pData ) + region.m_box.left * Tr2RenderContextEnum::GetBytesPerPixel( m_desc.GetFormat() ) + region.m_box.top * ms.RowPitch + region.m_box.front * ms.DepthPitch; |
| 933 | } |
| 934 | #if TRINITY_AL_GUARD_LOCKS |
| 935 | size_t size; |
| 936 | if( region.HasBox() ) |
| 937 | { |
| 938 | size = ms.RowPitch * ( region.m_box.bottom - region.m_box.top ); |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | size = ms.RowPitch * m_desc.GetMipHeight( region.m_startMipLevel ); |
| 943 | } |
| 944 | |
| 945 | m_lockGuard.Lock( size, ms.pData ); |
| 946 | data = m_lockGuard.GetMemory(); |
| 947 | pitch = ms.RowPitch; |
| 948 | #else |
nothing calls this directly
no test coverage detected