|
@@ -20,6 +20,7 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
|
|
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
|
|
// 2021-05-19: DirectX12: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
|
|
|
// 2021-02-18: DirectX12: Change blending equation to preserve alpha in output buffer.
|
|
@@ -83,7 +84,7 @@ struct VERTEX_CONSTANT_BUFFER_DX12
|
|
|
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
|
|
static ImGui_ImplDX12_Data* ImGui_ImplDX12_GetBackendData()
|
|
|
{
|
|
|
- return ImGui::GetCurrentContext() ? (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData : NULL;
|
|
|
+ return ImGui::GetCurrentContext() ? (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
|
}
|
|
|
|
|
|
// Functions
|
|
@@ -149,7 +150,7 @@ static inline void SafeRelease(T*& res)
|
|
|
{
|
|
|
if (res)
|
|
|
res->Release();
|
|
|
- res = NULL;
|
|
|
+ res = nullptr;
|
|
|
}
|
|
|
|
|
|
// Render function
|
|
@@ -166,7 +167,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[bd->frameIndex % bd->numFramesInFlight];
|
|
|
|
|
|
// Create and grow vertex/index buffers if needed
|
|
|
- if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
|
|
+ if (fr->VertexBuffer == nullptr || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
|
|
{
|
|
|
SafeRelease(fr->VertexBuffer);
|
|
|
fr->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
@@ -186,10 +187,10 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
|
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
|
- if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->VertexBuffer)) < 0)
|
|
|
+ if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->VertexBuffer)) < 0)
|
|
|
return;
|
|
|
}
|
|
|
- if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount)
|
|
|
+ if (fr->IndexBuffer == nullptr || fr->IndexBufferSize < draw_data->TotalIdxCount)
|
|
|
{
|
|
|
SafeRelease(fr->IndexBuffer);
|
|
|
fr->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
@@ -209,7 +210,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
|
|
|
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
|
- if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->IndexBuffer)) < 0)
|
|
|
+ if (bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&fr->IndexBuffer)) < 0)
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -248,7 +249,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
|
|
{
|
|
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
|
|
- if (pcmd->UserCallback != NULL)
|
|
|
+ if (pcmd->UserCallback != nullptr)
|
|
|
{
|
|
|
// User callback, registered via ImDrawList::AddCallback()
|
|
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
|
@@ -310,9 +311,9 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
|
|
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
|
|
|
|
|
|
- ID3D12Resource* pTexture = NULL;
|
|
|
+ ID3D12Resource* pTexture = nullptr;
|
|
|
bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
|
|
- D3D12_RESOURCE_STATE_COPY_DEST, NULL, IID_PPV_ARGS(&pTexture));
|
|
|
+ D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pTexture));
|
|
|
|
|
|
UINT uploadPitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
|
|
UINT uploadSize = height * uploadPitch;
|
|
@@ -332,12 +333,12 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
props.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
|
|
props.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
|
|
|
|
|
- ID3D12Resource* uploadBuffer = NULL;
|
|
|
+ ID3D12Resource* uploadBuffer = nullptr;
|
|
|
HRESULT hr = bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
|
|
- D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&uploadBuffer));
|
|
|
+ D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&uploadBuffer));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
- void* mapped = NULL;
|
|
|
+ void* mapped = nullptr;
|
|
|
D3D12_RANGE range = { 0, uploadSize };
|
|
|
hr = uploadBuffer->Map(0, &range, &mapped);
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
@@ -367,31 +368,31 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST;
|
|
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE;
|
|
|
|
|
|
- ID3D12Fence* fence = NULL;
|
|
|
+ ID3D12Fence* fence = nullptr;
|
|
|
hr = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
HANDLE event = CreateEvent(0, 0, 0, 0);
|
|
|
- IM_ASSERT(event != NULL);
|
|
|
+ IM_ASSERT(event != nullptr);
|
|
|
|
|
|
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
|
|
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
|
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
|
queueDesc.NodeMask = 1;
|
|
|
|
|
|
- ID3D12CommandQueue* cmdQueue = NULL;
|
|
|
+ ID3D12CommandQueue* cmdQueue = nullptr;
|
|
|
hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
- ID3D12CommandAllocator* cmdAlloc = NULL;
|
|
|
+ ID3D12CommandAllocator* cmdAlloc = nullptr;
|
|
|
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
- ID3D12GraphicsCommandList* cmdList = NULL;
|
|
|
- hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, NULL, IID_PPV_ARGS(&cmdList));
|
|
|
+ ID3D12GraphicsCommandList* cmdList = nullptr;
|
|
|
+ hr = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, cmdAlloc, nullptr, IID_PPV_ARGS(&cmdList));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
- cmdList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, NULL);
|
|
|
+ cmdList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, nullptr);
|
|
|
cmdList->ResourceBarrier(1, &barrier);
|
|
|
|
|
|
hr = cmdList->Close();
|
|
@@ -496,7 +497,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|
|
// Load d3d12.dll and D3D12SerializeRootSignature() function address dynamically to facilitate using with D3D12On7.
|
|
|
// See if any version of d3d12.dll is already loaded in the process. If so, give preference to that.
|
|
|
static HINSTANCE d3d12_dll = ::GetModuleHandleA("d3d12.dll");
|
|
|
- if (d3d12_dll == NULL)
|
|
|
+ if (d3d12_dll == nullptr)
|
|
|
{
|
|
|
// Attempt to load d3d12.dll from local directories. This will only succeed if
|
|
|
// (1) the current OS is Windows 7, and
|
|
@@ -504,23 +505,23 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|
|
// See https://github.com/ocornut/imgui/pull/3696 for details.
|
|
|
const char* localD3d12Paths[] = { ".\\d3d12.dll", ".\\d3d12on7\\d3d12.dll", ".\\12on7\\d3d12.dll" }; // A. current directory, B. used by some games, C. used in Microsoft D3D12On7 sample
|
|
|
for (int i = 0; i < IM_ARRAYSIZE(localD3d12Paths); i++)
|
|
|
- if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != NULL)
|
|
|
+ if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr)
|
|
|
break;
|
|
|
|
|
|
// If failed, we are on Windows >= 10.
|
|
|
- if (d3d12_dll == NULL)
|
|
|
+ if (d3d12_dll == nullptr)
|
|
|
d3d12_dll = ::LoadLibraryA("d3d12.dll");
|
|
|
|
|
|
- if (d3d12_dll == NULL)
|
|
|
+ if (d3d12_dll == nullptr)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignatureFn = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)::GetProcAddress(d3d12_dll, "D3D12SerializeRootSignature");
|
|
|
- if (D3D12SerializeRootSignatureFn == NULL)
|
|
|
+ if (D3D12SerializeRootSignatureFn == nullptr)
|
|
|
return false;
|
|
|
|
|
|
- ID3DBlob* blob = NULL;
|
|
|
- if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, NULL) != S_OK)
|
|
|
+ ID3DBlob* blob = nullptr;
|
|
|
+ if (D3D12SerializeRootSignatureFn(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &blob, nullptr) != S_OK)
|
|
|
return false;
|
|
|
|
|
|
bd->pd3dDevice->CreateRootSignature(0, blob->GetBufferPointer(), blob->GetBufferSize(), IID_PPV_ARGS(&bd->pRootSignature));
|
|
@@ -577,7 +578,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|
|
return output;\
|
|
|
}";
|
|
|
|
|
|
- if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_5_0", 0, 0, &vertexShaderBlob, NULL)))
|
|
|
+ if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_5_0", 0, 0, &vertexShaderBlob, nullptr)))
|
|
|
return false; // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
|
psoDesc.VS = { vertexShaderBlob->GetBufferPointer(), vertexShaderBlob->GetBufferSize() };
|
|
|
|
|
@@ -609,7 +610,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
|
|
|
return out_col; \
|
|
|
}";
|
|
|
|
|
|
- if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_5_0", 0, 0, &pixelShaderBlob, NULL)))
|
|
|
+ if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_5_0", 0, 0, &pixelShaderBlob, nullptr)))
|
|
|
{
|
|
|
vertexShaderBlob->Release();
|
|
|
return false; // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
|
@@ -680,7 +681,7 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
|
|
SafeRelease(bd->pRootSignature);
|
|
|
SafeRelease(bd->pPipelineState);
|
|
|
SafeRelease(bd->pFontTextureResource);
|
|
|
- io.Fonts->SetTexID(NULL); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
|
+ io.Fonts->SetTexID(0); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
|
|
|
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
|
|
{
|
|
@@ -694,7 +695,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|
|
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
|
|
|
{
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
- IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
|
|
|
+ IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
|
|
|
|
|
// Setup backend capabilities flags
|
|
|
ImGui_ImplDX12_Data* bd = IM_NEW(ImGui_ImplDX12_Data)();
|
|
@@ -715,8 +716,8 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|
|
for (int i = 0; i < num_frames_in_flight; i++)
|
|
|
{
|
|
|
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[i];
|
|
|
- fr->IndexBuffer = NULL;
|
|
|
- fr->VertexBuffer = NULL;
|
|
|
+ fr->IndexBuffer = nullptr;
|
|
|
+ fr->VertexBuffer = nullptr;
|
|
|
fr->IndexBufferSize = 10000;
|
|
|
fr->VertexBufferSize = 5000;
|
|
|
}
|
|
@@ -727,20 +728,20 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|
|
void ImGui_ImplDX12_Shutdown()
|
|
|
{
|
|
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
|
- IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?");
|
|
|
+ IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
ImGui_ImplDX12_InvalidateDeviceObjects();
|
|
|
delete[] bd->pFrameResources;
|
|
|
- io.BackendRendererName = NULL;
|
|
|
- io.BackendRendererUserData = NULL;
|
|
|
+ io.BackendRendererName = nullptr;
|
|
|
+ io.BackendRendererUserData = nullptr;
|
|
|
IM_DELETE(bd);
|
|
|
}
|
|
|
|
|
|
void ImGui_ImplDX12_NewFrame()
|
|
|
{
|
|
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
|
- IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX12_Init()?");
|
|
|
+ IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX12_Init()?");
|
|
|
|
|
|
if (!bd->pPipelineState)
|
|
|
ImGui_ImplDX12_CreateDeviceObjects();
|