From d5793102db4b2e2acde2d3d3c48b3af1fdbda395 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Aug 2018 17:42:53 +0200 Subject: [PATCH] imgui_impl_opengl3: Advertised as a ES2/ES3 renderer. Defaults to ES3 on Android. Default on "#version 300 es" on ES 3. (#2002, #1873) --- README.md | 2 +- examples/README.txt | 6 +++--- examples/imgui_impl_opengl3.cpp | 25 +++++++++++++++++++------ examples/imgui_impl_opengl3.h | 7 ++++--- imgui.cpp | 3 ++- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 51bf6017d..91a50748d 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Languages: (third-party bindings) - Swift [swift-imgui](https://github.com/mnmly/Swift-imgui) Frameworks: -- Renderers: DirectX 9, DirectX 10, DirectX 11, DirectX 12, Metal, OpenGL2, OpenGL3+, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) +- Renderers: DirectX 9, DirectX 10, DirectX 11, DirectX 12, Metal, OpenGL2, OpenGL3+/ES2/ES3, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Platform: GLFW, SDL, Win32, OSX, Freeglut: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Framework: Allegro 5, Marmalade: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Unmerged PR: SDL2 + OpenGLES + Emscripten: [#336](https://github.com/ocornut/imgui/pull/336) diff --git a/examples/README.txt b/examples/README.txt index e84fae8b0..e5764250a 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -111,7 +111,7 @@ List of Renderer Bindings in this repository: imgui_impl_dx12.cpp ; DirectX12 imgui_impl_metal.mm ; Metal (with ObjC) imgui_impl_opengl2.cpp ; OpenGL2 (legacy, fixed pipeline <- don't use with modern OpenGL context) - imgui_impl_opengl3.cpp ; OpenGL3 (modern programmable pipeline) + imgui_impl_opengl3.cpp ; OpenGL3, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline) imgui_impl_vulkan.cpp ; Vulkan List of high-level Frameworks Bindings in this repository: (combine Platform + Renderer) @@ -185,7 +185,7 @@ example_glfw_opengl2/ = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp example_glfw_opengl3/ - GLFW (Win32, Mac, Linux) + OpenGL3+ example (programmable pipeline, binding modern functions with GL3W). + GLFW (Win32, Mac, Linux) + OpenGL3+/ES2/ES3 example (programmable pipeline, binding modern functions with GL3W). This uses more modern OpenGL calls and custom shaders. Prefer using that if you are using modern OpenGL in your application (anything with shaders). = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp @@ -206,7 +206,7 @@ example_sdl_opengl2/ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp example_sdl_opengl3/ - SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+ example. + SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. This uses more modern OpenGL calls and custom shaders. Prefer using that if you are using modern OpenGL in your application (anything with shaders). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 1cd8c0513..c00f3c778 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -1,4 +1,4 @@ -// ImGui Renderer for: OpenGL3 (modern OpenGL with shaders / programmatic pipeline) +// ImGui Renderer for: OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) @@ -11,6 +11,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES". // 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation. // 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link. // 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples. @@ -61,13 +62,20 @@ #include "TargetConditionals.h" #endif -#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__EMSCRIPTEN__)) +// iOS, Android and Emscripten can use GL ES 3 +// Call ImGui_ImplOpenGL3_Init() with "#version 300 es" +#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) || (defined(__EMSCRIPTEN__)) +#define USE_GL_ES3 +#endif + +#ifdef USE_GL_ES3 +// OpenGL ES 3 #include // Use GL ES 3 #else -// About OpenGL function loaders: -// Modern OpenGL requires individual functions to be loaded manually. Helper libraries are often used for this purpose. -// Here we are using gl3w.h, which requires a call to gl3wInit(). -// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc. +// OpenGL Regular +// (About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual functions to be loaded manually. +// Helper libraries are often used for this purpose! Here we are using gl3w.h, which requires a call to gl3wInit(). +// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc.) #include //#include //#include @@ -86,8 +94,13 @@ static unsigned int g_VboHandle = 0, g_ElementsHandle = 0; bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. +#ifdef USE_GL_ES3 + if (glsl_version == NULL) + glsl_version = "#version 300 es"; +#else if (glsl_version == NULL) glsl_version = "#version 130"; +#endif IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString)); strcpy(g_GlslVersionString, glsl_version); strcat(g_GlslVersionString, "\n"); diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 825a09c19..8593b9f5d 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -1,4 +1,4 @@ -// ImGui Renderer for: OpenGL3 (modern OpenGL with shaders / programmatic pipeline) +// ImGui Renderer for: OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) @@ -15,8 +15,9 @@ // You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc. // About GLSL version: -// The 'glsl_version' initialization parameter defaults to "#version 130" if NULL. -// Only override if your GL version doesn't handle this GLSL version (see table at the top of imgui_impl_opengl3.cpp). Keep NULL if unsure! +// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. +// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" +// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); diff --git a/imgui.cpp b/imgui.cpp index e9da99da5..a8b4dca37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13929,8 +13929,9 @@ void ImGui::EndDragDropTarget() //----------------------------------------------------------------------------- #if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)) -#undef WIN32_LEAN_AND_MEAN +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #ifndef __MINGW32__ #include #else