Types Reference

Types are declared in include/metagl/Types.hpp. meta-gl re-exports the standard OpenGL ES primitive types from GLES3/gl32.h into the metagl namespace so calling code does not need to include any GL headers directly.

GL Primitive Types

These are simple using declarations that bring the GL types into metagl::.

metagl typeUnderlying typeTypical use
GLbitfieldunsigned intBitfield parameters (e.g. glClear)
GLbooleanunsigned charBoolean return values
GLbytesigned char8-bit signed vertex data
GLcharcharShader source / info log strings
GLclampffloatClamped [0,1] float parameters
GLenumunsigned intBase type for all GL enumerations
GLfixedint (16.16 fixed)Legacy fixed-point values
GLfloatfloatMost numeric GL parameters
GLhalfunsigned short16-bit IEEE half-float
GLintintGeneral integer parameters
GLint64long long64-bit state queries (ES3+)
GLintptrptrdiff_tBuffer byte offsets
GLshortshort16-bit signed vertex data
GLsizeiintNon-negative sizes and counts
GLsizeiptrptrdiff_tBuffer sizes in bytes
GLsyncstruct __GLsync*Fence sync handle
GLubyteunsigned charString returns, colour components
GLuintunsigned intObject names (textures, buffers, etc.)
GLuint64unsigned long longTimeout values, 64-bit queries
GLushortunsigned short16-bit unsigned index data
GLvoidvoidAlias for void
GLDEBUGPROCfunction pointerDebug message callback type

GetProcAddress Type

// In Types.hpp:
using GlGetProcAddressFn = void* (*)(const char* name);

// In Loader.hpp (alias for API ergonomics):
using GetProcAddress = GlGetProcAddressFn;

This is the type that must be passed to metagl::Initialize(). Any callable that returns a function pointer given a GL function name satisfies this type.

Lightweight Handle Structs

meta-gl defines thin wrapper structs around raw GLuint names to prevent accidentally passing a texture handle where a buffer handle is expected. These structs own nothing — they contain no destructor and no reference counting.

namespace metagl {

struct TextureId  { GLuint value{}; };
struct BufferId   { GLuint value{}; };
struct ShaderId   { GLuint value{}; };
struct ProgramId  { GLuint value{}; };
struct FramebufferId { GLuint value{}; };
struct RenderbufferId { GLuint value{}; };
struct VertexArrayId { GLuint value{}; };
struct SamplerId  { GLuint value{}; };

} // namespace metagl

Usage

// Create a texture and wrap it in a typed handle:
GLuint raw;
metagl::glGenTextures(1, &raw);
metagl::TextureId tex{ raw };

// Now tex.value carries the GLuint. It is just data — no lifetime management:
metagl::glBindTexture(metagl::TextureTarget::Texture2D, tex.value);

// When you're done, delete explicitly (as in raw OpenGL):
metagl::glDeleteTextures(1, &tex.value);
// RAII deletion belongs in easy-gl, not here.

Why Handle Structs Instead of GLuint?

Without handles

GLuint tex = 0, buf = 0;
glGenTextures(1, &tex);
glGenBuffers(1, &buf);
// Oops — compiles fine:
glBindTexture(GL_TEXTURE_2D, buf);

With handles

TextureId tex;
BufferId  buf;
metagl::glGenTextures(1, &tex.value);
metagl::glGenBuffers(1, &buf.value);
// type system helps catch swaps

EnumNames.hpp

include/metagl/EnumNames.hpp contains generated to_string() overloads for every enumerator in every enum class. The return type is std::string_view. Unknown values return "?".

#include <metagl/EnumNames.hpp>

metagl::BufferTarget t = metagl::BufferTarget::Array;
std::string_view name = metagl::to_string(t);
// name == "Array"

metagl::ShaderType st = metagl::ShaderType::Vertex;
std::string_view sname = metagl::to_string(st);
// sname == "Vertex"

This is used by the debug logger to print human-readable argument names instead of raw integer values.