fix shader init; remove GL11
This commit is contained in:
@@ -19,34 +19,32 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.render.glObject;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.seibel.distanthorizons.api.enums.config.EGLErrorHandlingMode;
|
||||
import com.seibel.distanthorizons.api.enums.config.EGpuUploadMethod;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.enums.EGLProxyContext;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.util.objects.GLMessage;
|
||||
import com.seibel.distanthorizons.core.util.objects.GLMessageOutputStream;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.opengl.GLUtil;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EGLErrorHandlingMode;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.opengl.GL;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
import org.lwjgl.opengl.GLCapabilities;
|
||||
import org.lwjgl.opengl.GLUtil;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.api.enums.config.EGpuUploadMethod;
|
||||
import com.seibel.distanthorizons.core.enums.EGLProxyContext;
|
||||
import com.seibel.distanthorizons.core.util.objects.GLMessage;
|
||||
import com.seibel.distanthorizons.core.util.objects.GLMessageOutputStream;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
|
||||
/**
|
||||
* A singleton that holds references to different openGL contexts
|
||||
* and GPU capabilities.
|
||||
@@ -108,7 +106,7 @@ public class GLProxy
|
||||
// this must be created on minecraft's render context to work correctly
|
||||
|
||||
GL_LOGGER.info("Creating " + GLProxy.class.getSimpleName() + "... If this is the last message you see there must have been an OpenGL error.");
|
||||
GL_LOGGER.info("Lod Render OpenGL version [" + GL11.glGetString(GL11.GL_VERSION) + "].");
|
||||
GL_LOGGER.info("Lod Render OpenGL version [" + GL32.glGetString(GL32.GL_VERSION) + "].");
|
||||
|
||||
// getting Minecraft's context has to be done on the render thread,
|
||||
// where the GL context is
|
||||
|
||||
+3
-3
@@ -30,15 +30,15 @@ public abstract class AbstractShaderRenderer
|
||||
|
||||
protected ShaderProgram shader;
|
||||
|
||||
boolean init = false;
|
||||
protected boolean init = false;
|
||||
|
||||
|
||||
protected AbstractShaderRenderer() {}
|
||||
|
||||
public void init()
|
||||
{
|
||||
if (init) return;
|
||||
init = true;
|
||||
//if (init) return false;
|
||||
this.init = true;
|
||||
}
|
||||
|
||||
public void free()
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ public class DarkShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
if (this.init) return;
|
||||
super.init();
|
||||
|
||||
this.shader = new ShaderProgram(
|
||||
|
||||
+24
-11
@@ -44,27 +44,37 @@ public class FogShader extends AbstractShaderRenderer
|
||||
private static final IVersionConstants VERSION_CONSTANTS = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||
|
||||
|
||||
public final int gInvertedModelViewProjectionUniform;
|
||||
public final int gDepthMapUniform;
|
||||
private final LodFogConfig fogConfig;
|
||||
public int gInvertedModelViewProjectionUniform;
|
||||
public int gDepthMapUniform;
|
||||
|
||||
// Fog Uniforms
|
||||
public final int fogColorUniform;
|
||||
public final int fogScaleUniform;
|
||||
public final int fogVerticalScaleUniform;
|
||||
public final int nearFogStartUniform;
|
||||
public final int nearFogLengthUniform;
|
||||
public final int fullFogModeUniform;
|
||||
public int fogColorUniform;
|
||||
public int fogScaleUniform;
|
||||
public int fogVerticalScaleUniform;
|
||||
public int nearFogStartUniform;
|
||||
public int nearFogLengthUniform;
|
||||
public int fullFogModeUniform;
|
||||
|
||||
|
||||
public FogShader(LodFogConfig fogConfig)
|
||||
{
|
||||
this.fogConfig = fogConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
if (this.init) return;
|
||||
super.init();
|
||||
|
||||
this.shader = new ShaderProgram(
|
||||
// TODO rename normal.vert to something like "postProcess.vert"
|
||||
() -> Shader.loadFile("shaders/normal.vert", false, new StringBuilder()).toString(),
|
||||
() -> fogConfig.loadAndProcessFragShader("shaders/fog/fog.frag", false).toString(),
|
||||
() -> this.fogConfig.loadAndProcessFragShader("shaders/fog/fog.frag", false).toString(),
|
||||
"fragColor", new String[]{"vPosition"}
|
||||
);
|
||||
|
||||
|
||||
// all uniforms should be tryGet...
|
||||
// because disabling fog can cause the GLSL to optimize out most (if not all) uniforms
|
||||
|
||||
@@ -131,6 +141,8 @@ public class FogShader extends AbstractShaderRenderer
|
||||
|
||||
public void setModelViewProjectionMatrix(Mat4f combinedModelViewProjectionMatrix)
|
||||
{
|
||||
this.init();
|
||||
|
||||
this.shader.bind();
|
||||
|
||||
Mat4f inverseMvmProjMatrix = new Mat4f(combinedModelViewProjectionMatrix);
|
||||
@@ -167,4 +179,5 @@ public class FogShader extends AbstractShaderRenderer
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
state.restore();
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public class SSAOApplyShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
if (this.init) return;
|
||||
super.init();
|
||||
|
||||
this.shader = new ShaderProgram(
|
||||
|
||||
+2
-2
@@ -25,7 +25,6 @@ import com.seibel.distanthorizons.core.render.renderer.ScreenQuad;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
public class SSAOShader extends AbstractShaderRenderer
|
||||
@@ -52,6 +51,7 @@ public class SSAOShader extends AbstractShaderRenderer
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
if (this.init) return;
|
||||
super.init();
|
||||
|
||||
this.shader = new ShaderProgram("shaders/normal.vert", "shaders/ssao/ao.frag",
|
||||
@@ -128,7 +128,7 @@ public class SSAOShader extends AbstractShaderRenderer
|
||||
GL32.glViewport(0, 0, width, height);
|
||||
GL32.glDisable(GL32.GL_SCISSOR_TEST);
|
||||
GL32.glDisable(GL32.GL_DEPTH_TEST);
|
||||
GL32.glDisable(GL11.GL_BLEND);
|
||||
GL32.glDisable(GL32.GL_BLEND);
|
||||
|
||||
ScreenQuad.INSTANCE.render();
|
||||
|
||||
|
||||
+8
-8
@@ -19,7 +19,7 @@
|
||||
|
||||
package com.seibel.distanthorizons.core.render.vertexFormat;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
/**
|
||||
* This object is used to build LodVertexFormats.
|
||||
@@ -80,13 +80,13 @@ public class LodVertexFormatElement
|
||||
|
||||
public enum DataType
|
||||
{
|
||||
FLOAT(4, "Float", GL11.GL_FLOAT),
|
||||
UBYTE(1, "Unsigned Byte", GL11.GL_UNSIGNED_BYTE),
|
||||
BYTE(1, "Byte", GL11.GL_BYTE),
|
||||
USHORT(2, "Unsigned Short", GL11.GL_UNSIGNED_SHORT),
|
||||
SHORT(2, "Short", GL11.GL_SHORT),
|
||||
UINT(4, "Unsigned Int", GL11.GL_UNSIGNED_INT),
|
||||
INT(4, "Int", GL11.GL_INT);
|
||||
FLOAT(4, "Float", GL32.GL_FLOAT),
|
||||
UBYTE(1, "Unsigned Byte", GL32.GL_UNSIGNED_BYTE),
|
||||
BYTE(1, "Byte", GL32.GL_BYTE),
|
||||
USHORT(2, "Unsigned Short", GL32.GL_UNSIGNED_SHORT),
|
||||
SHORT(2, "Short", GL32.GL_SHORT),
|
||||
UINT(4, "Unsigned Int", GL32.GL_UNSIGNED_INT),
|
||||
INT(4, "Int", GL32.GL_INT);
|
||||
|
||||
private final int size;
|
||||
private final String name;
|
||||
|
||||
@@ -28,6 +28,10 @@ vec3 quantize(vec3 val, int stepSize) {
|
||||
return floor(val * stepSize) / stepSize;
|
||||
}
|
||||
|
||||
vec3 RgbToLinear(const in vec3 color) {
|
||||
return pow(color, vec3(2.2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fragment Shader
|
||||
@@ -40,6 +44,9 @@ void main()
|
||||
{
|
||||
fragColor = vertexColor;
|
||||
|
||||
// WARN: DEBUG TEST!
|
||||
//fragColor.rgb = RgbToLinear(fragColor.rgb) * 3.0;
|
||||
|
||||
// TODO: Move into its own function instead of in an if statement
|
||||
if (noiseEnabled) {
|
||||
vec3 vertexNormal = normalize(cross(dFdy(vPos.xyz), dFdx(vPos.xyz)));
|
||||
|
||||
Reference in New Issue
Block a user