diff --git a/src/main/java/me/cortex/voxelmon/core/gl/GlFramebuffer.java b/src/main/java/me/cortex/voxelmon/core/gl/GlFramebuffer.java index 35d6e311..e956f81d 100644 --- a/src/main/java/me/cortex/voxelmon/core/gl/GlFramebuffer.java +++ b/src/main/java/me/cortex/voxelmon/core/gl/GlFramebuffer.java @@ -1,10 +1,9 @@ package me.cortex.voxelmon.core.gl; import me.cortex.voxelmon.core.util.TrackedObject; +import org.lwjgl.opengl.GL30C; -import static org.lwjgl.opengl.ARBFramebufferObject.*; -import static org.lwjgl.opengl.GL45C.glCreateFramebuffers; -import static org.lwjgl.opengl.GL45C.glNamedFramebufferTexture; +import static org.lwjgl.opengl.GL45C.*; public class GlFramebuffer extends TrackedObject { public final int id; @@ -22,4 +21,8 @@ public class GlFramebuffer extends TrackedObject { super.free0(); glDeleteFramebuffers(this.id); } + + public void verify() { + glCheckNamedFramebufferStatus(this.id, GL_FRAMEBUFFER); + } } diff --git a/src/main/java/me/cortex/voxelmon/core/gl/GlTexture.java b/src/main/java/me/cortex/voxelmon/core/gl/GlTexture.java index 9007b7d4..1bf8049d 100644 --- a/src/main/java/me/cortex/voxelmon/core/gl/GlTexture.java +++ b/src/main/java/me/cortex/voxelmon/core/gl/GlTexture.java @@ -12,6 +12,10 @@ import static org.lwjgl.opengl.GL45C.glTextureStorage2D; public class GlTexture extends TrackedObject { final int id; private final int type; + public GlTexture() { + this(GL_TEXTURE_2D) + } + public GlTexture(int type) { this.id = glCreateTextures(type); this.type = type; diff --git a/src/main/java/me/cortex/voxelmon/core/rendering/PostProcessing.java b/src/main/java/me/cortex/voxelmon/core/rendering/PostProcessing.java index 98d8589a..a5ed09fd 100644 --- a/src/main/java/me/cortex/voxelmon/core/rendering/PostProcessing.java +++ b/src/main/java/me/cortex/voxelmon/core/rendering/PostProcessing.java @@ -3,14 +3,46 @@ package me.cortex.voxelmon.core.rendering; import me.cortex.voxelmon.core.gl.GlFramebuffer; import me.cortex.voxelmon.core.gl.GlTexture; +import static org.lwjgl.opengl.ARBFramebufferObject.*; +import static org.lwjgl.opengl.GL11.GL_RGBA8; + public class PostProcessing { private final GlFramebuffer framebuffer; + private int width; + private int height; private GlTexture colour; - private GlTexture depth; + private GlTexture depthStencil; public PostProcessing() { this.framebuffer = new GlFramebuffer(); } + public void setSize(int width, int height) { + if (this.width != width || this.height != height) { + this.width = width; + this.height = height; + if (this.colour != null) { + this.colour.free(); + this.depthStencil.free(); + } + + this.colour = new GlTexture().store(GL_RGBA8, 1, width, height); + this.depthStencil = new GlTexture().store(GL_DEPTH24_STENCIL8, 1, width, height); + + this.framebuffer.bind(GL_COLOR_ATTACHMENT0, this.colour); + this.framebuffer.bind(GL_DEPTH_STENCIL_ATTACHMENT, this.depthStencil); + this.framebuffer.verify(); + } + } + + //Bind and clears the post processing frame buffer + public void bindClearFramebuffer() { + + } + + //Executes the post processing and emits to whatever framebuffer is currently bound via a blit + public void renderPost() { + + } }