Avara3D 0.2.0
C++ API reference
GLTypes.h
1//
2// GLTypes.h
3// avara3d
4//
5// Created by Morgan Davis on 12/31/25.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_RENDER_BACKEND_OPENGL_GLTYPES_H
10#define AVARA3D_RENDER_BACKEND_OPENGL_GLTYPES_H
11
12#include <cstdint>
13#include <cstddef> // std::ptrdiff_t
14
15namespace a3d::gl {
16
17 using enum_t = std::uint32_t; // GLenum
18 using uint_t = std::uint32_t; // GLuint
19 using int_t = std::int32_t; // GLint
20 using sizei_t = std::int32_t; // GLsizei
21 using boolean_t = std::uint8_t; // GLboolean
22 using bitfield_t = std::uint32_t; // GLbitfield
23
24 using sizeiptr_t = std::ptrdiff_t; // GLsizeiptr
25 using intptr_t = std::ptrdiff_t; // GLintptr
26
27 using char_t = char; // GLchar
28 using float_t = float; // GLfloat
29 using double_t = double; // GLdouble
30
31 using int64_t = std::int64_t; // GLint64
32 using uint64_t = std::uint64_t; // GLuint64
33
34 namespace value {
35
36 constexpr enum_t false_ = 0u;
37 constexpr enum_t true_ = 1u;
38
39 constexpr enum_t unsigned_byte = 0x1401u; // GL_UNSIGNED_BYTE
40 constexpr enum_t unsigned_short = 0x1403u; // GL_UNSIGNED_SHORT
41 constexpr enum_t unsigned_int = 0x1405u; // GL_UNSIGNED_INT
42 constexpr enum_t float32 = 0x1406u; // GL_FLOAT
43
44 constexpr enum_t invalid_index = 0xFFFFFFFFu; // GL_INVALID_INDEX
45 constexpr uint_t null_handle = 0u; // “0” object name
46
47 }
48
49 enum class index_type : enum_t {
50 u8 = value::unsigned_byte,
51 u16 = value::unsigned_short,
52 u32 = value::unsigned_int,
53 };
54
55 // helpers
56 template<class E>
57 constexpr enum_t raw(E e) noexcept {
58 return static_cast<enum_t>(e);
59 }
60
61 constexpr boolean_t gl_bool(bool b) noexcept {
62 return b ? static_cast<boolean_t>(value::true_) : static_cast<boolean_t>(value::false_);
63 }
64
65 // strong-typed handles (zero-cost)
66 template<class Tag>
67 struct handle {
68 uint_t id = value::null_handle;
69
70 constexpr explicit operator bool() const noexcept {
71 return id != value::null_handle;
72 }
73
74 friend constexpr bool operator==(handle, handle) = default;
75 };
76
77 struct buffer_tag {};
78
79 struct texture_tag {};
80
81 struct vao_tag {};
82
83 struct program_tag {};
84
85 struct shader_tag {};
86
87 struct framebuffer_tag {};
88
89 using buffer = handle<buffer_tag>;
90 using texture = handle<texture_tag>;
91 using vao = handle<vao_tag>;
92 using program = handle<program_tag>;
93 using shader = handle<shader_tag>;
94 using framebuffer = handle<framebuffer_tag>;
95
96}
97
98#endif // AVARA3D_RENDER_BACKEND_OPENGL_GLTYPES_H