MCPcopy Create free account
hub / github.com/defold/defold / InitializeFrameBuffers

Function InitializeFrameBuffers

engine/graphics/src/dx12/graphics_dx12.cpp:196–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194 }
195
196 static void InitializeFrameBuffers(HContext _context, DXGI_FORMAT color_format, DXGI_FORMAT depth_format)
197 {
198 DX12Context* context = (DX12Context*) _context;
199
200 uint32_t window_width = dmPlatform::GetWindowWidth(context->m_BaseContext.m_Window);
201 uint32_t window_height = dmPlatform::GetWindowHeight(context->m_BaseContext.m_Window);
202
203 TextureCreationParams texture_create_params;
204 texture_create_params.m_Width = window_width;
205 texture_create_params.m_Height = window_height;
206 texture_create_params.m_OriginalWidth = window_width;
207 texture_create_params.m_OriginalHeight = window_height;
208
209 // get a handle to the first descriptor in the descriptor heap. a handle is basically a pointer,
210 // but we cannot literally use it like a c++ pointer.
211 CD3DX12_CPU_DESCRIPTOR_HANDLE rtv_handle(context->m_RtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
212
213 for (int i = 0; i < MAX_FRAMEBUFFERS; i++)
214 {
215 context->m_FrameResources[i].m_TextureColor = NewTexture(_context, texture_create_params);
216 context->m_FrameResources[i].m_TextureDepthStencil = NewTexture(_context, texture_create_params);
217 DX12Texture* texture_color = GetAssetFromContainer<DX12Texture>(context->m_BaseContext.m_AssetHandleContainer, context->m_FrameResources[i].m_TextureColor);
218 DX12Texture* texture_depth = GetAssetFromContainer<DX12Texture>(context->m_BaseContext.m_AssetHandleContainer, context->m_FrameResources[i].m_TextureDepthStencil);
219
220 HRESULT hr = S_OK;
221
222// TODO: clean up this somehow
223#if !defined(DM_PLATFORM_VENDOR)
224 // first we get the n'th buffer in the swap chain and store it in the n'th
225 // position of our ID3D12Resource array
226 hr = context->m_SwapChain->GetBuffer(i, DM_IID_PPV_ARGS(&texture_color->m_Resource));
227 CHECK_HR_ERROR(hr);
228#else
229 texture_color->m_Resource = context->m_FrameResources[i].m_RenderTarget.m_Resource;
230 texture_color->m_Resource->AddRef();
231#endif
232
233 // we "create" a render target view which binds the swap chain buffer (ID3D12Resource[n]) to the rtv handle
234 context->m_Device->CreateRenderTargetView(texture_color->m_Resource, NULL, rtv_handle);
235 rtv_handle.Offset(1, context->m_RtvDescriptorSize);
236
237
238 // If the project is using multisampling, we need to create a secondary RT that we render into.
239 // This will later be resolved into the swap chain RT before presenting (via EndRenderPass).
240 if (context->m_MSAASampleCount > 1)
241 {
242 D3D12_RESOURCE_DESC msaa_desc = {};
243 msaa_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
244 msaa_desc.Width = window_width;
245 msaa_desc.Height = window_height;
246 msaa_desc.DepthOrArraySize = 1;
247 msaa_desc.MipLevels = 1;
248 msaa_desc.Format = color_format;
249 msaa_desc.SampleDesc.Count = context->m_MSAASampleCount;
250 msaa_desc.SampleDesc.Quality = 0;
251 msaa_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
252 msaa_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
253

Callers 1

DX12InitializeFunction · 0.85

Calls 5

NewTextureFunction · 0.85
GetBufferMethod · 0.80
GetWindowWidthFunction · 0.50
GetWindowHeightFunction · 0.50
InitializeMethod · 0.45

Tested by

no test coverage detected