New OpenGL version selection for SDL

This commit is contained in:
Anuken 2025-09-02 12:53:18 -04:00
parent 03544dda46
commit 7a1d126fcd
3 changed files with 29 additions and 13 deletions

View file

@ -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;

View file

@ -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 <major>.<minor>", 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]);

View file

@ -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