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

Method CreateTexture

trinity/Tr2TextureAtlas.cpp:1079–1164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1077}
1078
1079ALResult Tr2TextureAtlas::CreateTexture( unsigned int width, unsigned int height, AtlasTextureType type, Tr2AtlasTexture** result )
1080{
1081 Tr2AtlasTexturePtr tex;
1082 tex.CreateInstance();
1083 tex->m_textureAtlas = this;
1084
1085 Tr2TextureAtlasArea* area = NULL;
1086
1087 if( type == ATT_DEFAULT && !IsLargeTexture( width, height ) )
1088 {
1089 area = GetFreeArea( width + m_margin * 2, height + m_margin * 2 );
1090
1091 if( !area && m_optimizationWarranted )
1092 {
1093 CollapseFreeAreas();
1094 area = GetFreeArea( width + m_margin * 2, height + m_margin * 2 );
1095 }
1096 }
1097
1098 if( area )
1099 {
1100 area->type = Tr2TextureAtlasArea::IN_USE;
1101 area->tex = tex;
1102 tex->m_atlasArea = area;
1103
1104 // Set up the texture window into the atlas
1105 tex->m_renderTarget = nullptr;
1106 tex->m_x = area->rect.left + m_margin;
1107 tex->m_y = area->rect.top + m_margin;
1108 tex->m_width = width;
1109 tex->m_height = height;
1110 tex->m_textureWidth = m_width;
1111 tex->m_textureHeight = m_height;
1112
1113 RegisterInsider( tex );
1114 PaintEmptyArea( area );
1115 }
1116 else if( m_createOutsiders )
1117 {
1118 if( !Tr2Renderer::IsResourceCreationAllowed() )
1119 {
1120 *result = nullptr;
1121 return E_DEVICELOST;
1122 }
1123
1124 USE_MAIN_THREAD_RENDER_CONTEXT();
1125 HRESULT hr = tex->m_texture.Create(
1126 Tr2BitmapDimensions( width, height, 1, m_format ),
1127 Tr2GpuUsage::SHADER_RESOURCE,
1128 Tr2CpuUsage::READ | Tr2CpuUsage::WRITE,
1129 renderContext )
1130 .GetResult();
1131 if( FAILED( hr ) )
1132 {
1133 *result = nullptr;
1134 return hr;
1135 }
1136

Callers 2

OnPrepareResourcesMethod · 0.45

Calls 6

CreateInstanceMethod · 0.80
SetStandAloneMethod · 0.80
FinalizePrepareMethod · 0.80
DetachMethod · 0.80
GetResultMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected