Go to the documentation of this file.
67 #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
68 #define _CRT_SECURE_NO_WARNINGS
74 #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
79 #if defined(__APPLE__)
80 #include "TargetConditionals.h"
84 #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
85 #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
86 #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
87 #elif defined(__EMSCRIPTEN__)
88 #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
92 #if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
93 #undef IMGUI_IMPL_OPENGL_LOADER_GL3W
94 #undef IMGUI_IMPL_OPENGL_LOADER_GLEW
95 #undef IMGUI_IMPL_OPENGL_LOADER_GLAD
96 #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING2
97 #undef IMGUI_IMPL_OPENGL_LOADER_GLBINDING3
98 #undef IMGUI_IMPL_OPENGL_LOADER_CUSTOM
102 #if defined(IMGUI_IMPL_OPENGL_ES2)
103 #include <GLES2/gl2.h>
104 #elif defined(IMGUI_IMPL_OPENGL_ES3)
105 #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
106 #include <OpenGLES/ES3/gl.h>
108 #include <GLES3/gl3.h>
115 #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
117 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
119 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
120 #include <glad/glad.h>
121 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
122 #define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
123 #include <glbinding/Binding.h>
124 #include <glbinding/gl/gl.h>
126 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
127 #define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
128 #include <glbinding/glbinding.h>
129 #include <glbinding/gl/gl.h>
132 #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
137 #if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3) || !defined(GL_VERSION_3_2)
138 #define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET 0
140 #define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET 1
156 #if !defined(IMGUI_IMPL_OPENGL_ES2)
168 #if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
175 #if defined(IMGUI_IMPL_OPENGL_ES2)
176 if (glsl_version ==
NULL)
177 glsl_version =
"#version 100";
178 #elif defined(IMGUI_IMPL_OPENGL_ES3)
179 if (glsl_version ==
NULL)
180 glsl_version =
"#version 300 es";
182 if (glsl_version ==
NULL)
183 glsl_version =
"#version 130";
194 const char* gl_loader =
"Unknown";
196 #if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
198 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
200 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
202 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING2)
203 gl_loader =
"glbinding2";
204 #elif defined(IMGUI_IMPL_OPENGL_LOADER_GLBINDING3)
205 gl_loader =
"glbinding3";
206 #elif defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM)
207 gl_loader =
"custom";
215 GLint current_texture;
241 #ifdef GL_POLYGON_MODE
252 const float ortho_projection[4][4] =
254 { 2.0f/(R-L), 0.0
f, 0.0
f, 0.0
f },
255 { 0.0f, 2.0f/(
T-B), 0.0
f, 0.0
f },
256 { 0.0f, 0.0f, -1.0f, 0.0f },
257 { (R+L)/(L-R), (
T+B)/(B-
T), 0.0f, 1.0f },
262 #ifdef GL_SAMPLER_BINDING
266 (
void)vertex_array_object;
267 #ifndef IMGUI_IMPL_OPENGL_ES2
290 if (fb_width <= 0 || fb_height <= 0)
298 #ifdef GL_SAMPLER_BINDING
302 #ifndef IMGUI_IMPL_OPENGL_ES2
305 #ifdef GL_POLYGON_MODE
320 bool clip_origin_lower_left =
true;
321 #if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
324 clip_origin_lower_left =
false;
330 GLuint vertex_array_object = 0;
331 #ifndef IMGUI_IMPL_OPENGL_ES2
349 for (
int cmd_i = 0; cmd_i < cmd_list->
CmdBuffer.
Size; cmd_i++)
365 clip_rect.
x = (pcmd->
ClipRect.
x - clip_off.
x) * clip_scale.
x;
366 clip_rect.
y = (pcmd->
ClipRect.
y - clip_off.
y) * clip_scale.
y;
367 clip_rect.
z = (pcmd->
ClipRect.
z - clip_off.
x) * clip_scale.
x;
368 clip_rect.
w = (pcmd->
ClipRect.
w - clip_off.
y) * clip_scale.
y;
370 if (clip_rect.
x < fb_width && clip_rect.
y < fb_height && clip_rect.
z >= 0.0f && clip_rect.
w >= 0.0f)
373 if (clip_origin_lower_left)
374 glScissor((
int)clip_rect.
x, (
int)(fb_height - clip_rect.
w), (
int)(clip_rect.
z - clip_rect.
x), (
int)(clip_rect.
w - clip_rect.
y));
376 glScissor((
int)clip_rect.
x, (
int)clip_rect.
y, (
int)clip_rect.
z, (
int)clip_rect.
w);
380 #if IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET
392 #ifndef IMGUI_IMPL_OPENGL_ES2
399 #ifdef GL_SAMPLER_BINDING
403 #ifndef IMGUI_IMPL_OPENGL_ES2
408 glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
413 #ifdef GL_POLYGON_MODE
417 glScissor(last_scissor_box[0], last_scissor_box[1], (
GLsizei)last_scissor_box[2], (
GLsizei)last_scissor_box[3]);
435 #ifdef GL_UNPACK_ROW_LENGTH
463 GLint status = 0, log_length = 0;
467 fprintf(stderr,
"ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n",
desc);
471 buf.resize((
int)(log_length + 1));
473 fprintf(stderr,
"%s\n",
buf.begin());
481 GLint status = 0, log_length = 0;
485 fprintf(stderr,
"ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n",
desc,
g_GlslVersionString);
489 buf.resize((
int)(log_length + 1));
491 fprintf(stderr,
"%s\n",
buf.begin());
499 GLint last_texture, last_array_buffer;
502 #ifndef IMGUI_IMPL_OPENGL_ES2
503 GLint last_vertex_array;
508 int glsl_version = 130;
511 const GLchar* vertex_shader_glsl_120 =
512 "uniform mat4 ProjMtx;\n"
513 "attribute vec2 Position;\n"
514 "attribute vec2 UV;\n"
515 "attribute vec4 Color;\n"
516 "varying vec2 Frag_UV;\n"
517 "varying vec4 Frag_Color;\n"
521 " Frag_Color = Color;\n"
522 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
525 const GLchar* vertex_shader_glsl_130 =
526 "uniform mat4 ProjMtx;\n"
527 "in vec2 Position;\n"
530 "out vec2 Frag_UV;\n"
531 "out vec4 Frag_Color;\n"
535 " Frag_Color = Color;\n"
536 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
539 const GLchar* vertex_shader_glsl_300_es =
540 "precision mediump float;\n"
541 "layout (location = 0) in vec2 Position;\n"
542 "layout (location = 1) in vec2 UV;\n"
543 "layout (location = 2) in vec4 Color;\n"
544 "uniform mat4 ProjMtx;\n"
545 "out vec2 Frag_UV;\n"
546 "out vec4 Frag_Color;\n"
550 " Frag_Color = Color;\n"
551 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
554 const GLchar* vertex_shader_glsl_410_core =
555 "layout (location = 0) in vec2 Position;\n"
556 "layout (location = 1) in vec2 UV;\n"
557 "layout (location = 2) in vec4 Color;\n"
558 "uniform mat4 ProjMtx;\n"
559 "out vec2 Frag_UV;\n"
560 "out vec4 Frag_Color;\n"
564 " Frag_Color = Color;\n"
565 " gl_Position = ProjMtx * vec4(Position.xy,0,1);\n"
568 const GLchar* fragment_shader_glsl_120 =
570 " precision mediump float;\n"
572 "uniform sampler2D Texture;\n"
573 "varying vec2 Frag_UV;\n"
574 "varying vec4 Frag_Color;\n"
577 " gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st);\n"
580 const GLchar* fragment_shader_glsl_130 =
581 "uniform sampler2D Texture;\n"
583 "in vec4 Frag_Color;\n"
584 "out vec4 Out_Color;\n"
587 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
590 const GLchar* fragment_shader_glsl_300_es =
591 "precision mediump float;\n"
592 "uniform sampler2D Texture;\n"
594 "in vec4 Frag_Color;\n"
595 "layout (location = 0) out vec4 Out_Color;\n"
598 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
601 const GLchar* fragment_shader_glsl_410_core =
603 "in vec4 Frag_Color;\n"
604 "uniform sampler2D Texture;\n"
605 "layout (location = 0) out vec4 Out_Color;\n"
608 " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n"
614 if (glsl_version < 130)
616 vertex_shader = vertex_shader_glsl_120;
617 fragment_shader = fragment_shader_glsl_120;
619 else if (glsl_version >= 410)
621 vertex_shader = vertex_shader_glsl_410_core;
622 fragment_shader = fragment_shader_glsl_410_core;
624 else if (glsl_version == 300)
626 vertex_shader = vertex_shader_glsl_300_es;
627 fragment_shader = fragment_shader_glsl_300_es;
631 vertex_shader = vertex_shader_glsl_130;
632 fragment_shader = fragment_shader_glsl_130;
669 #ifndef IMGUI_IMPL_OPENGL_ES2
static int g_AttribLocationTex
GLint GLsizei GLsizei height
ImVector< ImDrawIdx > IdxBuffer
#define GL_TEXTURE_MIN_FILTER
#define GL_VERTEX_ARRAY_BINDING
#define glGetShaderInfoLog
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData *draw_data)
static int g_AttribLocationVtxUV
static GLuint g_FontTexture
#define GL_FRAGMENT_SHADER
void ImGui_ImplOpenGL3_DestroyFontsTexture()
#define GL_ACTIVE_TEXTURE
static int g_AttribLocationProjMtx
#define glVertexAttribPointer
#define GL_BLEND_EQUATION_ALPHA
void ImGui_ImplOpenGL3_Shutdown()
#define glGetProgramInfoLog
bool ImGui_ImplOpenGL3_Init(const char *glsl_version)
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
static char g_GlslVersionString[32]
#define GL_TEXTURE_BINDING_2D
#define GL_UNSIGNED_SHORT
#define GL_BLEND_SRC_ALPHA
#define glGetAttribLocation
#define GL_BLEND_EQUATION_RGB
IMGUI_API ImGuiIO & GetIO()
#define T(upbtypeconst, upbtype, ctype, default_value)
#define GL_FRONT_AND_BACK
ImVector< ImDrawCmd > CmdBuffer
#define GL_UNPACK_ROW_LENGTH
ImDrawCallback UserCallback
#define glGetUniformLocation
static int g_AttribLocationVtxPos
#define glEnableVertexAttribArray
#define GL_BLEND_DST_ALPHA
#define glDrawElementsBaseVertex
#define GL_TEXTURE_MAG_FILTER
#define glUniformMatrix4fv
#define IM_OFFSETOF(_TYPE, _MEMBER)
#define IM_ARRAYSIZE(_ARR)
#define GL_ELEMENT_ARRAY_BUFFER
static int g_AttribLocationVtxColor
#define GL_INFO_LOG_LENGTH
#define GL_SAMPLER_BINDING
static unsigned int g_VboHandle
#define GL_ARRAY_BUFFER_BINDING
static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData *draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define glBlendEquationSeparate
@ ImGuiBackendFlags_RendererHasVtxOffset
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
ImVector< ImDrawVert > VtxBuffer
#define glDeleteVertexArrays
#define glBindVertexArray
#define glBlendFuncSeparate
#define GL_ONE_MINUS_SRC_ALPHA
static bool CheckProgram(GLuint handle, const char *desc)
static unsigned int g_ElementsHandle
#define ImDrawCallback_ResetRenderState
const char * BackendRendererName
static GLuint g_VertHandle
void ImGui_ImplOpenGL3_DestroyDeviceObjects()
#define glGenVertexArrays
void ImGui_ImplOpenGL3_NewFrame()
#define GL_COMPILE_STATUS
static GLuint g_GlVersion
GLint GLint GLsizei GLint GLenum GLenum const GLvoid * pixels
static bool CheckShader(GLuint handle, const char *desc)
#define GL_CURRENT_PROGRAM
bool ImGui_ImplOpenGL3_CreateFontsTexture()
ImGuiBackendFlags BackendFlags
static GLuint g_ShaderHandle
static GLuint g_FragHandle
IMGUI_API void GetTexDataAsRGBA32(unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel=NULL)
libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54