Skip to content

Commit eddd0bb

Browse files
committed
fix(GLFW): Fix glfwGetWindowAttrib returning GL Version 0.0
Implements janky per-renderer handling for glfwGetWindowAttrib() Signed-off-by: alexytomi <60690056+alexytomi@users.noreply.github.com>
1 parent 433f217 commit eddd0bb

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw

jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,31 @@ public static void glfwSetWindowMonitor(@NativeType("GLFWwindow *") long window,
895895
}
896896

897897
public static int glfwGetWindowAttrib(@NativeType("GLFWwindow *") long window, int attrib) {
898+
// Turnip + Zink is the only way to get compliant GL 4.6
899+
boolean hasTurnipZink = Objects.requireNonNull(glGetString(GL_RENDERER)).contains("zink") &&
900+
Objects.requireNonNull(glGetString(GL_RENDERER)).contains("Turnip");
901+
if (hasTurnipZink) {
902+
if (attrib == GLFW_CONTEXT_VERSION_MAJOR) return 4;
903+
if (attrib == GLFW_CONTEXT_VERSION_MINOR) return 6;
904+
}
905+
// It's been common consensus that virgl exports GL 4.3 on ES 3.2
906+
// I can't find any sources on this though...well besides the implied claim here
907+
// https://github.com/PojavLauncherTeam/PojavLauncher/issues/2697#issuecomment-1030837683
908+
boolean isVirgl = Objects.requireNonNull(glGetString(GL_RENDERER)).contains("virgl");
909+
if (isVirgl) {
910+
if (attrib == GLFW_CONTEXT_VERSION_MAJOR) return 4;
911+
if (attrib == GLFW_CONTEXT_VERSION_MINOR) return 3;
912+
}
913+
// MobileGlues returns 4.0.0 as well as has compute shaders (from GL 4.0)
914+
boolean isMobileGlues = Objects.requireNonNull(glGetString(GL_VERSION)).contains("MobileGlues");
915+
if (isMobileGlues) { // In MobileGlues, GL_RENDERER returns GPU,( ANGLE, Vulkan,) ES while GL_VERSION returns
916+
if (attrib == GLFW_CONTEXT_VERSION_MAJOR) return 4; // 4.0.0 MobileGlues <MobileGlues Release Version>
917+
if (attrib == GLFW_CONTEXT_VERSION_MINOR) return 0;
918+
}
919+
// We can assume GL 3.3 for everything else just to be safe stuff
920+
// doesn't ask for tesselation when we probably don't have any :(
921+
if (attrib == GLFW_CONTEXT_VERSION_MAJOR) return 3;
922+
if (attrib == GLFW_CONTEXT_VERSION_MINOR) return 3;
898923
return internalGetWindow(window).windowAttribs.getOrDefault(attrib, 0);
899924
}
900925

0 commit comments

Comments
 (0)