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

Method OnPrepareResources

trinity/Tr2TextureAtlas.cpp:72–128  ·  view source on GitHub ↗

This gets called after a device reset

Source from the content-addressed store, hash-verified

70
71// This gets called after a device reset
72bool Tr2TextureAtlas::OnPrepareResources()
73{
74 if( m_texture.IsValid() )
75 {
76 return true;
77 }
78
79 HRESULT hr;
80
81 do
82 {
83 if( m_height <= 1 || m_width <= 1 )
84 {
85 return false;
86 }
87
88 m_mipLevels = m_hasMipMaps ? unsigned( 0.5 + log( double( std::max( m_height, m_width ) ) ) / log( 2.0 ) ) : 1;
89 USE_MAIN_THREAD_RENDER_CONTEXT();
90 hr = m_texture.Create(
91 Tr2BitmapDimensions( m_width, m_height, m_mipLevels, m_format ),
92 Tr2GpuUsage::SHADER_RESOURCE,
93 Tr2CpuUsage::READ | Tr2CpuUsage::WRITE,
94 renderContext );
95
96 if( FAILED( hr ) )
97 {
98 if( m_width > m_height )
99 {
100 m_width /= 2;
101 }
102 else
103 {
104 m_height /= 2;
105 }
106 }
107 } while( FAILED( hr ) );
108
109 Tr2TextureAtlasArea* area = CCP_NEW( "Tr2TextureAtlas/Area" ) Tr2TextureAtlasArea;
110 area->type = Tr2TextureAtlasArea::FREE;
111 area->rect.left = 0;
112 area->rect.top = 0;
113 area->rect.right = m_width;
114 area->rect.bottom = m_height;
115 area->tex = NULL;
116
117 m_freeAreas.clear();
118 m_pendingFreeAreas.clear();
119 FreeArea( area );
120
121 m_freeTexels = m_width * m_height;
122 m_freeMaxWidth = m_width;
123 m_freeMaxHeight = m_height;
124
125 m_onTextureChange();
126
127 return true;
128}
129

Callers

nothing calls this directly

Calls 2

IsValidMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected