Skip to content

New GL/GLES backend for jme (Work in progress)#2585

Draft
riccardobl wants to merge 6 commits intojMonkeyEngine:masterfrom
riccardobl:angle
Draft

New GL/GLES backend for jme (Work in progress)#2585
riccardobl wants to merge 6 commits intojMonkeyEngine:masterfrom
riccardobl:angle

Conversation

@riccardobl
Copy link
Copy Markdown
Member

@riccardobl riccardobl commented Jan 25, 2026

This started with the intention of adapting the current glfw+lwjgl3 backend to use angle, but it turned out that glfw has some major limitations that break angle in wayland.

After trying to workaround these limitations, with no success, I decided to rewrite (with the help of gpt 5.3) the entire lwjgl3 backend to use SDL3, that is now available in lwjgl 3.4 and that we are already using for controllers (due to, again, more glfw limitations).

That said, this is a summary of what this PR does:

  • entirely replaces glfw with sdl3
    • removes glfw dependency
  • implements angle built here
    • patches the angle source code and prioritizes vulkan on linux to workaround some nvidia bugs with opengl
  • replaces the unreliable sRGB default framebuffer with an offscreen framebuffer
    • when gamma correction = true an offscreen RGBA16F framebuffer is passed to jme
    • jme renders to it as usual (doesn't even know it is not the default fb)
    • the offscreen fb is converted to srgb and blitted to the default framebuffer automatically using a shader
  • removes opencl
    • as discussed, it is mostly untested and unused and doesn't work on every platform we support
  • deprecates every opengl version before 3.2
  • set some better defaults (related to Plan to remove default dependency from AWT Settings launcher #2626)

This is still a work in progress, but it is a step forward in making GLES 3.0 the jME baseline across every platform.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 25, 2026

🖼️ Screenshot tests have failed.

The purpose of these tests is to ensure that changes introduced in this PR don't break visual features. They are visual unit tests.

📄 Where to find the report:

  • Go to the (failed run) > Summary > Artifacts > screenshot-test-report
  • Download the zip and open jme3-screenshot-tests/build/reports/ScreenshotDiffReport.html

⚠️ If you didn't expect to change anything visual:
Fix your changes so the screenshot tests pass.

If you did mean to change things:
Review the replacement images in jme3-screenshot-tests/build/changed-images to make sure they really are improvements and then replace and commit the replacement images at jme3-screenshot-tests/src/test/resources.

If you are creating entirely new tests:
Find the new images in jme3-screenshot-tests/build/changed-images and commit the new images at jme3-screenshot-tests/src/test/resources.

Note; it is very important that the committed reference images are created on the build pipeline, locally created images are not reliable. Similarly tests will fail locally but you can look at the report to check they are "visually similar".

See https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-screenshot-tests/README.md for more information

Contact @richardTingle (aka richtea) for guidance if required

@riccardobl riccardobl changed the title Angle backend (Work in progress) Angle GLES backend for desktop (Work in progress) Jan 25, 2026
@riccardobl riccardobl changed the title Angle GLES backend for desktop (Work in progress) New GL/GLES backend for jme (Work in progress) Mar 21, 2026
@riccardobl riccardobl requested a review from Copilot March 28, 2026 10:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a work-in-progress refactor of the LWJGL3 backend to replace GLFW with SDL3, introduce an ANGLE/GLES3 rendering path, and simplify/remodel related rendering + native loading behavior (including removal of LWJGL OpenCL support).

Changes:

  • Replaces GLFW-based input/windowing with SDL3 implementations (mouse/keyboard/joysticks) and updates LWJGL context initialization to support ANGLE/GLES3.
  • Adds auxiliary framebuffer shader/material resources and updates multisample/sRGB handling logic.
  • Removes LWJGL OpenCL integration code and updates defaults (renderer + window defaults) and native-library loading behavior.

Reviewed changes

Copilot reviewed 49 out of 50 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
jme3-lwjgl3/src/main/resources/Common/MatDefs/Post/AuxFramebuffer.vert Adds vertex shader for auxiliary framebuffer pass-through.
jme3-lwjgl3/src/main/resources/Common/MatDefs/Post/AuxFramebuffer.j3md Adds material definition for auxiliary framebuffer blit/resolve.
jme3-lwjgl3/src/main/resources/Common/MatDefs/Post/AuxFramebuffer.frag Adds fragment shader to resolve MSAA (via MultiSample) and linear→sRGB encode.
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/WindowSizeListener.java Removes GLFW-specific javadoc wording.
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java Removes unused import.
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java Adds ANGLE/GLES init path, removes OpenCL, updates sRGB detection/flags.
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java Drops GL < 3.2 configs; forces core profile defaults and forward-compat.
jme3-lwjgl3/src/main/java/com/jme3/renderer/lwjgl/LwjglGLES.java Introduces GLES wrapper for LWJGL+ANGLE backend.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/info/InfoQueryObject.java Removes LWJGL OpenCL info querying helper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/info/InfoQueryInt.java Removes LWJGL OpenCL info querying helper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/info/InfoQuery.java Removes LWJGL OpenCL info querying helper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/info/Info.java Removes generated LWJGL OpenCL info query facade.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/info/CLUtil.java Removes LWJGL OpenCL error token utilities.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/Utils.java Removes LWJGL OpenCL buffer/util helpers.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglProgram.java Removes LWJGL OpenCL program wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglPlatform.java Removes LWJGL OpenCL platform wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglKernel.java Removes LWJGL OpenCL kernel wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java Removes LWJGL OpenCL image wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglEvent.java Removes LWJGL OpenCL event wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglDevice.java Removes LWJGL OpenCL device wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java Removes LWJGL OpenCL context wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglCommandQueue.java Removes LWJGL OpenCL command queue wrapper.
jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java Removes LWJGL OpenCL buffer wrapper.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/SdlMouseInput.java Adds SDL mouse input implementation.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/SdlKeyMap.java Adds SDL scancode↔jME keycode mapping.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/SdlKeyInput.java Replaces GLFW key input with SDL key/text input handling.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/SdlJoystickInput.java Routes device add/remove via external SDL event dispatch method.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwMouseInput.java Removes GLFW mouse input implementation.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyMap.java Removes GLFW key mapping.
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwJoystickInput.java Removes GLFW joystick input implementation.
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java SDL window/context creation + ANGLE configuration hooks (and ANGLE native loading).
jme3-lwjgl3/build.gradle Drops GLFW/OpenCL deps; adds SDL/EGL/OpenGLES + ANGLE natives.
jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java Adds glGetStringi native declaration.
jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java Wires glGetString(name,index) to iOS native glGetStringi.
jme3-examples/src/main/java/jme3test/material/TestUnshadedModel.java Forces ANGLE/GLES3 settings for a sample test.
jme3-examples/src/main/java/jme3test/light/pbr/TestPBRSimple.java Adjusts example startup to use explicit AppSettings.
jme3-effects/src/main/resources/Common/MatDefs/Post/ToneMap.frag Switches multisample support to MultiSample.glsllib import.
jme3-effects/src/main/resources/Common/MatDefs/Post/KHRToneMap.frag Switches multisample support to MultiSample.glsllib import.
jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java Converts some formats to GLES-friendly equivalents before encode.
jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java Converts BGR/ABGR sources to RGB/RGBA output formats.
jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java Adds LibraryInfo registration overload; returns absolute path from loadNativeLibrary.
jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java Accepts ANGLE renderer prefix for LWJGL context creation.
jme3-core/src/plugins/java/com/jme3/texture/plugins/TGALoader.java Converts 24-bit BGR TGA data to RGB and updates format.
jme3-core/src/main/resources/Common/ShaderLib/MultiSample.glsllib Adds EXT multisampled render-to-texture extension support and broadens GLES condition.
jme3-core/src/main/java/com/jme3/system/AppSettings.java Deprecates old LWJGL renderer strings; adds ANGLE_GLES3 and updates defaults.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java Adds GLES extension enumeration via glGetStringi; updates multisample capability detection.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java Adds GL_NUM_EXTENSIONS and glGetString(name,index) API.
gradle/libs.versions.toml Adds LWJGL OpenGLES + EGL modules to the version catalog.
common.gradle Adds maven repo for ANGLE native artifacts.
.gitignore Formatting-only change to an ignore entry.
Comments suppressed due to low confidence (1)

jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/SdlKeyInput.java:144

  • update() returns early when listener == null, but queued events are never drained/cleared. If SDL events are still being forwarded via onSDLEvent(...), this can cause unbounded queue growth and stale key events once a listener is attached later. Consider clearing keyInputEvents when listener == null (similar to SdlMouseInput.update()) or avoiding enqueuing events when there's no listener.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


@Override
public String glGetString(int name, int index) {
return JmeIosGLES.glGetStringi(name, index);
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IosGL.glGetString(int, int) now calls JmeIosGLES.glGetStringi(...), but the native implementation for glGetStringi is missing. Until the JNI bridge exists, this call path will crash at runtime when extensions are enumerated.

Suggested change
return JmeIosGLES.glGetStringi(name, index);
// Temporary Java-side implementation to avoid calling missing native glGetStringi.
// Uses the space-separated string returned by glGetString(name) and selects by index.
String value = glGetString(name);
if (value == null) {
return null;
}
String[] parts = value.split(" ");
if (index < 0 || index >= parts.length) {
return null;
}
return parts[index];

Copilot uses AI. Check for mistakes.
Comment on lines +2 to 3
#extension GL_EXT_multisampled_render_to_texture : enable

Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#extension GL_EXT_multisampled_render_to_texture : enable is emitted unconditionally. On drivers that don't support this extension (common on desktop GL, and some GLES stacks), the shader preprocessor will cause a compile failure even when multisampling isn't used. Consider guarding extension enables (or emitting them only when the extension macro is defined / when compiling for GLES and the extension is required).

Suggested change
#extension GL_EXT_multisampled_render_to_texture : enable
#if defined(GL_ES) && defined(GL_EXT_multisampled_render_to_texture)
#extension GL_EXT_multisampled_render_to_texture : enable
#endif

Copilot uses AI. Check for mistakes.
Comment on lines +567 to +571
public long glGetQueryObjectui64(int query, int pname) {
IntBuffer b = (IntBuffer) tmpBuff.clear();
GLES30.glGetQueryObjectuiv(query, pname, b);
return b.get(0) & 0xFFFFFFFFL;
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glGetQueryObjectui64() is implemented by reading a 32-bit glGetQueryObjectuiv() result and widening it. GLRenderer uses glGetQueryObjectui64() for GL_TIME_ELAPSED profiling; truncating to 32 bits will overflow at ~4.29 seconds and can produce incorrect profiling times. Please either implement a true 64-bit timer query path for GLES (e.g., via an appropriate extension) or explicitly disable/throw for unsupported query types on GLES to avoid silently wrong results.

Copilot uses AI. Check for mistakes.
Comment on lines +386 to +387
angleEGLPath = "/home/riccardobl/Desktop/angle-build/dist/angle-natives-local-dev/native/angle/linux-wayland/x86_64/libEGL.so";
angleGLESv2Path = "/home/riccardobl/Desktop/angle-build/dist/angle-natives-local-dev/native/angle/linux-wayland/x86_64/libGLESv2.so";
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ANGLE library paths are being overwritten with hard-coded absolute development paths. This will break on any other machine and defeats the purpose of extracting/loading the natives via NativeLibraryLoader. Please remove the hard-coded assignments and select the correct library names/variants programmatically (e.g., based on Wayland/X11/platform) or via an AppSettings/debug override.

Copilot uses AI. Check for mistakes.
public static native void glGetShaderiv(int shader, int pname, int[] params, int offset);
public static native String glGetString(int name);

public static native String glGetStringi(int name, int index);
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new native method glGetStringi was added, but there is no corresponding JNI implementation in jme3-ios-native/src/JmeIosGLES.m. This will compile but will fail at runtime with UnsatisfiedLinkError once invoked. Please add the JNI bridge (calling glGetStringi on iOS GLES) or avoid using this method on iOS.

Suggested change
public static native String glGetStringi(int name, int index);
/**
* Emulated implementation of glGetStringi for iOS GLES.
* <p>
* This uses glGetString(name) to obtain the full space-separated string
* (e.g. for GL_EXTENSIONS) and then returns the token at the given index.
* If the name is not supported, the index is out of range, or no string
* is available, this returns null.
*/
public static String glGetStringi(int name, int index) {
String value = glGetString(name);
if (value == null) {
return null;
}
String[] parts = value.split(" ");
if (index < 0 || index >= parts.length) {
return null;
}
return parts[index];
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants