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

Method DoPrepare

trinity/Tr2TextureAtlas.cpp:131–178  ·  view source on GitHub ↗

This gets called when atlas textures are preparing themselves

Source from the content-addressed store, hash-verified

129
130// This gets called when atlas textures are preparing themselves
131bool Tr2TextureAtlas::DoPrepare( Tr2AtlasTexture* tex )
132{
133 CCP_STATS_ZONE( __FUNCTION__ );
134
135 USE_MAIN_THREAD_RENDER_CONTEXT();
136
137 unsigned int width = tex->m_loadedBitmap->GetWidth();
138 unsigned int height = tex->m_loadedBitmap->GetHeight();
139 const unsigned areaWidth = width + m_margin * 2;
140 const unsigned areaHeight = height + m_margin * 2;
141
142 // Large textures are not good for atlassing, end up with a lot of small outsiders
143 if( areaWidth * areaHeight > m_maxTextureArea )
144 {
145 return false;
146 }
147
148 Tr2TextureAtlasArea* area = GetFreeArea( areaWidth, areaHeight );
149
150 if( !area )
151 {
152 // There isn't room in the atlas for this texture. This isn't an error per se,
153 // we'll fall back to creating it as a standalone texture.
154 return false;
155 }
156
157 area->type = Tr2TextureAtlasArea::IN_USE;
158 area->tex = tex;
159 tex->m_atlasArea = area;
160
161 tex->m_x = area->rect.left + m_margin;
162 tex->m_y = area->rect.top + m_margin;
163 tex->m_width = width;
164 tex->m_height = height;
165 tex->m_textureWidth = m_width;
166 tex->m_textureHeight = m_height;
167
168 Tr2ImageIOHelpers::CopyToTexture( *tex->m_loadedBitmap, m_texture, area->rect.left, area->rect.top, m_margin, renderContext );
169
170 if( m_hasMipMaps )
171 {
172 m_dirtyMipRegions.push_back( area->rect );
173 }
174
175 RegisterInsider( tex );
176
177 return true;
178}
179
180// Register an atlas texture that lives inside the atlas
181void Tr2TextureAtlas::RegisterInsider( Tr2AtlasTexture* tex )

Callers

nothing calls this directly

Calls 3

CopyToTextureFunction · 0.85
GetWidthMethod · 0.45
GetHeightMethod · 0.45

Tested by

no test coverage detected