Repository navigation
Add an OpenGL ES 3.0 backend that draws into a host framebuffer - #10
Merged
Merged
Conversation
A host that already renders with OpenGL ES, such as a Qt Quick application with a QQuickFramebufferObject, had to share Vulkan images with its GL context to show a chart. `-Dgpu=gles` now builds the library with an OpenGL ES 3.0 backend. It draws the same prepared scene as the other backends, with the same vertex streams, blend state, draw order and batcher. The host attaches its current context with the new kind CHARTTABLE_NATIVE_GLES_CONTEXT and a charttable_gles_context, which carries the host's get_proc_address. The library loads every GL function through it and links no GL library. charttable_render_gles draws into a framebuffer the host names, at the size the host gives. charttable_render draws into the framebuffer bound for drawing. charttable creates no window, no EGL surface and no context, and it never swaps buffers. Every call that issues GL commands saves the state it changes and restores it before it returns. The backend needs no depth attachment. No pipeline of the Vulkan backend writes depth, so its depth test only refuses depth 1.0, which no range uses. makeScene runs on the build worker, where the host's context is not current. In this backend it copies the scene to CPU memory, and adoptScene makes the GL objects on the owner thread. With kind CHARTTABLE_NATIVE_NONE the backend opens libEGL at run time and makes a headless context of its own, for snapshots and for the tests. attach_surface now refuses a kind the backend does not know with CHARTTABLE_ERR_UNSUPPORTED, where it converted it with @enumFromInt. The shaders are GLSL ES 3.00 ports of shaders/vk, in shaders/gles. A CI job builds and tests the backend with Mesa through a headless EGL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
A build with
-Dgpu=glesdraws through OpenGL ES 3.0, into a framebuffer of a context the host owns. This is the integration the issue asks for: a Qt Quick host with aQQuickFramebufferObjectgives its current context and its framebuffer, and charttable draws the chart there. The layout, the scene, the batcher and the CPU side stay as they are. The backend is one more implementation of theGpuAPI behindsrc/gpu/gpu.zig.What changed
src/gpu/gpu_gles.zigis the new backend. It draws the same prepared scene as the Vulkan backend: the same vertex streams, blend state, draw order and batcher. It has the fill, pattern, sprite and SDF programs. Raster tiles ride the sprite program, as in the other backends.shaders/gles/holds GLSL ES 3.00 ports ofshaders/vk/. The context compiles them at attach.prelude.glsldeclares the uniform block and the per-draw uniforms once for every stage.include/charttable.h,src/capi.zig):CHARTTABLE_NATIVE_GLES_CONTEXT(11) with acharttable_gles_context, which carries the host'sget_proc_addressand a user pointer.charttable_render_gles(ct, &(charttable_gles_target){fbo, w, h})draws into that framebuffer. The size of the target becomes the pixel size of the frame, so a resized framebuffer needs only a new target.charttable_renderon a GLES surface draws into the framebuffer that is bound for drawing.charttable_snapshot_rgbadraws into a framebuffer of its own and leaves the host's alone.build.zig:-Dgpu=gleson any target off Apple.shaders/gles/README.md, and aglesCI job.How the requirements in the issue are met
charttable_render_glestakes the size from its target. Callcharttable_resizetoo, for the viewport in points.makeScenecopies the scene to CPU memory, andadoptScenemakes the GL objects on the owner thread.Choices to review
-Dgpu=vkis on Windows. One library holds one backend, so the released archives do not change. A Linux host that wants GLES builds with-Dgpu=gles.CHARTTABLE_NATIVE_NONEthe GLES build opens libEGL at run time (surfaceless Mesa first, then the default display) and makes a headless context, for snapshots and tests. On Windows the Zig standard library cannot open a shared library, so there only a host context works.charttable_attach_surfacenow returnsCHARTTABLE_ERR_UNSUPPORTEDfor a kind the backend does not know. Before,@enumFromInton such a kind was undefined behaviour. This is how a Vulkan build refuses the new kind.GpuAPI that the rest of the library calls.How it was tested
zig build test -Dgpu=gles: 235 pass, 18 skip, 0 fail. The GPU tests draw through a headless EGL context. The new tests check:charttable_attach_surfacewith a host loader,charttable_render_glesinto the host's framebuffer with its binding restored, and a snapshot that leaves the host's pixels alone.zig build teston the default Vulkan backend: 231 pass, 18 skip, 0 fail. The new C ABI test checks that Vulkan refuses the kind.zig fmt --check src/ build/ build.zigpasses.zig build lib shared -Dgpu=glesbuilds for x86_64-linux-gnu, aarch64-linux-gnu, x86_64-windows-gnu and aarch64-windows-gnu. The default backend still builds for aarch64-linux-gnu and x86_64-windows-gnu.-Wall -Werror.crt1.ohas.sframerelocations that the Zig 0.16 linker rejects. The same happens onmainbefore this change. I ran the builds with-Dtarget=x86_64-linux-gnuto work around it, and the Vulkan tests also needed--search-prefix /usr. CI is not affected.