reformat AbstractShaderRenderer

This commit is contained in:
James Seibel
2023-08-11 07:08:43 -05:00
parent 857979b7f2
commit d1ecec9ee9
2 changed files with 49 additions and 38 deletions
@@ -264,6 +264,7 @@ public class LodRenderer
}
{
// TODO add the model view/projection matricies to the render() function
FogShader.INSTANCE.setModelViewProjectionMatrix(modelViewProjectionMatrix);
FogShader.INSTANCE.render(partialTicks);
@@ -48,7 +48,8 @@ public abstract class AbstractShaderRenderer {
this.applyShader = applyShader;
}
private void init() {
private void init()
{
if (init) return;
init = true;
@@ -61,7 +62,7 @@ public abstract class AbstractShaderRenderer {
// Some shader stuff needs to be set a bit later than
this.postInit();
// Framebuffer
createBuffer();
this.createBuffer();
}
/** Sets all the vertex attributes */
@@ -76,16 +77,18 @@ public abstract class AbstractShaderRenderer {
void postInit() {};
// TODO pass in the Model View and Projection Matrices along with the ticks
public void render(float partialTicks) {
public void render(float partialTicks)
{
GLState state = new GLState();
init();
this.init();
int width = MC_RENDER.getTargetFrameBufferViewportWidth();
int height = MC_RENDER.getTargetFrameBufferViewportHeight();
if (this.width != width || this.height != height) {
if (this.width != width || this.height != height)
{
this.width = width;
this.height = height;
createFramebuffer(width, height);
this.createFramebuffer(width, height);
}
@@ -101,17 +104,18 @@ public abstract class AbstractShaderRenderer {
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);
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());
@@ -125,41 +129,47 @@ public abstract class AbstractShaderRenderer {
}
private void createFramebuffer(int width, int height) {
if (framebuffer != -1) {
GL32.glDeleteFramebuffers(framebuffer);
framebuffer = -1;
private void createFramebuffer(int width, int height)
{
if (this.framebuffer != -1)
{
GL32.glDeleteFramebuffers(this.framebuffer);
this.framebuffer = -1;
}
if (shaderTexture != -1) {
GL32.glDeleteTextures(shaderTexture);
shaderTexture = -1;
if (this.shaderTexture != -1)
{
GL32.glDeleteTextures(this.shaderTexture);
this.shaderTexture = -1;
}
framebuffer = GL32.glGenFramebuffers();
GL32.glBindFramebuffer(GL32.GL_FRAMEBUFFER, framebuffer);
shaderTexture = GL32.glGenTextures();
GL32.glBindTexture(GL32.GL_TEXTURE_2D, shaderTexture);
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, shaderTexture, 0);
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();
boxBuffer = new GLVertexBuffer(false);
boxBuffer.bind();
boxBuffer.uploadBuffer(buffer, box_vertices.length, EGpuUploadMethod.DATA, box_vertices.length * Float.BYTES);
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);
}
public void free() {
this.shader.free();
if (this.applyShader != null)
this.applyShader.free();
public void free()
{
this.shader.free();
if (this.applyShader != null)
this.applyShader.free();
}
}