Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit f1816a1

Browse files
update imgui
1 parent ed44767 commit f1816a1

File tree

12 files changed

+856
-182
lines changed

12 files changed

+856
-182
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ LogoOFP.xcf
1313
OFP.png
1414
TODO.txt
1515
.vscode/settings.json
16+
remedy.rdbg

OFS-lib/OFS_BinarySerialization.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <limits>
32
#include "bitsery/bitsery.h"
43
#include "bitsery/adapter/buffer.h"
54
#include "bitsery/traits/vector.h"

OFS-lib/imgui_impl/imgui_impl_opengl3.cpp

Lines changed: 32 additions & 62 deletions
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
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
19+
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.
1920
// 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).
2021
// 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state.
2122
// 2021-06-21: OpenGL: Destroy individual vertex/fragment shader objects right after they are linked into the main shader.
@@ -110,36 +111,16 @@
110111
#else
111112
#include <GLES3/gl3.h> // Use GL ES 3
112113
#endif
113-
#else
114-
// About Desktop OpenGL function loaders:
115-
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
116-
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
117-
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
118-
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
119-
#include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
120-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
121-
#include <GL/glew.h> // Needs to be initialized with glewInit() in user's code.
122-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
123-
#include <glad/glad.h> // Needs to be initialized with gladLoadGL() in user's code.
124-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
125-
#include <glad/gl.h> // Needs to be initialized with gladLoadGL(...) or gladLoaderLoadGL() in user's code.
126-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
127-
#ifndef GLFW_INCLUDE_NONE
128-
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
129-
#endif
130-
#include <glbinding/Binding.h> // Needs to be initialized with glbinding::Binding::initialize() in user's code.
131-
#include <glbinding/gl/gl.h>
132-
using namespace gl;
133-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
134-
#ifndef GLFW_INCLUDE_NONE
135-
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
136-
#endif
137-
#include <glbinding/glbinding.h>// Needs to be initialized with glbinding::initialize() in user's code.
138-
#include <glbinding/gl/gl.h>
139-
using namespace gl;
140-
#else
141-
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
142-
#endif
114+
#elif !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
115+
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
116+
// Helper libraries are often used for this purpose! Here we are using our own minimal custom loader based on gl3w.
117+
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
118+
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
119+
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
120+
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
121+
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
122+
#define IMGL3W_IMPL
123+
#include "imgui_impl_opengl3_loader.h"
143124
#endif
144125

145126
// Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension
@@ -153,6 +134,11 @@ using namespace gl;
153134
#define GL_VERTEX_ARRAY_BINDING GL_VERTEX_ARRAY_BINDING_OES
154135
#endif
155136

137+
// Desktop GL 2.0+ has glPolygonMode() which GL ES and WebGL don't have.
138+
#ifdef GL_POLYGON_MODE
139+
#define IMGUI_IMPL_HAS_POLYGON_MODE
140+
#endif
141+
156142
// Desktop GL 3.2+ has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
157143
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_2)
158144
#define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
@@ -208,8 +194,17 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
208194
ImGuiIO& io = ImGui::GetIO();
209195
IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
210196

197+
// Initialize our loader
198+
#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
199+
if (imgl3wInit() != 0)
200+
{
201+
fprintf(stderr, "Failed to initialize OpenGL loader!\n");
202+
return false;
203+
}
204+
#endif
205+
211206
// Setup backend capabilities flags
212-
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();;
207+
ImGui_ImplOpenGL3_Data* bd = IM_NEW(ImGui_ImplOpenGL3_Data)();
213208
io.BackendRendererUserData = (void*)bd;
214209
io.BackendRendererName = "imgui_impl_opengl3";
215210

@@ -254,34 +249,8 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
254249
strcpy(bd->GlslVersionString, glsl_version);
255250
strcat(bd->GlslVersionString, "\n");
256251

257-
// Debugging construct to make it easily visible in the IDE and debugger which GL loader has been selected.
258-
// The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
259-
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
260-
// you are likely to get a crash below.
261-
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
262-
const char* gl_loader = "Unknown";
263-
IM_UNUSED(gl_loader);
264-
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
265-
gl_loader = "GL3W";
266-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
267-
gl_loader = "GLEW";
268-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
269-
gl_loader = "GLAD";
270-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2)
271-
gl_loader = "GLAD2";
272-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
273-
gl_loader = "glbinding2";
274-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
275-
gl_loader = "glbinding3";
276-
#elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
277-
gl_loader = "custom";
278-
#else
279-
gl_loader = "none";
280-
#endif
281-
282252
// Make an arbitrary GL call (we don't actually need the result)
283-
// IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
284-
// Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
253+
// IF YOU GET A CRASH HERE: it probably means the OpenGL function loader didn't do its job. Let us know!
285254
GLint current_texture;
286255
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
287256

@@ -341,7 +310,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
341310
if (bd->GlVersion >= 310)
342311
glDisable(GL_PRIMITIVE_RESTART);
343312
#endif
344-
#ifdef GL_POLYGON_MODE
313+
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
345314
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
346315
#endif
347316

@@ -423,7 +392,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
423392
#ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY
424393
GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object);
425394
#endif
426-
#ifdef GL_POLYGON_MODE
395+
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
427396
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
428397
#endif
429398
GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
@@ -532,11 +501,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
532501
if (bd->GlVersion >= 310) { if (last_enable_primitive_restart) glEnable(GL_PRIMITIVE_RESTART); else glDisable(GL_PRIMITIVE_RESTART); }
533502
#endif
534503

535-
#ifdef GL_POLYGON_MODE
504+
#ifdef IMGUI_IMPL_HAS_POLYGON_MODE
536505
glPolygonMode(GL_FRONT_AND_BACK, (GLenum)last_polygon_mode[0]);
537506
#endif
538507
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
539508
glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]);
509+
(void)bd; // Not all compilation paths use this
540510
}
541511

542512
bool ImGui_ImplOpenGL3_CreateFontsTexture()
@@ -556,7 +526,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
556526
glBindTexture(GL_TEXTURE_2D, bd->FontTexture);
557527
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
558528
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
559-
#ifdef GL_UNPACK_ROW_LENGTH
529+
#ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES
560530
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
561531
#endif
562532
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

OFS-lib/imgui_impl/imgui_impl_opengl3.h

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
99
// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices.
1010

11-
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
11+
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
1212
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
1313
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
1414
// Read online: https://github.com/ocornut/imgui/tree/master/docs
1515

16-
// About Desktop OpenGL function loaders:
17-
// Modern Desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
18-
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
19-
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
20-
2116
// About GLSL version:
2217
// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
2318
// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
@@ -42,19 +37,9 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
4237
//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
4338
//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
4439

45-
// Attempt to auto-detect the default Desktop GL loader based on available header files.
46-
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
47-
// you are likely to get a crash in ImGui_ImplOpenGL3_Init().
48-
// You can explicitly select a loader by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
40+
// You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
4941
#if !defined(IMGUI_IMPL_OPENGL_ES2) \
50-
&& !defined(IMGUI_IMPL_OPENGL_ES3) \
51-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
52-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
53-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
54-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD2) \
55-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2) \
56-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3) \
57-
&& !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
42+
&& !defined(IMGUI_IMPL_OPENGL_ES3)
5843

5944
// Try to detect GLES on matching platforms
6045
#if defined(__APPLE__)
@@ -64,26 +49,8 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
6449
#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
6550
#elif defined(__EMSCRIPTEN__)
6651
#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
67-
68-
// Otherwise try to detect supported Desktop OpenGL loaders..
69-
#elif defined(__has_include)
70-
#if __has_include(<GL/glew.h>)
71-
#define IMGUI_IMPL_OPENGL_LOADER_GLEW
72-
#elif __has_include(<glad/glad.h>)
73-
#define IMGUI_IMPL_OPENGL_LOADER_GLAD
74-
#elif __has_include(<glad/gl.h>)
75-
#define IMGUI_IMPL_OPENGL_LOADER_GLAD2
76-
#elif __has_include(<GL/gl3w.h>)
77-
#define IMGUI_IMPL_OPENGL_LOADER_GL3W
78-
#elif __has_include(<glbinding/glbinding.h>)
79-
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
80-
#elif __has_include(<glbinding/Binding.h>)
81-
#define IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
82-
#else
83-
#error "Cannot detect OpenGL loader!"
84-
#endif
8552
#else
86-
#define IMGUI_IMPL_OPENGL_LOADER_GL3W // Default to GL3W embedded in our repository
53+
// Otherwise imgui_impl_opengl3_loader.h will be used.
8754
#endif
8855

8956
#endif

0 commit comments

Comments
 (0)