hoist common FB

This commit is contained in:
mcrcortex
2025-12-15 09:12:08 +10:00
parent 4ca9cdbaa8
commit 561337e10c
5 changed files with 18 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ import me.cortex.voxy.client.core.rendering.hierachical.HierarchicalOcclusionTra
import me.cortex.voxy.client.core.rendering.hierachical.NodeCleaner; import me.cortex.voxy.client.core.rendering.hierachical.NodeCleaner;
import me.cortex.voxy.client.core.rendering.post.FullscreenBlit; import me.cortex.voxy.client.core.rendering.post.FullscreenBlit;
import me.cortex.voxy.client.core.rendering.section.backend.AbstractSectionRenderer; import me.cortex.voxy.client.core.rendering.section.backend.AbstractSectionRenderer;
import me.cortex.voxy.client.core.rendering.util.DepthFramebuffer;
import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.DownloadStream;
import me.cortex.voxy.common.util.TrackedObject; import me.cortex.voxy.common.util.TrackedObject;
import org.joml.Matrix4f; import org.joml.Matrix4f;
@@ -31,6 +32,7 @@ import static org.lwjgl.opengl.GL11C.glEnable;
import static org.lwjgl.opengl.GL11C.glStencilFunc; import static org.lwjgl.opengl.GL11C.glStencilFunc;
import static org.lwjgl.opengl.GL11C.glStencilMask; import static org.lwjgl.opengl.GL11C.glStencilMask;
import static org.lwjgl.opengl.GL11C.glStencilOp; import static org.lwjgl.opengl.GL11C.glStencilOp;
import static org.lwjgl.opengl.GL30C.GL_DEPTH24_STENCIL8;
import static org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER; import static org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER;
import static org.lwjgl.opengl.GL30C.glBindFramebuffer; import static org.lwjgl.opengl.GL30C.glBindFramebuffer;
import static org.lwjgl.opengl.GL42.GL_LEQUAL; import static org.lwjgl.opengl.GL42.GL_LEQUAL;
@@ -53,6 +55,9 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
private final FullscreenBlit depthMaskBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/noop.frag"); private final FullscreenBlit depthMaskBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/noop.frag");
private final FullscreenBlit depthSetBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth0.frag"); private final FullscreenBlit depthSetBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth0.frag");
private final FullscreenBlit depthCopy = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth_copy.frag"); private final FullscreenBlit depthCopy = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth_copy.frag");
public final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
private static final int DEPTH_SAMPLER = glGenSamplers(); private static final int DEPTH_SAMPLER = glGenSamplers();
static { static {
glSamplerParameteri(DEPTH_SAMPLER, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glSamplerParameteri(DEPTH_SAMPLER, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -208,6 +213,7 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
@Override @Override
protected void free0() { protected void free0() {
this.fb.free();
this.sectionRenderer.free(); this.sectionRenderer.free();
this.depthMaskBlit.delete(); this.depthMaskBlit.delete();
this.depthSetBlit.delete(); this.depthSetBlit.delete();

View File

@@ -26,8 +26,7 @@ import static org.lwjgl.opengl.GL45C.*;
public class IrisVoxyRenderPipeline extends AbstractRenderPipeline { public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
private final IrisVoxyRenderPipelineData data; private final IrisVoxyRenderPipelineData data;
private final FullscreenBlit depthBlit = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag"); private final FullscreenBlit depthBlit = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag");
public final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8); public final DepthFramebuffer fbTranslucent = new DepthFramebuffer(this.fb.getDepthTex().getFormat());
public final DepthFramebuffer fbTranslucent = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
private final GlBuffer shaderUniforms; private final GlBuffer shaderUniforms;
@@ -79,7 +78,6 @@ public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
this.data.thePipeline = null; this.data.thePipeline = null;
this.depthBlit.delete(); this.depthBlit.delete();
this.fb.free();
this.fbTranslucent.free(); this.fbTranslucent.free();
if (this.shaderUniforms != null) { if (this.shaderUniforms != null) {

View File

@@ -37,7 +37,6 @@ public class NormalRenderPipeline extends AbstractRenderPipeline {
private GlTexture colourTex; private GlTexture colourTex;
private GlTexture colourSSAOTex; private GlTexture colourSSAOTex;
private final GlFramebuffer fbSSAO = new GlFramebuffer(); private final GlFramebuffer fbSSAO = new GlFramebuffer();
private final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
private final boolean useEnvFog; private final boolean useEnvFog;
private final FullscreenBlit finalBlit; private final FullscreenBlit finalBlit;
@@ -66,7 +65,7 @@ public class NormalRenderPipeline extends AbstractRenderPipeline {
this.colourSSAOTex = new GlTexture().store(GL_RGBA8, 1, viewport.width, viewport.height); this.colourSSAOTex = new GlTexture().store(GL_RGBA8, 1, viewport.width, viewport.height);
this.fb.framebuffer.bind(GL_COLOR_ATTACHMENT0, this.colourTex).verify(); this.fb.framebuffer.bind(GL_COLOR_ATTACHMENT0, this.colourTex).verify();
this.fbSSAO.bind(GL_DEPTH_STENCIL_ATTACHMENT, this.fb.getDepthTex()).bind(GL_COLOR_ATTACHMENT0, this.colourSSAOTex).verify(); this.fbSSAO.bind(this.fb.getDepthAttachmentType(), this.fb.getDepthTex()).bind(GL_COLOR_ATTACHMENT0, this.colourSSAOTex).verify();
glTextureParameterf(this.colourTex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTextureParameterf(this.colourTex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -145,7 +144,6 @@ public class NormalRenderPipeline extends AbstractRenderPipeline {
public void free() { public void free() {
this.finalBlit.delete(); this.finalBlit.delete();
this.ssaoCompute.free(); this.ssaoCompute.free();
this.fb.free();
this.fbSSAO.free(); this.fbSSAO.free();
if (this.colourTex != null) { if (this.colourTex != null) {
this.colourTex.free(); this.colourTex.free();

View File

@@ -96,6 +96,11 @@ public class GlTexture extends TrackedObject {
return this.levels; return this.levels;
} }
public int getFormat() {
this.assertAllocated();
return this.format;
}
private long getEstimatedSize() { private long getEstimatedSize() {
this.assertAllocated(); this.assertAllocated();
long elemSize = switch (this.format) { long elemSize = switch (this.format) {

View File

@@ -28,12 +28,16 @@ public class DepthFramebuffer {
this.depthBuffer.free(); this.depthBuffer.free();
} }
this.depthBuffer = new GlTexture().store(this.depthType, 1, width, height); this.depthBuffer = new GlTexture().store(this.depthType, 1, width, height);
this.framebuffer.bind(this.depthType == GL_DEPTH24_STENCIL8?GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH_ATTACHMENT, this.depthBuffer).verify(); this.framebuffer.bind(this.getDepthAttachmentType(), this.depthBuffer).verify();
return true; return true;
} }
return false; return false;
} }
public int getDepthAttachmentType() {
return this.depthType == GL_DEPTH24_STENCIL8?GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH_ATTACHMENT;
}
public void clear() { public void clear() {
this.clear(1.0f); this.clear(1.0f);
} }