Skip to content

Commit a9d0ed0

Browse files
authored
[feature] update with changes on imgui 1.9x (#4)
1 parent 0295495 commit a9d0ed0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+13444
-5643
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.4)
1+
cmake_minimum_required(VERSION 3.10)
22

33
project(covscript-imgui)
44
include_directories(backends)

backends/imgui_impl_dx11.cpp

+96-80
Large diffs are not rendered by default.

backends/imgui_impl_dx11.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,42 @@
44
// Implemented features:
55
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID!
66
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
7+
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
78

89
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
910
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
10-
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
11-
// Read online: https://github.com/ocornut/imgui/tree/master/docs
11+
// Learn about Dear ImGui:
12+
// - FAQ https://dearimgui.com/faq
13+
// - Getting Started https://dearimgui.com/getting-started
14+
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
15+
// - Introduction, links and more at the top of imgui.cpp
1216

1317
#pragma once
1418
#include "imgui.h" // IMGUI_IMPL_API
1519
#ifndef IMGUI_DISABLE
1620

1721
struct ID3D11Device;
1822
struct ID3D11DeviceContext;
23+
struct ID3D11SamplerState;
1924

25+
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
2026
IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context);
2127
IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown();
2228
IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame();
2329
IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
2430

2531
// Use if you want to reset your rendering device without losing Dear ImGui state.
26-
IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects();
2732
IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects();
33+
IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects();
34+
35+
// [BETA] Selected render state data shared with callbacks.
36+
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplDX11_RenderDrawData() call.
37+
// (Please open an issue if you feel you need access to more data)
38+
struct ImGui_ImplDX11_RenderState
39+
{
40+
ID3D11Device* Device;
41+
ID3D11DeviceContext* DeviceContext;
42+
ID3D11SamplerState* SamplerDefault;
43+
};
2844

2945
#endif // #ifndef IMGUI_DISABLE

backends/imgui_impl_dx9.cpp

+112-77
Large diffs are not rendered by default.

backends/imgui_impl_dx9.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77

88
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
99
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
10-
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
11-
// Read online: https://github.com/ocornut/imgui/tree/master/docs
10+
// Learn about Dear ImGui:
11+
// - FAQ https://dearimgui.com/faq
12+
// - Getting Started https://dearimgui.com/getting-started
13+
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
14+
// - Introduction, links and more at the top of imgui.cpp
1215

1316
#pragma once
1417
#include "imgui.h" // IMGUI_IMPL_API
1518
#ifndef IMGUI_DISABLE
1619

1720
struct IDirect3DDevice9;
1821

22+
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
1923
IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
2024
IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
2125
IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();

backends/imgui_impl_glfw.cpp

+171-43
Large diffs are not rendered by default.

backends/imgui_impl_glfw.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
// Implemented features:
66
// [X] Platform: Clipboard support.
77
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
8-
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
8+
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values are obsolete since 1.87 and not supported since 1.91.5]
99
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
1010
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
1111

1212
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
1313
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
14-
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
15-
// Read online: https://github.com/ocornut/imgui/tree/master/docs
14+
// Learn about Dear ImGui:
15+
// - FAQ https://dearimgui.com/faq
16+
// - Getting Started https://dearimgui.com/getting-started
17+
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
18+
// - Introduction, links and more at the top of imgui.cpp
1619

1720
#pragma once
1821
#include "imgui.h" // IMGUI_IMPL_API
@@ -21,12 +24,19 @@
2124
struct GLFWwindow;
2225
struct GLFWmonitor;
2326

27+
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
2428
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
2529
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
2630
IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
2731
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
2832
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
2933

34+
// Emscripten related initialization phase methods (call after ImGui_ImplGlfw_InitForOpenGL)
35+
#ifdef __EMSCRIPTEN__
36+
IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* canvas_selector);
37+
//static inline void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector) { ImGui_ImplGlfw_InstallEmscriptenCallbacks(nullptr, canvas_selector); } } // Renamed in 1.91.0
38+
#endif
39+
3040
// GLFW callbacks install
3141
// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
3242
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
@@ -47,4 +57,7 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key,
4757
IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
4858
IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
4959

60+
// GLFW helpers
61+
IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds);
62+
5063
#endif // #ifndef IMGUI_DISABLE

backends/imgui_impl_opengl2.cpp

+24-14
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
88
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
9-
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
10-
// Read online: https://github.com/ocornut/imgui/tree/master/docs
9+
// Learn about Dear ImGui:
10+
// - FAQ https://dearimgui.com/faq
11+
// - Getting Started https://dearimgui.com/getting-started
12+
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
13+
// - Introduction, links and more at the top of imgui.cpp
1114

1215
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
1316
// **Prefer using the code in imgui_impl_opengl3.cpp**
@@ -19,8 +22,10 @@
1922

2023
// CHANGELOG
2124
// (minor and older changes stripped away, please see git history for details)
25+
// 2024-10-07: OpenGL: Changed default texture sampler to Clamp instead of Repeat/Wrap.
26+
// 2024-06-28: OpenGL: ImGui_ImplOpenGL2_NewFrame() recreates font texture if it has been destroyed by ImGui_ImplOpenGL2_DestroyFontsTexture(). (#7748)
2227
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
23-
// 2021-12-08: OpenGL: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
28+
// 2021-12-08: OpenGL: Fixed mishandling of the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
2429
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
2530
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
2631
// 2021-01-03: OpenGL: Backup, setup and restore GL_SHADE_MODEL state, disable GL_STENCIL_TEST and disable GL_NORMAL_ARRAY client state to increase compatibility with legacy OpenGL applications.
@@ -80,6 +85,7 @@ static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData()
8085
bool ImGui_ImplOpenGL2_Init()
8186
{
8287
ImGuiIO& io = ImGui::GetIO();
88+
IMGUI_CHECKVERSION();
8389
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
8490

8591
// Setup backend capabilities flags
@@ -105,10 +111,12 @@ void ImGui_ImplOpenGL2_Shutdown()
105111
void ImGui_ImplOpenGL2_NewFrame()
106112
{
107113
ImGui_ImplOpenGL2_Data* bd = ImGui_ImplOpenGL2_GetBackendData();
108-
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplOpenGL2_Init()?");
114+
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplOpenGL2_Init()?");
109115

110116
if (!bd->FontTexture)
111117
ImGui_ImplOpenGL2_CreateDeviceObjects();
118+
if (!bd->FontTexture)
119+
ImGui_ImplOpenGL2_CreateFontsTexture();
112120
}
113121

114122
static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
@@ -185,24 +193,24 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
185193
// Render command lists
186194
for (int n = 0; n < draw_data->CmdListsCount; n++)
187195
{
188-
const ImDrawList* cmd_list = draw_data->CmdLists[n];
189-
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
190-
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
191-
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)));
192-
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)));
193-
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)));
194-
195-
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
196+
const ImDrawList* draw_list = draw_data->CmdLists[n];
197+
const ImDrawVert* vtx_buffer = draw_list->VtxBuffer.Data;
198+
const ImDrawIdx* idx_buffer = draw_list->IdxBuffer.Data;
199+
glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, pos)));
200+
glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, uv)));
201+
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + offsetof(ImDrawVert, col)));
202+
203+
for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
196204
{
197-
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
205+
const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
198206
if (pcmd->UserCallback)
199207
{
200208
// User callback, registered via ImDrawList::AddCallback()
201209
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
202210
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
203211
ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
204212
else
205-
pcmd->UserCallback(cmd_list, pcmd);
213+
pcmd->UserCallback(draw_list, pcmd);
206214
}
207215
else
208216
{
@@ -256,6 +264,8 @@ bool ImGui_ImplOpenGL2_CreateFontsTexture()
256264
glBindTexture(GL_TEXTURE_2D, bd->FontTexture);
257265
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
258266
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
267+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
268+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
259269
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
260270
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
261271

backends/imgui_impl_opengl2.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
88
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
9-
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
10-
// Read online: https://github.com/ocornut/imgui/tree/master/docs
9+
// Learn about Dear ImGui:
10+
// - FAQ https://dearimgui.com/faq
11+
// - Getting Started https://dearimgui.com/getting-started
12+
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
13+
// - Introduction, links and more at the top of imgui.cpp
1114

1215
// **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)**
1316
// **Prefer using the code in imgui_impl_opengl3.cpp**
@@ -21,6 +24,7 @@
2124
#include "imgui.h" // IMGUI_IMPL_API
2225
#ifndef IMGUI_DISABLE
2326

27+
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
2428
IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init();
2529
IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown();
2630
IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame();

0 commit comments

Comments
 (0)