From 7a1d126fcda159d29a256e8cb873e3807b68257b Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 2 Sep 2025 12:53:18 -0400 Subject: [PATCH] New OpenGL version selection for SDL --- .../mindustry/graphics/g3d/MeshBuilder.java | 8 ++--- .../mindustry/desktop/DesktopLauncher.java | 32 ++++++++++++++----- gradle.properties | 2 +- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/core/src/mindustry/graphics/g3d/MeshBuilder.java b/core/src/mindustry/graphics/g3d/MeshBuilder.java index fc5fd4664d..11ac762e61 100644 --- a/core/src/mindustry/graphics/g3d/MeshBuilder.java +++ b/core/src/mindustry/graphics/g3d/MeshBuilder.java @@ -8,7 +8,7 @@ import mindustry.graphics.g3d.PlanetGrid.*; import mindustry.maps.generators.*; public class MeshBuilder{ - private static final boolean gl30 = Core.gl30 != null; + private static final boolean packNormals = Core.gl30 != null && (Core.app.isMobile() || Core.graphics.getGLVersion().atLeast(3, 3)); private static volatile float[] tmpHeights = new float[14580]; //highest amount of corners in vanilla /** Note that the resulting icosphere does not have normals or a color. */ @@ -110,7 +110,7 @@ public class MeshBuilder{ int position = 0; short[] shorts = indexed ? new short[12] : null; - float[] floats = new float[3 + (gl30 ? 1 : 3) + 1 + (emit ? 1 : 0)]; + float[] floats = new float[3 + (packNormals ? 1 : 3) + 1 + (emit ? 1 : 0)]; Vec3 nor = new Vec3(); Color tmpCol = new Color(); @@ -199,7 +199,7 @@ public class MeshBuilder{ if(normal){ //only GL30 supports GL_INT_2_10_10_10_REV - attributes.add(gl30 ? VertexAttribute.packedNormal : VertexAttribute.normal); + attributes.add(packNormals ? VertexAttribute.packedNormal : VertexAttribute.normal); } attributes.add(VertexAttribute.color); @@ -262,7 +262,7 @@ public class MeshBuilder{ floats[1] = y; floats[2] = z; - if(gl30){ + if(packNormals){ floats[3] = packNormals(normal.x, normal.y, normal.z); floats[4] = color; diff --git a/desktop/src/mindustry/desktop/DesktopLauncher.java b/desktop/src/mindustry/desktop/DesktopLauncher.java index 633361904f..6d45124e5d 100644 --- a/desktop/src/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/mindustry/desktop/DesktopLauncher.java @@ -47,13 +47,20 @@ public class DesktopLauncher extends ClientLauncher{ new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{ title = "Mindustry"; maximized = true; + coreProfile = true; width = 900; height = 700; - gl30Minor = 2; - //on Windows, Intel drivers might be buggy with OpenGL 3.x, so disable it. See https://github.com/Anuken/Mindustry/issues/11041 - if(!GpuDetect.isIntel){ - gl30 = true; + //on Windows, Intel drivers might be buggy with OpenGL 3.x, so only use 2.0. See https://github.com/Anuken/Mindustry/issues/11041 + if(GpuDetect.isIntel){ + coreProfile = false; + glVersions = new int[][]{{2, 0}}; + }else if(OS.isMac){ + //MacOS supports 4.1 at most + glVersions = new int[][]{{4, 1}, {3, 2}, {2, 0}}; + }else{ + //try essentially every OpenGL version + glVersions = new int[][]{{4, 6}, {4, 1}, {3, 3}, {3, 2}, {3, 1}, {2, 0}}; } for(int i = 0; i < arg.length; i++){ @@ -62,11 +69,20 @@ public class DesktopLauncher extends ClientLauncher{ switch(name){ case "width" -> width = Strings.parseInt(arg[i + 1], width); case "height" -> height = Strings.parseInt(arg[i + 1], height); - case "glMajor" -> gl30Major = Strings.parseInt(arg[i + 1], gl30Major); - case "glMinor" -> gl30Minor = Strings.parseInt(arg[i + 1], gl30Minor); - case "gl3" -> gl30 = true; - case "gl2" -> gl30 = false; + case "gl" -> { + String str = arg[i + 1]; + if(str.contains(".")){ + String[] split = str.split("\\."); + if(split.length == 2 && Strings.canParsePositiveInt(split[0]) && Strings.canParsePositiveInt(split[1])){ + glVersions = new int[][]{{Strings.parseInt(split[0]), Strings.parseInt(split[1])}}; + break; + } + + } + Log.err("Invalid GL version format string: '@'. GL version must be of the form .", str); + } case "coreGl" -> coreProfile = true; + case "compatibilityGl" -> coreProfile = false; case "antialias" -> samples = 16; case "debug" -> Log.level = LogLevel.debug; case "maximized" -> maximized = Boolean.parseBoolean(arg[i + 1]); diff --git a/gradle.properties b/gradle.properties index b406739587..816af52630 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ org.gradle.caching=true org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 android.enableR8.fullMode=false -archash=f4edc7709d +archash=bf0cbe10da