• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Regenerate with:
13 //   python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
14 //
15 // More info:
16 //   https://github.com/dearimgui/gl3w_stripped
17 //   https://github.com/ocornut/imgui/issues/4445
18 //-----------------------------------------------------------------------------
19 
20 /*
21  * This file was generated with gl3w_gen.py, part of imgl3w
22  * (hosted at https://github.com/dearimgui/gl3w_stripped)
23  *
24  * This is free and unencumbered software released into the public domain.
25  *
26  * Anyone is free to copy, modify, publish, use, compile, sell, or
27  * distribute this software, either in source code form or as a compiled
28  * binary, for any purpose, commercial or non-commercial, and by any
29  * means.
30  *
31  * In jurisdictions that recognize copyright laws, the author or authors
32  * of this software dedicate any and all copyright interest in the
33  * software to the public domain. We make this dedication for the benefit
34  * of the public at large and to the detriment of our heirs and
35  * successors. We intend this dedication to be an overt act of
36  * relinquishment in perpetuity of all present and future rights to this
37  * software under copyright law.
38  *
39  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
40  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
43  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
44  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
45  * OTHER DEALINGS IN THE SOFTWARE.
46  */
47 
48 #ifndef __gl3w_h_
49 #define __gl3w_h_
50 
51 // Adapted from KHR/khrplatform.h to avoid including entire file.
52 #ifndef __khrplatform_h_
53 typedef          float         khronos_float_t;
54 typedef signed   char          khronos_int8_t;
55 typedef unsigned char          khronos_uint8_t;
56 typedef signed   short int     khronos_int16_t;
57 typedef unsigned short int     khronos_uint16_t;
58 #ifdef _WIN64
59 typedef signed   long long int khronos_intptr_t;
60 typedef signed   long long int khronos_ssize_t;
61 #else
62 typedef signed   long  int     khronos_intptr_t;
63 typedef signed   long  int     khronos_ssize_t;
64 #endif
65 
66 #if defined(_MSC_VER) && !defined(__clang__)
67 typedef signed   __int64       khronos_int64_t;
68 typedef unsigned __int64       khronos_uint64_t;
69 #elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
70 #include <stdint.h>
71 typedef          int64_t       khronos_int64_t;
72 typedef          uint64_t      khronos_uint64_t;
73 #else
74 typedef signed   long long     khronos_int64_t;
75 typedef unsigned long long     khronos_uint64_t;
76 #endif
77 #endif  // __khrplatform_h_
78 
79 #ifndef __gl_glcorearb_h_
80 #define __gl_glcorearb_h_ 1
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 /*
85 ** Copyright 2013-2020 The Khronos Group Inc.
86 ** SPDX-License-Identifier: MIT
87 **
88 ** This header is generated from the Khronos OpenGL / OpenGL ES XML
89 ** API Registry. The current version of the Registry, generator scripts
90 ** used to make the header, and the header can be found at
91 **   https://github.com/KhronosGroup/OpenGL-Registry
92 */
93 #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
94 #ifndef WIN32_LEAN_AND_MEAN
95 #define WIN32_LEAN_AND_MEAN 1
96 #endif
97 #include <windows.h>
98 #endif
99 #ifndef APIENTRY
100 #define APIENTRY
101 #endif
102 #ifndef APIENTRYP
103 #define APIENTRYP APIENTRY *
104 #endif
105 #ifndef GLAPI
106 #define GLAPI extern
107 #endif
108 /* glcorearb.h is for use with OpenGL core profile implementations.
109 ** It should should be placed in the same directory as gl.h and
110 ** included as <GL/glcorearb.h>.
111 **
112 ** glcorearb.h includes only APIs in the latest OpenGL core profile
113 ** implementation together with APIs in newer ARB extensions which
114 ** can be supported by the core profile. It does not, and never will
115 ** include functionality removed from the core profile, such as
116 ** fixed-function vertex and fragment processing.
117 **
118 ** Do not #include both <GL/glcorearb.h> and either of <GL/gl.h> or
119 ** <GL/glext.h> in the same source file.
120 */
121 /* Generated C header for:
122  * API: gl
123  * Profile: core
124  * Versions considered: .*
125  * Versions emitted: .*
126  * Default extensions included: glcore
127  * Additional extensions included: _nomatch_^
128  * Extensions removed: _nomatch_^
129  */
130 #ifndef GL_VERSION_1_0
131 typedef void GLvoid;
132 typedef unsigned int GLenum;
133 
134 typedef khronos_float_t GLfloat;
135 typedef int GLint;
136 typedef int GLsizei;
137 typedef unsigned int GLbitfield;
138 typedef double GLdouble;
139 typedef unsigned int GLuint;
140 typedef unsigned char GLboolean;
141 typedef khronos_uint8_t GLubyte;
142 #define GL_COLOR_BUFFER_BIT               0x00004000
143 #define GL_FALSE                          0
144 #define GL_TRUE                           1
145 #define GL_TRIANGLES                      0x0004
146 #define GL_ONE                            1
147 #define GL_SRC_ALPHA                      0x0302
148 #define GL_ONE_MINUS_SRC_ALPHA            0x0303
149 #define GL_FRONT_AND_BACK                 0x0408
150 #define GL_POLYGON_MODE                   0x0B40
151 #define GL_CULL_FACE                      0x0B44
152 #define GL_DEPTH_TEST                     0x0B71
153 #define GL_STENCIL_TEST                   0x0B90
154 #define GL_VIEWPORT                       0x0BA2
155 #define GL_BLEND                          0x0BE2
156 #define GL_SCISSOR_BOX                    0x0C10
157 #define GL_SCISSOR_TEST                   0x0C11
158 #define GL_UNPACK_ROW_LENGTH              0x0CF2
159 #define GL_PACK_ALIGNMENT                 0x0D05
160 #define GL_TEXTURE_2D                     0x0DE1
161 #define GL_UNSIGNED_BYTE                  0x1401
162 #define GL_UNSIGNED_SHORT                 0x1403
163 #define GL_UNSIGNED_INT                   0x1405
164 #define GL_FLOAT                          0x1406
165 #define GL_RGBA                           0x1908
166 #define GL_FILL                           0x1B02
167 #define GL_VERSION                        0x1F02
168 #define GL_EXTENSIONS                     0x1F03
169 #define GL_LINEAR                         0x2601
170 #define GL_TEXTURE_MAG_FILTER             0x2800
171 #define GL_TEXTURE_MIN_FILTER             0x2801
172 typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
173 typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
174 typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
175 typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
176 typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
177 typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
178 typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
179 typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
180 typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
181 typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
182 typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
183 typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
184 typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
185 typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
186 typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
187 #ifdef GL_GLEXT_PROTOTYPES
188 GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
189 GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
190 GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
191 GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
192 GLAPI void APIENTRY glClear (GLbitfield mask);
193 GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
194 GLAPI void APIENTRY glDisable (GLenum cap);
195 GLAPI void APIENTRY glEnable (GLenum cap);
196 GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
197 GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
198 GLAPI GLenum APIENTRY glGetError (void);
199 GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
200 GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
201 GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
202 GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
203 #endif
204 #endif /* GL_VERSION_1_0 */
205 #ifndef GL_VERSION_1_1
206 typedef khronos_float_t GLclampf;
207 typedef double GLclampd;
208 #define GL_TEXTURE_BINDING_2D             0x8069
209 typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
210 typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
211 typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
212 typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
213 #ifdef GL_GLEXT_PROTOTYPES
214 GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
215 GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
216 GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
217 GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
218 #endif
219 #endif /* GL_VERSION_1_1 */
220 #ifndef GL_VERSION_1_3
221 #define GL_TEXTURE0                       0x84C0
222 #define GL_ACTIVE_TEXTURE                 0x84E0
223 typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
224 #ifdef GL_GLEXT_PROTOTYPES
225 GLAPI void APIENTRY glActiveTexture (GLenum texture);
226 #endif
227 #endif /* GL_VERSION_1_3 */
228 #ifndef GL_VERSION_1_4
229 #define GL_BLEND_DST_RGB                  0x80C8
230 #define GL_BLEND_SRC_RGB                  0x80C9
231 #define GL_BLEND_DST_ALPHA                0x80CA
232 #define GL_BLEND_SRC_ALPHA                0x80CB
233 #define GL_FUNC_ADD                       0x8006
234 typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
235 typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
236 #ifdef GL_GLEXT_PROTOTYPES
237 GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
238 GLAPI void APIENTRY glBlendEquation (GLenum mode);
239 #endif
240 #endif /* GL_VERSION_1_4 */
241 #ifndef GL_VERSION_1_5
242 typedef khronos_ssize_t GLsizeiptr;
243 typedef khronos_intptr_t GLintptr;
244 #define GL_ARRAY_BUFFER                   0x8892
245 #define GL_ELEMENT_ARRAY_BUFFER           0x8893
246 #define GL_ARRAY_BUFFER_BINDING           0x8894
247 #define GL_STREAM_DRAW                    0x88E0
248 typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
249 typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
250 typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
251 typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
252 #ifdef GL_GLEXT_PROTOTYPES
253 GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
254 GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
255 GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
256 GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
257 #endif
258 #endif /* GL_VERSION_1_5 */
259 #ifndef GL_VERSION_2_0
260 typedef char GLchar;
261 typedef khronos_int16_t GLshort;
262 typedef khronos_int8_t GLbyte;
263 typedef khronos_uint16_t GLushort;
264 #define GL_BLEND_EQUATION_RGB             0x8009
265 #define GL_BLEND_EQUATION_ALPHA           0x883D
266 #define GL_FRAGMENT_SHADER                0x8B30
267 #define GL_VERTEX_SHADER                  0x8B31
268 #define GL_COMPILE_STATUS                 0x8B81
269 #define GL_LINK_STATUS                    0x8B82
270 #define GL_INFO_LOG_LENGTH                0x8B84
271 #define GL_CURRENT_PROGRAM                0x8B8D
272 #define GL_UPPER_LEFT                     0x8CA2
273 typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
274 typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
275 typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
276 typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
277 typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
278 typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
279 typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
280 typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
281 typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
282 typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
283 typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
284 typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
285 typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
286 typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
287 typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
288 typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
289 typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
290 typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
291 typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
292 typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
293 typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
294 #ifdef GL_GLEXT_PROTOTYPES
295 GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
296 GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
297 GLAPI void APIENTRY glCompileShader (GLuint shader);
298 GLAPI GLuint APIENTRY glCreateProgram (void);
299 GLAPI GLuint APIENTRY glCreateShader (GLenum type);
300 GLAPI void APIENTRY glDeleteProgram (GLuint program);
301 GLAPI void APIENTRY glDeleteShader (GLuint shader);
302 GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
303 GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
304 GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
305 GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
306 GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
307 GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
308 GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
309 GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
310 GLAPI void APIENTRY glLinkProgram (GLuint program);
311 GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
312 GLAPI void APIENTRY glUseProgram (GLuint program);
313 GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
314 GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
315 GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
316 #endif
317 #endif /* GL_VERSION_2_0 */
318 #ifndef GL_VERSION_3_0
319 typedef khronos_uint16_t GLhalf;
320 #define GL_MAJOR_VERSION                  0x821B
321 #define GL_MINOR_VERSION                  0x821C
322 #define GL_NUM_EXTENSIONS                 0x821D
323 #define GL_FRAMEBUFFER_SRGB               0x8DB9
324 #define GL_VERTEX_ARRAY_BINDING           0x85B5
325 typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
326 typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
327 typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
328 typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
329 typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
330 typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
331 #ifdef GL_GLEXT_PROTOTYPES
332 GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
333 GLAPI void APIENTRY glBindVertexArray (GLuint array);
334 GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
335 GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
336 #endif
337 #endif /* GL_VERSION_3_0 */
338 #ifndef GL_VERSION_3_1
339 #define GL_VERSION_3_1 1
340 #define GL_PRIMITIVE_RESTART              0x8F9D
341 #endif /* GL_VERSION_3_1 */
342 #ifndef GL_VERSION_3_2
343 #define GL_VERSION_3_2 1
344 typedef struct __GLsync *GLsync;
345 typedef khronos_uint64_t GLuint64;
346 typedef khronos_int64_t GLint64;
347 typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
348 typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
349 #ifdef GL_GLEXT_PROTOTYPES
350 GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
351 #endif
352 #endif /* GL_VERSION_3_2 */
353 #ifndef GL_VERSION_3_3
354 #define GL_VERSION_3_3 1
355 #define GL_SAMPLER_BINDING                0x8919
356 typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
357 #ifdef GL_GLEXT_PROTOTYPES
358 GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
359 #endif
360 #endif /* GL_VERSION_3_3 */
361 #ifndef GL_VERSION_4_1
362 typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
363 typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
364 #endif /* GL_VERSION_4_1 */
365 #ifndef GL_VERSION_4_3
366 typedef void (APIENTRY  *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
367 #endif /* GL_VERSION_4_3 */
368 #ifndef GL_VERSION_4_5
369 #define GL_CLIP_ORIGIN                    0x935C
370 typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
371 typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
372 #endif /* GL_VERSION_4_5 */
373 #ifndef GL_ARB_bindless_texture
374 typedef khronos_uint64_t GLuint64EXT;
375 #endif /* GL_ARB_bindless_texture */
376 #ifndef GL_ARB_cl_event
377 struct _cl_context;
378 struct _cl_event;
379 #endif /* GL_ARB_cl_event */
380 #ifndef GL_ARB_clip_control
381 #define GL_ARB_clip_control 1
382 #endif /* GL_ARB_clip_control */
383 #ifndef GL_ARB_debug_output
384 typedef void (APIENTRY  *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
385 #endif /* GL_ARB_debug_output */
386 #ifndef GL_EXT_EGL_image_storage
387 typedef void *GLeglImageOES;
388 #endif /* GL_EXT_EGL_image_storage */
389 #ifndef GL_EXT_direct_state_access
390 typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
391 typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
392 typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
393 typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
394 typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
395 #endif /* GL_EXT_direct_state_access */
396 #ifndef GL_NV_draw_vulkan_image
397 typedef void (APIENTRY  *GLVULKANPROCNV)(void);
398 #endif /* GL_NV_draw_vulkan_image */
399 #ifndef GL_NV_gpu_shader5
400 typedef khronos_int64_t GLint64EXT;
401 #endif /* GL_NV_gpu_shader5 */
402 #ifndef GL_NV_vertex_buffer_unified_memory
403 typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
404 #endif /* GL_NV_vertex_buffer_unified_memory */
405 #ifdef __cplusplus
406 }
407 #endif
408 #endif
409 
410 #ifndef GL3W_API
411 #define GL3W_API
412 #endif
413 
414 #ifndef __gl_h_
415 #define __gl_h_
416 #endif
417 
418 #ifdef __cplusplus
419 extern "C" {
420 #endif
421 
422 #define GL3W_OK 0
423 #define GL3W_ERROR_INIT -1
424 #define GL3W_ERROR_LIBRARY_OPEN -2
425 #define GL3W_ERROR_OPENGL_VERSION -3
426 
427 typedef void (*GL3WglProc)(void);
428 typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
429 
430 /* gl3w api */
431 GL3W_API int imgl3wInit(void);
432 GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
433 GL3W_API int imgl3wIsSupported(int major, int minor);
434 GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
435 
436 /* gl3w internal state */
437 union GL3WProcs {
438     GL3WglProc ptr[53];
439     struct {
440         PFNGLACTIVETEXTUREPROC           ActiveTexture;
441         PFNGLATTACHSHADERPROC            AttachShader;
442         PFNGLBINDBUFFERPROC              BindBuffer;
443         PFNGLBINDSAMPLERPROC             BindSampler;
444         PFNGLBINDTEXTUREPROC             BindTexture;
445         PFNGLBINDVERTEXARRAYPROC         BindVertexArray;
446         PFNGLBLENDEQUATIONPROC           BlendEquation;
447         PFNGLBLENDEQUATIONSEPARATEPROC   BlendEquationSeparate;
448         PFNGLBLENDFUNCSEPARATEPROC       BlendFuncSeparate;
449         PFNGLBUFFERDATAPROC              BufferData;
450         PFNGLCLEARPROC                   Clear;
451         PFNGLCLEARCOLORPROC              ClearColor;
452         PFNGLCOMPILESHADERPROC           CompileShader;
453         PFNGLCREATEPROGRAMPROC           CreateProgram;
454         PFNGLCREATESHADERPROC            CreateShader;
455         PFNGLDELETEBUFFERSPROC           DeleteBuffers;
456         PFNGLDELETEPROGRAMPROC           DeleteProgram;
457         PFNGLDELETESHADERPROC            DeleteShader;
458         PFNGLDELETETEXTURESPROC          DeleteTextures;
459         PFNGLDELETEVERTEXARRAYSPROC      DeleteVertexArrays;
460         PFNGLDETACHSHADERPROC            DetachShader;
461         PFNGLDISABLEPROC                 Disable;
462         PFNGLDRAWELEMENTSPROC            DrawElements;
463         PFNGLDRAWELEMENTSBASEVERTEXPROC  DrawElementsBaseVertex;
464         PFNGLENABLEPROC                  Enable;
465         PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
466         PFNGLGENBUFFERSPROC              GenBuffers;
467         PFNGLGENTEXTURESPROC             GenTextures;
468         PFNGLGENVERTEXARRAYSPROC         GenVertexArrays;
469         PFNGLGETATTRIBLOCATIONPROC       GetAttribLocation;
470         PFNGLGETERRORPROC                GetError;
471         PFNGLGETINTEGERVPROC             GetIntegerv;
472         PFNGLGETPROGRAMINFOLOGPROC       GetProgramInfoLog;
473         PFNGLGETPROGRAMIVPROC            GetProgramiv;
474         PFNGLGETSHADERINFOLOGPROC        GetShaderInfoLog;
475         PFNGLGETSHADERIVPROC             GetShaderiv;
476         PFNGLGETSTRINGPROC               GetString;
477         PFNGLGETSTRINGIPROC              GetStringi;
478         PFNGLGETUNIFORMLOCATIONPROC      GetUniformLocation;
479         PFNGLISENABLEDPROC               IsEnabled;
480         PFNGLLINKPROGRAMPROC             LinkProgram;
481         PFNGLPIXELSTOREIPROC             PixelStorei;
482         PFNGLPOLYGONMODEPROC             PolygonMode;
483         PFNGLREADPIXELSPROC              ReadPixels;
484         PFNGLSCISSORPROC                 Scissor;
485         PFNGLSHADERSOURCEPROC            ShaderSource;
486         PFNGLTEXIMAGE2DPROC              TexImage2D;
487         PFNGLTEXPARAMETERIPROC           TexParameteri;
488         PFNGLUNIFORM1IPROC               Uniform1i;
489         PFNGLUNIFORMMATRIX4FVPROC        UniformMatrix4fv;
490         PFNGLUSEPROGRAMPROC              UseProgram;
491         PFNGLVERTEXATTRIBPOINTERPROC     VertexAttribPointer;
492         PFNGLVIEWPORTPROC                Viewport;
493     } gl;
494 };
495 
496 GL3W_API extern union GL3WProcs imgl3wProcs;
497 
498 /* OpenGL functions */
499 #define glActiveTexture                  imgl3wProcs.gl.ActiveTexture
500 #define glAttachShader                   imgl3wProcs.gl.AttachShader
501 #define glBindBuffer                     imgl3wProcs.gl.BindBuffer
502 #define glBindSampler                    imgl3wProcs.gl.BindSampler
503 #define glBindTexture                    imgl3wProcs.gl.BindTexture
504 #define glBindVertexArray                imgl3wProcs.gl.BindVertexArray
505 #define glBlendEquation                  imgl3wProcs.gl.BlendEquation
506 #define glBlendEquationSeparate          imgl3wProcs.gl.BlendEquationSeparate
507 #define glBlendFuncSeparate              imgl3wProcs.gl.BlendFuncSeparate
508 #define glBufferData                     imgl3wProcs.gl.BufferData
509 #define glClear                          imgl3wProcs.gl.Clear
510 #define glClearColor                     imgl3wProcs.gl.ClearColor
511 #define glCompileShader                  imgl3wProcs.gl.CompileShader
512 #define glCreateProgram                  imgl3wProcs.gl.CreateProgram
513 #define glCreateShader                   imgl3wProcs.gl.CreateShader
514 #define glDeleteBuffers                  imgl3wProcs.gl.DeleteBuffers
515 #define glDeleteProgram                  imgl3wProcs.gl.DeleteProgram
516 #define glDeleteShader                   imgl3wProcs.gl.DeleteShader
517 #define glDeleteTextures                 imgl3wProcs.gl.DeleteTextures
518 #define glDeleteVertexArrays             imgl3wProcs.gl.DeleteVertexArrays
519 #define glDetachShader                   imgl3wProcs.gl.DetachShader
520 #define glDisable                        imgl3wProcs.gl.Disable
521 #define glDrawElements                   imgl3wProcs.gl.DrawElements
522 #define glDrawElementsBaseVertex         imgl3wProcs.gl.DrawElementsBaseVertex
523 #define glEnable                         imgl3wProcs.gl.Enable
524 #define glEnableVertexAttribArray        imgl3wProcs.gl.EnableVertexAttribArray
525 #define glGenBuffers                     imgl3wProcs.gl.GenBuffers
526 #define glGenTextures                    imgl3wProcs.gl.GenTextures
527 #define glGenVertexArrays                imgl3wProcs.gl.GenVertexArrays
528 #define glGetAttribLocation              imgl3wProcs.gl.GetAttribLocation
529 #define glGetError                       imgl3wProcs.gl.GetError
530 #define glGetIntegerv                    imgl3wProcs.gl.GetIntegerv
531 #define glGetProgramInfoLog              imgl3wProcs.gl.GetProgramInfoLog
532 #define glGetProgramiv                   imgl3wProcs.gl.GetProgramiv
533 #define glGetShaderInfoLog               imgl3wProcs.gl.GetShaderInfoLog
534 #define glGetShaderiv                    imgl3wProcs.gl.GetShaderiv
535 #define glGetString                      imgl3wProcs.gl.GetString
536 #define glGetStringi                     imgl3wProcs.gl.GetStringi
537 #define glGetUniformLocation             imgl3wProcs.gl.GetUniformLocation
538 #define glIsEnabled                      imgl3wProcs.gl.IsEnabled
539 #define glLinkProgram                    imgl3wProcs.gl.LinkProgram
540 #define glPixelStorei                    imgl3wProcs.gl.PixelStorei
541 #define glPolygonMode                    imgl3wProcs.gl.PolygonMode
542 #define glReadPixels                     imgl3wProcs.gl.ReadPixels
543 #define glScissor                        imgl3wProcs.gl.Scissor
544 #define glShaderSource                   imgl3wProcs.gl.ShaderSource
545 #define glTexImage2D                     imgl3wProcs.gl.TexImage2D
546 #define glTexParameteri                  imgl3wProcs.gl.TexParameteri
547 #define glUniform1i                      imgl3wProcs.gl.Uniform1i
548 #define glUniformMatrix4fv               imgl3wProcs.gl.UniformMatrix4fv
549 #define glUseProgram                     imgl3wProcs.gl.UseProgram
550 #define glVertexAttribPointer            imgl3wProcs.gl.VertexAttribPointer
551 #define glViewport                       imgl3wProcs.gl.Viewport
552 
553 #ifdef __cplusplus
554 }
555 #endif
556 
557 #endif
558 
559 #ifdef IMGL3W_IMPL
560 #ifdef __cplusplus
561 extern "C" {
562 #endif
563 
564 #include <stdlib.h>
565 
566 #define ARRAY_SIZE(x)  (sizeof(x) / sizeof((x)[0]))
567 
568 #if defined(_WIN32)
569 #ifndef WIN32_LEAN_AND_MEAN
570 #define WIN32_LEAN_AND_MEAN 1
571 #endif
572 #include <windows.h>
573 
574 static HMODULE libgl;
575 typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
576 static GL3WglGetProcAddr wgl_get_proc_address;
577 
open_libgl(void)578 static int open_libgl(void)
579 {
580     libgl = LoadLibraryA("opengl32.dll");
581     if (!libgl)
582         return GL3W_ERROR_LIBRARY_OPEN;
583     wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
584     return GL3W_OK;
585 }
586 
close_libgl(void)587 static void close_libgl(void) { FreeLibrary(libgl); }
get_proc(const char * proc)588 static GL3WglProc get_proc(const char *proc)
589 {
590     GL3WglProc res;
591     res = (GL3WglProc)wgl_get_proc_address(proc);
592     if (!res)
593         res = (GL3WglProc)GetProcAddress(libgl, proc);
594     return res;
595 }
596 #elif defined(__APPLE__)
597 #include <dlfcn.h>
598 
599 static void *libgl;
600 static int open_libgl(void)
601 {
602     libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
603     if (!libgl)
604         return GL3W_ERROR_LIBRARY_OPEN;
605     return GL3W_OK;
606 }
607 
608 static void close_libgl(void) { dlclose(libgl); }
609 
610 static GL3WglProc get_proc(const char *proc)
611 {
612     GL3WglProc res;
613     *(void **)(&res) = dlsym(libgl, proc);
614     return res;
615 }
616 #else
617 #include <dlfcn.h>
618 
619 static void *libgl;
620 static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
621 
622 static int open_libgl(void)
623 {
624     libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
625     if (!libgl)
626         return GL3W_ERROR_LIBRARY_OPEN;
627     *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
628     return GL3W_OK;
629 }
630 
631 static void close_libgl(void) { dlclose(libgl); }
632 
633 static GL3WglProc get_proc(const char *proc)
634 {
635     GL3WglProc res;
636     res = glx_get_proc_address((const GLubyte *)proc);
637     if (!res)
638         *(void **)(&res) = dlsym(libgl, proc);
639     return res;
640 }
641 #endif
642 
643 static struct { int major, minor; } version;
644 
parse_version(void)645 static int parse_version(void)
646 {
647     if (!glGetIntegerv)
648         return GL3W_ERROR_INIT;
649     glGetIntegerv(GL_MAJOR_VERSION, &version.major);
650     glGetIntegerv(GL_MINOR_VERSION, &version.minor);
651     if (version.major < 3)
652         return GL3W_ERROR_OPENGL_VERSION;
653     return GL3W_OK;
654 }
655 
656 static void load_procs(GL3WGetProcAddressProc proc);
657 
imgl3wInit(void)658 int imgl3wInit(void)
659 {
660     int res = open_libgl();
661     if (res)
662         return res;
663     atexit(close_libgl);
664     return imgl3wInit2(get_proc);
665 }
666 
imgl3wInit2(GL3WGetProcAddressProc proc)667 int imgl3wInit2(GL3WGetProcAddressProc proc)
668 {
669     load_procs(proc);
670     return parse_version();
671 }
672 
imgl3wIsSupported(int major,int minor)673 int imgl3wIsSupported(int major, int minor)
674 {
675     if (major < 3)
676         return 0;
677     if (version.major == major)
678         return version.minor >= minor;
679     return version.major >= major;
680 }
681 
imgl3wGetProcAddress(const char * proc)682 GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
683 
684 static const char *proc_names[] = {
685     "glActiveTexture",
686     "glAttachShader",
687     "glBindBuffer",
688     "glBindSampler",
689     "glBindTexture",
690     "glBindVertexArray",
691     "glBlendEquation",
692     "glBlendEquationSeparate",
693     "glBlendFuncSeparate",
694     "glBufferData",
695     "glClear",
696     "glClearColor",
697     "glCompileShader",
698     "glCreateProgram",
699     "glCreateShader",
700     "glDeleteBuffers",
701     "glDeleteProgram",
702     "glDeleteShader",
703     "glDeleteTextures",
704     "glDeleteVertexArrays",
705     "glDetachShader",
706     "glDisable",
707     "glDrawElements",
708     "glDrawElementsBaseVertex",
709     "glEnable",
710     "glEnableVertexAttribArray",
711     "glGenBuffers",
712     "glGenTextures",
713     "glGenVertexArrays",
714     "glGetAttribLocation",
715     "glGetError",
716     "glGetIntegerv",
717     "glGetProgramInfoLog",
718     "glGetProgramiv",
719     "glGetShaderInfoLog",
720     "glGetShaderiv",
721     "glGetString",
722     "glGetStringi",
723     "glGetUniformLocation",
724     "glIsEnabled",
725     "glLinkProgram",
726     "glPixelStorei",
727     "glPolygonMode",
728     "glReadPixels",
729     "glScissor",
730     "glShaderSource",
731     "glTexImage2D",
732     "glTexParameteri",
733     "glUniform1i",
734     "glUniformMatrix4fv",
735     "glUseProgram",
736     "glVertexAttribPointer",
737     "glViewport",
738 };
739 
740 GL3W_API union GL3WProcs imgl3wProcs;
741 
load_procs(GL3WGetProcAddressProc proc)742 static void load_procs(GL3WGetProcAddressProc proc)
743 {
744     size_t i;
745     for (i = 0; i < ARRAY_SIZE(proc_names); i++)
746         imgl3wProcs.ptr[i] = proc(proc_names[i]);
747 }
748 
749 #ifdef __cplusplus
750 }
751 #endif
752 #endif
753