Pass render target format in ImGui_ImplDX12_Init() instead of hard-coded.

This commit is contained in:
Jefferson Montgomery 2017-09-24 14:57:38 -07:00 committed by Jefferson Montgomery
parent f6b6dace9e
commit 3fd5790814
3 changed files with 7 additions and 1 deletions

View File

@ -32,6 +32,7 @@ static ID3D10Blob* g_pVertexShaderBlob = NULL;
static ID3D10Blob* g_pPixelShaderBlob = NULL; static ID3D10Blob* g_pPixelShaderBlob = NULL;
static ID3D12RootSignature* g_pRootSignature = NULL; static ID3D12RootSignature* g_pRootSignature = NULL;
static ID3D12PipelineState* g_pPipelineState = NULL; static ID3D12PipelineState* g_pPipelineState = NULL;
static DXGI_FORMAT g_RTVFormat = DXGI_FORMAT_UNKNOWN;
static ID3D12Resource* g_pFontTextureResource = NULL; static ID3D12Resource* g_pFontTextureResource = NULL;
static D3D12_CPU_DESCRIPTOR_HANDLE g_hFontSrvCpuDescHandle = {}; static D3D12_CPU_DESCRIPTOR_HANDLE g_hFontSrvCpuDescHandle = {};
static D3D12_GPU_DESCRIPTOR_HANDLE g_hFontSrvGpuDescHandle = {}; static D3D12_GPU_DESCRIPTOR_HANDLE g_hFontSrvGpuDescHandle = {};
@ -489,7 +490,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
psoDesc.pRootSignature = g_pRootSignature; psoDesc.pRootSignature = g_pRootSignature;
psoDesc.SampleMask = UINT_MAX; psoDesc.SampleMask = UINT_MAX;
psoDesc.NumRenderTargets = 1; psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM; psoDesc.RTVFormats[0] = g_RTVFormat;
psoDesc.SampleDesc.Count = 1; psoDesc.SampleDesc.Count = 1;
psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
@ -630,11 +631,13 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
bool ImGui_ImplDX12_Init(void* hwnd, int num_frames_in_flight, bool ImGui_ImplDX12_Init(void* hwnd, int num_frames_in_flight,
ID3D12Device* device, ID3D12Device* device,
DXGI_FORMAT rtv_format,
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle,
D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle) D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
{ {
g_hWnd = (HWND)hwnd; g_hWnd = (HWND)hwnd;
g_pd3dDevice = device; g_pd3dDevice = device;
g_RTVFormat = rtv_format;
g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle; g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
g_hFontSrvGpuDescHandle = font_srv_gpu_desc_handle; g_hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
g_pFrameResources = new FrameResources [num_frames_in_flight]; g_pFrameResources = new FrameResources [num_frames_in_flight];

View File

@ -6,6 +6,7 @@
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// https://github.com/ocornut/imgui // https://github.com/ocornut/imgui
enum DXGI_FORMAT;
struct ID3D12Device; struct ID3D12Device;
struct ID3D12GraphicsCommandList; struct ID3D12GraphicsCommandList;
struct D3D12_CPU_DESCRIPTOR_HANDLE; struct D3D12_CPU_DESCRIPTOR_HANDLE;
@ -22,6 +23,7 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE;
// descriptor to use for the internal font texture. // descriptor to use for the internal font texture.
IMGUI_API bool ImGui_ImplDX12_Init(void* hwnd, int numFramesInFlight, IMGUI_API bool ImGui_ImplDX12_Init(void* hwnd, int numFramesInFlight,
ID3D12Device* device, ID3D12Device* device,
DXGI_FORMAT rtv_format,
D3D12_CPU_DESCRIPTOR_HANDLE fontSrvCpuDescHandle, D3D12_CPU_DESCRIPTOR_HANDLE fontSrvCpuDescHandle,
D3D12_GPU_DESCRIPTOR_HANDLE fontSrvGpuDescHandle); D3D12_GPU_DESCRIPTOR_HANDLE fontSrvGpuDescHandle);
IMGUI_API void ImGui_ImplDX12_Shutdown(); IMGUI_API void ImGui_ImplDX12_Shutdown();

View File

@ -301,6 +301,7 @@ int main(int, char**)
// Setup ImGui binding // Setup ImGui binding
ImGui_ImplDX12_Init(hwnd, NUM_FRAMES_IN_FLIGHT, g_pd3dDevice, ImGui_ImplDX12_Init(hwnd, NUM_FRAMES_IN_FLIGHT, g_pd3dDevice,
DXGI_FORMAT_R8G8B8A8_UNORM,
g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(), g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart()); g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());