MCPcopy Create free account
hub / github.com/carbonengine/trinity / CopyTextureIntoAtlas

Method CopyTextureIntoAtlas

trinity/Tr2TextureAtlas.cpp:1036–1077  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1034}
1035
1036bool Tr2TextureAtlas::CopyTextureIntoAtlas( Tr2AtlasTexture* tex )
1037{
1038 CCP_STATS_ZONE( __FUNCTION__ );
1039
1040 USE_MAIN_THREAD_RENDER_CONTEXT();
1041
1042 if( !m_texture.IsValid() || !tex || !tex->GetTexture() )
1043 {
1044 // assuming that RTs don't use this, seems nonsensical
1045 CCP_LOGERR( "CopyTextureIntoAtlas failed, target or source textures invalid" );
1046 return false;
1047 }
1048
1049 const auto& r = tex->m_atlasArea->rect;
1050
1051 if( !m_margin )
1052 {
1053 Tr2TextureSubresource dest( 0, 0 );
1054 dest.m_box.left = r.left;
1055 dest.m_box.top = r.top;
1056 return SUCCEEDED( m_texture.CopySubresourceRegion( dest, *tex->GetTexture(), Tr2TextureSubresource( 0, 0 ), renderContext ) );
1057 }
1058
1059 if( m_hasMipMaps )
1060 {
1061 m_dirtyMipRegions.push_back( r );
1062 }
1063
1064 const void* srcData = nullptr;
1065 unsigned srcPitch = 0;
1066 CR_RETURN_VAL( tex->GetTexture()->MapForReading( Tr2TextureSubresource( 0 ), srcData, srcPitch, renderContext ), false );
1067 ON_BLOCK_EXIT( [&] { tex->GetTexture()->UnmapForReading( renderContext ); } );
1068
1069 std::vector<unsigned char> pixels;
1070 unsigned pitch = 0;
1071 Tr2ImageIOHelpers::AddMargin( m_texture.GetFormat(), (const unsigned char*)srcData, tex->GetWidth(), tex->GetHeight(), m_margin, pixels, pitch );
1072
1073 // Area may be larger than texture due to alignment
1074 uint32_t right = r.left + tex->GetWidth() + 2 * m_margin;
1075 uint32_t bottom = r.top + tex->GetHeight() + 2 * m_margin;
1076 return SUCCEEDED( m_texture.UpdateSubresource( Tr2TextureSubresource( 0 ).SetRect( r.left, r.top, right, bottom ), &pixels[0], pitch, 0, renderContext ) );
1077}
1078
1079ALResult Tr2TextureAtlas::CreateTexture( unsigned int width, unsigned int height, AtlasTextureType type, Tr2AtlasTexture** result )
1080{

Callers

nothing calls this directly

Calls 12

AddMarginFunction · 0.85
SetRectMethod · 0.80
IsValidMethod · 0.45
GetTextureMethod · 0.45
CopySubresourceRegionMethod · 0.45
MapForReadingMethod · 0.45
UnmapForReadingMethod · 0.45
GetFormatMethod · 0.45
GetWidthMethod · 0.45
GetHeightMethod · 0.45
UpdateSubresourceMethod · 0.45

Tested by

no test coverage detected