mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
shader: auto versioning and feature selection to allow broader compatibility
This commit is contained in:
@@ -33,7 +33,7 @@ public class Float16FrameBuffer extends FrameBuffer {
|
||||
* @param hasDepth whether to attach a depth buffer
|
||||
* @throws GdxRuntimeException in case the FrameBuffer could not be created */
|
||||
public Float16FrameBuffer (int width, int height, boolean hasDepth) {
|
||||
if (App.operationSystem.equals("OSX")) { // disable float framebuffer for Apple M chips
|
||||
/*if (!App.gl40capable || App.operationSystem.equals("OSX")) { // disable float framebuffer for Apple M chips
|
||||
FrameBufferBuilder bufferBuilder = new FrameBufferBuilder(width, height);
|
||||
bufferBuilder.addColorTextureAttachment(GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_SHORT); // but 16bpp int works perfectly?!
|
||||
if (hasDepth) bufferBuilder.addBasicDepthRenderBuffer();
|
||||
@@ -44,14 +44,19 @@ public class Float16FrameBuffer extends FrameBuffer {
|
||||
bufferBuilder.addFloatAttachment(GL30.GL_RGBA16F, GL30.GL_RGBA, GL30.GL_FLOAT, false);
|
||||
if (hasDepth) bufferBuilder.addBasicDepthRenderBuffer();
|
||||
this.bufferBuilder = bufferBuilder;
|
||||
}
|
||||
}*/
|
||||
|
||||
FrameBufferBuilder bufferBuilder = new FrameBufferBuilder(width, height);
|
||||
bufferBuilder.addColorTextureAttachment(GL20.GL_RGBA, GL20.GL_RGBA, GL20.GL_UNSIGNED_SHORT); // but 16bpp int works perfectly?!
|
||||
if (hasDepth) bufferBuilder.addBasicDepthRenderBuffer();
|
||||
this.bufferBuilder = bufferBuilder;
|
||||
|
||||
build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Texture createTexture (FrameBufferTextureAttachmentSpec attachmentSpec) {
|
||||
if (App.operationSystem.equals("OSX")) {
|
||||
/*if (!App.gl40capable || App.operationSystem.equals("OSX")) {
|
||||
GLOnlyTextureData data = new GLOnlyTextureData(bufferBuilder.width, bufferBuilder.height, 0, attachmentSpec.internalFormat,
|
||||
attachmentSpec.format, attachmentSpec.type);
|
||||
Texture result = new Texture(data);
|
||||
@@ -66,7 +71,14 @@ public class Float16FrameBuffer extends FrameBuffer {
|
||||
result.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
result.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
|
||||
return result;
|
||||
}
|
||||
}*/
|
||||
|
||||
GLOnlyTextureData data = new GLOnlyTextureData(bufferBuilder.width, bufferBuilder.height, 0, attachmentSpec.internalFormat,
|
||||
attachmentSpec.format, attachmentSpec.type);
|
||||
Texture result = new Texture(data);
|
||||
result.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
|
||||
result.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 v_color;
|
||||
in vec2 v_texCoords;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
|
||||
|
||||
in vec4 v_color; // lightCol
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
in vec4 v_color;
|
||||
in vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec2 a_texCoord0;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* http://momentsingraphics.de/BlueNoise.html
|
||||
*/
|
||||
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* http://momentsingraphics.de/BlueNoise.html
|
||||
*/
|
||||
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
|
||||
in vec4 a_position;
|
||||
in vec4 a_color;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
in vec4 v_color;
|
||||
in vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
in vec4 v_color;
|
||||
in vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
#version 400
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#version 400
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#version 150
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user