mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 12:34:11 +01:00
Shaders and ladders
- Compile with progressively lower glsl versions to test which are available. - Properly returns 460 on my machine even with a gl version of 320 - Remove glsl enums below 150
This commit is contained in:
parent
e40f50f4f7
commit
069679689f
@ -134,7 +134,7 @@ public class Compilation {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean compiledSuccessfully(int handle) {
|
||||
public static boolean compiledSuccessfully(int handle) {
|
||||
return GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS) == GL20.GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,14 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
import org.lwjgl.opengl.GL20C;
|
||||
import org.lwjgl.opengl.GL31C;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.opengl.KHRShaderSubgroup;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
|
||||
import com.jozufozu.flywheel.backend.compile.core.Compilation;
|
||||
import com.jozufozu.flywheel.backend.glsl.GlslVersion;
|
||||
import com.jozufozu.flywheel.lib.math.MoreMath;
|
||||
|
||||
@ -88,28 +90,6 @@ public final class GlCompat {
|
||||
return DRIVER == Driver.AMD || DRIVER == Driver.MESA ? 64 : 32;
|
||||
}
|
||||
|
||||
private static GlslVersion maxGlslVersion() {
|
||||
if (CAPABILITIES.OpenGL46) {
|
||||
return GlslVersion.V460;
|
||||
} else if (CAPABILITIES.OpenGL45) {
|
||||
return GlslVersion.V450;
|
||||
} else if (CAPABILITIES.OpenGL44) {
|
||||
return GlslVersion.V440;
|
||||
} else if (CAPABILITIES.OpenGL43) {
|
||||
return GlslVersion.V430;
|
||||
} else if (CAPABILITIES.OpenGL42) {
|
||||
return GlslVersion.V420;
|
||||
} else if (CAPABILITIES.OpenGL41) {
|
||||
return GlslVersion.V410;
|
||||
} else if (CAPABILITIES.OpenGL40) {
|
||||
return GlslVersion.V400;
|
||||
} else if (CAPABILITIES.OpenGL33) {
|
||||
return GlslVersion.V330;
|
||||
} else {
|
||||
return GlslVersion.V150;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInstancingSupported() {
|
||||
if (CAPABILITIES.OpenGL33) {
|
||||
return true;
|
||||
@ -131,4 +111,42 @@ public final class GlCompat {
|
||||
&& CAPABILITIES.GL_ARB_shading_language_420pack
|
||||
&& CAPABILITIES.GL_ARB_vertex_attrib_binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to compile a shader with progressively lower glsl versions.
|
||||
* The first version to compile successfully is returned.
|
||||
* @return The highest glsl version that could be compiled.
|
||||
*/
|
||||
private static GlslVersion maxGlslVersion() {
|
||||
var glslVersions = GlslVersion.values();
|
||||
// No need to test glsl 150 as that is guaranteed to be supported by MC.
|
||||
for (int i = glslVersions.length - 1; i > 0; i--) {
|
||||
var version = glslVersions[i];
|
||||
|
||||
if (canCompileVersion(version)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
return GlslVersion.V150;
|
||||
}
|
||||
|
||||
private static boolean canCompileVersion(GlslVersion version) {
|
||||
int handle = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);
|
||||
|
||||
// Compile the simplest possible shader.
|
||||
var source = """
|
||||
#version %d
|
||||
void main() {}
|
||||
""".formatted(version.version);
|
||||
|
||||
safeShaderSource(handle, source);
|
||||
GL20.glCompileShader(handle);
|
||||
|
||||
boolean success = Compilation.compiledSuccessfully(handle);
|
||||
|
||||
GL20.glDeleteShader(handle);
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.jozufozu.flywheel.backend.glsl;
|
||||
|
||||
public enum GlslVersion {
|
||||
V110(110),
|
||||
V120(120),
|
||||
V130(130),
|
||||
V140(140),
|
||||
V150(150),
|
||||
V330(330),
|
||||
V400(400),
|
||||
|
Loading…
Reference in New Issue
Block a user