Skip to content

Commit 7b5a8e4

Browse files
committed
Merge branch 'master' into docking (wanted for #4468, #3381, #2981, #4825, #4832, #5127)
# Conflicts: # backends/imgui_impl_opengl3.cpp
2 parents 250333d + e23c5ed commit 7b5a8e4

12 files changed

+239
-90
lines changed

.github/issue_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
2. PLEASE CAREFULLY READ: [FAQ](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md)
66

7-
3. PLEASE CAREFULLY READ: [Issue Submitting Guidelines](https://github.com/ocornut/imgui/issues/2261)
7+
3. PLEASE CAREFULLY READ: [Contributing Guidelines](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md)
88

99
4. PLEASE MAKE SURE that you have: read the FAQ; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the links above.
1010

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(Click "Preview" to turn any http URL into a clickable link)
22

3-
1. PLEASE CAREFULLY READ: [Issue Submitting Guidelines](https://github.com/ocornut/imgui/issues/2261)
3+
1. PLEASE CAREFULLY READ: [Contributing Guidelines](https://github.com/ocornut/imgui/blob/master/docs/CONTRIBUTING.md)
44

55
2. Clear this template before submitting your PR.
66

backends/imgui_impl_opengl3.cpp

+34-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// CHANGELOG
1717
// (minor and older changes stripped away, please see git history for details)
1818
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
19+
// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127).
1920
// 2022-05-13: OpenGL: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states.
2021
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
2122
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
@@ -98,6 +99,9 @@
9899
#else
99100
#include <stdint.h> // intptr_t
100101
#endif
102+
#if defined(__APPLE__)
103+
#include <TargetConditionals.h>
104+
#endif
101105

102106
// Clang warnings with -Weverything
103107
#if defined(__clang__)
@@ -123,9 +127,6 @@
123127
#include <GLES2/gl2ext.h>
124128
#endif
125129
#elif defined(IMGUI_IMPL_OPENGL_ES3)
126-
#if defined(__APPLE__)
127-
#include <TargetConditionals.h>
128-
#endif
129130
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
130131
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
131132
#else
@@ -195,6 +196,7 @@ struct ImGui_ImplOpenGL3_Data
195196
GLsizeiptr VertexBufferSize;
196197
GLsizeiptr IndexBufferSize;
197198
bool HasClipOrigin;
199+
bool UseBufferSubData;
198200

199201
ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
200202
};
@@ -267,6 +269,14 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
267269
sscanf(gl_version, "%d.%d", &major, &minor);
268270
}
269271
bd->GlVersion = (GLuint)(major * 100 + minor * 10);
272+
273+
// Query vendor to enable glBufferSubData kludge
274+
#ifdef _WIN32
275+
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
276+
if (strncmp(vendor, "Intel", 5) == 0)
277+
bd->UseBufferSubData = true;
278+
#endif
279+
//printf("GL_MAJOR_VERSION = %d\nGL_MINOR_VERSION = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", major, minor, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG]
270280
#else
271281
bd->GlVersion = 200; // GLES 2
272282
#endif
@@ -485,20 +495,31 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
485495
const ImDrawList* cmd_list = draw_data->CmdLists[n];
486496

487497
// Upload vertex/index buffers
488-
GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
489-
GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
490-
if (bd->VertexBufferSize < vtx_buffer_size)
498+
// - On Intel windows drivers we got reports that regular glBufferData() led to accumulating leaks when using multi-viewports, so we started using orphaning + glBufferSubData(). (See https://github.com/ocornut/imgui/issues/4468)
499+
// - On NVIDIA drivers we got reports that using orphaning + glBufferSubData() led to glitches when using multi-viewports.
500+
// - OpenGL drivers are in a very sorry state in 2022, for now we are switching code path based on vendors.
501+
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
502+
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
503+
if (bd->UseBufferSubData)
491504
{
492-
bd->VertexBufferSize = vtx_buffer_size;
493-
glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW);
505+
if (bd->VertexBufferSize < vtx_buffer_size)
506+
{
507+
bd->VertexBufferSize = vtx_buffer_size;
508+
glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW);
509+
}
510+
if (bd->IndexBufferSize < idx_buffer_size)
511+
{
512+
bd->IndexBufferSize = idx_buffer_size;
513+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW);
514+
}
515+
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data);
516+
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data);
494517
}
495-
if (bd->IndexBufferSize < idx_buffer_size)
518+
else
496519
{
497-
bd->IndexBufferSize = idx_buffer_size;
498-
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW);
520+
glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
521+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
499522
}
500-
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data);
501-
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data);
502523

503524
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
504525
{

backends/imgui_impl_opengl3_loader.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ typedef khronos_uint8_t GLubyte;
164164
#define GL_FLOAT 0x1406
165165
#define GL_RGBA 0x1908
166166
#define GL_FILL 0x1B02
167+
#define GL_VENDOR 0x1F00
168+
#define GL_RENDERER 0x1F01
167169
#define GL_VERSION 0x1F02
168170
#define GL_EXTENSIONS 0x1F03
169171
#define GL_LINEAR 0x2601

docs/CHANGELOG.txt

+18
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ Other changes:
104104

105105
Breaking changes:
106106

107+
- Renamed CaptureMouseFromApp() and CaptureKeyboardFromApp() to SetNextFrameWantCaptureMouse()
108+
and SetNextFrameWantCaptureKeyboard() to clarify purpose, old name was too misleading.
109+
Kept inline redirection functions (will obsolete).
107110
- Renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete).
108111
(This was never used in public API functions but technically present in imgui.h and ImGuiIO).
109112
- Backends: OSX: Removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend
110113
automatically handling event capture. Examples that are using the OSX backend have removed
111114
all the now-unnecessary calls to ImGui_ImplOSX_HandleEvent(), applications can do as well.
112115
[@stuartcarnie] (#4821)
116+
- Internals: calling ButtonBehavior() without calling ItemAdd() now requires a KeepAliveID().
117+
This is because the KeepAliveID() call was moved from GetID() to ItemAdd()). (#5181)
113118

114119
Other Changes:
115120

@@ -125,6 +130,8 @@ Other Changes:
125130
Not that even thought you shouldn't need to disable io.ConfigInputTrickleEventQueue, you can
126131
technically dynamically change its setting based on the context (e.g. disable only when hovering
127132
or interacting with a game/3D view).
133+
- IO: Fixed input queue trickling of mouse wheel events: multiple wheel events are merged, while
134+
a mouse pos followed by a mouse wheel are now trickled. (#4921, #4821)
128135
- Windows: Fixed first-time windows appearing in negative coordinates from being initialized
129136
with a wrong size. This would most often be noticeable in multi-viewport mode (docking branch)
130137
when spawning a window in a monitor with negative coordinates. (#5215, #3414) [@DimaKoltun]
@@ -143,6 +150,8 @@ Other Changes:
143150
return value is overriden by focus when gamepad/keyboard navigation is active.
144151
- InputText: Fixed pressing Tab emitting two tabs characters because of dual Keys/Chars events being
145152
trickled with the new input queue (happened on some backends only). (#2467, #1336)
153+
- InputText: Fixed a one-frame display glitch where pressing Escape to revert after a deletion
154+
would lead to small garbage being displayed for one frame. Curiously a rather old bug! (#3008)
146155
- Tables: Fixed incorrect border height used for logic when resizing one of several synchronized
147156
instance of a same table ID, when instances have a different height. (#3955).
148157
- Tables: Fixed incorrect auto-fit of parent windows when using non-resizable weighted columns. (#5276)
@@ -152,12 +161,14 @@ Other Changes:
152161
always lead to menu closure. Fixes using items that are not MenuItem() or BeginItem() at the root
153162
level of a popup with a child menu opened.
154163
- Stack Tool: Added option to copy item path to clipboard. (#4631)
164+
- Settings: Fixed out-of-bounds read when .ini file on disk is empty. (#5351) [@quantum5]
155165
- DrawList: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd]
156166
- DrawList: Fixed texture-based anti-aliasing path with RGBA textures (#5132, #3245) [@cfillion]
157167
- DrawList: Fixed divide-by-zero or glitches with Radius/Rounding values close to zero. (#5249, #5293, #3491)
158168
- DrawList: Circle with a radius smaller than 0.5f won't appear, to be consistent with other primitives. [@thedmd]
159169
- Debug: Added DebugTextEncoding() function to facilitate diagnosing issues when not sure about whether
160170
you have a UTF-8 text encoding issue or a font loading issue. [@LaMarche05, @ocornut]
171+
- Demo: Add better demo of how to use SetNextFrameWantCaptureMouse()/SetNextFrameWantCaptureKeyboard().
161172
- Metrics: Added a "UTF-8 Encoding Viewer" section using the aforementioned DebugTextEncoding() function.
162173
- Misc: Fixed calling GetID("label") _before_ a widget emitting this item inside a group (such as InputInt())
163174
from causing an assertion when closing the group. (#5181).
@@ -180,6 +191,13 @@ Other Changes:
180191
- Backends: OSX: Monitor NSKeyUp events to catch missing keyUp for key when user press Cmd + key (#5128) [@thedmd]
181192
- Backends: OSX, Metal: Store backend data in a per-context struct, allowing to use these backends with
182193
multiple contexts. (#5203, #5221, #4141) [@noisewuwei]
194+
- Backends: OpenGL3: Partially revert 1.86 change of using glBufferSubData(): now only done on Windows and
195+
Intel GPU, based on querying glGetString(GL_VENDOR). Essentially we got report of accumulating leaks on Intel
196+
with multi-viewports when using simple glBufferData() without orphaning, and report of corruptions on other
197+
GPUs with multi-viewports when using orphaning and glBufferSubData(), so currently switching technique based
198+
on GPU vendor, which unfortunately reinforce the cargo-cult nature of dealing with OpenGL drivers.
199+
Navigating the space of mysterious OpenGL drivers is particularly difficult as they are known to rely on
200+
application specific whitelisting. (#4468, #3381, #2981, #4825, #4832, #5127).
183201
- Backends: OpenGL3: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING
184202
and vertex attribute states. [@rokups]
185203
- Examples: Emscripten+WebGPU: Fix building for latest WebGPU specs. (#3632)

0 commit comments

Comments
 (0)