12 #ifndef GL_COMMON_NO_GLAD
13 #include "glad/glad.h"
15 #ifndef GLFW_INCLUDE_NONE
16 #define GLFW_INCLUDE_NONE
19 typedef unsigned int GLuint;
21 typedef unsigned int GLenum;
23 typedef float GLfloat;
24 typedef unsigned char GLboolean;
25 typedef long GLsizeiptr;
26 typedef long GLintptr;
28 typedef unsigned long long GLuint64;
30 typedef unsigned int GLbitfield;
34 #define GL_TEXTURE_2D 0x0DE1
35 #define GL_TEXTURE_MIN_FILTER 0x2801
36 #define GL_TEXTURE_MAG_FILTER 0x2800
37 #define GL_TEXTURE_WRAP_S 0x2802
38 #define GL_TEXTURE_WRAP_T 0x2803
39 #define GL_TEXTURE_WIDTH 0x1000
40 #define GL_TEXTURE_HEIGHT 0x1001
41 #define GL_TEXTURE_INTERNAL_FORMAT 0x1003
42 #define GL_LINEAR 0x2601
43 #define GL_LINEAR_MIPMAP_LINEAR 0x2703
44 #define GL_CLAMP_TO_EDGE 0x812F
45 #define GL_REPEAT 0x2901
46 #define GL_RGBA32F 0x8814
47 #define GL_RGBA16F 0x881A
48 #define GL_RGBA 0x1908
49 #define GL_FLOAT 0x1406
50 #define GL_HALF_FLOAT 0x140B
51 #define GL_UNSIGNED_BYTE 0x1401
52 #define GL_UNSIGNED_INT 0x1405
53 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
54 #define GL_STREAM_DRAW 0x88E0
55 #define GL_WRITE_ONLY 0x88B9
56 #define GL_UNPACK_ALIGNMENT 0x0CF5
58 #define GL_DEBUG_SOURCE_APPLICATION 0x824A
60 #define GL_MAP_UNSYNCHRONIZED_BIT 0x0020
61 #define GL_MAP_WRITE_BIT 0x0010
62 #define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008
63 #define GL_TIMESTAMP 0x8E28
64 #define GL_QUERY_RESULT 0x8866
65 #define GL_QUERY_RESULT_AVAILABLE 0x8867
66 #define GL_TIME_ELAPSED 0x88BF
69 GLenum glGetError(
void);
70 void glGenTextures(GLsizei n, GLuint* ids);
71 void glBindTexture(GLenum target, GLuint
id);
72 void glPixelStorei(GLenum pname, GLint param);
73 void glTexStorage2D(GLenum target, GLsizei levels, GLenum internalformat,
74 GLsizei width, GLsizei height);
75 void glTexImage2D(GLenum t, GLint l, GLint i, GLsizei w, GLsizei h, GLint b,
76 GLenum f, GLenum ty,
const void* p);
77 void glTexSubImage2D(GLenum t, GLint l, GLint x, GLint y, GLsizei w, GLsizei h,
78 GLenum f, GLenum ty,
const void* p);
79 void glTexParameteri(GLenum target, GLenum pname, GLint param);
80 void glGenerateMipmap(GLenum target);
81 void glDeleteTextures(GLsizei n,
const GLuint* ids);
82 void glActiveTexture(GLenum texture);
83 void glGenBuffers(GLsizei n, GLuint* buffers);
84 void glBindBuffer(GLenum target, GLuint buffer);
85 void glBufferData(GLenum target, GLsizeiptr size,
const void* data,
87 void glDeleteBuffers(GLsizei n,
const GLuint* buffers);
88 void* glMapBuffer(GLenum target, GLenum access);
89 void* glMapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length,
91 GLboolean glUnmapBuffer(GLenum target);
92 void glGetTexLevelParameteriv(GLenum target, GLint level, GLenum pname,
94 void glGenQueries(GLsizei n, GLuint* ids);
95 void glDeleteQueries(GLsizei n,
const GLuint* ids);
96 void glQueryCounter(GLuint
id, GLenum target);
97 void glGetQueryObjectiv(GLuint
id, GLenum pname, GLint* params);
98 void glGetQueryObjectui64v(GLuint
id, GLenum pname, GLuint64* params);
101 void glUseProgram(GLuint program);
102 void glPopDebugGroup(
void);
103 void glPushDebugGroup(GLenum source, GLuint
id, GLsizei length,
104 const GLchar* message);
107 #ifndef GL_COMMON_NO_GLFW
108 #include <GLFW/glfw3.h>
146 #define GL_UBO_ALIGNED __attribute__((aligned(GL_UBO_ALIGNMENT)))
153 #define GL_ASSERT_UBO_ALIGNMENT(type) \
154 _Static_assert(_Alignof(type) >= GL_UBO_ALIGNMENT, \
155 #type " must be >= 32-byte aligned for AVX (cglm)")
161 #define GL_DEBUG_PUSH(name) \
162 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name)
165 #define GL_DEBUG_POP() glPopDebugGroup()
180 #define GL_SCOPE_DEBUG_GROUP(name) \
181 glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); \
182 const char* _gl_dbg_##__LINE__ \
183 __attribute__((cleanup(cleanup_gl_debug_group))) \
184 __attribute__((unused)) = name
200 #define GL_SCOPE_USE_PROGRAM(prog) \
201 glUseProgram(prog); \
202 GLuint _gl_prog_##__LINE__ \
203 __attribute__((cleanup(cleanup_gl_use_program))) \
204 __attribute__((unused)) = prog
213 glDeleteTextures(1, tex);
218 #define CLEANUP_TEXTURE __attribute__((cleanup(cleanup_gl_texture)))
226 #define GL_SAFE_DELETE_TEXTURE(tex) \
229 glDeleteTextures(1, &(tex)); \
234 #define GL_SAFE_DELETE_BUFFER(buf) \
237 glDeleteBuffers(1, &(buf)); \
242 #define GL_SAFE_DELETE_BUFFERS(count, ids) \
244 if ((ids) != NULL) { \
245 glDeleteBuffers(count, ids); \
246 for (int i = 0; i < (count); i++) { \
252 #define GL_SAFE_DELETE_VAO(vao) \
255 glDeleteVertexArrays(1, &(vao)); \
260 #define GL_SAFE_DELETE_VAOS(count, vaos) \
262 if ((vaos) != NULL) { \
263 glDeleteVertexArrays(count, vaos); \
264 for (int i = 0; i < (count); i++) { \
270 #define GL_SAFE_DELETE_PROGRAM(prog) \
273 glDeleteProgram(prog); \
278 #define GL_SAFE_DELETE_FRAMEBUFFER(fbo) \
281 glDeleteFramebuffers(1, &(fbo)); \
@ SIMD_ALIGNMENT
Definition: gl_common.h:131
@ GL_UBO_ALIGNMENT
Definition: gl_common.h:140
static void cleanup_gl_texture(GLuint *tex)
RAII-style cleanup for OpenGL textures. Deletes the texture if the handle is non-zero.
Definition: gl_common.h:210
@ INSTANCE_ATTR_START
Definition: gl_common.h:117
@ MAX_VERTEX_ATTRIBS_BASELINE
Definition: gl_common.h:114
@ SYNC_ATTR_START
Definition: gl_common.h:121
static void cleanup_gl_debug_group(const char **dummy)
RAII-style cleanup for OpenGL debug groups.
Definition: gl_common.h:170
@ SCREEN_QUAD_VERTEX_COUNT
Definition: gl_common.h:125
static void cleanup_gl_use_program(const GLuint *dummy)
RAII-style cleanup for OpenGL shader program binding.
Definition: gl_common.h:189