mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-23 22:05:51 +12:00
Add ImGui bindings to Lua
This commit is contained in:
parent
da797831ba
commit
d29e76da8c
212 changed files with 49453 additions and 21919 deletions
|
@ -6,4 +6,4 @@
|
|||
@set SOURCES=main.cpp ..\..\backends\imgui_impl_dx12.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp
|
||||
@set LIBS=d3d12.lib d3dcompiler.lib dxgi.lib
|
||||
mkdir Debug
|
||||
cl /nologo /Zi /MD %INCLUDES% /D ImTextureID=ImU64 /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS%
|
||||
cl /nologo /Zi /MD /utf-8 %INCLUDES% /D ImTextureID=ImU64 /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS%
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{b4cf9797-519d-4afe-a8f4-5141a6b521d3}</ProjectGuid>
|
||||
<RootNamespace>example_win32_directx12</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
|
@ -88,6 +88,7 @@
|
|||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -102,6 +103,7 @@
|
|||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -118,6 +120,7 @@
|
|||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -136,6 +139,7 @@
|
|||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>..\..;..\..\backends;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -164,9 +168,13 @@
|
|||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\misc\debuggers\imgui.natstepfilter" />
|
||||
<None Include="..\README.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="..\..\misc\debuggers\imgui.natvis" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
|
@ -53,5 +53,13 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\README.txt" />
|
||||
<None Include="..\..\misc\debuggers\imgui.natstepfilter">
|
||||
<Filter>imgui</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<Natvis Include="..\..\misc\debuggers\imgui.natvis">
|
||||
<Filter>imgui</Filter>
|
||||
</Natvis>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,6 +1,10 @@
|
|||
// 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.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// 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*.
|
||||
|
@ -34,16 +38,16 @@ static FrameContext g_frameContext[NUM_FRAMES_IN_FLIGHT] = {};
|
|||
static UINT g_frameIndex = 0;
|
||||
|
||||
static int const NUM_BACK_BUFFERS = 3;
|
||||
static ID3D12Device* g_pd3dDevice = NULL;
|
||||
static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = NULL;
|
||||
static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = NULL;
|
||||
static ID3D12CommandQueue* g_pd3dCommandQueue = NULL;
|
||||
static ID3D12GraphicsCommandList* g_pd3dCommandList = NULL;
|
||||
static ID3D12Fence* g_fence = NULL;
|
||||
static HANDLE g_fenceEvent = NULL;
|
||||
static ID3D12Device* g_pd3dDevice = nullptr;
|
||||
static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = nullptr;
|
||||
static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = nullptr;
|
||||
static ID3D12CommandQueue* g_pd3dCommandQueue = nullptr;
|
||||
static ID3D12GraphicsCommandList* g_pd3dCommandList = nullptr;
|
||||
static ID3D12Fence* g_fence = nullptr;
|
||||
static HANDLE g_fenceEvent = nullptr;
|
||||
static UINT64 g_fenceLastSignaledValue = 0;
|
||||
static IDXGISwapChain3* g_pSwapChain = NULL;
|
||||
static HANDLE g_hSwapChainWaitableObject = NULL;
|
||||
static IDXGISwapChain3* g_pSwapChain = nullptr;
|
||||
static HANDLE g_hSwapChainWaitableObject = nullptr;
|
||||
static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
|
||||
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
|
||||
|
||||
|
@ -54,7 +58,6 @@ void CreateRenderTarget();
|
|||
void CleanupRenderTarget();
|
||||
void WaitForLastSubmittedFrame();
|
||||
FrameContext* WaitForNextFrameResources();
|
||||
void ResizeSwapChain(HWND hWnd, int width, int height);
|
||||
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
// Main code
|
||||
|
@ -62,15 +65,15 @@ int main(int, char**)
|
|||
{
|
||||
// Create application window
|
||||
//ImGui_ImplWin32_EnableDpiAwareness();
|
||||
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
|
||||
::RegisterClassEx(&wc);
|
||||
HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX12 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
|
||||
WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr };
|
||||
::RegisterClassExW(&wc);
|
||||
HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX12 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr);
|
||||
|
||||
// Initialize Direct3D
|
||||
if (!CreateDeviceD3D(hwnd))
|
||||
{
|
||||
CleanupDeviceD3D();
|
||||
::UnregisterClass(wc.lpszClassName, wc.hInstance);
|
||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -82,12 +85,24 @@ int main(int, char**)
|
|||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
//io.ConfigViewportsNoAutoMerge = true;
|
||||
//io.ConfigViewportsNoTaskBarIcon = true;
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsClassic();
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
style.WindowRounding = 0.0f;
|
||||
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
||||
}
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
|
@ -99,17 +114,18 @@ int main(int, char**)
|
|||
// Load Fonts
|
||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||
//io.Fonts->AddFontDefault();
|
||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != NULL);
|
||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
||||
//IM_ASSERT(font != nullptr);
|
||||
|
||||
// Our state
|
||||
bool show_demo_window = true;
|
||||
|
@ -117,21 +133,21 @@ int main(int, char**)
|
|||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
|
||||
// Main loop
|
||||
MSG msg;
|
||||
ZeroMemory(&msg, sizeof(msg));
|
||||
while (msg.message != WM_QUIT)
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Poll and handle messages (inputs, window resize, etc.)
|
||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||
// See the WndProc() function below for our to dispatch events to the Win32 backend.
|
||||
MSG msg;
|
||||
while (::PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE))
|
||||
{
|
||||
::TranslateMessage(&msg);
|
||||
::DispatchMessage(&msg);
|
||||
continue;
|
||||
if (msg.message == WM_QUIT)
|
||||
done = true;
|
||||
}
|
||||
if (done)
|
||||
break;
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplDX12_NewFrame();
|
||||
|
@ -142,7 +158,7 @@ int main(int, char**)
|
|||
if (show_demo_window)
|
||||
ImGui::ShowDemoWindow(&show_demo_window);
|
||||
|
||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
|
||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
||||
{
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
@ -161,7 +177,7 @@ int main(int, char**)
|
|||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
@ -189,13 +205,13 @@ int main(int, char**)
|
|||
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
g_pd3dCommandList->Reset(frameCtx->CommandAllocator, NULL);
|
||||
g_pd3dCommandList->Reset(frameCtx->CommandAllocator, nullptr);
|
||||
g_pd3dCommandList->ResourceBarrier(1, &barrier);
|
||||
|
||||
// Render Dear ImGui graphics
|
||||
const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };
|
||||
g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], clear_color_with_alpha, 0, NULL);
|
||||
g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, NULL);
|
||||
g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], clear_color_with_alpha, 0, nullptr);
|
||||
g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, nullptr);
|
||||
g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap);
|
||||
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), g_pd3dCommandList);
|
||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||
|
@ -205,6 +221,13 @@ int main(int, char**)
|
|||
|
||||
g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList);
|
||||
|
||||
// Update and Render additional Platform Windows
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault(nullptr, (void*)g_pd3dCommandList);
|
||||
}
|
||||
|
||||
g_pSwapChain->Present(1, 0); // Present with vsync
|
||||
//g_pSwapChain->Present(0, 0); // Present without vsync
|
||||
|
||||
|
@ -223,13 +246,12 @@ int main(int, char**)
|
|||
|
||||
CleanupDeviceD3D();
|
||||
::DestroyWindow(hwnd);
|
||||
::UnregisterClass(wc.lpszClassName, wc.hInstance);
|
||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
|
||||
bool CreateDeviceD3D(HWND hWnd)
|
||||
{
|
||||
// Setup swap chain
|
||||
|
@ -252,21 +274,21 @@ bool CreateDeviceD3D(HWND hWnd)
|
|||
|
||||
// [DEBUG] Enable debug interface
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
ID3D12Debug* pdx12Debug = NULL;
|
||||
ID3D12Debug* pdx12Debug = nullptr;
|
||||
if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pdx12Debug))))
|
||||
pdx12Debug->EnableDebugLayer();
|
||||
#endif
|
||||
|
||||
// Create device
|
||||
D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
|
||||
if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
|
||||
if (D3D12CreateDevice(nullptr, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
|
||||
return false;
|
||||
|
||||
// [DEBUG] Setup debug interface to break on any warnings/errors
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
if (pdx12Debug != NULL)
|
||||
if (pdx12Debug != nullptr)
|
||||
{
|
||||
ID3D12InfoQueue* pInfoQueue = NULL;
|
||||
ID3D12InfoQueue* pInfoQueue = nullptr;
|
||||
g_pd3dDevice->QueryInterface(IID_PPV_ARGS(&pInfoQueue));
|
||||
pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, true);
|
||||
pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, true);
|
||||
|
@ -316,23 +338,23 @@ bool CreateDeviceD3D(HWND hWnd)
|
|||
if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
|
||||
return false;
|
||||
|
||||
if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, NULL, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
|
||||
if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, nullptr, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
|
||||
g_pd3dCommandList->Close() != S_OK)
|
||||
return false;
|
||||
|
||||
if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK)
|
||||
return false;
|
||||
|
||||
g_fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (g_fenceEvent == NULL)
|
||||
g_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
if (g_fenceEvent == nullptr)
|
||||
return false;
|
||||
|
||||
{
|
||||
IDXGIFactory4* dxgiFactory = NULL;
|
||||
IDXGISwapChain1* swapChain1 = NULL;
|
||||
IDXGIFactory4* dxgiFactory = nullptr;
|
||||
IDXGISwapChain1* swapChain1 = nullptr;
|
||||
if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK)
|
||||
return false;
|
||||
if (dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1) != S_OK)
|
||||
if (dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, nullptr, nullptr, &swapChain1) != S_OK)
|
||||
return false;
|
||||
if (swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK)
|
||||
return false;
|
||||
|
@ -349,20 +371,20 @@ bool CreateDeviceD3D(HWND hWnd)
|
|||
void CleanupDeviceD3D()
|
||||
{
|
||||
CleanupRenderTarget();
|
||||
if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
|
||||
if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
|
||||
if (g_pSwapChain) { g_pSwapChain->SetFullscreenState(false, nullptr); g_pSwapChain->Release(); g_pSwapChain = nullptr; }
|
||||
if (g_hSwapChainWaitableObject != nullptr) { CloseHandle(g_hSwapChainWaitableObject); }
|
||||
for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
|
||||
if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
|
||||
if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = NULL; }
|
||||
if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = NULL; }
|
||||
if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = NULL; }
|
||||
if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = NULL; }
|
||||
if (g_fence) { g_fence->Release(); g_fence = NULL; }
|
||||
if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; }
|
||||
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
|
||||
if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = nullptr; }
|
||||
if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = nullptr; }
|
||||
if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = nullptr; }
|
||||
if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = nullptr; }
|
||||
if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = nullptr; }
|
||||
if (g_fence) { g_fence->Release(); g_fence = nullptr; }
|
||||
if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = nullptr; }
|
||||
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = nullptr; }
|
||||
|
||||
#ifdef DX12_ENABLE_DEBUG_LAYER
|
||||
IDXGIDebug1* pDebug = NULL;
|
||||
IDXGIDebug1* pDebug = nullptr;
|
||||
if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug))))
|
||||
{
|
||||
pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_SUMMARY);
|
||||
|
@ -375,9 +397,9 @@ void CreateRenderTarget()
|
|||
{
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
|
||||
{
|
||||
ID3D12Resource* pBackBuffer = NULL;
|
||||
ID3D12Resource* pBackBuffer = nullptr;
|
||||
g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
|
||||
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, g_mainRenderTargetDescriptor[i]);
|
||||
g_pd3dDevice->CreateRenderTargetView(pBackBuffer, nullptr, g_mainRenderTargetDescriptor[i]);
|
||||
g_mainRenderTargetResource[i] = pBackBuffer;
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +409,7 @@ void CleanupRenderTarget()
|
|||
WaitForLastSubmittedFrame();
|
||||
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
|
||||
if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = NULL; }
|
||||
if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = nullptr; }
|
||||
}
|
||||
|
||||
void WaitForLastSubmittedFrame()
|
||||
|
@ -411,7 +433,7 @@ FrameContext* WaitForNextFrameResources()
|
|||
UINT nextFrameIndex = g_frameIndex + 1;
|
||||
g_frameIndex = nextFrameIndex;
|
||||
|
||||
HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
|
||||
HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, nullptr };
|
||||
DWORD numWaitableObjects = 1;
|
||||
|
||||
FrameContext* frameCtx = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
|
||||
|
@ -429,35 +451,14 @@ FrameContext* WaitForNextFrameResources()
|
|||
return frameCtx;
|
||||
}
|
||||
|
||||
void ResizeSwapChain(HWND hWnd, int width, int height)
|
||||
{
|
||||
DXGI_SWAP_CHAIN_DESC1 sd;
|
||||
g_pSwapChain->GetDesc1(&sd);
|
||||
sd.Width = width;
|
||||
sd.Height = height;
|
||||
|
||||
IDXGIFactory4* dxgiFactory = NULL;
|
||||
g_pSwapChain->GetParent(IID_PPV_ARGS(&dxgiFactory));
|
||||
|
||||
g_pSwapChain->Release();
|
||||
CloseHandle(g_hSwapChainWaitableObject);
|
||||
|
||||
IDXGISwapChain1* swapChain1 = NULL;
|
||||
dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1);
|
||||
swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain));
|
||||
swapChain1->Release();
|
||||
dxgiFactory->Release();
|
||||
|
||||
g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
|
||||
|
||||
g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
|
||||
assert(g_hSwapChainWaitableObject != NULL);
|
||||
}
|
||||
|
||||
// Forward declare message handler from imgui_impl_win32.cpp
|
||||
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
// Win32 message handler
|
||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
|
||||
|
@ -466,14 +467,13 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
switch (msg)
|
||||
{
|
||||
case WM_SIZE:
|
||||
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
|
||||
if (g_pd3dDevice != nullptr && wParam != SIZE_MINIMIZED)
|
||||
{
|
||||
WaitForLastSubmittedFrame();
|
||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||
CleanupRenderTarget();
|
||||
ResizeSwapChain(hWnd, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam));
|
||||
HRESULT result = g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT);
|
||||
assert(SUCCEEDED(result) && "Failed to resize swapchain.");
|
||||
CreateRenderTarget();
|
||||
ImGui_ImplDX12_CreateDeviceObjects();
|
||||
}
|
||||
return 0;
|
||||
case WM_SYSCOMMAND:
|
||||
|
@ -484,5 +484,5 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
::PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
return ::DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue