Common OpenGL definitions, RAII helpers, and utilities.
More...
#include "glad/glad.h"
#include <GLFW/glfw3.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Common OpenGL definitions, RAII helpers, and utilities.
This header ensures correct inclusion order for GLAD and GLFW, and provides C-style RAII macros using the __cleanup__ attribute.
◆ CLEANUP_TEXTURE
Attribute to automatically delete an OpenGL texture on scope exit.
◆ GL_ASSERT_UBO_ALIGNMENT
| #define GL_ASSERT_UBO_ALIGNMENT |
( |
|
type | ) |
|
Value:
#type " must be >= 32-byte aligned for AVX (cglm)")
@ GL_UBO_ALIGNMENT
Definition: gl_common.h:140
_Static_assert(_Alignof(PostProcessUBO) >=GL_UBO_ALIGNMENT, "PostProcessUBO" " must be >= 32-byte aligned for AVX (cglm)")
Compile-time assertion that a UBO struct meets AVX alignment. Place after the typedef to catch misconfigurations at build time.
- Parameters
-
| type | The UBO struct type name. |
◆ GL_DEBUG_POP
| #define GL_DEBUG_POP |
( |
| ) |
glPopDebugGroup() |
Pops the current debug group.
◆ GL_DEBUG_PUSH
| #define GL_DEBUG_PUSH |
( |
|
name | ) |
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name) |
Pushes a debug group to the OpenGL command stream for debugging tools.
- Parameters
-
| name | String label for the group. |
◆ GL_SAFE_DELETE_BUFFER
| #define GL_SAFE_DELETE_BUFFER |
( |
|
buf | ) |
|
Value: do { \
if ((buf) != 0) { \
glDeleteBuffers(1, &(buf)); \
(buf) = 0; \
} \
} while (0)
◆ GL_SAFE_DELETE_BUFFERS
| #define GL_SAFE_DELETE_BUFFERS |
( |
|
count, |
|
|
|
ids |
|
) |
| |
Value: do { \
if ((ids) != NULL) { \
glDeleteBuffers(count, ids); \
for (int i = 0; i < (count); i++) { \
(ids)[i] = 0; \
} \
} \
} while (0)
◆ GL_SAFE_DELETE_FRAMEBUFFER
| #define GL_SAFE_DELETE_FRAMEBUFFER |
( |
|
fbo | ) |
|
Value: do { \
if ((fbo) != 0) { \
glDeleteFramebuffers(1, &(fbo)); \
(fbo) = 0; \
} \
} while (0)
◆ GL_SAFE_DELETE_PROGRAM
| #define GL_SAFE_DELETE_PROGRAM |
( |
|
prog | ) |
|
Value: do { \
if ((prog) != 0) { \
glDeleteProgram(prog); \
(prog) = 0; \
} \
} while (0)
◆ GL_SAFE_DELETE_TEXTURE
| #define GL_SAFE_DELETE_TEXTURE |
( |
|
tex | ) |
|
Value: do { \
if ((tex) != 0) { \
glDeleteTextures(1, &(tex)); \
(tex) = 0; \
} \
} while (0)
Idempotent OpenGL resource deletion macros. These macros check if the resource handle is non-zero, delete the resource, and set the handle to 0 to prevent double-deletion.
◆ GL_SAFE_DELETE_VAO
| #define GL_SAFE_DELETE_VAO |
( |
|
vao | ) |
|
Value: do { \
if ((vao) != 0) { \
glDeleteVertexArrays(1, &(vao)); \
(vao) = 0; \
} \
} while (0)
◆ GL_SAFE_DELETE_VAOS
| #define GL_SAFE_DELETE_VAOS |
( |
|
count, |
|
|
|
vaos |
|
) |
| |
Value: do { \
if ((vaos) != NULL) { \
glDeleteVertexArrays(count, vaos); \
for (int i = 0; i < (count); i++) { \
(vaos)[i] = 0; \
} \
} \
} while (0)
◆ GL_SCOPE_DEBUG_GROUP
| #define GL_SCOPE_DEBUG_GROUP |
( |
|
name | ) |
|
Value: glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, name); \
const char* _gl_dbg_##__LINE__ \
__attribute__((unused)) = name
static void cleanup_gl_debug_group(const char **dummy)
RAII-style cleanup for OpenGL debug groups.
Definition: gl_common.h:170
Scoped OpenGL debug group. Automatically pops when leaving scope.
- Parameters
-
◆ GL_SCOPE_USE_PROGRAM
| #define GL_SCOPE_USE_PROGRAM |
( |
|
prog | ) |
|
Value: glUseProgram(prog); \
GLuint _gl_prog_##__LINE__ \
__attribute__((unused)) = prog
static void cleanup_gl_use_program(const GLuint *dummy)
RAII-style cleanup for OpenGL shader program binding.
Definition: gl_common.h:189
Scoped shader program binding. Unbinds (glUseProgram(0)) when leaving scope.
- Parameters
-
◆ GL_UBO_ALIGNED
Attribute to apply on UBO typedef to enforce AVX alignment. Usage: } GL_UBO_ALIGNED MyUBOType;.
◆ anonymous enum
Starting index for instanced vertex attributes.
| Enumerator |
|---|
| INSTANCE_ATTR_START | |
◆ anonymous enum
Starting index for synchronization vertex attributes (motion blur).
| Enumerator |
|---|
| SYNC_ATTR_START | |
◆ anonymous enum
Number of vertices in a standard screen-filling quad (2 triangles).
| Enumerator |
|---|
| SCREEN_QUAD_VERTEX_COUNT | |
◆ anonymous enum
Memory alignment for SIMD/AVX (64-byte is AVX-512 safe and L1 cache line aligned).
◆ anonymous enum
Required alignment for UBO structs used with cglm (AVX mat4 ops).
cglm's glm_mat4_copy uses AVX _mm256_store_ps which requires 32-byte alignment. Any UBO struct containing mat4 (float[16]) fields must be tagged with GL_UBO_ALIGNED to guarantee safe stack/heap allocation.
| Enumerator |
|---|
| GL_UBO_ALIGNMENT | |
◆ anonymous enum
Minimum number of vertex attributes guaranteed by OpenGL 3.3+.
| Enumerator |
|---|
| MAX_VERTEX_ATTRIBS_BASELINE | |
◆ cleanup_gl_debug_group()
| static void cleanup_gl_debug_group |
( |
const char ** |
dummy | ) |
|
|
inlinestatic |
RAII-style cleanup for OpenGL debug groups.
◆ cleanup_gl_texture()
| static void cleanup_gl_texture |
( |
GLuint * |
tex | ) |
|
|
inlinestatic |
RAII-style cleanup for OpenGL textures. Deletes the texture if the handle is non-zero.
◆ cleanup_gl_use_program()
| static void cleanup_gl_use_program |
( |
const GLuint * |
dummy | ) |
|
|
inlinestatic |
RAII-style cleanup for OpenGL shader program binding.