Skip to content

Commit 561337e

Browse files
committed
hoist common FB
1 parent 4ca9cdb commit 561337e

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/main/java/me/cortex/voxy/client/core/AbstractRenderPipeline.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import me.cortex.voxy.client.core.rendering.hierachical.NodeCleaner;
1111
import me.cortex.voxy.client.core.rendering.post.FullscreenBlit;
1212
import me.cortex.voxy.client.core.rendering.section.backend.AbstractSectionRenderer;
13+
import me.cortex.voxy.client.core.rendering.util.DepthFramebuffer;
1314
import me.cortex.voxy.client.core.rendering.util.DownloadStream;
1415
import me.cortex.voxy.common.util.TrackedObject;
1516
import org.joml.Matrix4f;
@@ -31,6 +32,7 @@
3132
import static org.lwjgl.opengl.GL11C.glStencilFunc;
3233
import static org.lwjgl.opengl.GL11C.glStencilMask;
3334
import static org.lwjgl.opengl.GL11C.glStencilOp;
35+
import static org.lwjgl.opengl.GL30C.GL_DEPTH24_STENCIL8;
3436
import static org.lwjgl.opengl.GL30C.GL_FRAMEBUFFER;
3537
import static org.lwjgl.opengl.GL30C.glBindFramebuffer;
3638
import static org.lwjgl.opengl.GL42.GL_LEQUAL;
@@ -53,6 +55,9 @@ public abstract class AbstractRenderPipeline extends TrackedObject {
5355
private final FullscreenBlit depthMaskBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/noop.frag");
5456
private final FullscreenBlit depthSetBlit = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth0.frag");
5557
private final FullscreenBlit depthCopy = new FullscreenBlit("voxy:post/fullscreen2.vert", "voxy:post/depth_copy.frag");
58+
59+
public final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
60+
5661
private static final int DEPTH_SAMPLER = glGenSamplers();
5762
static {
5863
glSamplerParameteri(DEPTH_SAMPLER, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -208,6 +213,7 @@ protected void innerPrimaryWork(Viewport<?> viewport, int depthBuffer) {
208213

209214
@Override
210215
protected void free0() {
216+
this.fb.free();
211217
this.sectionRenderer.free();
212218
this.depthMaskBlit.delete();
213219
this.depthSetBlit.delete();

src/main/java/me/cortex/voxy/client/core/IrisVoxyRenderPipeline.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
public class IrisVoxyRenderPipeline extends AbstractRenderPipeline {
2727
private final IrisVoxyRenderPipelineData data;
2828
private final FullscreenBlit depthBlit = new FullscreenBlit("voxy:post/blit_texture_depth_cutout.frag");
29-
public final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
30-
public final DepthFramebuffer fbTranslucent = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
29+
public final DepthFramebuffer fbTranslucent = new DepthFramebuffer(this.fb.getDepthTex().getFormat());
3130

3231
private final GlBuffer shaderUniforms;
3332

@@ -79,7 +78,6 @@ public void free() {
7978
this.data.thePipeline = null;
8079

8180
this.depthBlit.delete();
82-
this.fb.free();
8381
this.fbTranslucent.free();
8482

8583
if (this.shaderUniforms != null) {

src/main/java/me/cortex/voxy/client/core/NormalRenderPipeline.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class NormalRenderPipeline extends AbstractRenderPipeline {
3737
private GlTexture colourTex;
3838
private GlTexture colourSSAOTex;
3939
private final GlFramebuffer fbSSAO = new GlFramebuffer();
40-
private final DepthFramebuffer fb = new DepthFramebuffer(GL_DEPTH24_STENCIL8);
4140

4241
private final boolean useEnvFog;
4342
private final FullscreenBlit finalBlit;
@@ -66,7 +65,7 @@ protected int setup(Viewport<?> viewport, int sourceFB, int srcWidth, int srcHei
6665
this.colourSSAOTex = new GlTexture().store(GL_RGBA8, 1, viewport.width, viewport.height);
6766

6867
this.fb.framebuffer.bind(GL_COLOR_ATTACHMENT0, this.colourTex).verify();
69-
this.fbSSAO.bind(GL_DEPTH_STENCIL_ATTACHMENT, this.fb.getDepthTex()).bind(GL_COLOR_ATTACHMENT0, this.colourSSAOTex).verify();
68+
this.fbSSAO.bind(this.fb.getDepthAttachmentType(), this.fb.getDepthTex()).bind(GL_COLOR_ATTACHMENT0, this.colourSSAOTex).verify();
7069

7170

7271
glTextureParameterf(this.colourTex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -145,7 +144,6 @@ public void setupAndBindTranslucent(Viewport<?> viewport) {
145144
public void free() {
146145
this.finalBlit.delete();
147146
this.ssaoCompute.free();
148-
this.fb.free();
149147
this.fbSSAO.free();
150148
if (this.colourTex != null) {
151149
this.colourTex.free();

src/main/java/me/cortex/voxy/client/core/gl/GlTexture.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public int getLevels() {
9696
return this.levels;
9797
}
9898

99+
public int getFormat() {
100+
this.assertAllocated();
101+
return this.format;
102+
}
103+
99104
private long getEstimatedSize() {
100105
this.assertAllocated();
101106
long elemSize = switch (this.format) {

src/main/java/me/cortex/voxy/client/core/rendering/util/DepthFramebuffer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ public boolean resize(int width, int height) {
2828
this.depthBuffer.free();
2929
}
3030
this.depthBuffer = new GlTexture().store(this.depthType, 1, width, height);
31-
this.framebuffer.bind(this.depthType == GL_DEPTH24_STENCIL8?GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH_ATTACHMENT, this.depthBuffer).verify();
31+
this.framebuffer.bind(this.getDepthAttachmentType(), this.depthBuffer).verify();
3232
return true;
3333
}
3434
return false;
3535
}
3636

37+
public int getDepthAttachmentType() {
38+
return this.depthType == GL_DEPTH24_STENCIL8?GL_DEPTH_STENCIL_ATTACHMENT: GL_DEPTH_ATTACHMENT;
39+
}
40+
3741
public void clear() {
3842
this.clear(1.0f);
3943
}

0 commit comments

Comments
 (0)