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

Method PrepareResources

PostProcess/DepthOfField/src/DepthOfField.cpp:175–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173DepthOfField::~DepthOfField() {}
174
175void DepthOfField::PrepareResources(IRenderDevice* pDevice, IDeviceContext* pDeviceContext, PostFXContext* pPostFXContext, FEATURE_FLAGS FeatureFlags)
176{
177 DEV_CHECK_ERR(pDevice != nullptr, "pDevice must not be null");
178 DEV_CHECK_ERR(pPostFXContext != nullptr, "pPostFXContext must not be null");
179
180 const auto& FrameDesc = pPostFXContext->GetFrameDesc();
181
182 m_CurrentFrameIdx = FrameDesc.Index;
183
184 if (m_BackBufferWidth == FrameDesc.Width && m_BackBufferHeight == FrameDesc.Height && m_FeatureFlags == FeatureFlags)
185 return;
186
187 for (auto& Iter : m_RenderTech)
188 Iter.second.SRB.Release();
189
190 m_BackBufferWidth = FrameDesc.Width;
191 m_BackBufferHeight = FrameDesc.Height;
192 m_FeatureFlags = FeatureFlags;
193
194 RenderDeviceWithCache_N Device{pDevice};
195
196 {
197 TextureDesc Desc;
198 Desc.Name = "DepthOfField::CircleOfConfusion";
199 Desc.Type = RESOURCE_DIM_TEX_2D;
200 Desc.Width = m_BackBufferWidth;
201 Desc.Height = m_BackBufferHeight;
202 Desc.Format = TEX_FORMAT_R16_FLOAT;
203 Desc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET;
204 m_Resources.Insert(RESOURCE_IDENTIFIER_CIRCLE_OF_CONFUSION_TEXTURE, Device.CreateTexture(Desc));
205 }
206
207 if (FeatureFlags & FEATURE_FLAG_ENABLE_TEMPORAL_SMOOTHING)
208 {
209 for (Uint32 TextureIdx = RESOURCE_IDENTIFIER_CIRCLE_OF_CONFUSION_TEMPORAL_TEXTURE0; TextureIdx <= RESOURCE_IDENTIFIER_CIRCLE_OF_CONFUSION_TEMPORAL_TEXTURE1; ++TextureIdx)
210 {
211 TextureDesc Desc;
212 Desc.Name = "DepthOfField::TemporalCircleOfConfusion";
213 Desc.Type = RESOURCE_DIM_TEX_2D;
214 Desc.Width = m_BackBufferWidth;
215 Desc.Height = m_BackBufferHeight;
216 Desc.Format = TEX_FORMAT_R16_FLOAT;
217 Desc.BindFlags = BIND_SHADER_RESOURCE | BIND_RENDER_TARGET;
218 auto pTexture = Device.CreateTexture(Desc);
219 float ClearColor[] = {0.0, 0.0, 0.0, 0.0};
220 pPostFXContext->ClearRenderTarget({nullptr, nullptr, pDeviceContext}, pTexture, ClearColor);
221 m_Resources.Insert(TextureIdx, pTexture);
222 }
223 }
224
225 TEXTURE_FORMAT TextureCoCFormat = TEX_FORMAT_R16_FLOAT;
226 if (pDevice->GetTextureFormatInfo(TEX_FORMAT_R16_UNORM).Supported)
227 TextureCoCFormat = TEX_FORMAT_R16_UNORM;
228
229 for (Uint32 TextureIdx = RESOURCE_IDENTIFIER_CIRCLE_OF_CONFUSION_DILATION_TEXTURE_MIP0; TextureIdx <= RESOURCE_IDENTIFIER_CIRCLE_OF_CONFUSION_DILATION_TEXTURE_LAST_MIP; ++TextureIdx)
230 {
231 TextureDesc Desc;
232 Desc.Name = "DepthOfField::DilationCircleOfConfusion";

Callers

nothing calls this directly

Calls 1

ClearRenderTargetMethod · 0.80

Tested by

no test coverage detected