upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/imgui/imgui_impl_opengl3_loader.h
diff options
context:
space:
mode:
authorbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
committerbitflash-coin <bookofshamers@outlook.com>2026-08-04 06:34:32 -0700
commit5ce650382352c1503f40abf08129ada69402af55 (patch)
tree6a18198901f1e2c4933f1ac53c9365eec512bf63 /src/imgui/imgui_impl_opengl3_loader.h
parentf34113291da7e5e3dc7d2468d4f9c212c05c584b (diff)
public commit
Diffstat (limited to 'src/imgui/imgui_impl_opengl3_loader.h')
-rw-r--r--src/imgui/imgui_impl_opengl3_loader.h958
1 files changed, 958 insertions, 0 deletions
diff --git a/src/imgui/imgui_impl_opengl3_loader.h b/src/imgui/imgui_impl_opengl3_loader.h
new file mode 100644
index 0000000..2c48584
--- /dev/null
+++ b/src/imgui/imgui_impl_opengl3_loader.h
@@ -0,0 +1,958 @@
1//-----------------------------------------------------------------------------
2// About imgui_impl_opengl3_loader.h:
3//
4// We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
5// which proved to be endless problems for users.
6// Our loader is custom-generated, based on gl3w but automatically filtered to only include
7// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
8//
9// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
10// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
11//
12// IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
13// IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCLUDING 'imgui_impl_opengl3_loader.h'
14// IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
15// (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
16// YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
17// BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
18// WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
19//
20// Regenerate with:
21// python3 gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
22//
23// More info:
24// https://github.com/dearimgui/gl3w_stripped
25// https://github.com/ocornut/imgui/issues/4445
26//-----------------------------------------------------------------------------
27
28/*
29 * This file was generated with gl3w_gen.py, part of imgl3w
30 * (hosted at https://github.com/dearimgui/gl3w_stripped)
31 *
32 * This is free and unencumbered software released into the public domain.
33 *
34 * Anyone is free to copy, modify, publish, use, compile, sell, or
35 * distribute this software, either in source code form or as a compiled
36 * binary, for any purpose, commercial or non-commercial, and by any
37 * means.
38 *
39 * In jurisdictions that recognize copyright laws, the author or authors
40 * of this software dedicate any and all copyright interest in the
41 * software to the public domain. We make this dedication for the benefit
42 * of the public at large and to the detriment of our heirs and
43 * successors. We intend this dedication to be an overt act of
44 * relinquishment in perpetuity of all present and future rights to this
45 * software under copyright law.
46 *
47 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
51 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
52 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53 * OTHER DEALINGS IN THE SOFTWARE.
54 */
55
56#ifndef __gl3w_h_
57#define __gl3w_h_
58
59// Adapted from KHR/khrplatform.h to avoid including entire file.
60#ifndef __khrplatform_h_
61typedef float khronos_float_t;
62typedef signed char khronos_int8_t;
63typedef unsigned char khronos_uint8_t;
64typedef signed short int khronos_int16_t;
65typedef unsigned short int khronos_uint16_t;
66#ifdef _WIN64
67typedef signed long long int khronos_intptr_t;
68typedef signed long long int khronos_ssize_t;
69#else
70typedef signed long int khronos_intptr_t;
71typedef signed long int khronos_ssize_t;
72#endif
73
74#if defined(_MSC_VER) && !defined(__clang__)
75typedef signed __int64 khronos_int64_t;
76typedef unsigned __int64 khronos_uint64_t;
77#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
78#include <stdint.h>
79typedef int64_t khronos_int64_t;
80typedef uint64_t khronos_uint64_t;
81#else
82typedef signed long long khronos_int64_t;
83typedef unsigned long long khronos_uint64_t;
84#endif
85#endif // __khrplatform_h_
86
87#ifndef __gl_glcorearb_h_
88#define __gl_glcorearb_h_ 1
89#ifdef __cplusplus
90extern "C" {
91#endif
92/*
93** Copyright 2013-2020 The Khronos Group Inc.
94** SPDX-License-Identifier: MIT
95**
96** This header is generated from the Khronos OpenGL / OpenGL ES XML
97** API Registry. The current version of the Registry, generator scripts
98** used to make the header, and the header can be found at
99** https://github.com/KhronosGroup/OpenGL-Registry
100*/
101#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
102#ifndef WIN32_LEAN_AND_MEAN
103#define WIN32_LEAN_AND_MEAN 1
104#endif
105#include <windows.h>
106#endif
107#ifndef APIENTRY
108#define APIENTRY
109#endif
110#ifndef APIENTRYP
111#define APIENTRYP APIENTRY *
112#endif
113#ifndef GLAPI
114#define GLAPI extern
115#endif
116/* glcorearb.h is for use with OpenGL core profile implementations.
117** It should should be placed in the same directory as gl.h and
118** included as <GL/glcorearb.h>.
119**
120** glcorearb.h includes only APIs in the latest OpenGL core profile
121** implementation together with APIs in newer ARB extensions which
122** can be supported by the core profile. It does not, and never will
123** include functionality removed from the core profile, such as
124** fixed-function vertex and fragment processing.
125**
126** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
127** <GL/glext.h> in the same source file.
128*/
129/* Generated C header for:
130 * API: gl
131 * Profile: core
132 * Versions considered: .*
133 * Versions emitted: .*
134 * Default extensions included: glcore
135 * Additional extensions included: _nomatch_^
136 * Extensions removed: _nomatch_^
137 */
138#ifndef GL_VERSION_1_0
139typedef void GLvoid;
140typedef unsigned int GLenum;
141
142typedef khronos_float_t GLfloat;
143typedef int GLint;
144typedef int GLsizei;
145typedef unsigned int GLbitfield;
146typedef double GLdouble;
147typedef unsigned int GLuint;
148typedef unsigned char GLboolean;
149typedef khronos_uint8_t GLubyte;
150#define GL_COLOR_BUFFER_BIT 0x00004000
151#define GL_FALSE 0
152#define GL_TRUE 1
153#define GL_TRIANGLES 0x0004
154#define GL_ONE 1
155#define GL_SRC_ALPHA 0x0302
156#define GL_ONE_MINUS_SRC_ALPHA 0x0303
157#define GL_FRONT 0x0404
158#define GL_BACK 0x0405
159#define GL_FRONT_AND_BACK 0x0408
160#define GL_POLYGON_MODE 0x0B40
161#define GL_CULL_FACE 0x0B44
162#define GL_DEPTH_TEST 0x0B71
163#define GL_STENCIL_TEST 0x0B90
164#define GL_VIEWPORT 0x0BA2
165#define GL_BLEND 0x0BE2
166#define GL_SCISSOR_BOX 0x0C10
167#define GL_SCISSOR_TEST 0x0C11
168#define GL_UNPACK_ROW_LENGTH 0x0CF2
169#define GL_UNPACK_ALIGNMENT 0x0CF5
170#define GL_PACK_ALIGNMENT 0x0D05
171#define GL_MAX_TEXTURE_SIZE 0x0D33
172#define GL_TEXTURE_2D 0x0DE1
173#define GL_UNSIGNED_BYTE 0x1401
174#define GL_UNSIGNED_SHORT 0x1403
175#define GL_UNSIGNED_INT 0x1405
176#define GL_FLOAT 0x1406
177#define GL_RGBA 0x1908
178#define GL_FILL 0x1B02
179#define GL_VENDOR 0x1F00
180#define GL_RENDERER 0x1F01
181#define GL_VERSION 0x1F02
182#define GL_EXTENSIONS 0x1F03
183#define GL_NEAREST 0x2600
184#define GL_LINEAR 0x2601
185#define GL_TEXTURE_MAG_FILTER 0x2800
186#define GL_TEXTURE_MIN_FILTER 0x2801
187#define GL_TEXTURE_WRAP_S 0x2802
188#define GL_TEXTURE_WRAP_T 0x2803
189#define GL_REPEAT 0x2901
190typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
191typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
192typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
193typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
194typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
195typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
196typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
197typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
198typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
199typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
200typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
201typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
202typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
203typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
204typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
205typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
206#ifdef GL_GLEXT_PROTOTYPES
207GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
208GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
209GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
210GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
211GLAPI void APIENTRY glClear (GLbitfield mask);
212GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
213GLAPI void APIENTRY glDisable (GLenum cap);
214GLAPI void APIENTRY glEnable (GLenum cap);
215GLAPI void APIENTRY glFlush (void);
216GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
217GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
218GLAPI GLenum APIENTRY glGetError (void);
219GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
220GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
221GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
222GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
223#endif
224#endif /* GL_VERSION_1_0 */
225#ifndef GL_VERSION_1_1
226typedef khronos_float_t GLclampf;
227typedef double GLclampd;
228#define GL_TEXTURE_BINDING_2D 0x8069
229typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
230typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
231typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
232typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
233typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
234#ifdef GL_GLEXT_PROTOTYPES
235GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
236GLAPI void APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels);
237GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
238GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
239GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
240#endif
241#endif /* GL_VERSION_1_1 */
242#ifndef GL_VERSION_1_2
243#define GL_CLAMP_TO_EDGE 0x812F
244#endif /* GL_VERSION_1_2 */
245#ifndef GL_VERSION_1_3
246#define GL_TEXTURE0 0x84C0
247#define GL_ACTIVE_TEXTURE 0x84E0
248typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
249#ifdef GL_GLEXT_PROTOTYPES
250GLAPI void APIENTRY glActiveTexture (GLenum texture);
251#endif
252#endif /* GL_VERSION_1_3 */
253#ifndef GL_VERSION_1_4
254#define GL_BLEND_DST_RGB 0x80C8
255#define GL_BLEND_SRC_RGB 0x80C9
256#define GL_BLEND_DST_ALPHA 0x80CA
257#define GL_BLEND_SRC_ALPHA 0x80CB
258#define GL_FUNC_ADD 0x8006
259typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
260typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
261#ifdef GL_GLEXT_PROTOTYPES
262GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
263GLAPI void APIENTRY glBlendEquation (GLenum mode);
264#endif
265#endif /* GL_VERSION_1_4 */
266#ifndef GL_VERSION_1_5
267typedef khronos_ssize_t GLsizeiptr;
268typedef khronos_intptr_t GLintptr;
269#define GL_ARRAY_BUFFER 0x8892
270#define GL_ELEMENT_ARRAY_BUFFER 0x8893
271#define GL_ARRAY_BUFFER_BINDING 0x8894
272#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
273#define GL_STREAM_DRAW 0x88E0
274typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
275typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
276typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
277typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
278typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
279#ifdef GL_GLEXT_PROTOTYPES
280GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
281GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
282GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
283GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
284GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
285#endif
286#endif /* GL_VERSION_1_5 */
287#ifndef GL_VERSION_2_0
288typedef char GLchar;
289typedef khronos_int16_t GLshort;
290typedef khronos_int8_t GLbyte;
291typedef khronos_uint16_t GLushort;
292#define GL_BLEND_EQUATION_RGB 0x8009
293#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
294#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
295#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
296#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
297#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
298#define GL_BLEND_EQUATION_ALPHA 0x883D
299#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
300#define GL_FRAGMENT_SHADER 0x8B30
301#define GL_VERTEX_SHADER 0x8B31
302#define GL_COMPILE_STATUS 0x8B81
303#define GL_LINK_STATUS 0x8B82
304#define GL_INFO_LOG_LENGTH 0x8B84
305#define GL_CURRENT_PROGRAM 0x8B8D
306#define GL_UPPER_LEFT 0x8CA2
307typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
308typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
309typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
310typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
311typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
312typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
313typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
314typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
315typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
316typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
317typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
318typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
319typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
320typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
321typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
322typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
323typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
324typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
325typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
326typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
327typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
328typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
329typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
330typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
331typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
332#ifdef GL_GLEXT_PROTOTYPES
333GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
334GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
335GLAPI void APIENTRY glCompileShader (GLuint shader);
336GLAPI GLuint APIENTRY glCreateProgram (void);
337GLAPI GLuint APIENTRY glCreateShader (GLenum type);
338GLAPI void APIENTRY glDeleteProgram (GLuint program);
339GLAPI void APIENTRY glDeleteShader (GLuint shader);
340GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
341GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
342GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
343GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
344GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
345GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
346GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
347GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
348GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
349GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
350GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
351GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
352GLAPI void APIENTRY glLinkProgram (GLuint program);
353GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
354GLAPI void APIENTRY glUseProgram (GLuint program);
355GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
356GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
357GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
358#endif
359#endif /* GL_VERSION_2_0 */
360#ifndef GL_VERSION_2_1
361#define GL_PIXEL_UNPACK_BUFFER 0x88EC
362#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF
363#endif /* GL_VERSION_2_1 */
364#ifndef GL_VERSION_3_0
365typedef khronos_uint16_t GLhalf;
366#define GL_MAJOR_VERSION 0x821B
367#define GL_MINOR_VERSION 0x821C
368#define GL_NUM_EXTENSIONS 0x821D
369#define GL_FRAMEBUFFER_SRGB 0x8DB9
370#define GL_VERTEX_ARRAY_BINDING 0x85B5
371typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
372typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
373typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
374typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
375typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
376typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
377#ifdef GL_GLEXT_PROTOTYPES
378GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
379GLAPI void APIENTRY glBindVertexArray (GLuint array);
380GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
381GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
382#endif
383#endif /* GL_VERSION_3_0 */
384#ifndef GL_VERSION_3_1
385#define GL_VERSION_3_1 1
386#define GL_PRIMITIVE_RESTART 0x8F9D
387#endif /* GL_VERSION_3_1 */
388#ifndef GL_VERSION_3_2
389#define GL_VERSION_3_2 1
390typedef struct __GLsync *GLsync;
391typedef khronos_uint64_t GLuint64;
392typedef khronos_int64_t GLint64;
393#define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
394#define GL_CONTEXT_PROFILE_MASK 0x9126
395typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
396typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
397#ifdef GL_GLEXT_PROTOTYPES
398GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
399#endif
400#endif /* GL_VERSION_3_2 */
401#ifndef GL_VERSION_3_3
402#define GL_VERSION_3_3 1
403#define GL_SAMPLER_BINDING 0x8919
404typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers);
405typedef void (APIENTRYP PFNGLDELETESAMPLERSPROC) (GLsizei count, const GLuint *samplers);
406typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
407typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIPROC) (GLuint sampler, GLenum pname, GLint param);
408#ifdef GL_GLEXT_PROTOTYPES
409GLAPI void APIENTRY glGenSamplers (GLsizei count, GLuint *samplers);
410GLAPI void APIENTRY glDeleteSamplers (GLsizei count, const GLuint *samplers);
411GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
412GLAPI void APIENTRY glSamplerParameteri (GLuint sampler, GLenum pname, GLint param);
413#endif
414#endif /* GL_VERSION_3_3 */
415#ifndef GL_VERSION_4_1
416typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
417typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
418#endif /* GL_VERSION_4_1 */
419#ifndef GL_VERSION_4_3
420typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
421#endif /* GL_VERSION_4_3 */
422#ifndef GL_VERSION_4_5
423#define GL_CLIP_ORIGIN 0x935C
424typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
425typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
426#endif /* GL_VERSION_4_5 */
427#ifndef GL_ARB_bindless_texture
428typedef khronos_uint64_t GLuint64EXT;
429#endif /* GL_ARB_bindless_texture */
430#ifndef GL_ARB_cl_event
431struct _cl_context;
432struct _cl_event;
433#endif /* GL_ARB_cl_event */
434#ifndef GL_ARB_clip_control
435#define GL_ARB_clip_control 1
436#endif /* GL_ARB_clip_control */
437#ifndef GL_ARB_debug_output
438typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
439#endif /* GL_ARB_debug_output */
440#ifndef GL_EXT_EGL_image_storage
441typedef void *GLeglImageOES;
442#endif /* GL_EXT_EGL_image_storage */
443#ifndef GL_EXT_direct_state_access
444typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
445typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
446typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
447typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
448typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
449#endif /* GL_EXT_direct_state_access */
450#ifndef GL_NV_draw_vulkan_image
451typedef void (APIENTRY *GLVULKANPROCNV)(void);
452#endif /* GL_NV_draw_vulkan_image */
453#ifndef GL_NV_gpu_shader5
454typedef khronos_int64_t GLint64EXT;
455#endif /* GL_NV_gpu_shader5 */
456#ifndef GL_NV_vertex_buffer_unified_memory
457typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
458#endif /* GL_NV_vertex_buffer_unified_memory */
459#ifdef __cplusplus
460}
461#endif
462#endif
463
464#ifndef GL3W_API
465#define GL3W_API
466#endif
467
468#ifndef __gl_h_
469#define __gl_h_
470#endif
471
472#ifdef __cplusplus
473extern "C" {
474#endif
475
476#define GL3W_OK 0
477#define GL3W_ERROR_INIT -1
478#define GL3W_ERROR_LIBRARY_OPEN -2
479#define GL3W_ERROR_OPENGL_VERSION -3
480
481typedef void (*GL3WglProc)(void);
482typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
483
484/* gl3w api */
485GL3W_API int imgl3wInit(void);
486GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
487GL3W_API void imgl3wShutdown(void);
488GL3W_API int imgl3wIsSupported(int major, int minor);
489GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
490
491/* gl3w internal state */
492union ImGL3WProcs {
493 GL3WglProc ptr[63];
494 struct {
495 PFNGLACTIVETEXTUREPROC ActiveTexture;
496 PFNGLATTACHSHADERPROC AttachShader;
497 PFNGLBINDBUFFERPROC BindBuffer;
498 PFNGLBINDSAMPLERPROC BindSampler;
499 PFNGLBINDTEXTUREPROC BindTexture;
500 PFNGLBINDVERTEXARRAYPROC BindVertexArray;
501 PFNGLBLENDEQUATIONPROC BlendEquation;
502 PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
503 PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
504 PFNGLBUFFERDATAPROC BufferData;
505 PFNGLBUFFERSUBDATAPROC BufferSubData;
506 PFNGLCLEARPROC Clear;
507 PFNGLCLEARCOLORPROC ClearColor;
508 PFNGLCOMPILESHADERPROC CompileShader;
509 PFNGLCREATEPROGRAMPROC CreateProgram;
510 PFNGLCREATESHADERPROC CreateShader;
511 PFNGLDELETEBUFFERSPROC DeleteBuffers;
512 PFNGLDELETEPROGRAMPROC DeleteProgram;
513 PFNGLDELETESAMPLERSPROC DeleteSamplers;
514 PFNGLDELETESHADERPROC DeleteShader;
515 PFNGLDELETETEXTURESPROC DeleteTextures;
516 PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
517 PFNGLDETACHSHADERPROC DetachShader;
518 PFNGLDISABLEPROC Disable;
519 PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
520 PFNGLDRAWELEMENTSPROC DrawElements;
521 PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
522 PFNGLENABLEPROC Enable;
523 PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
524 PFNGLFLUSHPROC Flush;
525 PFNGLGENBUFFERSPROC GenBuffers;
526 PFNGLGENSAMPLERSPROC GenSamplers;
527 PFNGLGENTEXTURESPROC GenTextures;
528 PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
529 PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
530 PFNGLGETERRORPROC GetError;
531 PFNGLGETINTEGERVPROC GetIntegerv;
532 PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
533 PFNGLGETPROGRAMIVPROC GetProgramiv;
534 PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
535 PFNGLGETSHADERIVPROC GetShaderiv;
536 PFNGLGETSTRINGPROC GetString;
537 PFNGLGETSTRINGIPROC GetStringi;
538 PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
539 PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
540 PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
541 PFNGLISENABLEDPROC IsEnabled;
542 PFNGLISPROGRAMPROC IsProgram;
543 PFNGLLINKPROGRAMPROC LinkProgram;
544 PFNGLPIXELSTOREIPROC PixelStorei;
545 PFNGLPOLYGONMODEPROC PolygonMode;
546 PFNGLREADPIXELSPROC ReadPixels;
547 PFNGLSAMPLERPARAMETERIPROC SamplerParameteri;
548 PFNGLSCISSORPROC Scissor;
549 PFNGLSHADERSOURCEPROC ShaderSource;
550 PFNGLTEXIMAGE2DPROC TexImage2D;
551 PFNGLTEXPARAMETERIPROC TexParameteri;
552 PFNGLTEXSUBIMAGE2DPROC TexSubImage2D;
553 PFNGLUNIFORM1IPROC Uniform1i;
554 PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
555 PFNGLUSEPROGRAMPROC UseProgram;
556 PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
557 PFNGLVIEWPORTPROC Viewport;
558 } gl;
559};
560
561GL3W_API extern union ImGL3WProcs imgl3wProcs;
562
563/* OpenGL functions */
564#define glActiveTexture imgl3wProcs.gl.ActiveTexture
565#define glAttachShader imgl3wProcs.gl.AttachShader
566#define glBindBuffer imgl3wProcs.gl.BindBuffer
567#define glBindSampler imgl3wProcs.gl.BindSampler
568#define glBindTexture imgl3wProcs.gl.BindTexture
569#define glBindVertexArray imgl3wProcs.gl.BindVertexArray
570#define glBlendEquation imgl3wProcs.gl.BlendEquation
571#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
572#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
573#define glBufferData imgl3wProcs.gl.BufferData
574#define glBufferSubData imgl3wProcs.gl.BufferSubData
575#define glClear imgl3wProcs.gl.Clear
576#define glClearColor imgl3wProcs.gl.ClearColor
577#define glCompileShader imgl3wProcs.gl.CompileShader
578#define glCreateProgram imgl3wProcs.gl.CreateProgram
579#define glCreateShader imgl3wProcs.gl.CreateShader
580#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
581#define glDeleteProgram imgl3wProcs.gl.DeleteProgram
582#define glDeleteSamplers imgl3wProcs.gl.DeleteSamplers
583#define glDeleteShader imgl3wProcs.gl.DeleteShader
584#define glDeleteTextures imgl3wProcs.gl.DeleteTextures
585#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
586#define glDetachShader imgl3wProcs.gl.DetachShader
587#define glDisable imgl3wProcs.gl.Disable
588#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
589#define glDrawElements imgl3wProcs.gl.DrawElements
590#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
591#define glEnable imgl3wProcs.gl.Enable
592#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
593#define glFlush imgl3wProcs.gl.Flush
594#define glGenBuffers imgl3wProcs.gl.GenBuffers
595#define glGenSamplers imgl3wProcs.gl.GenSamplers
596#define glGenTextures imgl3wProcs.gl.GenTextures
597#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
598#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
599#define glGetError imgl3wProcs.gl.GetError
600#define glGetIntegerv imgl3wProcs.gl.GetIntegerv
601#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
602#define glGetProgramiv imgl3wProcs.gl.GetProgramiv
603#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
604#define glGetShaderiv imgl3wProcs.gl.GetShaderiv
605#define glGetString imgl3wProcs.gl.GetString
606#define glGetStringi imgl3wProcs.gl.GetStringi
607#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
608#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
609#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
610#define glIsEnabled imgl3wProcs.gl.IsEnabled
611#define glIsProgram imgl3wProcs.gl.IsProgram
612#define glLinkProgram imgl3wProcs.gl.LinkProgram
613#define glPixelStorei imgl3wProcs.gl.PixelStorei
614#define glPolygonMode imgl3wProcs.gl.PolygonMode
615#define glReadPixels imgl3wProcs.gl.ReadPixels
616#define glSamplerParameteri imgl3wProcs.gl.SamplerParameteri
617#define glScissor imgl3wProcs.gl.Scissor
618#define glShaderSource imgl3wProcs.gl.ShaderSource
619#define glTexImage2D imgl3wProcs.gl.TexImage2D
620#define glTexParameteri imgl3wProcs.gl.TexParameteri
621#define glTexSubImage2D imgl3wProcs.gl.TexSubImage2D
622#define glUniform1i imgl3wProcs.gl.Uniform1i
623#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
624#define glUseProgram imgl3wProcs.gl.UseProgram
625#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
626#define glViewport imgl3wProcs.gl.Viewport
627
628#ifdef __cplusplus
629}
630#endif
631
632#endif
633
634#ifdef IMGL3W_IMPL
635#ifdef __cplusplus
636extern "C" {
637#endif
638
639#include <stdlib.h>
640
641#define GL3W_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
642
643#if defined(_WIN32)
644#ifndef WIN32_LEAN_AND_MEAN
645#define WIN32_LEAN_AND_MEAN 1
646#endif
647#include <windows.h>
648
649static HMODULE libgl = NULL;
650typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
651static GL3WglGetProcAddr wgl_get_proc_address;
652
653static int open_libgl(void)
654{
655 libgl = LoadLibraryA("opengl32.dll");
656 if (!libgl)
657 return GL3W_ERROR_LIBRARY_OPEN;
658 wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
659 return GL3W_OK;
660}
661
662static void close_libgl(void) { FreeLibrary(libgl); libgl = NULL; }
663static GL3WglProc get_proc(const char *proc)
664{
665 GL3WglProc res;
666 res = (GL3WglProc)wgl_get_proc_address(proc);
667 if (!res)
668 res = (GL3WglProc)GetProcAddress(libgl, proc);
669 return res;
670}
671#elif defined(__APPLE__)
672#include <dlfcn.h>
673
674static void *libgl = NULL;
675static int open_libgl(void)
676{
677 libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
678 if (!libgl)
679 return GL3W_ERROR_LIBRARY_OPEN;
680 return GL3W_OK;
681}
682
683static void close_libgl(void) { dlclose(libgl); libgl = NULL; }
684
685static GL3WglProc get_proc(const char *proc)
686{
687 GL3WglProc res;
688 *(void **)(&res) = dlsym(libgl, proc);
689 return res;
690}
691#else
692#include <dlfcn.h>
693
694static void* libgl; // OpenGL library
695static void* libglx; // GLX library
696static void* libegl; // EGL library
697static GL3WGetProcAddressProc gl_get_proc_address;
698
699static void close_libgl(void)
700{
701 if (libgl) {
702 dlclose(libgl);
703 libgl = NULL;
704 }
705 if (libegl) {
706 dlclose(libegl);
707 libegl = NULL;
708 }
709 if (libglx) {
710 dlclose(libglx);
711 libglx = NULL;
712 }
713}
714
715static int is_library_loaded(const char* name, void** lib)
716{
717#if defined(__HAIKU__)
718 *lib = NULL; // no support for RTLD_NOLOAD on Haiku.
719#else
720 *lib = dlopen(name, RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
721#endif
722 return *lib != NULL;
723}
724
725static int open_libs(void)
726{
727 // On Linux we have two APIs to get process addresses: EGL and GLX.
728 // EGL is supported under both X11 and Wayland, whereas GLX is X11-specific.
729
730 libgl = NULL;
731 libegl = NULL;
732 libglx = NULL;
733
734 // First check what's already loaded, the windowing library might have
735 // already loaded either EGL or GLX and we want to use the same one.
736
737 if (is_library_loaded("libEGL.so.1", &libegl) ||
738 is_library_loaded("libGLX.so.0", &libglx)) {
739 libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
740 if (libgl)
741 return GL3W_OK;
742 else
743 close_libgl();
744 }
745
746 if (is_library_loaded("libGL.so", &libgl))
747 return GL3W_OK;
748 if (is_library_loaded("libGL.so.1", &libgl))
749 return GL3W_OK;
750 if (is_library_loaded("libGL.so.3", &libgl))
751 return GL3W_OK;
752
753 // Neither is already loaded, so we have to load one. Try EGL first
754 // because it is supported under both X11 and Wayland.
755
756 // Load OpenGL + EGL
757 libgl = dlopen("libOpenGL.so.0", RTLD_LAZY | RTLD_LOCAL);
758 libegl = dlopen("libEGL.so.1", RTLD_LAZY | RTLD_LOCAL);
759 if (libgl && libegl)
760 return GL3W_OK;
761 else
762 close_libgl();
763
764 // Fall back to legacy libGL, which includes GLX
765 // While most systems use libGL.so.1, NetBSD seems to use that libGL.so.3. See https://github.com/ocornut/imgui/issues/6983
766 libgl = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
767 if (!libgl)
768 libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
769 if (!libgl)
770 libgl = dlopen("libGL.so.3", RTLD_LAZY | RTLD_LOCAL);
771
772 if (libgl)
773 return GL3W_OK;
774
775 return GL3W_ERROR_LIBRARY_OPEN;
776}
777
778static int open_libgl(void)
779{
780 int res = open_libs();
781 if (res)
782 return res;
783
784 if (libegl)
785 *(void**)(&gl_get_proc_address) = dlsym(libegl, "eglGetProcAddress");
786 else if (libglx)
787 *(void**)(&gl_get_proc_address) = dlsym(libglx, "glXGetProcAddressARB");
788 else
789 *(void**)(&gl_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
790
791 if (!gl_get_proc_address) {
792 close_libgl();
793 return GL3W_ERROR_LIBRARY_OPEN;
794 }
795
796 return GL3W_OK;
797}
798
799static GL3WglProc get_proc(const char* proc)
800{
801 GL3WglProc res = NULL;
802
803 // Before EGL version 1.5, eglGetProcAddress doesn't support querying core
804 // functions and may return a dummy function if we try, so try to load the
805 // function from the GL library directly first.
806 if (libegl)
807 *(void**)(&res) = dlsym(libgl, proc);
808
809 if (!res)
810 res = gl_get_proc_address(proc);
811
812 if (!libegl && !res)
813 *(void**)(&res) = dlsym(libgl, proc);
814
815 return res;
816}
817#endif
818
819static struct { int major, minor; } version;
820
821static int parse_version(void)
822{
823 if (!glGetIntegerv)
824 return GL3W_ERROR_INIT;
825 glGetIntegerv(GL_MAJOR_VERSION, &version.major);
826 glGetIntegerv(GL_MINOR_VERSION, &version.minor);
827 if (version.major == 0 && version.minor == 0)
828 {
829 // Query GL_VERSION in desktop GL 2.x, the string will start with "<major>.<minor>"
830 if (const char* gl_version = (const char*)glGetString(GL_VERSION))
831 sscanf(gl_version, "%d.%d", &version.major, &version.minor);
832 }
833 if (version.major < 2)
834 return GL3W_ERROR_OPENGL_VERSION;
835 return GL3W_OK;
836}
837
838static void load_procs(GL3WGetProcAddressProc proc);
839static void clear_procs();
840
841int imgl3wInit(void)
842{
843 int res = open_libgl();
844 if (res)
845 return res;
846 atexit(close_libgl);
847 return imgl3wInit2(get_proc);
848}
849
850int imgl3wInit2(GL3WGetProcAddressProc proc)
851{
852 load_procs(proc);
853 return parse_version();
854}
855
856void imgl3wShutdown(void)
857{
858 close_libgl();
859 clear_procs();
860}
861
862int imgl3wIsSupported(int major, int minor)
863{
864 if (major < 2)
865 return 0;
866 if (version.major == major)
867 return version.minor >= minor;
868 return version.major >= major;
869}
870
871GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
872
873static const char *proc_names[] = {
874 "glActiveTexture",
875 "glAttachShader",
876 "glBindBuffer",
877 "glBindSampler",
878 "glBindTexture",
879 "glBindVertexArray",
880 "glBlendEquation",
881 "glBlendEquationSeparate",
882 "glBlendFuncSeparate",
883 "glBufferData",
884 "glBufferSubData",
885 "glClear",
886 "glClearColor",
887 "glCompileShader",
888 "glCreateProgram",
889 "glCreateShader",
890 "glDeleteBuffers",
891 "glDeleteProgram",
892 "glDeleteSamplers",
893 "glDeleteShader",
894 "glDeleteTextures",
895 "glDeleteVertexArrays",
896 "glDetachShader",
897 "glDisable",
898 "glDisableVertexAttribArray",
899 "glDrawElements",
900 "glDrawElementsBaseVertex",
901 "glEnable",
902 "glEnableVertexAttribArray",
903 "glFlush",
904 "glGenBuffers",
905 "glGenSamplers",
906 "glGenTextures",
907 "glGenVertexArrays",
908 "glGetAttribLocation",
909 "glGetError",
910 "glGetIntegerv",
911 "glGetProgramInfoLog",
912 "glGetProgramiv",
913 "glGetShaderInfoLog",
914 "glGetShaderiv",
915 "glGetString",
916 "glGetStringi",
917 "glGetUniformLocation",
918 "glGetVertexAttribPointerv",
919 "glGetVertexAttribiv",
920 "glIsEnabled",
921 "glIsProgram",
922 "glLinkProgram",
923 "glPixelStorei",
924 "glPolygonMode",
925 "glReadPixels",
926 "glSamplerParameteri",
927 "glScissor",
928 "glShaderSource",
929 "glTexImage2D",
930 "glTexParameteri",
931 "glTexSubImage2D",
932 "glUniform1i",
933 "glUniformMatrix4fv",
934 "glUseProgram",
935 "glVertexAttribPointer",
936 "glViewport",
937};
938
939GL3W_API union ImGL3WProcs imgl3wProcs;
940
941static void load_procs(GL3WGetProcAddressProc proc)
942{
943 size_t i;
944 for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
945 imgl3wProcs.ptr[i] = proc(proc_names[i]);
946}
947
948static void clear_procs()
949{
950 size_t i;
951 for (i = 0; i < GL3W_ARRAY_SIZE(proc_names); i++)
952 imgl3wProcs.ptr[i] = nullptr;
953}
954
955#ifdef __cplusplus
956}
957#endif
958#endif