mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-13 07:06:06 +09:00
shader: auto versioning and feature selection to allow broader compatibility
This commit is contained in:
@@ -32,6 +32,7 @@ import net.torvald.terrarum.langpack.Lang;
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer;
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame;
|
||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
|
||||
import net.torvald.terrarum.serialise.Common;
|
||||
import net.torvald.terrarum.serialise.WriteConfig;
|
||||
import net.torvald.terrarum.ui.Toolkit;
|
||||
import net.torvald.terrarum.utils.JsonFetcher;
|
||||
@@ -330,6 +331,8 @@ public class App implements ApplicationListener {
|
||||
return new ShapeRenderer(5000, DefaultGL32Shaders.INSTANCE.createShapeRendererShader());
|
||||
}
|
||||
|
||||
public static boolean gl40capable = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
long st = System.nanoTime();
|
||||
@@ -473,6 +476,8 @@ public class App implements ApplicationListener {
|
||||
|
||||
|
||||
glInfo.create();
|
||||
gl40capable = (Gdx.graphics.getGLVersion().getMajorVersion() >= 4);
|
||||
printdbg(this, "GL40 capable? "+gl40capable);
|
||||
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("title_health1", () -> new Texture(Gdx.files.internal("./assets/graphics/gui/health_take_a_break.tga")));
|
||||
CommonResourcePool.INSTANCE.addToLoadingList("title_health2", () -> new Texture(Gdx.files.internal("./assets/graphics/gui/health_distance.tga")));
|
||||
@@ -1613,26 +1618,29 @@ public class App implements ApplicationListener {
|
||||
}
|
||||
|
||||
public static ShaderProgram loadShaderFromClasspath(String vert, String frag) {
|
||||
ShaderProgram s = new ShaderProgram(Gdx.files.classpath(vert), Gdx.files.classpath(frag));
|
||||
|
||||
if (s.getLog().toLowerCase().contains("error")) {
|
||||
throw new Error(String.format("Shader program loaded with %s, %s failed:\n%s", vert, frag, s.getLog()));
|
||||
}
|
||||
|
||||
return s;
|
||||
String v = Gdx.files.classpath(vert).readString("utf-8");
|
||||
String f = Gdx.files.classpath(frag).readString("utf-8");
|
||||
return loadShaderInline(v, f);
|
||||
}
|
||||
|
||||
public static ShaderProgram loadShaderFromFile(String vert, String frag) {
|
||||
ShaderProgram s = new ShaderProgram(Gdx.files.internal(vert), Gdx.files.internal(frag));
|
||||
|
||||
if (s.getLog().toLowerCase().contains("error")) {
|
||||
throw new Error(String.format("Shader program loaded with %s, %s failed:\n%s", vert, frag, s.getLog()));
|
||||
}
|
||||
|
||||
return s;
|
||||
String v = Gdx.files.internal(vert).readString("utf-8");
|
||||
String f = Gdx.files.internal(frag).readString("utf-8");
|
||||
return loadShaderInline(v, f);
|
||||
}
|
||||
|
||||
public static ShaderProgram loadShaderInline(String vert, String frag) {
|
||||
public static ShaderProgram loadShaderInline(String vert0, String frag0) {
|
||||
// insert version code
|
||||
String vert, frag;
|
||||
if (gl40capable) {
|
||||
vert = "#version 400\n"+vert0;
|
||||
frag = "#version 400\n"+frag0;
|
||||
}
|
||||
else {
|
||||
vert = "#version 150\n#define fma(a,b,c) ((a*b)+c)\n"+vert0;
|
||||
frag = "#version 150\n#define fma(a,b,c) ((a*b)+c)\n"+frag0;
|
||||
}
|
||||
|
||||
ShaderProgram s = new ShaderProgram(vert, frag);
|
||||
|
||||
if (s.getLog().toLowerCase().contains("error")) {
|
||||
|
||||
@@ -35,45 +35,43 @@ class UIHandler(//var UI: UICanvas,
|
||||
|
||||
companion object {
|
||||
private val SHADER_PROG_FRAG = """
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
in vec4 v_color;
|
||||
in vec4 v_generic;
|
||||
in vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
uniform float opacity;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
out vec4 fragColor;
|
||||
const vec2 boolean = vec2(0.0, 1.0);
|
||||
|
||||
void main(void) {
|
||||
vec4 color = texture(u_texture, v_texCoords).rgba;
|
||||
|
||||
void main() {
|
||||
vec4 color = texture(u_texture, v_texCoords);
|
||||
fragColor = v_color * vec4(color.rgb, color.a * opacity);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
private val SHADER_PROG_VERT = """
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
in vec4 a_generic;
|
||||
in vec2 a_texCoord0;
|
||||
|
||||
uniform mat4 u_projTrans;
|
||||
|
||||
out vec4 v_color;
|
||||
out vec2 v_texCoords;
|
||||
out vec4 v_generic;
|
||||
|
||||
void main() {
|
||||
v_color = a_color;
|
||||
v_color.a = v_color.a * (255.0/254.0);
|
||||
v_texCoords = a_texCoord0;
|
||||
v_generic = a_generic;
|
||||
gl_Position = u_projTrans * a_position;
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
// X/Y Position relative to the game window.
|
||||
|
||||
Reference in New Issue
Block a user