Skip to content

Commit

Permalink
Fix depth testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron committed Dec 31, 2024
1 parent 36756dd commit 8e56d1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public static boolean renderPreview(DrawContext context, Screen screen, int inde
}

matrices.pop();
RenderSystem.disableDepthTest();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.hysky.skyblocker.skyblock.profileviewer;

import com.mojang.blaze3d.systems.RenderSystem;
import de.hysky.skyblocker.skyblock.profileviewer.utils.ProfileViewerUtils;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -40,12 +39,8 @@ public ProfileViewerNavButton(ProfileViewerScreen screen, String tabName, int in

@Override
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
RenderSystem.disableDepthTest();

context.drawGuiTexture(RenderLayer::getGuiTextured, toggled ? BUTTON_TEXTURES_TOGGLED : BUTTON_TEXTURES, this.getX(), this.getY(), this.width, this.height - ((this.toggled) ? 0 : 4));
context.drawItem(this.icon, this.getX() + 6, this.getY() + (this.toggled ? 7 : 9));

RenderSystem.enableDepthTest();
}

@Override
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public static void renderLinesFromPoints(WorldRenderContext context, Vec3d[] poi
RenderSystem.lineWidth(1f);
RenderSystem.enableCull();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
RenderSystem.disableDepthTest();
}

public static void renderLineFromCursor(WorldRenderContext context, Vec3d point, float[] colorComponents, float alpha, float lineWidth) {
Expand Down Expand Up @@ -261,6 +262,7 @@ public static void renderLineFromCursor(WorldRenderContext context, Vec3d point,
RenderSystem.lineWidth(1f);
RenderSystem.enableCull();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
RenderSystem.disableDepthTest();
}

public static void renderQuad(WorldRenderContext context, Vec3d[] points, float[] colorComponents, float alpha, boolean throughWalls) {
Expand All @@ -276,6 +278,7 @@ public static void renderQuad(WorldRenderContext context, Vec3d[] points, float[
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.disableCull();
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL);

BufferBuilder buffer = tessellator.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
Expand All @@ -286,6 +289,7 @@ public static void renderQuad(WorldRenderContext context, Vec3d[] points, float[

RenderSystem.enableCull();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
RenderSystem.disableDepthTest();
}

public static void renderText(WorldRenderContext context, Text text, Vec3d pos, boolean throughWalls) {
Expand Down Expand Up @@ -323,11 +327,13 @@ public static void renderText(WorldRenderContext context, OrderedText text, Vec3
VertexConsumerProvider.Immediate consumers = VertexConsumerProvider.immediate(ALLOCATOR);

//Don't trust the render layer to do this for you!
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL);

textRenderer.draw(text, xOffset, yOffset, 0xFFFFFFFF, false, positionMatrix, consumers, throughWalls ? TextRenderer.TextLayerType.SEE_THROUGH : TextRenderer.TextLayerType.NORMAL, 0, LightmapTextureManager.MAX_LIGHT_COORDINATE);
consumers.draw();

RenderSystem.disableDepthTest();
RenderSystem.depthFunc(GL11.GL_LEQUAL);
}

Expand All @@ -338,8 +344,14 @@ private static void drawTranslucents(WorldRenderContext context) {
Profiler profiler = Profilers.get();

profiler.push("skyblockerTranslucentDraw");
//Draw all render layers that haven't been drawn yet - drawing a specific layer does nothing and idk why
((VertexConsumerProvider.Immediate) context.consumers()).draw();
VertexConsumerProvider.Immediate immediate = (VertexConsumerProvider.Immediate) context.consumers();

//Work around RenderLayer impl problems (DepthTest#ALWAYS not actually turning off depth testing)
RenderSystem.disableDepthTest();
immediate.draw(SkyblockerRenderLayers.FILLED_THROUGH_WALLS);

//Draw all render layers that haven't been drawn yet - drawing a specific layer does nothing and idk why (IF bug maybe?)
immediate.draw();
profiler.pop();
}

Expand Down

0 comments on commit 8e56d1a

Please sign in to comment.