|
|
@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
// Implemented features:
|
|
|
|
// Implemented features:
|
|
|
|
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
|
|
|
|
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
|
|
|
|
|
|
|
|
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
|
|
|
|
|
|
|
|
|
|
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
|
|
|
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
|
|
|
|
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
|
|
|
|
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
|
|
|
@ -10,6 +11,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
// CHANGELOG
|
|
|
|
// CHANGELOG
|
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
|
|
|
|
|
// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
|
|
// 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
|
|
|
|
// 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
|
|
|
|
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
|
|
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
|
|
|
|
// 2018-06-08: Misc: Extracted imgui_impl_dx9.cpp/.h away from the old combined DX9+Win32 example.
|
|
|
|
// 2018-06-08: Misc: Extracted imgui_impl_dx9.cpp/.h away from the old combined DX9+Win32 example.
|
|
|
@ -41,6 +43,10 @@ struct CUSTOMVERTEX
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
|
|
|
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forward Declarations
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_InitPlatformInterface();
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_ShutdownPlatformInterface();
|
|
|
|
|
|
|
|
|
|
|
|
// Render function.
|
|
|
|
// Render function.
|
|
|
|
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
|
|
|
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
|
|
|
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|
|
|
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|
|
@ -203,16 +209,22 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
|
|
|
|
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
|
|
|
|
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
|
|
|
|
io.BackendRendererName = "imgui_impl_dx9";
|
|
|
|
io.BackendRendererName = "imgui_impl_dx9";
|
|
|
|
|
|
|
|
|
|
|
|
g_pd3dDevice = device;
|
|
|
|
g_pd3dDevice = device;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
|
|
|
|
|
|
|
ImGui_ImplDX9_InitPlatformInterface();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ImGui_ImplDX9_Shutdown()
|
|
|
|
void ImGui_ImplDX9_Shutdown()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui_ImplDX9_ShutdownPlatformInterface();
|
|
|
|
ImGui_ImplDX9_InvalidateDeviceObjects();
|
|
|
|
ImGui_ImplDX9_InvalidateDeviceObjects();
|
|
|
|
g_pd3dDevice = NULL;
|
|
|
|
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool ImGui_ImplDX9_CreateFontsTexture()
|
|
|
|
static bool ImGui_ImplDX9_CreateFontsTexture()
|
|
|
@ -278,3 +290,112 @@ void ImGui_ImplDX9_NewFrame()
|
|
|
|
if (!g_FontTexture)
|
|
|
|
if (!g_FontTexture)
|
|
|
|
ImGui_ImplDX9_CreateDeviceObjects();
|
|
|
|
ImGui_ImplDX9_CreateDeviceObjects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
|
|
|
|
|
|
|
|
// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously.
|
|
|
|
|
|
|
|
// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ImGuiViewportDataDx9
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
IDirect3DSwapChain9* SwapChain;
|
|
|
|
|
|
|
|
D3DPRESENT_PARAMETERS d3dpp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGuiViewportDataDx9() { SwapChain = NULL; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); }
|
|
|
|
|
|
|
|
~ImGuiViewportDataDx9() { IM_ASSERT(SwapChain == NULL); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGuiViewportDataDx9* data = IM_NEW(ImGuiViewportDataDx9)();
|
|
|
|
|
|
|
|
viewport->RendererUserData = data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HWND hWnd = (HWND)viewport->PlatformHandle;
|
|
|
|
|
|
|
|
IM_ASSERT(hWnd != 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
|
|
|
data->d3dpp.Windowed = TRUE;
|
|
|
|
|
|
|
|
data->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
|
|
|
|
data->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
|
|
|
|
|
|
|
|
data->d3dpp.hDeviceWindow = hWnd;
|
|
|
|
|
|
|
|
data->d3dpp.EnableAutoDepthStencil = TRUE;
|
|
|
|
|
|
|
|
data->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
|
|
|
|
|
|
|
|
data->d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain);
|
|
|
|
|
|
|
|
IM_ASSERT(data->SwapChain != NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
if (ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (data->SwapChain)
|
|
|
|
|
|
|
|
data->SwapChain->Release();
|
|
|
|
|
|
|
|
data->SwapChain = NULL;
|
|
|
|
|
|
|
|
ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
|
|
|
|
|
|
|
|
IM_DELETE(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
viewport->RendererUserData = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
|
|
|
|
|
|
|
if (data->SwapChain)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data->SwapChain->Release();
|
|
|
|
|
|
|
|
data->SwapChain = NULL;
|
|
|
|
|
|
|
|
data->d3dpp.BackBufferWidth = (UINT)size.x;
|
|
|
|
|
|
|
|
data->d3dpp.BackBufferHeight = (UINT)size.y;
|
|
|
|
|
|
|
|
g_pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
|
|
|
|
|
|
|
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LPDIRECT3DSURFACE9 render_target = NULL;
|
|
|
|
|
|
|
|
LPDIRECT3DSURFACE9 last_render_target = NULL;
|
|
|
|
|
|
|
|
data->SwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &render_target);
|
|
|
|
|
|
|
|
g_pd3dDevice->GetRenderTarget(0, &last_render_target);
|
|
|
|
|
|
|
|
g_pd3dDevice->SetRenderTarget(0, render_target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f));
|
|
|
|
|
|
|
|
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui_ImplDX9_RenderDrawData(viewport->DrawData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restore render target
|
|
|
|
|
|
|
|
g_pd3dDevice->SetRenderTarget(0, last_render_target);
|
|
|
|
|
|
|
|
render_target->Release();
|
|
|
|
|
|
|
|
last_render_target->Release();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_SwapBuffers(ImGuiViewport* viewport, void*)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
|
|
|
|
|
|
|
|
data->SwapChain->Present(NULL, NULL, data->d3dpp.hDeviceWindow, NULL, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_InitPlatformInterface()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
|
|
|
|
|
|
|
platform_io.Renderer_CreateWindow = ImGui_ImplDX9_CreateWindow;
|
|
|
|
|
|
|
|
platform_io.Renderer_DestroyWindow = ImGui_ImplDX9_DestroyWindow;
|
|
|
|
|
|
|
|
platform_io.Renderer_SetWindowSize = ImGui_ImplDX9_SetWindowSize;
|
|
|
|
|
|
|
|
platform_io.Renderer_RenderWindow = ImGui_ImplDX9_RenderWindow;
|
|
|
|
|
|
|
|
platform_io.Renderer_SwapBuffers = ImGui_ImplDX9_SwapBuffers;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ImGui_ImplDX9_ShutdownPlatformInterface()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui::DestroyPlatformWindows();
|
|
|
|
|
|
|
|
}
|
|
|
|