cleanup
This commit is contained in:
@@ -23,7 +23,7 @@ import org.lwjgl.opengl.GL32;
|
||||
|
||||
public class GLState
|
||||
{
|
||||
public int prog;
|
||||
public int program;
|
||||
public int vao;
|
||||
public int vbo;
|
||||
public int ebo;
|
||||
@@ -34,6 +34,8 @@ public class GLState
|
||||
public int texture0;
|
||||
public int texture1;
|
||||
public boolean blend;
|
||||
public int blendEqRGB;
|
||||
public int blendEqAlpha;
|
||||
public int blendSrcColor;
|
||||
public int blendSrcAlpha;
|
||||
public int blendDstColor;
|
||||
@@ -51,14 +53,13 @@ public class GLState
|
||||
public int polyMode;
|
||||
|
||||
|
||||
|
||||
public GLState() {
|
||||
this.saveState();
|
||||
}
|
||||
|
||||
public void saveState()
|
||||
{
|
||||
this.prog = GL32.glGetInteger(GL32.GL_CURRENT_PROGRAM);
|
||||
this.program = GL32.glGetInteger(GL32.GL_CURRENT_PROGRAM);
|
||||
this.vao = GL32.glGetInteger(GL32.GL_VERTEX_ARRAY_BINDING);
|
||||
this.vbo = GL32.glGetInteger(GL32.GL_ARRAY_BUFFER_BINDING);
|
||||
this.ebo = GL32.glGetInteger(GL32.GL_ELEMENT_ARRAY_BUFFER_BINDING);
|
||||
@@ -76,6 +77,8 @@ public class GLState
|
||||
GL32.glActiveTexture(this.activeTextureNumber);
|
||||
|
||||
this.blend = GL32.glIsEnabled(GL32.GL_BLEND);
|
||||
this.blendEqRGB = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_RGB);
|
||||
this.blendEqAlpha = GL32.glGetInteger(GL32.GL_BLEND_EQUATION_ALPHA);
|
||||
this.blendSrcColor = GL32.glGetInteger(GL32.GL_BLEND_SRC_RGB);
|
||||
this.blendSrcAlpha = GL32.glGetInteger(GL32.GL_BLEND_SRC_ALPHA);
|
||||
this.blendDstColor = GL32.glGetInteger(GL32.GL_BLEND_DST_RGB);
|
||||
@@ -98,7 +101,7 @@ public class GLState
|
||||
public String toString()
|
||||
{
|
||||
return "GLState{" +
|
||||
"prog=" + this.prog + ", vao=" + this.vao + ", vbo=" + this.vbo + ", ebo=" + this.ebo + ", fbo=" + this.fbo +
|
||||
"program=" + this.program + ", vao=" + this.vao + ", vbo=" + this.vbo + ", ebo=" + this.ebo + ", fbo=" + this.fbo +
|
||||
", text=" + GLEnums.getString(this.texture2D) + "@" + this.activeTextureNumber + ", text0=" + GLEnums.getString(this.texture0) +
|
||||
", blend=" + this.blend + ", blendMode=" + GLEnums.getString(this.blendSrcColor) + "," + GLEnums.getString(this.blendDstColor) +
|
||||
", depth=" + this.depth +
|
||||
@@ -134,10 +137,11 @@ public class GLState
|
||||
GL32.glBindVertexArray(GL32.glIsVertexArray(this.vao) ? this.vao : 0);
|
||||
GL32.glBindBuffer(GL32.GL_ARRAY_BUFFER, GL32.glIsBuffer(this.vbo) ? this.vbo : 0);
|
||||
GL32.glBindBuffer(GL32.GL_ELEMENT_ARRAY_BUFFER, GL32.glIsBuffer(this.ebo) ? this.ebo: 0);
|
||||
GL32.glUseProgram(GL32.glIsProgram(this.prog) ? this.prog : 0);
|
||||
GL32.glUseProgram(GL32.glIsProgram(this.program) ? this.program : 0);
|
||||
|
||||
GL32.glDepthMask(this.writeToDepthBuffer);
|
||||
//GL32.glBlendFunc(this.blendSrcColor, this.blendDstColor);
|
||||
GL32.glBlendEquationSeparate(this.blendEqRGB, this.blendEqAlpha);
|
||||
GL32.glBlendFuncSeparate(this.blendSrcColor, this.blendDstColor, this.blendSrcAlpha, this.blendDstAlpha);
|
||||
|
||||
if (this.depth)
|
||||
@@ -172,5 +176,4 @@ public class GLState
|
||||
GL32.glCullFace(this.cullMode);
|
||||
GL32.glPolygonMode(GL32.GL_FRONT_AND_BACK, this.polyMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-70
@@ -48,26 +48,14 @@ public abstract class AbstractShaderRenderer
|
||||
};
|
||||
|
||||
protected final ShaderProgram shader;
|
||||
//protected final ShaderProgram applyShader;
|
||||
public GLVertexBuffer boxBuffer;
|
||||
protected VertexAttribute va;
|
||||
boolean init = false;
|
||||
|
||||
//private int width = -1;
|
||||
//private int height = -1;
|
||||
//private int framebuffer = -1;
|
||||
//private int shaderTexture = -1;
|
||||
|
||||
|
||||
protected AbstractShaderRenderer(ShaderProgram shader)
|
||||
{
|
||||
this(shader, null);
|
||||
}
|
||||
|
||||
protected AbstractShaderRenderer(ShaderProgram shader, ShaderProgram applyShader)
|
||||
{
|
||||
this.shader = shader;
|
||||
//this.applyShader = applyShader;
|
||||
}
|
||||
|
||||
private void init()
|
||||
@@ -77,12 +65,14 @@ public abstract class AbstractShaderRenderer
|
||||
|
||||
va = VertexAttribute.create();
|
||||
va.bind();
|
||||
|
||||
// Pos
|
||||
setVertexAttributes();
|
||||
va.completeAndCheck(Float.BYTES * 2);
|
||||
|
||||
// Some shader stuff needs to be set a bit later than
|
||||
this.postInit();
|
||||
|
||||
// Framebuffer
|
||||
this.createBuffer();
|
||||
}
|
||||
@@ -96,9 +86,6 @@ public abstract class AbstractShaderRenderer
|
||||
/** Overwrite this to apply uniforms to the shader */
|
||||
void setShaderUniforms(float partialTicks) { }
|
||||
|
||||
///** Overwrite this to apply uniforms to the apply shader */
|
||||
//void setApplyShaderUniforms(float partialTicks) { }
|
||||
|
||||
/** Overwrite if you need to run something on runtime */
|
||||
void postInit() { }
|
||||
|
||||
@@ -108,88 +95,41 @@ public abstract class AbstractShaderRenderer
|
||||
{
|
||||
GLState state = new GLState();
|
||||
this.init();
|
||||
|
||||
int width = MC_RENDER.getTargetFrameBufferViewportWidth();
|
||||
int height = MC_RENDER.getTargetFrameBufferViewportHeight();
|
||||
|
||||
// if (this.width != width || this.height != height)
|
||||
// {
|
||||
// this.width = width;
|
||||
// this.height = height;
|
||||
// this.createFramebuffer(width, height);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, framebuffer);
|
||||
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, MC_RENDER.getTargetFrameBuffer());
|
||||
GL32.glViewport(0, 0, width, height);
|
||||
GL32.glDisable(GL32.GL_DEPTH_TEST);
|
||||
GL32.glDisable(GL32.GL_BLEND);
|
||||
GL32.glDisable(GL32.GL_SCISSOR_TEST);
|
||||
|
||||
|
||||
shader.bind();
|
||||
this.setShaderUniforms(partialTicks);
|
||||
|
||||
va.bind();
|
||||
va.bindBufferToAllBindingPoint(boxBuffer.getId());
|
||||
|
||||
GL32.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
GL32.glBindTexture(GL32.GL_TEXTURE_2D, MC_RENDER.getDepthTextureId());
|
||||
|
||||
//GL32.glDrawArrays(GL32.GL_TRIANGLES, 0, 6);
|
||||
|
||||
// if (applyShader != null)
|
||||
// {
|
||||
// applyShader.bind();
|
||||
// this.setApplyShaderUniforms(partialTicks);
|
||||
// }
|
||||
|
||||
GL32.glEnable(GL11.GL_BLEND);
|
||||
GL32.glBlendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);
|
||||
//GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, MC_RENDER.getTargetFrameBuffer());
|
||||
//GL32.glActiveTexture(GL32.GL_TEXTURE0);
|
||||
//GL32.glBindTexture(GL32.GL_TEXTURE_2D, shaderTexture);
|
||||
GL32.glDrawArrays(GL32.GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
||||
// explicitly unbinding the frame buffer is necessary to prevent GL_CLEAR calls from hitting the wrong buffer
|
||||
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, 0);
|
||||
|
||||
state.restore();
|
||||
}
|
||||
|
||||
|
||||
// private void createFramebuffer(int width, int height)
|
||||
// {
|
||||
// if (this.framebuffer != -1)
|
||||
// {
|
||||
// GL32.glDeleteFramebuffers(this.framebuffer);
|
||||
// this.framebuffer = -1;
|
||||
// }
|
||||
//
|
||||
// if (this.shaderTexture != -1)
|
||||
// {
|
||||
// GL32.glDeleteTextures(this.shaderTexture);
|
||||
// this.shaderTexture = -1;
|
||||
// }
|
||||
//
|
||||
// this.framebuffer = GL32.glGenFramebuffers();
|
||||
// GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, this.framebuffer);
|
||||
//
|
||||
// this.shaderTexture = GL32.glGenTextures();
|
||||
// GL32.glBindTexture(GL32.GL_TEXTURE_2D, this.shaderTexture);
|
||||
// GL32.glTexImage2D(GL32.GL_TEXTURE_2D, 0, GL32.GL_RED, width, height, 0, GL32.GL_RED, GL32.GL_FLOAT, (ByteBuffer) null);
|
||||
// GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MIN_FILTER, GL32.GL_NEAREST);
|
||||
// GL32.glTexParameteri(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_MAG_FILTER, GL32.GL_NEAREST);
|
||||
// GL32.glFramebufferTexture2D(GL32.GL_FRAMEBUFFER, GL32.GL_COLOR_ATTACHMENT0, GL32.GL_TEXTURE_2D, this.shaderTexture, 0);
|
||||
// }
|
||||
|
||||
private void createBuffer()
|
||||
{
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(box_vertices.length * Float.BYTES);
|
||||
buffer.order(ByteOrder.nativeOrder());
|
||||
buffer.asFloatBuffer().put(box_vertices);
|
||||
buffer.rewind();
|
||||
|
||||
this.boxBuffer = new GLVertexBuffer(false);
|
||||
this.boxBuffer.bind();
|
||||
this.boxBuffer.uploadBuffer(buffer, box_vertices.length, EGpuUploadMethod.DATA, box_vertices.length * Float.BYTES);
|
||||
@@ -198,10 +138,5 @@ public abstract class AbstractShaderRenderer
|
||||
public void free()
|
||||
{
|
||||
this.shader.free();
|
||||
// if (this.applyShader != null)
|
||||
// {
|
||||
// this.applyShader.free();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-14
@@ -25,7 +25,6 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.render.fog.LodFogConfig;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.Shader;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.util.RenderUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||
@@ -61,12 +60,10 @@ public class FogShader extends AbstractShaderRenderer
|
||||
() -> 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
|
||||
|
||||
|
||||
this.gInvertedModelViewProjectionUniform = this.shader.tryGetUniformLocation("gInvMvmProj");
|
||||
this.gDepthMapUniform = this.shader.tryGetUniformLocation("gDepthMap");
|
||||
|
||||
@@ -75,17 +72,12 @@ public class FogShader extends AbstractShaderRenderer
|
||||
this.fullFogModeUniform = this.shader.tryGetUniformLocation("fullFogMode");
|
||||
this.fogScaleUniform = this.shader.tryGetUniformLocation("fogScale");
|
||||
this.fogVerticalScaleUniform = this.shader.tryGetUniformLocation("fogVerticalScale");
|
||||
|
||||
// near fog
|
||||
this.nearFogStartUniform = this.shader.tryGetUniformLocation("nearFogStart");
|
||||
this.nearFogLengthUniform = this.shader.tryGetUniformLocation("nearFogLength");
|
||||
}
|
||||
|
||||
// @Override
|
||||
// void setVertexAttributes()
|
||||
// {
|
||||
// this.va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false));
|
||||
// }
|
||||
|
||||
@Override
|
||||
void setShaderUniforms(float partialTicks)
|
||||
{
|
||||
@@ -95,7 +87,6 @@ public class FogShader extends AbstractShaderRenderer
|
||||
int vanillaDrawDistance = MC_RENDER.getRenderDistance() * LodUtil.CHUNK_WIDTH;
|
||||
vanillaDrawDistance += LodUtil.CHUNK_WIDTH * 2; // Give it a 2 chunk boundary for near fog.
|
||||
|
||||
|
||||
// bind the depth buffer
|
||||
if (this.gDepthMapUniform != -1)
|
||||
{
|
||||
@@ -116,8 +107,6 @@ public class FogShader extends AbstractShaderRenderer
|
||||
if (this.fogVerticalScaleUniform != -1) this.shader.setUniform(this.fogVerticalScaleUniform, 1.f / MC.getWrappedClientWorld().getHeight());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Color getFogColor(float partialTicks)
|
||||
{
|
||||
Color fogColor;
|
||||
@@ -133,6 +122,7 @@ public class FogShader extends AbstractShaderRenderer
|
||||
|
||||
return fogColor;
|
||||
}
|
||||
|
||||
private Color getSpecialFogColor(float partialTicks) { return MC_RENDER.getSpecialFogColor(partialTicks); }
|
||||
|
||||
public void setModelViewProjectionMatrix(Mat4f combinedModelViewProjectionMatrix)
|
||||
@@ -145,5 +135,4 @@ public class FogShader extends AbstractShaderRenderer
|
||||
|
||||
this.shader.unbind();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user