Capabilities API
Declared in include/metagl/Capabilities.hpp. After calling
metagl::Initialize(), the Capabilities API lets you query which
OpenGL ES and WebGL feature sets the current context supports.
Overview
meta-gl reads GL_VERSION, GL_VENDOR, GL_RENDERER,
GL_SHADING_LANGUAGE_VERSION, and enumerates GL_EXTENSIONS
during initialization. The results are cached in a Capabilities struct.
You can read this struct at any time without making additional GL calls.
Capabilities Struct
struct Capabilities { std::string version_string; std::string vendor; std::string renderer; std::string shading_language_version; std::vector<std::string> extensions; bool gles20 = false; // true for ES 2.0 or higher bool gles30 = false; // true for ES 3.0 or higher bool gles31 = false; // true for ES 3.1 or higher bool gles32 = false; // true for ES 3.2 or higher // Only meaningful when compiled with Emscripten: bool webgl1 = false; bool webgl2 = false; };
Note: Version flags are cumulative. If gles32 == true, then
gles31, gles30, and gles20 are all also true.
Query Functions
| Function | Returns | Description |
|---|---|---|
GetCapabilities() |
const Capabilities& |
Full capabilities struct, valid after Initialize() |
SupportsGLES20() |
bool |
True if context is ES 2.0+ |
SupportsGLES30() |
bool |
True if context is ES 3.0+ |
SupportsGLES31() |
bool |
True if context is ES 3.1+ |
SupportsGLES32() |
bool |
True if context is ES 3.2+ |
SupportsWebGL2() |
bool |
True when on WebGL 2 (Emscripten only) |
HasExtension(name) |
bool |
True if the named extension is present |
All functions are [[nodiscard]] and noexcept.
Extension Queries
// Check for a specific extension: if (metagl::HasExtension("GL_EXT_texture_filter_anisotropic")) { // enable anisotropic filtering } // Iterate all extensions: const auto& caps = metagl::GetCapabilities(); for (const auto& ext : caps.extensions) { std::cout << ext << "\n"; } // Print driver info: std::cout << "Vendor: " << caps.vendor << "\n"; std::cout << "Renderer: " << caps.renderer << "\n"; std::cout << "Version: " << caps.version_string << "\n";
Usage Patterns
Feature-gating at startup
metagl::Initialize(loader); const auto& caps = metagl::GetCapabilities(); bool canCompute = caps.gles31; bool canGeomShader = caps.gles32; bool hasFloatTex = caps.gles30 || metagl::HasExtension("GL_OES_texture_float");
Adaptive quality
if (metagl::SupportsGLES30()) { useTexStorage(); // immutable storage, ES3+ } else { useTexImage(); // mutable storage, ES2 } if (metagl::HasExtension("GL_EXT_texture_compression_s3tc")) { loadDXT1Textures(); } else if (metagl::SupportsGLES30()) { loadETC2Textures(); // required in ES3 } else { loadRGBATextures(); // fallback }
OpenGL ES Version Matrix
| ES version | Key new features | Flag |
|---|---|---|
| 2.0 | Vertex + fragment shaders, VBOs, textures, framebuffers (basic) | gles20 |
| 3.0 | VAOs, UBOs, transform feedback, MSAA FBOs, ETC2/EAC textures, integer formats, 3D textures, instancing, sync objects, queries | gles30 |
| 3.1 | Compute shaders, SSBOs, atomic counters, image load/store, indirect draw/dispatch, separate shader programs, vertex binding API | gles31 |
| 3.2 | Geometry shaders, tessellation, ASTC textures, robust context, debug output, draw indirect with base vertex, layered FBOs | gles32 |