@ -82,44 +82,14 @@
// Auto-detect GL version
# if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
# if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
# define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
# undef IMGUI_IMPL_OPENGL_LOADER_GL3W
# undef IMGUI_IMPL_OPENGL_LOADER_GLEW
# undef IMGUI_IMPL_OPENGL_LOADER_GLAD
# undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM
# define IMGUI_IMPL_OPENGL_ES2
# elif defined(__EMSCRIPTEN__)
# define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
# undef IMGUI_IMPL_OPENGL_LOADER_GL3W
# undef IMGUI_IMPL_OPENGL_LOADER_GLEW
# undef IMGUI_IMPL_OPENGL_LOADER_GLAD
# undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM
# define IMGUI_IMPL_OPENGL_ES2
# endif
# endif
// GL includes
# if defined(IMGUI_IMPL_OPENGL_ES2)
# include <GLES2/gl2.h>
# elif defined(IMGUI_IMPL_OPENGL_ES3)
# if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
# include <OpenGLES/ES3/gl.h> // Use GL ES 3
# else
# include <GLES3/gl3.h> // Use GL ES 3
# endif
# else
// About Desktop OpenGL function loaders:
// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
# if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
# include <GL/gl3w.h> // Needs to be initialized with gl3wInit() in user's code
# elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
# include <GL/glew.h> // Needs to be initialized with glewInit() in user's code
# elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
# include <glad.h> // Needs to be initialized with gladLoadGL() in user's code
# else
# include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
# endif
# endif
# include <glad.h>
// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
# if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
@ -147,66 +117,35 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
// Setup back-end capabilities flags
ImGuiIO & io = ImGui : : GetIO ( ) ;
io . BackendRendererName = " imgui_impl_opengl3 " ;
# if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
io . BackendFlags | = ImGuiBackendFlags_RendererHasVtxOffset ; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
# endif
io . BackendFlags | = ImGuiBackendFlags_RendererHasViewports ; // We can create multi-viewports on the Renderer side (optional)
// 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.
# if defined(IMGUI_IMPL_OPENGL_ES2)
if ( glsl_version = = NULL )
glsl_version = " #version 100 " ;
g_IsGLES = true ;
# elif defined(IMGUI_IMPL_OPENGL_ES3)
if ( glsl_version = = NULL )
glsl_version = " #version 300 es " ;
g_IsGLES = true ;
# else
if ( glsl_version = = NULL )
glsl_version = " #version 130 " ;
g_IsGLES = false ;
# endif
# if defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
if ( GLAD_GL_ES_VERSION_2_0 )
{
glsl_version = " #version 100 " ;
if ( glsl_version = = NULL )
glsl_version = " #version 100 " ;
g_IsGLES = true ;
}
else if ( GLAD_GL_ES_VERSION_3_0 )
{
glsl_version = " #version 300 es " ;
if ( glsl_version = = NULL )
glsl_version = " #version 300 es " ;
g_IsGLES = true ;
}
# endif
else
{
if ( glsl_version = = NULL )
glsl_version = " #version 130 " ;
g_IsGLES = false ;
}
if ( ! g_IsGLES )
io . BackendFlags | = ImGuiBackendFlags_RendererHasVtxOffset ; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
IM_ASSERT ( ( int ) strlen ( glsl_version ) + 2 < IM_ARRAYSIZE ( g_GlslVersionString ) ) ;
strcpy ( g_GlslVersionString , glsl_version ) ;
strcat ( g_GlslVersionString , " \n " ) ;
// Dummy construct to make it easily visible in the IDE and debugger which GL loader has been selected.
// The code actually never uses the 'gl_loader' variable! It is only here so you can read it!
// If auto-detection fails or doesn't select the same GL loader file as used by your application,
// you are likely to get a crash below.
// You can explicitly select a loader by using '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
const char * gl_loader = " Unknown " ;
IM_UNUSED ( gl_loader ) ;
# if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
gl_loader = " GL3W " ;
# elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
gl_loader = " GLEW " ;
# elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
gl_loader = " GLAD " ;
# else // IMGUI_IMPL_OPENGL_LOADER_CUSTOM
gl_loader = " Custom " ;
# endif
// Make a dummy GL call (we don't actually need the result)
// IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
// Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
GLint current_texture ;
glGetIntegerv ( GL_TEXTURE_BINDING_2D , & current_texture ) ;
if ( io . ConfigFlags & ImGuiConfigFlags_ViewportsEnable )
ImGui_ImplOpenGL3_InitPlatformInterface ( ) ;
@ -256,7 +195,7 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid
glUseProgram ( g_ShaderHandle ) ;
glUniform1i ( g_AttribLocationTex , 0 ) ;
glUniformMatrix4fv ( g_AttribLocationProjMtx , 1 , GL_FALSE , & ortho_projection [ 0 ] [ 0 ] ) ;
# if def GL_SAMPLER_BINDING
# if ndef IMGUI_IMPL_OPENGL_ES2
glBindSampler ( 0 , 0 ) ; // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
# endif
@ -398,11 +337,9 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
// Restore modified GL state
glUseProgram ( last_program ) ;
glBindTexture ( GL_TEXTURE_2D , last_texture ) ;
# ifdef GL_SAMPLER_BINDING
glBindSampler ( 0 , last_sampler ) ;
# endif
glActiveTexture ( last_active_texture ) ;
# ifndef IMGUI_IMPL_OPENGL_ES2
glBindSampler ( 0 , last_sampler ) ;
glBindVertexArray ( last_vertex_array_object ) ;
# endif
glBindBuffer ( GL_ARRAY_BUFFER , last_array_buffer ) ;