MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / Prepare

Method Prepare

Components/src/BoundBoxRenderer.cpp:176–223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void BoundBoxRenderer::Prepare(IDeviceContext* pContext, const RenderAttribs& Attribs)
177{
178 m_pCurrentPSO = GetPSO({Attribs.ConvertOutputToSRGB, Attribs.ComputeMotionVectors});
179 if (m_pCurrentPSO == nullptr)
180 {
181 UNEXPECTED("Failed to get PSO");
182 return;
183 }
184
185 if (m_pCurrentPSO->GetStatus() != PIPELINE_STATE_STATUS_READY)
186 return;
187
188 if (!m_SRB)
189 {
190 m_pCurrentPSO->CreateShaderResourceBinding(&m_SRB, true);
191 m_SRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbCameraAttribs")->Set(m_pCameraAttribsCB);
192 m_SRB->GetVariableByName(SHADER_TYPE_VERTEX, "cbBoundBoxAttribs")->Set(m_RenderAttribsCB);
193 }
194
195 VERIFY_EXPR(Attribs.BoundBoxTransform != nullptr);
196
197 if (m_ShaderAttribs)
198 {
199 const BoundBoxShaderAttribs ShaderAttribs{
200 m_PackMatrixRowMajor ? *Attribs.BoundBoxTransform : Attribs.BoundBoxTransform->Transpose(),
201 Attribs.Color != nullptr ? *Attribs.Color : float4{1.0, 1.0, 1.0, 1.0},
202 Attribs.PatternLength,
203 Attribs.PatternMask,
204 0,
205 0,
206 };
207 if (std::memcmp(m_ShaderAttribs.get(), &ShaderAttribs, sizeof(ShaderAttribs)) != 0)
208 {
209 *m_ShaderAttribs = ShaderAttribs;
210 pContext->UpdateBuffer(m_RenderAttribsCB, 0, sizeof(BoundBoxShaderAttribs), m_ShaderAttribs.get(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
211 StateTransitionDesc Barrier{m_RenderAttribsCB, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_CONSTANT_BUFFER, STATE_TRANSITION_FLAG_UPDATE_STATE};
212 pContext->TransitionResourceStates(1, &Barrier);
213 }
214 }
215 else
216 {
217 MapHelper<BoundBoxShaderAttribs> BBAttribs{pContext, m_RenderAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD};
218 WriteShaderMatrix(&BBAttribs->Transform, *Attribs.BoundBoxTransform, !m_PackMatrixRowMajor);
219 BBAttribs->Color = Attribs.Color != nullptr ? *Attribs.Color : float4{1.0, 1.0, 1.0, 1.0};
220 BBAttribs->PatternLength = Attribs.PatternLength;
221 BBAttribs->PatternMask = Attribs.PatternMask;
222 }
223}
224
225void BoundBoxRenderer::Render(IDeviceContext* pContext)
226{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected