Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/opengl_api.h

The OpenGL entry points, loaded by hand, and the three platform halves of a GL surface: WGL on Windows, NSOpenGLContext on macOS, GLX on X11.

#include <sonore/gfx/opengl_api.h>
On this page

Design notes

Why there is no GLEW and no glad

The SDK is header-only and vendors nothing it can avoid, and a loader is a table of function pointers and a lookup per entry -- a few hundred lines, not a dependency. More to the point, a plugin is a guest in a host process that may have loaded its OWN GL loader, with its own globals, and a second copy of GLEW's global function table is a link-time collision waiting for the right host. So the table here is a struct, owned by each context and loaded when that context is created, and nothing in it is global.

Why nothing links opengl32 / OpenGL.framework / libGL

Each is opened at RUNTIME, the same rule window_x11.h follows for libX11. A plugin that hard-links libGL fails to LOAD on a render farm without one, and fails with a loader error -- the least diagnosable failure a plugin can have. Opened at runtime, the plugin loads, OpenGLContext::attachTo returns false, and lastError() says which library was missing.

What a caller gets

The GL type names (GLuint, GLenum, ...) at global scope, exactly as the Khronos headers declare them, so a file that also includes <GL/gl.h> sees the same typedef twice, which C++ allows. The GL_* constants as macros, each guarded and spelled exactly as the Khronos headers spell it, so the same file sees an identical redefinition rather than a conflicting one. And the functions as members of OpenGLFunctions, reached through the context:

auto& gl = context.functions();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClear(GL_COLOR_BUFFER_BIT);

Members rather than free functions because a free glClear here would be ambiguous against the one <GL/gl.h> declares in any file that has both.

The platform surfaces

Each is a CHILD of the editor's own window or view, placed over the component the context is attached to. A separate native surface rather than GL drawn into the editor's window, because the editor's window is a GDI / CoreGraphics / XPutImage blit of the software-rasterised bitmap, and mixing that with a GL swap chain in one window is undefined on all three platforms. The child is transparent to the mouse, so the component tree under it still receives every click exactly as it did.

Windows is RUN by sdk/tests/opengl_test.cpp on real hardware. The macOS and X11 halves are compiled only -- against the Apple shims in tests/au_shim and against real Xlib headers -- and have not executed on any machine here.

Types 2

What the surface's pixels are made of.

multisamplingLevel only takes effect when the context's multisampling is enabled -- the two are separate so a plugin can offer an anti-aliasing toggle without rebuilding its format. When the driver cannot give the requested samples, the context falls back to none rather than failing: jagged edges are a worse picture, a black rectangle is no picture.

The GL entry points of one context, and what that context turned out to be.

Every pointer starts null and is resolved by load(). A null pointer is the library saying the driver lacks that function, and the feature flags below are derived from the VERSION rather than from non-null pointers alone: glXGetProcAddressARB returns a non-null stub for any name at all, so on X11 a pointer is not proof of anything.

Enums 1

Macros 1

↑↓ to move↵ to openEvery public name in the headers, and every guide