Skip to content

Commit

Permalink
Merge branch 'master' into docking (wanted for #4468, #3381, #2981, #…
Browse files Browse the repository at this point in the history
…4825, #4832, #5127)

# Conflicts:
#	backends/imgui_impl_opengl3.cpp
  • Loading branch information
ocornut committed May 30, 2022
2 parents 250333d + e23c5ed commit 7b5a8e4
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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

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.

Expand Down
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(Click "Preview" to turn any http URL into a clickable link)

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

2. Clear this template before submitting your PR.

47 changes: 34 additions & 13 deletions backends/imgui_impl_opengl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
// 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).
// 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-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
Expand Down Expand Up @@ -98,6 +99,9 @@
#else
#include <stdint.h> // intptr_t
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

// Clang warnings with -Weverything
#if defined(__clang__)
Expand All @@ -123,9 +127,6 @@
#include <GLES2/gl2ext.h>
#endif
#elif defined(IMGUI_IMPL_OPENGL_ES3)
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
#include <OpenGLES/ES3/gl.h> // Use GL ES 3
#else
Expand Down Expand Up @@ -195,6 +196,7 @@ struct ImGui_ImplOpenGL3_Data
GLsizeiptr VertexBufferSize;
GLsizeiptr IndexBufferSize;
bool HasClipOrigin;
bool UseBufferSubData;

ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); }
};
Expand Down Expand Up @@ -267,6 +269,14 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
sscanf(gl_version, "%d.%d", &major, &minor);
}
bd->GlVersion = (GLuint)(major * 100 + minor * 10);

// Query vendor to enable glBufferSubData kludge
#ifdef _WIN32
if (const char* vendor = (const char*)glGetString(GL_VENDOR))
if (strncmp(vendor, "Intel", 5) == 0)
bd->UseBufferSubData = true;
#endif
//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]
#else
bd->GlVersion = 200; // GLES 2
#endif
Expand Down Expand Up @@ -485,20 +495,31 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
const ImDrawList* cmd_list = draw_data->CmdLists[n];

// Upload vertex/index buffers
GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
if (bd->VertexBufferSize < vtx_buffer_size)
// - 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)
// - On NVIDIA drivers we got reports that using orphaning + glBufferSubData() led to glitches when using multi-viewports.
// - OpenGL drivers are in a very sorry state in 2022, for now we are switching code path based on vendors.
const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert);
const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx);
if (bd->UseBufferSubData)
{
bd->VertexBufferSize = vtx_buffer_size;
glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW);
if (bd->VertexBufferSize < vtx_buffer_size)
{
bd->VertexBufferSize = vtx_buffer_size;
glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW);
}
if (bd->IndexBufferSize < idx_buffer_size)
{
bd->IndexBufferSize = idx_buffer_size;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW);
}
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data);
}
if (bd->IndexBufferSize < idx_buffer_size)
else
{
bd->IndexBufferSize = idx_buffer_size;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW);
glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
}
glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data);

for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
Expand Down
2 changes: 2 additions & 0 deletions backends/imgui_impl_opengl3_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ typedef khronos_uint8_t GLubyte;
#define GL_FLOAT 0x1406
#define GL_RGBA 0x1908
#define GL_FILL 0x1B02
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
#define GL_VERSION 0x1F02
#define GL_EXTENSIONS 0x1F03
#define GL_LINEAR 0x2601
Expand Down
18 changes: 18 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,17 @@ Other changes:

Breaking changes:

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

Other Changes:

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

0 comments on commit 7b5a8e4

Please sign in to comment.