
Recall first from Memory, synchronisation, and validation layers
- A VkBuffer describes a resource and VkDeviceMemory supplies its backing storage.
- Host visibility and device locality can coexist in a single memory type.
- Pipeline barriers express execution and memory dependencies, semaphores coordinate queue operations, and fences report completion to the host.
From vertices to pixels with OpenGL ES
3 min readYou learned Vulkan compute. Now the graphics side, and this lesson answers how OpenGL ES and EGL create contexts and present frames.
An embedded dashboard can render a correctly coloured speed indicator into a buffer while the panel keeps showing the old value. Producing new pixels and displaying them are separate operations. Linux DRM/KMS documents the display side in terms of framebuffers and the display hardware that reads them. In a windowed session, the application submits its buffer to the native window system, which handles the application window's contribution to the screen. Linux kernel mode setting documentation
OpenGL ES 3.x is the embedded graphics API in the OpenGL family. It shares concepts and many function names with desktop OpenGL, including shader programs, vertex buffers, textures, and framebuffers. A desktop GL program may still need changes to its shader sources, context request, and feature checks. An OpenGL ES 3.0 shader uses #version 300 es, for example, and a fragment shader that uses floating-point types needs suitable precision declarations, such as precision mediump float;. Features also vary within ES 3.x. Compute shaders entered the core API in ES 3.1, so software targeting ES 3.0 cannot require them. Once a context is current, glGetString(GL_VERSION) reports the actual client API version. Check the returned string before using it and choose features supported by that context.
Consider drawing a textured triangle for the dashboard. Each vertex supplies a position and a pair of texture coordinates. The program uploads these values into a A vertex buffer object, or VBO, is an OpenGL buffer used to hold vertex data. A vertex array object, or VAO, records how each enabled vertex attribute reads that data. Its state describes details such as the source buffer, component count, stride between vertices, and byte offset of the attribute. If positions and texture coordinates are interleaved, both attributes can refer to the same VBO at different offsets. The application can bind the prepared VAO on subsequent draws while the layout stays the same.
The application compiles a vertex shader and a fragment shader, checks their compile status, and links them into a program. Check the link status before using the program. During a draw, the vertex shader reads the position and texture coordinates. It writes the transformed position to gl_Position in clip coordinates and passes the texture coordinates onward. Primitive assembly groups the vertices into a triangle. After clipping and viewport transformation, rasterization determines which framebuffer locations the triangle covers and interpolates the texture coordinates for the resulting fragments.
A texture stores image data that a shader can sample. The application binds the texture to a texture unit and sets the shader's sampler uniform to that unit's index. The fragment shader uses the interpolated coordinates to sample the image and writes a colour output. Framebuffer operations such as depth testing and blending can affect the final stored result. The framebuffer receives the resulting pixels. For direct drawing to an EGL window surface, use framebuffer zero, the default framebuffer. An application-created framebuffer can instead render into a texture for a later draw.
Create an EGL context and make it current
3 min readEGL setup starts with the native platform. On X11, the application or its toolkit opens a connection to the X server. On Wayland, it connects to the compositor. The application obtains an An EGLDisplay is an EGL handle for a native display connection or another supported platform instance. It identifies where EGL resources are created and can exist without a corresponding physical monitor. eglGetPlatformDisplay can select the platform explicitly when the implementation supports the requested platform. Initialize the resulting display with eglInitialize before choosing configurations from it.
Select OpenGL ES with eglBindAPI(EGL_OPENGL_ES_API) on the thread that will create the context. Ask eglChooseConfig for an EGLConfig whose attributes include EGL_WINDOW_BIT under EGL_SURFACE_TYPE and EGL_OPENGL_ES3_BIT under EGL_RENDERABLE_TYPE. Request the colour channels and any depth buffer the drawing needs. Check both the function's success result and the number of matching configs. A successful search can return zero matches. The config describes the buffers and the rendering APIs that can use them. A context created from the config holds rendering state, such as the current shader program and bindings.
The application creates the native window through its platform or toolkit. On X11, the X window needs a visual compatible with the chosen EGL config. Use EGL_NATIVE_VISUAL_ID to identify the matching X visual when selecting the window's attributes. Under Wayland, a client creates a wl_surface, configures it as a window through the shell protocol, and supplies a wl_egl_window wrapper for EGL. The Wayland client must handle initial window configuration before submitting a buffer. Toolkits can perform these steps while exposing a window or a ready-to-use rendering context to the application.
With a suitable config and a native window, eglCreatePlatformWindowSurface creates the EGLSurface for the platform display. Create the context with eglCreateContext. In EGL 1.5, EGL_CONTEXT_MAJOR_VERSION and EGL_CONTEXT_MINOR_VERSION can request an ES 3.0 context. Pass EGL_NO_CONTEXT for the share context when this context is created without sharing GL objects with another one. The context and surface can be created in either order once their prerequisites exist. Then call eglMakeCurrent with the display, the window surface as both draw and read surface, and the context. The calling thread can now issue GL commands. A context can be current on only one thread at a time, so release it on its old thread before binding it on a different one.
Check each result before the next dependent call. A failed display, context, or surface creation returns its corresponding EGL_NO_DISPLAY, EGL_NO_CONTEXT, or EGL_NO_SURFACE handle. Boolean EGL operations report failure with EGL_FALSE. On failure, capture eglGetError() on the same thread immediately and record the failed call alongside it. This distinguishes failure to initialize a native platform from failure to create a compatible surface or bind a context. On shutdown, release the current binding with eglMakeCurrent using EGL_NO_SURFACE for both surfaces and EGL_NO_CONTEXT for the context. Destroy the EGL surface and context, then terminate the EGL display with eglTerminate. Keep the native window alive while its EGL surface is in use.
Submit a frame to the window system
3 min readWith the window surface current, bind framebuffer zero for the window draw. Set the viewport to the drawable's pixel dimensions and update it when those dimensions change. Clear the colour buffer, bind the linked program, VAO, and textures, then issue the draw, for example with glDrawArrays. Call eglSwapBuffers(display, surface) with the EGL window surface. The call implicitly flushes the current context's client API commands when the surface is bound to that context. For a back-buffered window surface, it submits the rendered colour buffer to the native window system for presentation.
The new pixels become visible when the window system presents them. A successful swap can return before that happens. The display refresh and window system scheduling determine when the window's contents appear. eglSwapInterval requests a minimum number of video frame periods per swap for the current draw surface, subject to the config's supported limits. Swap can block, for example when the implementation needs to wait for an available buffer. Timing the call measures time spent in that call. Measuring when the panel first shows the changed pixels requires evidence of presentation beyond that call's return time.
For a frame loop that works with ordinary window surfaces, clear and redraw the complete frame after every swap. The colour buffer contents available for the next draw depend on the surface's swap behaviour. Preservation requires support and the appropriate setting. If only the speed indicator changes, a full redraw still supplies the background, scale markings, and indicator to whichever buffer is available next. If the swap returns EGL_FALSE, capture the EGL error and check which display and surface were passed before treating the frame as submitted.
On X11, EGL integrates with the X window system. A compositing window manager may also be involved in displaying the window. On Wayland, clients submit buffers and the compositor controls how window contents appear on screen. Both paths let the application use the same ES drawing calls and an EGL window swap, with platform-specific window setup and event handling.
A headless process can produce pixels without a desktop or monitor. With a supported offscreen EGL platform, it may use a pbuffer, an EGL surface allocated for offscreen rendering, or a surfaceless context with an application-created framebuffer. A pbuffer requires a config supporting EGL_PBUFFER_BIT. Calling eglSwapBuffers on a pbuffer has no effect. A surfaceless binding needs implementation support, and rendering in that case needs an application-created framebuffer because there is no default framebuffer to draw into.
Direct display on embedded Linux uses DRM/KMS to configure display output and present buffers. A DRM render node provides rendering access without granting modesetting access. An EGL context that can render through such a node therefore establishes rendering capability, while placing pixels on a connected display uses the display-control path. DRM userspace API documentation
If a display stops updating, which result would you check first to distinguish a thread with no current context from a frame that failed to reach the window system? Follow the results of eglMakeCurrent and eglSwapBuffers in order. The next lesson, Headless EGL and DRM/KMS, follows the buffer beyond this windowed setup and explains how to render without a desktop and how DRM/KMS presents directly to a display.
Key takeaways
- OpenGL ES executes draws using the context current on the calling thread.
- The native platform creates the window and EGL creates the rendering surface associated with it.
- A successful window-surface swap submits the rendered buffer to the native window system.
- Offscreen rendering can produce an image without presenting it on a display.
Reflect
- Explain to a colleague, in two sentences: identify the roles of vertex shaders, fragment shaders, VBOs, VAOs, and textures in an OpenGL ES draw.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- SpecificationEGL reference pages: eglGetPlatformDisplay
- SpecificationOpenGL ES 3 reference pages
- Kernel documentationdrm-kms: kernel mode setting
- Kernel documentationDRM userspace API: device nodes and render nodes
Official documentation first. Links checked when the lesson was published.