Skip to content

Fix issues in GLES backends#2584

Open
riccardobl wants to merge 3 commits intojMonkeyEngine:masterfrom
riccardobl:glespatch
Open

Fix issues in GLES backends#2584
riccardobl wants to merge 3 commits intojMonkeyEngine:masterfrom
riccardobl:glespatch

Conversation

@riccardobl
Copy link
Member

  1. Avoid reallocating 1 length IntBuffers in glGetQueryObject in android
  2. fix misuse of glGetQueryiv instead of glGetQueryObjectuiv in android
  3. implement glGetStringi(name, index) on android and ios (?)
  4. use non-deprecated way to fetch extensions in GLES (was causing crashes in some implementations)

At this time, this is mostly untested in both android and ios.
If anyone wants to give it a try, please go ahead.

@riccardobl riccardobl added bug Something that is supposed to work, but doesn't. More severe than a "defect". Contribution welcome labels Jan 25, 2026
@riccardobl
Copy link
Member Author

@gemini-code-assist can you review this and compare with andoid gles documentation and the documentation of the binds/api we use for ios?

@gemini-code-assist
Copy link

Thank you for the request, @riccardobl. I've reviewed the changes in this pull request.

The modifications appear to directly address the issues outlined in the pull request description, particularly concerning the Android GLES backend and the implementation of glGetStringi for both Android and iOS. The changes to use tmpBuff.clear() for glGetQueryObjectui64 and glGetQueryObjectiv are good for efficiency, avoiding repeated buffer allocations. The correction from glGetQueryiv to glGetQueryObjectuiv and the implementation of glGetStringi for fetching extensions in GLES30 are important for correctness and adherence to the GLES API best practices, as you noted in the description.

While I can confirm that the code implements the described fixes and improvements, I am unable to perform a direct, real-time comparison against external Android GLES and iOS API documentation. My analysis is based on the provided code changes and the context of the pull request description.

Overall, the changes seem to be a positive step towards improving the GLES backends.

Copy link

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 updates the OpenGL ES backends (Android/iOS) and the core renderer’s extension loading to use GLES3/OpenGL3 indexed extension queries, and fixes Android query-object retrieval issues.

Changes:

  • Load extensions via glGetStringi + GL_NUM_EXTENSIONS for OpenGL 3 / OpenGL ES 3 contexts to avoid deprecated extension fetching.
  • Add glGetString(name, index) support to the GLES3 interface and implement it on Android and iOS backends.
  • Fix Android’s query-object integer retrieval to call glGetQueryObjectuiv (instead of glGetQueryiv) and reuse a preallocated buffer.

Reviewed changes

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

Show a summary per file
File Description
jme3-ios/src/main/java/com/jme3/renderer/ios/JmeIosGLES.java Adds a new native declaration for glGetStringi.
jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java Implements the new indexed glGetString by delegating to JmeIosGLES.glGetStringi.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java Uses glGetStringi on GLES3/OpenGL3 paths to enumerate extensions safely.
jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java Extends the GLES3 interface with GL_NUM_EXTENSIONS and indexed glGetString.
jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java Reuses temp buffers for query reads, fixes glGetQueryObjectiv to use glGetQueryObjectuiv, and implements indexed glGetString.

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

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 1, 2026

Choose a reason for hiding this comment

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

glGetStringi(int name, int index) is declared as a new native method here, but there is no corresponding JNI implementation in jme3-ios-native/src/JmeIosGLES.m (e.g., no Java_com_jme3_renderer_ios_JmeIosGLES_glGetStringi). This will compile but will fail at runtime with an UnsatisfiedLinkError when IosGL.glGetString(name, index) is invoked. Please add the native binding (and ensure it calls the ES3 glGetStringi).

Suggested change
public static native String glGetStringi(int name, int index);
public static String glGetStringi(int name, int index) {
String combined = glGetString(name);
if (combined == null) {
return null;
}
String[] parts = combined.split(" ");
if (index < 0 || index >= parts.length) {
throw new IllegalArgumentException("glGetStringi: index " + index + " out of range (0.." + (parts.length - 1) + ")");
}
return parts[index];
}

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

can you implement the jni binding instead?

….java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something that is supposed to work, but doesn't. More severe than a "defect". Contribution welcome

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants