mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-20 14:56:35 +00:00
Backends: Viewports: renamed viewport storage structures ImGuiViewportDataXXXX -> ImGui_ImplXXXX_ViewportData and locals (matching naming convention in 70c60385
)
This commit is contained in:
parent
0f7eb00f67
commit
36a0d1028c
@ -584,20 +584,20 @@ void ImGui_ImplDX10_NewFrame()
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataDx10
|
struct ImGui_ImplDX10_ViewportData
|
||||||
{
|
{
|
||||||
IDXGISwapChain* SwapChain;
|
IDXGISwapChain* SwapChain;
|
||||||
ID3D10RenderTargetView* RTView;
|
ID3D10RenderTargetView* RTView;
|
||||||
|
|
||||||
ImGuiViewportDataDx10() { SwapChain = NULL; RTView = NULL; }
|
ImGui_ImplDX10_ViewportData() { SwapChain = NULL; RTView = NULL; }
|
||||||
~ImGuiViewportDataDx10() { IM_ASSERT(SwapChain == NULL && RTView == NULL); }
|
~ImGui_ImplDX10_ViewportData() { IM_ASSERT(SwapChain == NULL && RTView == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
||||||
ImGuiViewportDataDx10* data = IM_NEW(ImGuiViewportDataDx10)();
|
ImGui_ImplDX10_ViewportData* vd = IM_NEW(ImGui_ImplDX10_ViewportData)();
|
||||||
viewport->RendererUserData = data;
|
viewport->RendererUserData = vd;
|
||||||
|
|
||||||
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
||||||
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
||||||
@ -619,15 +619,15 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
|
|||||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||||
sd.Flags = 0;
|
sd.Flags = 0;
|
||||||
|
|
||||||
IM_ASSERT(data->SwapChain == NULL && data->RTView == NULL);
|
IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL);
|
||||||
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &data->SwapChain);
|
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain);
|
||||||
|
|
||||||
// Create the render target
|
// Create the render target
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D10Texture2D* pBackBuffer;
|
ID3D10Texture2D* pBackBuffer;
|
||||||
data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
||||||
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
|
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView);
|
||||||
pBackBuffer->Release();
|
pBackBuffer->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,15 +635,15 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX10_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX10_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
// The main viewport (owned by the application) will always have RendererUserData == NULL here since we didn't create the data for it.
|
// The main viewport (owned by the application) will always have RendererUserData == NULL here since we didn't create the data for it.
|
||||||
if (ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData)
|
if (ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
data->SwapChain->Release();
|
vd->SwapChain->Release();
|
||||||
data->SwapChain = NULL;
|
vd->SwapChain = NULL;
|
||||||
if (data->RTView)
|
if (vd->RTView)
|
||||||
data->RTView->Release();
|
vd->RTView->Release();
|
||||||
data->RTView = NULL;
|
vd->RTView = NULL;
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->RendererUserData = NULL;
|
viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
@ -651,19 +651,19 @@ static void ImGui_ImplDX10_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
||||||
ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData;
|
ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
|
||||||
if (data->RTView)
|
if (vd->RTView)
|
||||||
{
|
{
|
||||||
data->RTView->Release();
|
vd->RTView->Release();
|
||||||
data->RTView = NULL;
|
vd->RTView = NULL;
|
||||||
}
|
}
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D10Texture2D* pBackBuffer = NULL;
|
ID3D10Texture2D* pBackBuffer = NULL;
|
||||||
data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
||||||
data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
||||||
if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; }
|
if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX10_SetWindowSize() failed creating buffers.\n"); return; }
|
||||||
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
|
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView);
|
||||||
pBackBuffer->Release();
|
pBackBuffer->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -671,18 +671,18 @@ static void ImGui_ImplDX10_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX10_RenderViewport(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
ImGui_ImplDX10_Data* bd = ImGui_ImplDX10_GetBackendData();
|
||||||
ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData;
|
ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
|
||||||
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
bd->pd3dDevice->OMSetRenderTargets(1, &data->RTView, NULL);
|
bd->pd3dDevice->OMSetRenderTargets(1, &vd->RTView, NULL);
|
||||||
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
||||||
bd->pd3dDevice->ClearRenderTargetView(data->RTView, (float*)&clear_color);
|
bd->pd3dDevice->ClearRenderTargetView(vd->RTView, (float*)&clear_color);
|
||||||
ImGui_ImplDX10_RenderDrawData(viewport->DrawData);
|
ImGui_ImplDX10_RenderDrawData(viewport->DrawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX10_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataDx10* data = (ImGuiViewportDataDx10*)viewport->RendererUserData;
|
ImGui_ImplDX10_ViewportData* vd = (ImGui_ImplDX10_ViewportData*)viewport->RendererUserData;
|
||||||
data->SwapChain->Present(0, 0); // Present without vsync
|
vd->SwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX10_InitPlatformInterface()
|
void ImGui_ImplDX10_InitPlatformInterface()
|
||||||
|
@ -601,20 +601,20 @@ void ImGui_ImplDX11_NewFrame()
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataDx11
|
struct ImGui_ImplDX11_ViewportData
|
||||||
{
|
{
|
||||||
IDXGISwapChain* SwapChain;
|
IDXGISwapChain* SwapChain;
|
||||||
ID3D11RenderTargetView* RTView;
|
ID3D11RenderTargetView* RTView;
|
||||||
|
|
||||||
ImGuiViewportDataDx11() { SwapChain = NULL; RTView = NULL; }
|
ImGui_ImplDX11_ViewportData() { SwapChain = NULL; RTView = NULL; }
|
||||||
~ImGuiViewportDataDx11() { IM_ASSERT(SwapChain == NULL && RTView == NULL); }
|
~ImGui_ImplDX11_ViewportData() { IM_ASSERT(SwapChain == NULL && RTView == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
||||||
ImGuiViewportDataDx11* data = IM_NEW(ImGuiViewportDataDx11)();
|
ImGui_ImplDX11_ViewportData* vd = IM_NEW(ImGui_ImplDX11_ViewportData)();
|
||||||
viewport->RendererUserData = data;
|
viewport->RendererUserData = vd;
|
||||||
|
|
||||||
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
||||||
// Some backend will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
// Some backend will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
||||||
@ -636,15 +636,15 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
|
|||||||
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
||||||
sd.Flags = 0;
|
sd.Flags = 0;
|
||||||
|
|
||||||
IM_ASSERT(data->SwapChain == NULL && data->RTView == NULL);
|
IM_ASSERT(vd->SwapChain == NULL && vd->RTView == NULL);
|
||||||
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &data->SwapChain);
|
bd->pFactory->CreateSwapChain(bd->pd3dDevice, &sd, &vd->SwapChain);
|
||||||
|
|
||||||
// Create the render target
|
// Create the render target
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D11Texture2D* pBackBuffer;
|
ID3D11Texture2D* pBackBuffer;
|
||||||
data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
||||||
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
|
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView);
|
||||||
pBackBuffer->Release();
|
pBackBuffer->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -652,15 +652,15 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX11_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX11_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
||||||
if (ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData)
|
if (ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
data->SwapChain->Release();
|
vd->SwapChain->Release();
|
||||||
data->SwapChain = NULL;
|
vd->SwapChain = NULL;
|
||||||
if (data->RTView)
|
if (vd->RTView)
|
||||||
data->RTView->Release();
|
vd->RTView->Release();
|
||||||
data->RTView = NULL;
|
vd->RTView = NULL;
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->RendererUserData = NULL;
|
viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
@ -668,19 +668,19 @@ static void ImGui_ImplDX11_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
||||||
ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData;
|
ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData;
|
||||||
if (data->RTView)
|
if (vd->RTView)
|
||||||
{
|
{
|
||||||
data->RTView->Release();
|
vd->RTView->Release();
|
||||||
data->RTView = NULL;
|
vd->RTView = NULL;
|
||||||
}
|
}
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D11Texture2D* pBackBuffer = NULL;
|
ID3D11Texture2D* pBackBuffer = NULL;
|
||||||
data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
||||||
data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
vd->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
|
||||||
if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; }
|
if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; }
|
||||||
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
|
bd->pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &vd->RTView);
|
||||||
pBackBuffer->Release();
|
pBackBuffer->Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -688,18 +688,18 @@ static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
|
||||||
ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData;
|
ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData;
|
||||||
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
bd->pd3dDeviceContext->OMSetRenderTargets(1, &data->RTView, NULL);
|
bd->pd3dDeviceContext->OMSetRenderTargets(1, &vd->RTView, NULL);
|
||||||
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
||||||
bd->pd3dDeviceContext->ClearRenderTargetView(data->RTView, (float*)&clear_color);
|
bd->pd3dDeviceContext->ClearRenderTargetView(vd->RTView, (float*)&clear_color);
|
||||||
ImGui_ImplDX11_RenderDrawData(viewport->DrawData);
|
ImGui_ImplDX11_RenderDrawData(viewport->DrawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData;
|
ImGui_ImplDX11_ViewportData* vd = (ImGui_ImplDX11_ViewportData*)viewport->RendererUserData;
|
||||||
data->SwapChain->Present(0, 0); // Present without vsync
|
vd->SwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX11_InitPlatformInterface()
|
static void ImGui_ImplDX11_InitPlatformInterface()
|
||||||
|
@ -93,7 +93,7 @@ struct ImGui_ImplDX12_FrameContext
|
|||||||
// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
// Main viewport created by application will only use the Resources field.
|
// Main viewport created by application will only use the Resources field.
|
||||||
// Secondary viewports created by this backend will use all the fields (including Window fields),
|
// Secondary viewports created by this backend will use all the fields (including Window fields),
|
||||||
struct ImGuiViewportDataDx12
|
struct ImGui_ImplDX12_ViewportData
|
||||||
{
|
{
|
||||||
// Window
|
// Window
|
||||||
ID3D12CommandQueue* CommandQueue;
|
ID3D12CommandQueue* CommandQueue;
|
||||||
@ -110,7 +110,7 @@ struct ImGuiViewportDataDx12
|
|||||||
UINT FrameIndex;
|
UINT FrameIndex;
|
||||||
ImGui_ImplDX12_RenderBuffers* FrameRenderBuffers;
|
ImGui_ImplDX12_RenderBuffers* FrameRenderBuffers;
|
||||||
|
|
||||||
ImGuiViewportDataDx12(UINT num_frames_in_flight)
|
ImGui_ImplDX12_ViewportData(UINT num_frames_in_flight)
|
||||||
{
|
{
|
||||||
CommandQueue = NULL;
|
CommandQueue = NULL;
|
||||||
CommandList = NULL;
|
CommandList = NULL;
|
||||||
@ -136,7 +136,7 @@ struct ImGuiViewportDataDx12
|
|||||||
FrameRenderBuffers[i].IndexBufferSize = 10000;
|
FrameRenderBuffers[i].IndexBufferSize = 10000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~ImGuiViewportDataDx12()
|
~ImGui_ImplDX12_ViewportData()
|
||||||
{
|
{
|
||||||
IM_ASSERT(CommandQueue == NULL && CommandList == NULL);
|
IM_ASSERT(CommandQueue == NULL && CommandList == NULL);
|
||||||
IM_ASSERT(RtvDescHeap == NULL);
|
IM_ASSERT(RtvDescHeap == NULL);
|
||||||
@ -245,9 +245,9 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGuiViewportDataDx12* render_data = (ImGuiViewportDataDx12*)draw_data->OwnerViewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)draw_data->OwnerViewport->RendererUserData;
|
||||||
render_data->FrameIndex++;
|
vd->FrameIndex++;
|
||||||
ImGui_ImplDX12_RenderBuffers* fr = &render_data->FrameRenderBuffers[render_data->FrameIndex % bd->numFramesInFlight];
|
ImGui_ImplDX12_RenderBuffers* fr = &vd->FrameRenderBuffers[vd->FrameIndex % bd->numFramesInFlight];
|
||||||
|
|
||||||
// Create and grow vertex/index buffers if needed
|
// Create and grow vertex/index buffers if needed
|
||||||
if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
||||||
@ -785,10 +785,10 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
ImGui_ImplDX12_InitPlatformInterface();
|
ImGui_ImplDX12_InitPlatformInterface();
|
||||||
|
|
||||||
// Create a dummy ImGuiViewportDataDx12 holder for the main viewport,
|
// Create a dummy ImGui_ImplDX12_ViewportData holder for the main viewport,
|
||||||
// Since this is created and managed by the application, we will only use the ->Resources[] fields.
|
// Since this is created and managed by the application, we will only use the ->Resources[] fields.
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataDx12)(bd->numFramesInFlight);
|
main_viewport->RendererUserData = IM_NEW(ImGui_ImplDX12_ViewportData)(bd->numFramesInFlight);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -800,12 +800,12 @@ void ImGui_ImplDX12_Shutdown()
|
|||||||
|
|
||||||
// Manually delete main viewport render resources in-case we haven't initialized for viewports
|
// Manually delete main viewport render resources in-case we haven't initialized for viewports
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)main_viewport->RendererUserData)
|
if (ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)main_viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
// We could just call ImGui_ImplDX12_DestroyWindow(main_viewport) as a convenience but that would be misleading since we only use data->Resources[]
|
// We could just call ImGui_ImplDX12_DestroyWindow(main_viewport) as a convenience but that would be misleading since we only use data->Resources[]
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
ImGui_ImplDX12_DestroyRenderBuffers(&data->FrameRenderBuffers[i]);
|
ImGui_ImplDX12_DestroyRenderBuffers(&vd->FrameRenderBuffers[i]);
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
main_viewport->RendererUserData = NULL;
|
main_viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,15 +834,15 @@ void ImGui_ImplDX12_NewFrame()
|
|||||||
static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGuiViewportDataDx12* data = IM_NEW(ImGuiViewportDataDx12)(bd->numFramesInFlight);
|
ImGui_ImplDX12_ViewportData* vd = IM_NEW(ImGui_ImplDX12_ViewportData)(bd->numFramesInFlight);
|
||||||
viewport->RendererUserData = data;
|
viewport->RendererUserData = vd;
|
||||||
|
|
||||||
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
||||||
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
||||||
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
||||||
IM_ASSERT(hwnd != 0);
|
IM_ASSERT(hwnd != 0);
|
||||||
|
|
||||||
data->FrameIndex = UINT_MAX;
|
vd->FrameIndex = UINT_MAX;
|
||||||
|
|
||||||
// Create command queue.
|
// Create command queue.
|
||||||
D3D12_COMMAND_QUEUE_DESC queue_desc = {};
|
D3D12_COMMAND_QUEUE_DESC queue_desc = {};
|
||||||
@ -850,27 +850,27 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||||
|
|
||||||
HRESULT res = S_OK;
|
HRESULT res = S_OK;
|
||||||
res = bd->pd3dDevice->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&data->CommandQueue));
|
res = bd->pd3dDevice->CreateCommandQueue(&queue_desc, IID_PPV_ARGS(&vd->CommandQueue));
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
|
|
||||||
// Create command allocator.
|
// Create command allocator.
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; ++i)
|
for (UINT i = 0; i < bd->numFramesInFlight; ++i)
|
||||||
{
|
{
|
||||||
res = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&data->FrameCtx[i].CommandAllocator));
|
res = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&vd->FrameCtx[i].CommandAllocator));
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create command list.
|
// Create command list.
|
||||||
res = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, data->FrameCtx[0].CommandAllocator, NULL, IID_PPV_ARGS(&data->CommandList));
|
res = bd->pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, vd->FrameCtx[0].CommandAllocator, NULL, IID_PPV_ARGS(&vd->CommandList));
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
data->CommandList->Close();
|
vd->CommandList->Close();
|
||||||
|
|
||||||
// Create fence.
|
// Create fence.
|
||||||
res = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&data->Fence));
|
res = bd->pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&vd->Fence));
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
|
|
||||||
data->FenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
vd->FenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||||
IM_ASSERT(data->FenceEvent != NULL);
|
IM_ASSERT(vd->FenceEvent != NULL);
|
||||||
|
|
||||||
// Create swap chain
|
// Create swap chain
|
||||||
// FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application.
|
// FIXME-VIEWPORT: May want to copy/inherit swap chain settings from the user/application.
|
||||||
@ -893,18 +893,18 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
|
|
||||||
IDXGISwapChain1* swap_chain = NULL;
|
IDXGISwapChain1* swap_chain = NULL;
|
||||||
res = dxgi_factory->CreateSwapChainForHwnd(data->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain);
|
res = dxgi_factory->CreateSwapChainForHwnd(vd->CommandQueue, hwnd, &sd1, NULL, NULL, &swap_chain);
|
||||||
IM_ASSERT(res == S_OK);
|
IM_ASSERT(res == S_OK);
|
||||||
|
|
||||||
dxgi_factory->Release();
|
dxgi_factory->Release();
|
||||||
|
|
||||||
// Or swapChain.As(&mSwapChain)
|
// Or swapChain.As(&mSwapChain)
|
||||||
IM_ASSERT(data->SwapChain == NULL);
|
IM_ASSERT(vd->SwapChain == NULL);
|
||||||
swap_chain->QueryInterface(IID_PPV_ARGS(&data->SwapChain));
|
swap_chain->QueryInterface(IID_PPV_ARGS(&vd->SwapChain));
|
||||||
swap_chain->Release();
|
swap_chain->Release();
|
||||||
|
|
||||||
// Create the render targets
|
// Create the render targets
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||||
@ -912,42 +912,42 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
|
|||||||
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
||||||
desc.NodeMask = 1;
|
desc.NodeMask = 1;
|
||||||
|
|
||||||
HRESULT hr = bd->pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&data->RtvDescHeap));
|
HRESULT hr = bd->pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&vd->RtvDescHeap));
|
||||||
IM_ASSERT(hr == S_OK);
|
IM_ASSERT(hr == S_OK);
|
||||||
|
|
||||||
SIZE_T rtv_descriptor_size = bd->pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
SIZE_T rtv_descriptor_size = bd->pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = data->RtvDescHeap->GetCPUDescriptorHandleForHeapStart();
|
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle = vd->RtvDescHeap->GetCPUDescriptorHandleForHeapStart();
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
data->FrameCtx[i].RenderTargetCpuDescriptors = rtv_handle;
|
vd->FrameCtx[i].RenderTargetCpuDescriptors = rtv_handle;
|
||||||
rtv_handle.ptr += rtv_descriptor_size;
|
rtv_handle.ptr += rtv_descriptor_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12Resource* back_buffer;
|
ID3D12Resource* back_buffer;
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
IM_ASSERT(data->FrameCtx[i].RenderTarget == NULL);
|
IM_ASSERT(vd->FrameCtx[i].RenderTarget == NULL);
|
||||||
data->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
||||||
bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, data->FrameCtx[i].RenderTargetCpuDescriptors);
|
bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, vd->FrameCtx[i].RenderTargetCpuDescriptors);
|
||||||
data->FrameCtx[i].RenderTarget = back_buffer;
|
vd->FrameCtx[i].RenderTarget = back_buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
ImGui_ImplDX12_DestroyRenderBuffers(&data->FrameRenderBuffers[i]);
|
ImGui_ImplDX12_DestroyRenderBuffers(&vd->FrameRenderBuffers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_WaitForPendingOperations(ImGuiViewportDataDx12* data)
|
static void ImGui_WaitForPendingOperations(ImGui_ImplDX12_ViewportData* vd)
|
||||||
{
|
{
|
||||||
HRESULT hr = S_FALSE;
|
HRESULT hr = S_FALSE;
|
||||||
if (data && data->CommandQueue && data->Fence && data->FenceEvent)
|
if (vd && vd->CommandQueue && vd->Fence && vd->FenceEvent)
|
||||||
{
|
{
|
||||||
hr = data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue);
|
hr = vd->CommandQueue->Signal(vd->Fence, ++vd->FenceSignaledValue);
|
||||||
IM_ASSERT(hr == S_OK);
|
IM_ASSERT(hr == S_OK);
|
||||||
::WaitForSingleObject(data->FenceEvent, 0); // Reset any forgotten waits
|
::WaitForSingleObject(vd->FenceEvent, 0); // Reset any forgotten waits
|
||||||
hr = data->Fence->SetEventOnCompletion(data->FenceSignaledValue, data->FenceEvent);
|
hr = vd->Fence->SetEventOnCompletion(vd->FenceSignaledValue, vd->FenceEvent);
|
||||||
IM_ASSERT(hr == S_OK);
|
IM_ASSERT(hr == S_OK);
|
||||||
::WaitForSingleObject(data->FenceEvent, INFINITE);
|
::WaitForSingleObject(vd->FenceEvent, INFINITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,25 +955,25 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
{
|
{
|
||||||
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
if (ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData)
|
if (ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
ImGui_WaitForPendingOperations(data);
|
ImGui_WaitForPendingOperations(vd);
|
||||||
|
|
||||||
SafeRelease(data->CommandQueue);
|
SafeRelease(vd->CommandQueue);
|
||||||
SafeRelease(data->CommandList);
|
SafeRelease(vd->CommandList);
|
||||||
SafeRelease(data->SwapChain);
|
SafeRelease(vd->SwapChain);
|
||||||
SafeRelease(data->RtvDescHeap);
|
SafeRelease(vd->RtvDescHeap);
|
||||||
SafeRelease(data->Fence);
|
SafeRelease(vd->Fence);
|
||||||
::CloseHandle(data->FenceEvent);
|
::CloseHandle(vd->FenceEvent);
|
||||||
data->FenceEvent = NULL;
|
vd->FenceEvent = NULL;
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
SafeRelease(data->FrameCtx[i].RenderTarget);
|
SafeRelease(vd->FrameCtx[i].RenderTarget);
|
||||||
SafeRelease(data->FrameCtx[i].CommandAllocator);
|
SafeRelease(vd->FrameCtx[i].CommandAllocator);
|
||||||
ImGui_ImplDX12_DestroyRenderBuffers(&data->FrameRenderBuffers[i]);
|
ImGui_ImplDX12_DestroyRenderBuffers(&vd->FrameRenderBuffers[i]);
|
||||||
}
|
}
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->RendererUserData = NULL;
|
viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
@ -981,22 +981,22 @@ static void ImGui_ImplDX12_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
||||||
|
|
||||||
ImGui_WaitForPendingOperations(data);
|
ImGui_WaitForPendingOperations(vd);
|
||||||
|
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
SafeRelease(data->FrameCtx[i].RenderTarget);
|
SafeRelease(vd->FrameCtx[i].RenderTarget);
|
||||||
|
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
ID3D12Resource* back_buffer = NULL;
|
ID3D12Resource* back_buffer = NULL;
|
||||||
data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
vd->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0);
|
||||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||||
{
|
{
|
||||||
data->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
vd->SwapChain->GetBuffer(i, IID_PPV_ARGS(&back_buffer));
|
||||||
bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, data->FrameCtx[i].RenderTargetCpuDescriptors);
|
bd->pd3dDevice->CreateRenderTargetView(back_buffer, NULL, vd->FrameCtx[i].RenderTargetCpuDescriptors);
|
||||||
data->FrameCtx[i].RenderTarget = back_buffer;
|
vd->FrameCtx[i].RenderTarget = back_buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1004,29 +1004,29 @@ static void ImGui_ImplDX12_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||||
ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
||||||
|
|
||||||
ImGui_ImplDX12_FrameContext* frame_context = &data->FrameCtx[data->FrameIndex % bd->numFramesInFlight];
|
ImGui_ImplDX12_FrameContext* frame_context = &vd->FrameCtx[vd->FrameIndex % bd->numFramesInFlight];
|
||||||
UINT back_buffer_idx = data->SwapChain->GetCurrentBackBufferIndex();
|
UINT back_buffer_idx = vd->SwapChain->GetCurrentBackBufferIndex();
|
||||||
|
|
||||||
const ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
const ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
D3D12_RESOURCE_BARRIER barrier = {};
|
D3D12_RESOURCE_BARRIER barrier = {};
|
||||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||||
barrier.Transition.pResource = data->FrameCtx[back_buffer_idx].RenderTarget;
|
barrier.Transition.pResource = vd->FrameCtx[back_buffer_idx].RenderTarget;
|
||||||
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;
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
ID3D12GraphicsCommandList* cmd_list = data->CommandList;
|
ID3D12GraphicsCommandList* cmd_list = vd->CommandList;
|
||||||
|
|
||||||
frame_context->CommandAllocator->Reset();
|
frame_context->CommandAllocator->Reset();
|
||||||
cmd_list->Reset(frame_context->CommandAllocator, NULL);
|
cmd_list->Reset(frame_context->CommandAllocator, NULL);
|
||||||
cmd_list->ResourceBarrier(1, &barrier);
|
cmd_list->ResourceBarrier(1, &barrier);
|
||||||
cmd_list->OMSetRenderTargets(1, &data->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, FALSE, NULL);
|
cmd_list->OMSetRenderTargets(1, &vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, FALSE, NULL);
|
||||||
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
||||||
cmd_list->ClearRenderTargetView(data->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, (float*)&clear_color, 0, NULL);
|
cmd_list->ClearRenderTargetView(vd->FrameCtx[back_buffer_idx].RenderTargetCpuDescriptors, (float*)&clear_color, 0, NULL);
|
||||||
cmd_list->SetDescriptorHeaps(1, &bd->pd3dSrvDescHeap);
|
cmd_list->SetDescriptorHeaps(1, &bd->pd3dSrvDescHeap);
|
||||||
|
|
||||||
ImGui_ImplDX12_RenderDrawData(viewport->DrawData, cmd_list);
|
ImGui_ImplDX12_RenderDrawData(viewport->DrawData, cmd_list);
|
||||||
@ -1036,17 +1036,17 @@ static void ImGui_ImplDX12_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
cmd_list->ResourceBarrier(1, &barrier);
|
cmd_list->ResourceBarrier(1, &barrier);
|
||||||
cmd_list->Close();
|
cmd_list->Close();
|
||||||
|
|
||||||
data->CommandQueue->Wait(data->Fence, data->FenceSignaledValue);
|
vd->CommandQueue->Wait(vd->Fence, vd->FenceSignaledValue);
|
||||||
data->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list);
|
vd->CommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmd_list);
|
||||||
data->CommandQueue->Signal(data->Fence, ++data->FenceSignaledValue);
|
vd->CommandQueue->Signal(vd->Fence, ++vd->FenceSignaledValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX12_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataDx12* data = (ImGuiViewportDataDx12*)viewport->RendererUserData;
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)viewport->RendererUserData;
|
||||||
|
|
||||||
data->SwapChain->Present(0, 0);
|
vd->SwapChain->Present(0, 0);
|
||||||
while (data->Fence->GetCompletedValue() < data->FenceSignaledValue)
|
while (vd->Fence->GetCompletedValue() < vd->FenceSignaledValue)
|
||||||
::SwitchToThread();
|
::SwitchToThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,52 +393,52 @@ void ImGui_ImplDX9_NewFrame()
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataDx9
|
struct ImGui_ImplDX9_ViewportData
|
||||||
{
|
{
|
||||||
IDirect3DSwapChain9* SwapChain;
|
IDirect3DSwapChain9* SwapChain;
|
||||||
D3DPRESENT_PARAMETERS d3dpp;
|
D3DPRESENT_PARAMETERS d3dpp;
|
||||||
|
|
||||||
ImGuiViewportDataDx9() { SwapChain = NULL; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); }
|
ImGui_ImplDX9_ViewportData() { SwapChain = NULL; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); }
|
||||||
~ImGuiViewportDataDx9() { IM_ASSERT(SwapChain == NULL); }
|
~ImGui_ImplDX9_ViewportData() { IM_ASSERT(SwapChain == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
||||||
ImGuiViewportDataDx9* data = IM_NEW(ImGuiViewportDataDx9)();
|
ImGui_ImplDX9_ViewportData* vd = IM_NEW(ImGui_ImplDX9_ViewportData)();
|
||||||
viewport->RendererUserData = data;
|
viewport->RendererUserData = vd;
|
||||||
|
|
||||||
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
// PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
|
||||||
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
// Some backends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
|
||||||
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
|
||||||
IM_ASSERT(hwnd != 0);
|
IM_ASSERT(hwnd != 0);
|
||||||
|
|
||||||
ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
ZeroMemory(&vd->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
||||||
data->d3dpp.Windowed = TRUE;
|
vd->d3dpp.Windowed = TRUE;
|
||||||
data->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
vd->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||||
data->d3dpp.BackBufferWidth = (UINT)viewport->Size.x;
|
vd->d3dpp.BackBufferWidth = (UINT)viewport->Size.x;
|
||||||
data->d3dpp.BackBufferHeight = (UINT)viewport->Size.y;
|
vd->d3dpp.BackBufferHeight = (UINT)viewport->Size.y;
|
||||||
data->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
vd->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
||||||
data->d3dpp.hDeviceWindow = hwnd;
|
vd->d3dpp.hDeviceWindow = hwnd;
|
||||||
data->d3dpp.EnableAutoDepthStencil = FALSE;
|
vd->d3dpp.EnableAutoDepthStencil = FALSE;
|
||||||
data->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
|
vd->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
|
||||||
data->d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync
|
vd->d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync
|
||||||
|
|
||||||
HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain); IM_UNUSED(hr);
|
HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&vd->d3dpp, &vd->SwapChain); IM_UNUSED(hr);
|
||||||
IM_ASSERT(hr == D3D_OK);
|
IM_ASSERT(hr == D3D_OK);
|
||||||
IM_ASSERT(data->SwapChain != NULL);
|
IM_ASSERT(vd->SwapChain != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplDX9_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplDX9_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
||||||
if (ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData)
|
if (ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
data->SwapChain->Release();
|
vd->SwapChain->Release();
|
||||||
data->SwapChain = NULL;
|
vd->SwapChain = NULL;
|
||||||
ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
ZeroMemory(&vd->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->RendererUserData = NULL;
|
viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
@ -446,14 +446,14 @@ static void ImGui_ImplDX9_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
||||||
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData;
|
||||||
if (data->SwapChain)
|
if (vd->SwapChain)
|
||||||
{
|
{
|
||||||
data->SwapChain->Release();
|
vd->SwapChain->Release();
|
||||||
data->SwapChain = NULL;
|
vd->SwapChain = NULL;
|
||||||
data->d3dpp.BackBufferWidth = (UINT)size.x;
|
vd->d3dpp.BackBufferWidth = (UINT)size.x;
|
||||||
data->d3dpp.BackBufferHeight = (UINT)size.y;
|
vd->d3dpp.BackBufferHeight = (UINT)size.y;
|
||||||
HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain); IM_UNUSED(hr);
|
HRESULT hr = bd->pd3dDevice->CreateAdditionalSwapChain(&vd->d3dpp, &vd->SwapChain); IM_UNUSED(hr);
|
||||||
IM_ASSERT(hr == D3D_OK);
|
IM_ASSERT(hr == D3D_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,13 +461,13 @@ static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|||||||
static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
||||||
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData;
|
||||||
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
LPDIRECT3DSURFACE9 render_target = NULL;
|
LPDIRECT3DSURFACE9 render_target = NULL;
|
||||||
LPDIRECT3DSURFACE9 last_render_target = NULL;
|
LPDIRECT3DSURFACE9 last_render_target = NULL;
|
||||||
LPDIRECT3DSURFACE9 last_depth_stencil = NULL;
|
LPDIRECT3DSURFACE9 last_depth_stencil = NULL;
|
||||||
data->SwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &render_target);
|
vd->SwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &render_target);
|
||||||
bd->pd3dDevice->GetRenderTarget(0, &last_render_target);
|
bd->pd3dDevice->GetRenderTarget(0, &last_render_target);
|
||||||
bd->pd3dDevice->GetDepthStencilSurface(&last_depth_stencil);
|
bd->pd3dDevice->GetDepthStencilSurface(&last_depth_stencil);
|
||||||
bd->pd3dDevice->SetRenderTarget(0, render_target);
|
bd->pd3dDevice->SetRenderTarget(0, render_target);
|
||||||
@ -491,8 +491,8 @@ static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
|
|
||||||
static void ImGui_ImplDX9_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplDX9_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
ImGui_ImplDX9_ViewportData* vd = (ImGui_ImplDX9_ViewportData*)viewport->RendererUserData;
|
||||||
HRESULT hr = data->SwapChain->Present(NULL, NULL, data->d3dpp.hDeviceWindow, NULL, 0);
|
HRESULT hr = vd->SwapChain->Present(NULL, NULL, vd->d3dpp.hDeviceWindow, NULL, 0);
|
||||||
// Let main application handle D3DERR_DEVICELOST by resetting the device.
|
// Let main application handle D3DERR_DEVICELOST by resetting the device.
|
||||||
IM_ASSERT(hr == D3D_OK || hr == D3DERR_DEVICELOST);
|
IM_ASSERT(hr == D3D_OK || hr == D3DERR_DEVICELOST);
|
||||||
}
|
}
|
||||||
|
@ -545,15 +545,15 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataGlfw
|
struct ImGui_ImplGlfw_ViewportData
|
||||||
{
|
{
|
||||||
GLFWwindow* Window;
|
GLFWwindow* Window;
|
||||||
bool WindowOwned;
|
bool WindowOwned;
|
||||||
int IgnoreWindowPosEventFrame;
|
int IgnoreWindowPosEventFrame;
|
||||||
int IgnoreWindowSizeEventFrame;
|
int IgnoreWindowSizeEventFrame;
|
||||||
|
|
||||||
ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = IgnoreWindowPosEventFrame = -1; }
|
ImGui_ImplGlfw_ViewportData() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = IgnoreWindowPosEventFrame = -1; }
|
||||||
~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); }
|
~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window)
|
static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window)
|
||||||
@ -572,9 +572,9 @@ static void ImGui_ImplGlfw_WindowPosCallback(GLFWwindow* window, int, int)
|
|||||||
{
|
{
|
||||||
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
|
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
|
||||||
{
|
{
|
||||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowPosEventFrame + 1);
|
bool ignore_event = (ImGui::GetFrameCount() <= vd->IgnoreWindowPosEventFrame + 1);
|
||||||
//data->IgnoreWindowPosEventFrame = -1;
|
//data->IgnoreWindowPosEventFrame = -1;
|
||||||
if (ignore_event)
|
if (ignore_event)
|
||||||
return;
|
return;
|
||||||
@ -587,9 +587,9 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
|
|||||||
{
|
{
|
||||||
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
|
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
|
||||||
{
|
{
|
||||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1);
|
bool ignore_event = (ImGui::GetFrameCount() <= vd->IgnoreWindowSizeEventFrame + 1);
|
||||||
//data->IgnoreWindowSizeEventFrame = -1;
|
//data->IgnoreWindowSizeEventFrame = -1;
|
||||||
if (ignore_event)
|
if (ignore_event)
|
||||||
return;
|
return;
|
||||||
@ -601,8 +601,8 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
|
|||||||
static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
ImGuiViewportDataGlfw* data = IM_NEW(ImGuiViewportDataGlfw)();
|
ImGui_ImplGlfw_ViewportData* vd = IM_NEW(ImGui_ImplGlfw_ViewportData)();
|
||||||
viewport->PlatformUserData = data;
|
viewport->PlatformUserData = vd;
|
||||||
|
|
||||||
// GLFW 3.2 unfortunately always set focus on glfwCreateWindow() if GLFW_VISIBLE is set, regardless of GLFW_FOCUSED
|
// GLFW 3.2 unfortunately always set focus on glfwCreateWindow() if GLFW_VISIBLE is set, regardless of GLFW_FOCUSED
|
||||||
// With GLFW 3.3, the hint GLFW_FOCUS_ON_SHOW fixes this problem
|
// With GLFW 3.3, the hint GLFW_FOCUS_ON_SHOW fixes this problem
|
||||||
@ -616,25 +616,25 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
|||||||
glfwWindowHint(GLFW_FLOATING, (viewport->Flags & ImGuiViewportFlags_TopMost) ? true : false);
|
glfwWindowHint(GLFW_FLOATING, (viewport->Flags & ImGuiViewportFlags_TopMost) ? true : false);
|
||||||
#endif
|
#endif
|
||||||
GLFWwindow* share_window = (bd->ClientApi == GlfwClientApi_OpenGL) ? bd->Window : NULL;
|
GLFWwindow* share_window = (bd->ClientApi == GlfwClientApi_OpenGL) ? bd->Window : NULL;
|
||||||
data->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window);
|
vd->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window);
|
||||||
data->WindowOwned = true;
|
vd->WindowOwned = true;
|
||||||
viewport->PlatformHandle = (void*)data->Window;
|
viewport->PlatformHandle = (void*)vd->Window;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
viewport->PlatformHandleRaw = glfwGetWin32Window(data->Window);
|
viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window);
|
||||||
#endif
|
#endif
|
||||||
glfwSetWindowPos(data->Window, (int)viewport->Pos.x, (int)viewport->Pos.y);
|
glfwSetWindowPos(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y);
|
||||||
|
|
||||||
// Install GLFW callbacks for secondary viewports
|
// Install GLFW callbacks for secondary viewports
|
||||||
glfwSetMouseButtonCallback(data->Window, ImGui_ImplGlfw_MouseButtonCallback);
|
glfwSetMouseButtonCallback(vd->Window, ImGui_ImplGlfw_MouseButtonCallback);
|
||||||
glfwSetScrollCallback(data->Window, ImGui_ImplGlfw_ScrollCallback);
|
glfwSetScrollCallback(vd->Window, ImGui_ImplGlfw_ScrollCallback);
|
||||||
glfwSetKeyCallback(data->Window, ImGui_ImplGlfw_KeyCallback);
|
glfwSetKeyCallback(vd->Window, ImGui_ImplGlfw_KeyCallback);
|
||||||
glfwSetCharCallback(data->Window, ImGui_ImplGlfw_CharCallback);
|
glfwSetCharCallback(vd->Window, ImGui_ImplGlfw_CharCallback);
|
||||||
glfwSetWindowCloseCallback(data->Window, ImGui_ImplGlfw_WindowCloseCallback);
|
glfwSetWindowCloseCallback(vd->Window, ImGui_ImplGlfw_WindowCloseCallback);
|
||||||
glfwSetWindowPosCallback(data->Window, ImGui_ImplGlfw_WindowPosCallback);
|
glfwSetWindowPosCallback(vd->Window, ImGui_ImplGlfw_WindowPosCallback);
|
||||||
glfwSetWindowSizeCallback(data->Window, ImGui_ImplGlfw_WindowSizeCallback);
|
glfwSetWindowSizeCallback(vd->Window, ImGui_ImplGlfw_WindowSizeCallback);
|
||||||
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent(data->Window);
|
glfwMakeContextCurrent(vd->Window);
|
||||||
glfwSwapInterval(0);
|
glfwSwapInterval(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -642,9 +642,9 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
|
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
if (data->WindowOwned)
|
if (vd->WindowOwned)
|
||||||
{
|
{
|
||||||
#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)
|
#if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)
|
||||||
HWND hwnd = (HWND)viewport->PlatformHandleRaw;
|
HWND hwnd = (HWND)viewport->PlatformHandleRaw;
|
||||||
@ -654,13 +654,13 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
// Release any keys that were pressed in the window being destroyed and are still held down,
|
// Release any keys that were pressed in the window being destroyed and are still held down,
|
||||||
// because we will not receive any release events after window is destroyed.
|
// because we will not receive any release events after window is destroyed.
|
||||||
for (int i = 0; i < IM_ARRAYSIZE(bd->KeyOwnerWindows); i++)
|
for (int i = 0; i < IM_ARRAYSIZE(bd->KeyOwnerWindows); i++)
|
||||||
if (bd->KeyOwnerWindows[i] == data->Window)
|
if (bd->KeyOwnerWindows[i] == vd->Window)
|
||||||
ImGui_ImplGlfw_KeyCallback(data->Window, i, 0, GLFW_RELEASE, 0); // Later params are only used for main viewport, on which this function is never called.
|
ImGui_ImplGlfw_KeyCallback(vd->Window, i, 0, GLFW_RELEASE, 0); // Later params are only used for main viewport, on which this function is never called.
|
||||||
|
|
||||||
glfwDestroyWindow(data->Window);
|
glfwDestroyWindow(vd->Window);
|
||||||
}
|
}
|
||||||
data->Window = NULL;
|
vd->Window = NULL;
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
||||||
}
|
}
|
||||||
@ -687,7 +687,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR
|
|||||||
|
|
||||||
static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// GLFW hack: Hide icon from task bar
|
// GLFW hack: Hide icon from task bar
|
||||||
@ -721,60 +721,60 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glfwShowWindow(data->Window);
|
glfwShowWindow(vd->Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
glfwGetWindowPos(data->Window, &x, &y);
|
glfwGetWindowPos(vd->Window, &x, &y);
|
||||||
return ImVec2((float)x, (float)y);
|
return ImVec2((float)x, (float)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
static void ImGui_ImplGlfw_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
data->IgnoreWindowPosEventFrame = ImGui::GetFrameCount();
|
vd->IgnoreWindowPosEventFrame = ImGui::GetFrameCount();
|
||||||
glfwSetWindowPos(data->Window, (int)pos.x, (int)pos.y);
|
glfwSetWindowPos(vd->Window, (int)pos.x, (int)pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
glfwGetWindowSize(data->Window, &w, &h);
|
glfwGetWindowSize(vd->Window, &w, &h);
|
||||||
return ImVec2((float)w, (float)h);
|
return ImVec2((float)w, (float)h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
#if __APPLE__ && !GLFW_HAS_OSX_WINDOW_POS_FIX
|
#if __APPLE__ && !GLFW_HAS_OSX_WINDOW_POS_FIX
|
||||||
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
|
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
|
||||||
// positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it
|
// positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it
|
||||||
// doesn't handle it when changing size. We are manually moving the window in order for changes of size to be based
|
// doesn't handle it when changing size. We are manually moving the window in order for changes of size to be based
|
||||||
// on the upper-left corner.
|
// on the upper-left corner.
|
||||||
int x, y, width, height;
|
int x, y, width, height;
|
||||||
glfwGetWindowPos(data->Window, &x, &y);
|
glfwGetWindowPos(vd->Window, &x, &y);
|
||||||
glfwGetWindowSize(data->Window, &width, &height);
|
glfwGetWindowSize(vd->Window, &width, &height);
|
||||||
glfwSetWindowPos(data->Window, x, y - height + size.y);
|
glfwSetWindowPos(vd->Window, x, y - height + size.y);
|
||||||
#endif
|
#endif
|
||||||
data->IgnoreWindowSizeEventFrame = ImGui::GetFrameCount();
|
vd->IgnoreWindowSizeEventFrame = ImGui::GetFrameCount();
|
||||||
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
|
glfwSetWindowSize(vd->Window, (int)size.x, (int)size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
glfwSetWindowTitle(data->Window, title);
|
glfwSetWindowTitle(vd->Window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport)
|
static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
#if GLFW_HAS_FOCUS_WINDOW
|
#if GLFW_HAS_FOCUS_WINDOW
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
glfwFocusWindow(data->Window);
|
glfwFocusWindow(vd->Window);
|
||||||
#else
|
#else
|
||||||
// FIXME: What are the effect of not having this function? At the moment imgui doesn't actually call SetWindowFocus - we set that up ahead, will answer that question later.
|
// FIXME: What are the effect of not having this function? At the moment imgui doesn't actually call SetWindowFocus - we set that up ahead, will answer that question later.
|
||||||
(void)viewport;
|
(void)viewport;
|
||||||
@ -783,40 +783,40 @@ static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
static bool ImGui_ImplGlfw_GetWindowFocus(ImGuiViewport* viewport)
|
static bool ImGui_ImplGlfw_GetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
return glfwGetWindowAttrib(data->Window, GLFW_FOCUSED) != 0;
|
return glfwGetWindowAttrib(vd->Window, GLFW_FOCUSED) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplGlfw_GetWindowMinimized(ImGuiViewport* viewport)
|
static bool ImGui_ImplGlfw_GetWindowMinimized(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
return glfwGetWindowAttrib(data->Window, GLFW_ICONIFIED) != 0;
|
return glfwGetWindowAttrib(vd->Window, GLFW_ICONIFIED) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GLFW_HAS_WINDOW_ALPHA
|
#if GLFW_HAS_WINDOW_ALPHA
|
||||||
static void ImGui_ImplGlfw_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
static void ImGui_ImplGlfw_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
glfwSetWindowOpacity(data->Window, alpha);
|
glfwSetWindowOpacity(vd->Window, alpha);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
||||||
glfwMakeContextCurrent(data->Window);
|
glfwMakeContextCurrent(vd->Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
if (bd->ClientApi == GlfwClientApi_OpenGL)
|
||||||
{
|
{
|
||||||
glfwMakeContextCurrent(data->Window);
|
glfwMakeContextCurrent(vd->Window);
|
||||||
glfwSwapBuffers(data->Window);
|
glfwSwapBuffers(vd->Window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,9 +867,9 @@ extern "C" { extern GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance
|
|||||||
static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface)
|
static int ImGui_ImplGlfw_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface)
|
||||||
{
|
{
|
||||||
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
||||||
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
|
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(bd->ClientApi == GlfwClientApi_Vulkan);
|
IM_ASSERT(bd->ClientApi == GlfwClientApi_Vulkan);
|
||||||
VkResult err = glfwCreateWindowSurface((VkInstance)vk_instance, data->Window, (const VkAllocationCallbacks*)vk_allocator, (VkSurfaceKHR*)out_vk_surface);
|
VkResult err = glfwCreateWindowSurface((VkInstance)vk_instance, vd->Window, (const VkAllocationCallbacks*)vk_allocator, (VkSurfaceKHR*)out_vk_surface);
|
||||||
return (int)err;
|
return (int)err;
|
||||||
}
|
}
|
||||||
#endif // GLFW_HAS_VULKAN
|
#endif // GLFW_HAS_VULKAN
|
||||||
@ -905,10 +905,10 @@ static void ImGui_ImplGlfw_InitPlatformInterface()
|
|||||||
// Register main window handle (which is owned by the main application, not by us)
|
// Register main window handle (which is owned by the main application, not by us)
|
||||||
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGuiViewportDataGlfw* data = IM_NEW(ImGuiViewportDataGlfw)();
|
ImGui_ImplGlfw_ViewportData* vd = IM_NEW(ImGui_ImplGlfw_ViewportData)();
|
||||||
data->Window = bd->Window;
|
vd->Window = bd->Window;
|
||||||
data->WindowOwned = false;
|
vd->WindowOwned = false;
|
||||||
main_viewport->PlatformUserData = data;
|
main_viewport->PlatformUserData = vd;
|
||||||
main_viewport->PlatformHandle = (void*)bd->Window;
|
main_viewport->PlatformHandle = (void*)bd->Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,25 +522,25 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataSDL2
|
struct ImGui_ImplSDL2_ViewportData
|
||||||
{
|
{
|
||||||
SDL_Window* Window;
|
SDL_Window* Window;
|
||||||
Uint32 WindowID;
|
Uint32 WindowID;
|
||||||
bool WindowOwned;
|
bool WindowOwned;
|
||||||
SDL_GLContext GLContext;
|
SDL_GLContext GLContext;
|
||||||
|
|
||||||
ImGuiViewportDataSDL2() { Window = NULL; WindowID = 0; WindowOwned = false; GLContext = NULL; }
|
ImGui_ImplSDL2_ViewportData() { Window = NULL; WindowID = 0; WindowOwned = false; GLContext = NULL; }
|
||||||
~ImGuiViewportDataSDL2() { IM_ASSERT(Window == NULL && GLContext == NULL); }
|
~ImGui_ImplSDL2_ViewportData() { IM_ASSERT(Window == NULL && GLContext == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||||
ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)();
|
ImGui_ImplSDL2_ViewportData* vd = IM_NEW(ImGui_ImplSDL2_ViewportData)();
|
||||||
viewport->PlatformUserData = data;
|
viewport->PlatformUserData = vd;
|
||||||
|
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGuiViewportDataSDL2* main_viewport_data = (ImGuiViewportDataSDL2*)main_viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* main_viewport_data = (ImGui_ImplSDL2_ViewportData*)main_viewport->PlatformUserData;
|
||||||
|
|
||||||
// Share GL resources with main context
|
// Share GL resources with main context
|
||||||
bool use_opengl = (main_viewport_data->GLContext != NULL);
|
bool use_opengl = (main_viewport_data->GLContext != NULL);
|
||||||
@ -565,43 +565,43 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
|
|||||||
#if SDL_HAS_ALWAYS_ON_TOP
|
#if SDL_HAS_ALWAYS_ON_TOP
|
||||||
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0;
|
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0;
|
||||||
#endif
|
#endif
|
||||||
data->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Pos.x, (int)viewport->Pos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags);
|
vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Pos.x, (int)viewport->Pos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags);
|
||||||
data->WindowOwned = true;
|
vd->WindowOwned = true;
|
||||||
if (use_opengl)
|
if (use_opengl)
|
||||||
{
|
{
|
||||||
data->GLContext = SDL_GL_CreateContext(data->Window);
|
vd->GLContext = SDL_GL_CreateContext(vd->Window);
|
||||||
SDL_GL_SetSwapInterval(0);
|
SDL_GL_SetSwapInterval(0);
|
||||||
}
|
}
|
||||||
if (use_opengl && backup_context)
|
if (use_opengl && backup_context)
|
||||||
SDL_GL_MakeCurrent(data->Window, backup_context);
|
SDL_GL_MakeCurrent(vd->Window, backup_context);
|
||||||
|
|
||||||
viewport->PlatformHandle = (void*)data->Window;
|
viewport->PlatformHandle = (void*)vd->Window;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
SDL_SysWMinfo info;
|
SDL_SysWMinfo info;
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
if (SDL_GetWindowWMInfo(data->Window, &info))
|
if (SDL_GetWindowWMInfo(vd->Window, &info))
|
||||||
viewport->PlatformHandleRaw = info.info.win.window;
|
viewport->PlatformHandleRaw = info.info.win.window;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
if (ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData)
|
if (ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
if (data->GLContext && data->WindowOwned)
|
if (vd->GLContext && vd->WindowOwned)
|
||||||
SDL_GL_DeleteContext(data->GLContext);
|
SDL_GL_DeleteContext(vd->GLContext);
|
||||||
if (data->Window && data->WindowOwned)
|
if (vd->Window && vd->WindowOwned)
|
||||||
SDL_DestroyWindow(data->Window);
|
SDL_DestroyWindow(vd->Window);
|
||||||
data->GLContext = NULL;
|
vd->GLContext = NULL;
|
||||||
data->Window = NULL;
|
vd->Window = NULL;
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HWND hwnd = (HWND)viewport->PlatformHandleRaw;
|
HWND hwnd = (HWND)viewport->PlatformHandleRaw;
|
||||||
|
|
||||||
@ -623,83 +623,83 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_ShowWindow(data->Window);
|
SDL_ShowWindow(vd->Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplSDL2_GetWindowPos(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplSDL2_GetWindowPos(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
SDL_GetWindowPosition(data->Window, &x, &y);
|
SDL_GetWindowPosition(vd->Window, &x, &y);
|
||||||
return ImVec2((float)x, (float)y);
|
return ImVec2((float)x, (float)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
static void ImGui_ImplSDL2_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
SDL_SetWindowPosition(data->Window, (int)pos.x, (int)pos.y);
|
SDL_SetWindowPosition(vd->Window, (int)pos.x, (int)pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplSDL2_GetWindowSize(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplSDL2_GetWindowSize(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
int w = 0, h = 0;
|
int w = 0, h = 0;
|
||||||
SDL_GetWindowSize(data->Window, &w, &h);
|
SDL_GetWindowSize(vd->Window, &w, &h);
|
||||||
return ImVec2((float)w, (float)h);
|
return ImVec2((float)w, (float)h);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplSDL2_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
SDL_SetWindowSize(data->Window, (int)size.x, (int)size.y);
|
SDL_SetWindowSize(vd->Window, (int)size.x, (int)size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
static void ImGui_ImplSDL2_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
SDL_SetWindowTitle(data->Window, title);
|
SDL_SetWindowTitle(vd->Window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SDL_HAS_WINDOW_ALPHA
|
#if SDL_HAS_WINDOW_ALPHA
|
||||||
static void ImGui_ImplSDL2_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
static void ImGui_ImplSDL2_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
SDL_SetWindowOpacity(data->Window, alpha);
|
SDL_SetWindowOpacity(vd->Window, alpha);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SetWindowFocus(ImGuiViewport* viewport)
|
static void ImGui_ImplSDL2_SetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
SDL_RaiseWindow(data->Window);
|
SDL_RaiseWindow(vd->Window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplSDL2_GetWindowFocus(ImGuiViewport* viewport)
|
static bool ImGui_ImplSDL2_GetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
return (SDL_GetWindowFlags(data->Window) & SDL_WINDOW_INPUT_FOCUS) != 0;
|
return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplSDL2_GetWindowMinimized(ImGuiViewport* viewport)
|
static bool ImGui_ImplSDL2_GetWindowMinimized(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
return (SDL_GetWindowFlags(data->Window) & SDL_WINDOW_MINIMIZED) != 0;
|
return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_MINIMIZED) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
if (data->GLContext)
|
if (vd->GLContext)
|
||||||
SDL_GL_MakeCurrent(data->Window, data->GLContext);
|
SDL_GL_MakeCurrent(vd->Window, vd->GLContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
if (data->GLContext)
|
if (vd->GLContext)
|
||||||
{
|
{
|
||||||
SDL_GL_MakeCurrent(data->Window, data->GLContext);
|
SDL_GL_MakeCurrent(vd->Window, vd->GLContext);
|
||||||
SDL_GL_SwapWindow(data->Window);
|
SDL_GL_SwapWindow(vd->Window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,9 +709,9 @@ static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport, void*)
|
|||||||
#include <SDL_vulkan.h>
|
#include <SDL_vulkan.h>
|
||||||
static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface)
|
static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
|
ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
|
||||||
(void)vk_allocator;
|
(void)vk_allocator;
|
||||||
SDL_bool ret = SDL_Vulkan_CreateSurface(data->Window, (VkInstance)vk_instance, (VkSurfaceKHR*)out_vk_surface);
|
SDL_bool ret = SDL_Vulkan_CreateSurface(vd->Window, (VkInstance)vk_instance, (VkSurfaceKHR*)out_vk_surface);
|
||||||
return ret ? 0 : 1; // ret ? VK_SUCCESS : VK_NOT_READY
|
return ret ? 0 : 1; // ret ? VK_SUCCESS : VK_NOT_READY
|
||||||
}
|
}
|
||||||
#endif // SDL_HAS_VULKAN
|
#endif // SDL_HAS_VULKAN
|
||||||
@ -748,13 +748,13 @@ static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_g
|
|||||||
// Register main window handle (which is owned by the main application, not by us)
|
// Register main window handle (which is owned by the main application, not by us)
|
||||||
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGuiViewportDataSDL2* data = IM_NEW(ImGuiViewportDataSDL2)();
|
ImGui_ImplSDL2_ViewportData* vd = IM_NEW(ImGui_ImplSDL2_ViewportData)();
|
||||||
data->Window = window;
|
vd->Window = window;
|
||||||
data->WindowID = SDL_GetWindowID(window);
|
vd->WindowID = SDL_GetWindowID(window);
|
||||||
data->WindowOwned = false;
|
vd->WindowOwned = false;
|
||||||
data->GLContext = sdl_gl_context;
|
vd->GLContext = sdl_gl_context;
|
||||||
main_viewport->PlatformUserData = data;
|
main_viewport->PlatformUserData = vd;
|
||||||
main_viewport->PlatformHandle = data->Window;
|
main_viewport->PlatformHandle = vd->Window;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_ShutdownPlatformInterface()
|
static void ImGui_ImplSDL2_ShutdownPlatformInterface()
|
||||||
|
@ -81,14 +81,14 @@ struct ImGui_ImplVulkanH_WindowRenderBuffers
|
|||||||
|
|
||||||
// For multi-viewport support:
|
// For multi-viewport support:
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataVulkan
|
struct ImGui_ImplVulkan_ViewportData
|
||||||
{
|
{
|
||||||
bool WindowOwned;
|
bool WindowOwned;
|
||||||
ImGui_ImplVulkanH_Window Window; // Used by secondary viewports only
|
ImGui_ImplVulkanH_Window Window; // Used by secondary viewports only
|
||||||
ImGui_ImplVulkanH_WindowRenderBuffers RenderBuffers; // Used by all viewports
|
ImGui_ImplVulkanH_WindowRenderBuffers RenderBuffers; // Used by all viewports
|
||||||
|
|
||||||
ImGuiViewportDataVulkan() { WindowOwned = false; memset(&RenderBuffers, 0, sizeof(RenderBuffers)); }
|
ImGui_ImplVulkan_ViewportData() { WindowOwned = false; memset(&RenderBuffers, 0, sizeof(RenderBuffers)); }
|
||||||
~ImGuiViewportDataVulkan() { }
|
~ImGui_ImplVulkan_ViewportData() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vulkan data
|
// Vulkan data
|
||||||
@ -114,7 +114,7 @@ struct ImGui_ImplVulkan_Data
|
|||||||
VkDeviceMemory UploadBufferMemory;
|
VkDeviceMemory UploadBufferMemory;
|
||||||
VkBuffer UploadBuffer;
|
VkBuffer UploadBuffer;
|
||||||
|
|
||||||
// Render buffers
|
// Render buffers for main window
|
||||||
ImGui_ImplVulkanH_WindowRenderBuffers MainWindowRenderBuffers;
|
ImGui_ImplVulkanH_WindowRenderBuffers MainWindowRenderBuffers;
|
||||||
|
|
||||||
ImGui_ImplVulkan_Data()
|
ImGui_ImplVulkan_Data()
|
||||||
@ -460,7 +460,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
|
|||||||
pipeline = bd->Pipeline;
|
pipeline = bd->Pipeline;
|
||||||
|
|
||||||
// Allocate array to store enough vertex/index buffers. Each unique viewport gets its own storage.
|
// Allocate array to store enough vertex/index buffers. Each unique viewport gets its own storage.
|
||||||
ImGuiViewportDataVulkan* viewport_renderer_data = (ImGuiViewportDataVulkan*)draw_data->OwnerViewport->RendererUserData;
|
ImGui_ImplVulkan_ViewportData* viewport_renderer_data = (ImGui_ImplVulkan_ViewportData*)draw_data->OwnerViewport->RendererUserData;
|
||||||
IM_ASSERT(viewport_renderer_data != NULL);
|
IM_ASSERT(viewport_renderer_data != NULL);
|
||||||
ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &viewport_renderer_data->RenderBuffers;
|
ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &viewport_renderer_data->RenderBuffers;
|
||||||
if (wrb->FrameRenderBuffers == NULL)
|
if (wrb->FrameRenderBuffers == NULL)
|
||||||
@ -1080,7 +1080,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
|
|||||||
|
|
||||||
// Our render function expect RendererUserData to be storing the window render buffer we need (for the main viewport we won't use ->Window)
|
// Our render function expect RendererUserData to be storing the window render buffer we need (for the main viewport we won't use ->Window)
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataVulkan)();
|
main_viewport->RendererUserData = IM_NEW(ImGui_ImplVulkan_ViewportData)();
|
||||||
|
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
ImGui_ImplVulkan_InitPlatformInterface();
|
ImGui_ImplVulkan_InitPlatformInterface();
|
||||||
@ -1095,8 +1095,8 @@ void ImGui_ImplVulkan_Shutdown()
|
|||||||
|
|
||||||
// Manually delete main viewport render data in-case we haven't initialized for viewports
|
// Manually delete main viewport render data in-case we haven't initialized for viewports
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)main_viewport->RendererUserData)
|
if (ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)main_viewport->RendererUserData)
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
main_viewport->RendererUserData = NULL;
|
main_viewport->RendererUserData = NULL;
|
||||||
|
|
||||||
// Clean up windows
|
// Clean up windows
|
||||||
@ -1516,8 +1516,8 @@ void ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(VkDevice device, const V
|
|||||||
{
|
{
|
||||||
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
for (int n = 0; n < platform_io.Viewports.Size; n++)
|
for (int n = 0; n < platform_io.Viewports.Size; n++)
|
||||||
if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)platform_io.Viewports[n]->RendererUserData)
|
if (ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)platform_io.Viewports[n]->RendererUserData)
|
||||||
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(device, &data->RenderBuffers, allocator);
|
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(device, &vd->RenderBuffers, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
@ -1529,9 +1529,9 @@ void ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(VkDevice device, const V
|
|||||||
static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
||||||
ImGuiViewportDataVulkan* data = IM_NEW(ImGuiViewportDataVulkan)();
|
ImGui_ImplVulkan_ViewportData* vd = IM_NEW(ImGui_ImplVulkan_ViewportData)();
|
||||||
viewport->RendererUserData = data;
|
viewport->RendererUserData = vd;
|
||||||
ImGui_ImplVulkanH_Window* wd = &data->Window;
|
ImGui_ImplVulkanH_Window* wd = &vd->Window;
|
||||||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
||||||
|
|
||||||
// Create surface
|
// Create surface
|
||||||
@ -1562,20 +1562,20 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
|
|||||||
// Create SwapChain, RenderPass, Framebuffer, etc.
|
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||||
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
|
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
|
||||||
data->WindowOwned = true;
|
vd->WindowOwned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
|
||||||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
||||||
if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData)
|
if (ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
||||||
if (data->WindowOwned)
|
if (vd->WindowOwned)
|
||||||
ImGui_ImplVulkanH_DestroyWindow(v->Instance, v->Device, &data->Window, v->Allocator);
|
ImGui_ImplVulkanH_DestroyWindow(v->Instance, v->Device, &vd->Window, v->Allocator);
|
||||||
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &data->RenderBuffers, v->Allocator);
|
ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &vd->RenderBuffers, v->Allocator);
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->RendererUserData = NULL;
|
viewport->RendererUserData = NULL;
|
||||||
}
|
}
|
||||||
@ -1583,19 +1583,19 @@ static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport)
|
|||||||
static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
||||||
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
|
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
|
||||||
if (data == NULL) // This is NULL for the main viewport (which is left to the user/app to handle)
|
if (vd == NULL) // This is NULL for the main viewport (which is left to the user/app to handle)
|
||||||
return;
|
return;
|
||||||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
||||||
data->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
|
vd->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &data->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &vd->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
||||||
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
|
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
|
||||||
ImGui_ImplVulkanH_Window* wd = &data->Window;
|
ImGui_ImplVulkanH_Window* wd = &vd->Window;
|
||||||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
|
||||||
@ -1668,8 +1668,8 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
|
|||||||
static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
|
static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
|
||||||
{
|
{
|
||||||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
|
||||||
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
|
ImGui_ImplVulkan_ViewportData* vd = (ImGui_ImplVulkan_ViewportData*)viewport->RendererUserData;
|
||||||
ImGui_ImplVulkanH_Window* wd = &data->Window;
|
ImGui_ImplVulkanH_Window* wd = &vd->Window;
|
||||||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
|
||||||
|
|
||||||
VkResult err;
|
VkResult err;
|
||||||
@ -1685,7 +1685,7 @@ static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
|
|||||||
info.pImageIndices = &present_index;
|
info.pImageIndices = &present_index;
|
||||||
err = vkQueuePresentKHR(v->Queue, &info);
|
err = vkQueuePresentKHR(v->Queue, &info);
|
||||||
if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
|
if (err == VK_ERROR_OUT_OF_DATE_KHR || err == VK_SUBOPTIMAL_KHR)
|
||||||
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &data->Window, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
|
ImGui_ImplVulkanH_CreateOrResizeWindow(v->Instance, v->PhysicalDevice, v->Device, &vd->Window, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
|
||||||
else
|
else
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
|
|
||||||
|
@ -673,15 +673,15 @@ static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos)
|
|||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
// Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data.
|
||||||
struct ImGuiViewportDataWin32
|
struct ImGui_ImplWin32_ViewportData
|
||||||
{
|
{
|
||||||
HWND Hwnd;
|
HWND Hwnd;
|
||||||
bool HwndOwned;
|
bool HwndOwned;
|
||||||
DWORD DwStyle;
|
DWORD DwStyle;
|
||||||
DWORD DwExStyle;
|
DWORD DwExStyle;
|
||||||
|
|
||||||
ImGuiViewportDataWin32() { Hwnd = NULL; HwndOwned = false; DwStyle = DwExStyle = 0; }
|
ImGui_ImplWin32_ViewportData() { Hwnd = NULL; HwndOwned = false; DwStyle = DwExStyle = 0; }
|
||||||
~ImGuiViewportDataWin32() { IM_ASSERT(Hwnd == NULL); }
|
~ImGui_ImplWin32_ViewportData() { IM_ASSERT(Hwnd == NULL); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ImGui_ImplWin32_GetWin32StyleFromViewportFlags(ImGuiViewportFlags flags, DWORD* out_style, DWORD* out_ex_style)
|
static void ImGui_ImplWin32_GetWin32StyleFromViewportFlags(ImGuiViewportFlags flags, DWORD* out_style, DWORD* out_ex_style)
|
||||||
@ -702,11 +702,11 @@ static void ImGui_ImplWin32_GetWin32StyleFromViewportFlags(ImGuiViewportFlags fl
|
|||||||
|
|
||||||
static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = IM_NEW(ImGuiViewportDataWin32)();
|
ImGui_ImplWin32_ViewportData* vd = IM_NEW(ImGui_ImplWin32_ViewportData)();
|
||||||
viewport->PlatformUserData = data;
|
viewport->PlatformUserData = vd;
|
||||||
|
|
||||||
// Select style and parent window
|
// Select style and parent window
|
||||||
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &data->DwStyle, &data->DwExStyle);
|
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &vd->DwStyle, &vd->DwExStyle);
|
||||||
HWND parent_window = NULL;
|
HWND parent_window = NULL;
|
||||||
if (viewport->ParentViewportId != 0)
|
if (viewport->ParentViewportId != 0)
|
||||||
if (ImGuiViewport* parent_viewport = ImGui::FindViewportByID(viewport->ParentViewportId))
|
if (ImGuiViewport* parent_viewport = ImGui::FindViewportByID(viewport->ParentViewportId))
|
||||||
@ -714,170 +714,170 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
|
|||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
||||||
::AdjustWindowRectEx(&rect, data->DwStyle, FALSE, data->DwExStyle);
|
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle);
|
||||||
data->Hwnd = ::CreateWindowEx(
|
vd->Hwnd = ::CreateWindowEx(
|
||||||
data->DwExStyle, _T("ImGui Platform"), _T("Untitled"), data->DwStyle, // Style, class name, window name
|
vd->DwExStyle, _T("ImGui Platform"), _T("Untitled"), vd->DwStyle, // Style, class name, window name
|
||||||
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, // Window area
|
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, // Window area
|
||||||
parent_window, NULL, ::GetModuleHandle(NULL), NULL); // Parent window, Menu, Instance, Param
|
parent_window, NULL, ::GetModuleHandle(NULL), NULL); // Parent window, Menu, Instance, Param
|
||||||
data->HwndOwned = true;
|
vd->HwndOwned = true;
|
||||||
viewport->PlatformRequestResize = false;
|
viewport->PlatformRequestResize = false;
|
||||||
viewport->PlatformHandle = viewport->PlatformHandleRaw = data->Hwnd;
|
viewport->PlatformHandle = viewport->PlatformHandleRaw = vd->Hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_DestroyWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_DestroyWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
||||||
if (ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData)
|
if (ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData)
|
||||||
{
|
{
|
||||||
if (::GetCapture() == data->Hwnd)
|
if (::GetCapture() == vd->Hwnd)
|
||||||
{
|
{
|
||||||
// Transfer capture so if we started dragging from a window that later disappears, we'll still receive the MOUSEUP event.
|
// Transfer capture so if we started dragging from a window that later disappears, we'll still receive the MOUSEUP event.
|
||||||
::ReleaseCapture();
|
::ReleaseCapture();
|
||||||
::SetCapture(bd->hWnd);
|
::SetCapture(bd->hWnd);
|
||||||
}
|
}
|
||||||
if (data->Hwnd && data->HwndOwned)
|
if (vd->Hwnd && vd->HwndOwned)
|
||||||
::DestroyWindow(data->Hwnd);
|
::DestroyWindow(vd->Hwnd);
|
||||||
data->Hwnd = NULL;
|
vd->Hwnd = NULL;
|
||||||
IM_DELETE(data);
|
IM_DELETE(vd);
|
||||||
}
|
}
|
||||||
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_ShowWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_ShowWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
|
if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
|
||||||
::ShowWindow(data->Hwnd, SW_SHOWNA);
|
::ShowWindow(vd->Hwnd, SW_SHOWNA);
|
||||||
else
|
else
|
||||||
::ShowWindow(data->Hwnd, SW_SHOW);
|
::ShowWindow(vd->Hwnd, SW_SHOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_UpdateWindow(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_UpdateWindow(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
// (Optional) Update Win32 style if it changed _after_ creation.
|
// (Optional) Update Win32 style if it changed _after_ creation.
|
||||||
// Generally they won't change unless configuration flags are changed, but advanced uses (such as manually rewriting viewport flags) make this useful.
|
// Generally they won't change unless configuration flags are changed, but advanced uses (such as manually rewriting viewport flags) make this useful.
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
DWORD new_style;
|
DWORD new_style;
|
||||||
DWORD new_ex_style;
|
DWORD new_ex_style;
|
||||||
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &new_style, &new_ex_style);
|
ImGui_ImplWin32_GetWin32StyleFromViewportFlags(viewport->Flags, &new_style, &new_ex_style);
|
||||||
|
|
||||||
// Only reapply the flags that have been changed from our point of view (as other flags are being modified by Windows)
|
// Only reapply the flags that have been changed from our point of view (as other flags are being modified by Windows)
|
||||||
if (data->DwStyle != new_style || data->DwExStyle != new_ex_style)
|
if (vd->DwStyle != new_style || vd->DwExStyle != new_ex_style)
|
||||||
{
|
{
|
||||||
// (Optional) Update TopMost state if it changed _after_ creation
|
// (Optional) Update TopMost state if it changed _after_ creation
|
||||||
bool top_most_changed = (data->DwExStyle & WS_EX_TOPMOST) != (new_ex_style & WS_EX_TOPMOST);
|
bool top_most_changed = (vd->DwExStyle & WS_EX_TOPMOST) != (new_ex_style & WS_EX_TOPMOST);
|
||||||
HWND insert_after = top_most_changed ? ((viewport->Flags & ImGuiViewportFlags_TopMost) ? HWND_TOPMOST : HWND_NOTOPMOST) : 0;
|
HWND insert_after = top_most_changed ? ((viewport->Flags & ImGuiViewportFlags_TopMost) ? HWND_TOPMOST : HWND_NOTOPMOST) : 0;
|
||||||
UINT swp_flag = top_most_changed ? 0 : SWP_NOZORDER;
|
UINT swp_flag = top_most_changed ? 0 : SWP_NOZORDER;
|
||||||
|
|
||||||
// Apply flags and position (since it is affected by flags)
|
// Apply flags and position (since it is affected by flags)
|
||||||
data->DwStyle = new_style;
|
vd->DwStyle = new_style;
|
||||||
data->DwExStyle = new_ex_style;
|
vd->DwExStyle = new_ex_style;
|
||||||
::SetWindowLong(data->Hwnd, GWL_STYLE, data->DwStyle);
|
::SetWindowLong(vd->Hwnd, GWL_STYLE, vd->DwStyle);
|
||||||
::SetWindowLong(data->Hwnd, GWL_EXSTYLE, data->DwExStyle);
|
::SetWindowLong(vd->Hwnd, GWL_EXSTYLE, vd->DwExStyle);
|
||||||
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) };
|
||||||
::AdjustWindowRectEx(&rect, data->DwStyle, FALSE, data->DwExStyle); // Client to Screen
|
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); // Client to Screen
|
||||||
::SetWindowPos(data->Hwnd, insert_after, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, swp_flag | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
::SetWindowPos(vd->Hwnd, insert_after, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, swp_flag | SWP_NOACTIVATE | SWP_FRAMECHANGED);
|
||||||
::ShowWindow(data->Hwnd, SW_SHOWNA); // This is necessary when we alter the style
|
::ShowWindow(vd->Hwnd, SW_SHOWNA); // This is necessary when we alter the style
|
||||||
viewport->PlatformRequestMove = viewport->PlatformRequestResize = true;
|
viewport->PlatformRequestMove = viewport->PlatformRequestResize = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplWin32_GetWindowPos(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplWin32_GetWindowPos(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
POINT pos = { 0, 0 };
|
POINT pos = { 0, 0 };
|
||||||
::ClientToScreen(data->Hwnd, &pos);
|
::ClientToScreen(vd->Hwnd, &pos);
|
||||||
return ImVec2((float)pos.x, (float)pos.y);
|
return ImVec2((float)pos.x, (float)pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
static void ImGui_ImplWin32_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
RECT rect = { (LONG)pos.x, (LONG)pos.y, (LONG)pos.x, (LONG)pos.y };
|
RECT rect = { (LONG)pos.x, (LONG)pos.y, (LONG)pos.x, (LONG)pos.y };
|
||||||
::AdjustWindowRectEx(&rect, data->DwStyle, FALSE, data->DwExStyle);
|
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle);
|
||||||
::SetWindowPos(data->Hwnd, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
|
::SetWindowPos(vd->Hwnd, NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImVec2 ImGui_ImplWin32_GetWindowSize(ImGuiViewport* viewport)
|
static ImVec2 ImGui_ImplWin32_GetWindowSize(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
RECT rect;
|
RECT rect;
|
||||||
::GetClientRect(data->Hwnd, &rect);
|
::GetClientRect(vd->Hwnd, &rect);
|
||||||
return ImVec2(float(rect.right - rect.left), float(rect.bottom - rect.top));
|
return ImVec2(float(rect.right - rect.left), float(rect.bottom - rect.top));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
static void ImGui_ImplWin32_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
RECT rect = { 0, 0, (LONG)size.x, (LONG)size.y };
|
RECT rect = { 0, 0, (LONG)size.x, (LONG)size.y };
|
||||||
::AdjustWindowRectEx(&rect, data->DwStyle, FALSE, data->DwExStyle); // Client to Screen
|
::AdjustWindowRectEx(&rect, vd->DwStyle, FALSE, vd->DwExStyle); // Client to Screen
|
||||||
::SetWindowPos(data->Hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
|
::SetWindowPos(vd->Hwnd, NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_SetWindowFocus(ImGuiViewport* viewport)
|
static void ImGui_ImplWin32_SetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
::BringWindowToTop(data->Hwnd);
|
::BringWindowToTop(vd->Hwnd);
|
||||||
::SetForegroundWindow(data->Hwnd);
|
::SetForegroundWindow(vd->Hwnd);
|
||||||
::SetFocus(data->Hwnd);
|
::SetFocus(vd->Hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplWin32_GetWindowFocus(ImGuiViewport* viewport)
|
static bool ImGui_ImplWin32_GetWindowFocus(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
return ::GetForegroundWindow() == data->Hwnd;
|
return ::GetForegroundWindow() == vd->Hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplWin32_GetWindowMinimized(ImGuiViewport* viewport)
|
static bool ImGui_ImplWin32_GetWindowMinimized(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
return ::IsIconic(data->Hwnd) != 0;
|
return ::IsIconic(vd->Hwnd) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* title)
|
||||||
{
|
{
|
||||||
// ::SetWindowTextA() doesn't properly handle UTF-8 so we explicitely convert our string.
|
// ::SetWindowTextA() doesn't properly handle UTF-8 so we explicitely convert our string.
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
int n = ::MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
|
int n = ::MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
|
||||||
ImVector<wchar_t> title_w;
|
ImVector<wchar_t> title_w;
|
||||||
title_w.resize(n);
|
title_w.resize(n);
|
||||||
::MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w.Data, n);
|
::MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w.Data, n);
|
||||||
::SetWindowTextW(data->Hwnd, title_w.Data);
|
::SetWindowTextW(vd->Hwnd, title_w.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplWin32_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
static void ImGui_ImplWin32_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
IM_ASSERT(alpha >= 0.0f && alpha <= 1.0f);
|
IM_ASSERT(alpha >= 0.0f && alpha <= 1.0f);
|
||||||
if (alpha < 1.0f)
|
if (alpha < 1.0f)
|
||||||
{
|
{
|
||||||
DWORD style = ::GetWindowLongW(data->Hwnd, GWL_EXSTYLE) | WS_EX_LAYERED;
|
DWORD style = ::GetWindowLongW(vd->Hwnd, GWL_EXSTYLE) | WS_EX_LAYERED;
|
||||||
::SetWindowLongW(data->Hwnd, GWL_EXSTYLE, style);
|
::SetWindowLongW(vd->Hwnd, GWL_EXSTYLE, style);
|
||||||
::SetLayeredWindowAttributes(data->Hwnd, 0, (BYTE)(255 * alpha), LWA_ALPHA);
|
::SetLayeredWindowAttributes(vd->Hwnd, 0, (BYTE)(255 * alpha), LWA_ALPHA);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DWORD style = ::GetWindowLongW(data->Hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED;
|
DWORD style = ::GetWindowLongW(vd->Hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED;
|
||||||
::SetWindowLongW(data->Hwnd, GWL_EXSTYLE, style);
|
::SetWindowLongW(vd->Hwnd, GWL_EXSTYLE, style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float ImGui_ImplWin32_GetWindowDpiScale(ImGuiViewport* viewport)
|
static float ImGui_ImplWin32_GetWindowDpiScale(ImGuiViewport* viewport)
|
||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGui_ImplWin32_ViewportData* vd = (ImGui_ImplWin32_ViewportData*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(vd->Hwnd != 0);
|
||||||
return ImGui_ImplWin32_GetDpiScaleForHwnd(data->Hwnd);
|
return ImGui_ImplWin32_GetDpiScaleForHwnd(vd->Hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME-DPI: Testing DPI related ideas
|
// FIXME-DPI: Testing DPI related ideas
|
||||||
@ -976,10 +976,10 @@ static void ImGui_ImplWin32_InitPlatformInterface()
|
|||||||
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
// This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
|
||||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||||
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
||||||
ImGuiViewportDataWin32* data = IM_NEW(ImGuiViewportDataWin32)();
|
ImGui_ImplWin32_ViewportData* vd = IM_NEW(ImGui_ImplWin32_ViewportData)();
|
||||||
data->Hwnd = bd->hWnd;
|
vd->Hwnd = bd->hWnd;
|
||||||
data->HwndOwned = false;
|
vd->HwndOwned = false;
|
||||||
main_viewport->PlatformUserData = data;
|
main_viewport->PlatformUserData = vd;
|
||||||
main_viewport->PlatformHandle = (void*)bd->hWnd;
|
main_viewport->PlatformHandle = (void*)bd->hWnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user