|
@@ -1,7 +1,10 @@
|
|
// Dear ImGui: standalone example application for DirectX 12
|
|
// Dear ImGui: standalone example application for DirectX 12
|
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
-// FIXME: 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*))
|
|
|
|
|
|
+
|
|
|
|
+// Important: to compile on 32-bit systems, the DirectX12 backend requires code to be compiled with '#define ImTextureID ImU64'.
|
|
|
|
+// This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*.
|
|
|
|
+// This define is set in the example .vcxproj file and need to be replicated in your app or by adding it to your imconfig.h file.
|
|
|
|
|
|
#include "imgui.h"
|
|
#include "imgui.h"
|
|
#include "imgui_impl_win32.h"
|
|
#include "imgui_impl_win32.h"
|
|
@@ -173,9 +176,11 @@ int main(int, char**)
|
|
}
|
|
}
|
|
|
|
|
|
// Rendering
|
|
// Rendering
|
|
- FrameContext* frameCtxt = WaitForNextFrameResources();
|
|
|
|
|
|
+ ImGui::Render();
|
|
|
|
+
|
|
|
|
+ FrameContext* frameCtx = WaitForNextFrameResources();
|
|
UINT backBufferIdx = g_pSwapChain->GetCurrentBackBufferIndex();
|
|
UINT backBufferIdx = g_pSwapChain->GetCurrentBackBufferIndex();
|
|
- frameCtxt->CommandAllocator->Reset();
|
|
|
|
|
|
+ frameCtx->CommandAllocator->Reset();
|
|
|
|
|
|
D3D12_RESOURCE_BARRIER barrier = {};
|
|
D3D12_RESOURCE_BARRIER barrier = {};
|
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
@@ -184,13 +189,13 @@ int main(int, char**)
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
-
|
|
|
|
- g_pd3dCommandList->Reset(frameCtxt->CommandAllocator, NULL);
|
|
|
|
|
|
+ g_pd3dCommandList->Reset(frameCtx->CommandAllocator, NULL);
|
|
g_pd3dCommandList->ResourceBarrier(1, &barrier);
|
|
g_pd3dCommandList->ResourceBarrier(1, &barrier);
|
|
|
|
+
|
|
|
|
+ // Render Dear ImGui graphics
|
|
g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], (float*)&clear_color, 0, NULL);
|
|
g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], (float*)&clear_color, 0, NULL);
|
|
g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, NULL);
|
|
g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, NULL);
|
|
g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap);
|
|
g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap);
|
|
- ImGui::Render();
|
|
|
|
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), g_pd3dCommandList);
|
|
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), g_pd3dCommandList);
|
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
|
|
@@ -205,10 +210,12 @@ int main(int, char**)
|
|
UINT64 fenceValue = g_fenceLastSignaledValue + 1;
|
|
UINT64 fenceValue = g_fenceLastSignaledValue + 1;
|
|
g_pd3dCommandQueue->Signal(g_fence, fenceValue);
|
|
g_pd3dCommandQueue->Signal(g_fence, fenceValue);
|
|
g_fenceLastSignaledValue = fenceValue;
|
|
g_fenceLastSignaledValue = fenceValue;
|
|
- frameCtxt->FenceValue = fenceValue;
|
|
|
|
|
|
+ frameCtx->FenceValue = fenceValue;
|
|
}
|
|
}
|
|
|
|
|
|
WaitForLastSubmittedFrame();
|
|
WaitForLastSubmittedFrame();
|
|
|
|
+
|
|
|
|
+ // Cleanup
|
|
ImGui_ImplDX12_Shutdown();
|
|
ImGui_ImplDX12_Shutdown();
|
|
ImGui_ImplWin32_Shutdown();
|
|
ImGui_ImplWin32_Shutdown();
|
|
ImGui::DestroyContext();
|
|
ImGui::DestroyContext();
|
|
@@ -382,13 +389,13 @@ void CleanupRenderTarget()
|
|
|
|
|
|
void WaitForLastSubmittedFrame()
|
|
void WaitForLastSubmittedFrame()
|
|
{
|
|
{
|
|
- FrameContext* frameCtxt = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
|
|
|
|
|
|
+ FrameContext* frameCtx = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
|
|
|
|
|
|
- UINT64 fenceValue = frameCtxt->FenceValue;
|
|
|
|
|
|
+ UINT64 fenceValue = frameCtx->FenceValue;
|
|
if (fenceValue == 0)
|
|
if (fenceValue == 0)
|
|
return; // No fence was signaled
|
|
return; // No fence was signaled
|
|
|
|
|
|
- frameCtxt->FenceValue = 0;
|
|
|
|
|
|
+ frameCtx->FenceValue = 0;
|
|
if (g_fence->GetCompletedValue() >= fenceValue)
|
|
if (g_fence->GetCompletedValue() >= fenceValue)
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -404,11 +411,11 @@ FrameContext* WaitForNextFrameResources()
|
|
HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
|
|
HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
|
|
DWORD numWaitableObjects = 1;
|
|
DWORD numWaitableObjects = 1;
|
|
|
|
|
|
- FrameContext* frameCtxt = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
|
|
|
|
- UINT64 fenceValue = frameCtxt->FenceValue;
|
|
|
|
|
|
+ FrameContext* frameCtx = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
|
|
|
|
+ UINT64 fenceValue = frameCtx->FenceValue;
|
|
if (fenceValue != 0) // means no fence was signaled
|
|
if (fenceValue != 0) // means no fence was signaled
|
|
{
|
|
{
|
|
- frameCtxt->FenceValue = 0;
|
|
|
|
|
|
+ frameCtx->FenceValue = 0;
|
|
g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
|
|
g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
|
|
waitableObjects[1] = g_fenceEvent;
|
|
waitableObjects[1] = g_fenceEvent;
|
|
numWaitableObjects = 2;
|
|
numWaitableObjects = 2;
|
|
@@ -416,7 +423,7 @@ FrameContext* WaitForNextFrameResources()
|
|
|
|
|
|
WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
|
|
WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
|
|
|
|
|
|
- return frameCtxt;
|
|
|
|
|
|
+ return frameCtx;
|
|
}
|
|
}
|
|
|
|
|
|
void ResizeSwapChain(HWND hWnd, int width, int height)
|
|
void ResizeSwapChain(HWND hWnd, int width, int height)
|