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

Method Clear

trinityal/dx12/Tr2RenderContextDx12.cpp:181–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179
180
181ALResult Tr2RenderContextAL::Clear( uint32_t clearFlags, uint32_t color, float depth, uint32_t stencil, uint32_t slot ) throw()
182{
183 bool rtClear = false;
184 bool dsClear = false;
185
186 if( clearFlags & Tr2RenderContextEnum::CLEARFLAGS_TARGET )
187 {
188 if( m_boundRenderTargets[slot].texture.IsValid() )
189 {
190 rtClear = true;
191 }
192 }
193 if( ( clearFlags & Tr2RenderContextEnum::CLEARFLAGS_ZBUFFER ) != 0 || ( clearFlags & Tr2RenderContextEnum::CLEARFLAGS_STENCIL ) != 0 )
194 {
195 if( m_boundDepthStencil.IsValid() )
196 {
197 dsClear = true;
198 }
199 else
200 {
201 return E_INVALIDCALL;
202 }
203 }
204
205 if( rtClear || dsClear )
206 {
207 ID3D12Resource* resources[2];
208 size_t count = 0;
209 if( rtClear )
210 {
211 resources[count++] = m_boundRenderTargets[slot].texture.m_texture->GetResourceDx12();
212 }
213 if( dsClear )
214 {
215 resources[count++] = m_boundDepthStencil.m_texture->GetResourceDx12();
216 }
217 FlushBarriersDx12( count, resources );
218
219 if( rtClear )
220 {
221 float f = 1.0f / 255.0f;
222 float colorComponents[] = {
223 f * (float)(uint8_t)( color >> 16 ),
224 f * (float)(uint8_t)( color >> 8 ),
225 f * (float)(uint8_t)( color >> 0 ),
226 f * (float)(uint8_t)( color >> 24 )
227 };
228
229 const std::shared_ptr<RenderTargetViewDx12>& rtv = m_boundRenderTargets[slot].texture.m_texture->GetRtvDescriptorHandleDx12( Tr2RenderContextEnum::COLOR_SPACE_LINEAR, m_boundRenderTargets[slot].slice );
230 m_commandList->ClearRenderTargetView( rtv->GetHandleCPU(), colorComponents, 0, nullptr );
231 }
232 if( dsClear )
233 {
234 D3D12_CLEAR_FLAGS flags = D3D12_CLEAR_FLAGS();
235 if( clearFlags & Tr2RenderContextEnum::CLEARFLAGS_ZBUFFER )
236 {
237 flags |= D3D12_CLEAR_FLAG_DEPTH;
238 }

Callers 5

DestroyMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 5

GetResourceDx12Method · 0.80
ClearRenderTargetViewMethod · 0.80
ClearDepthStencilViewMethod · 0.80
IsValidMethod · 0.45
GetHandleCPUMethod · 0.45

Tested by 4

TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36