Class RenderUtils

java.lang.Object
me.hackware.api.util.RenderUtils

public final class RenderUtils extends Object
Direct-draw API for 3D overlays: box outlines/fills, lines, quads and camera-facing strips (tracers), plus world-to-screen projection. Draw calls are valid between Render3DEvent begin/end; the client drives the lifecycle. Shader-mod routing and AA selection go through RenderBridge.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.joml.Matrix4f
    The combined bobHurt + bobView transform for the current frame.
    static float
    Last FOV captured from GameRenderer.renderLevel (degrees).
    static final float
    Near-plane distance for manual strip clipping (matches vanilla).
    static final org.joml.Matrix4f
    View-projection matrix for the current frame (proj * bob * view).
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    argb(int r, int g, int b, int a)
     
    static void
    Called once per frame from GameRendererMixin before Render3DEvent is posted.
    static void
    beginRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource bufferSource, com.mojang.blaze3d.vertex.PoseStack poseStack, net.minecraft.client.Camera camera, net.minecraft.client.renderer.culling.Frustum frameFrustum)
    Begins the per-frame direct-draw context.
    static void
    Clears the direct-draw pipeline/type caches (called from RenderState.clearAllCaches).
    static void
    countDraws(int draws)
    Counts draws against this frame's budget: for geometry emitted directly (emitLine(double, double, double, double, double, double, int, float) and the like), which counts nothing by itself — a caller drawing a lot of it charges what it drew (a box outline, twelve segments, is one draw).
    static void
    drawBoxFill(net.minecraft.world.phys.AABB box, int color)
     
    static void
    drawBoxOutline(net.minecraft.world.phys.AABB box, int color, float lineWidth)
     
    static void
    drawBoxOutlineDepth(net.minecraft.world.phys.AABB box, int color, float lineWidth)
     
    static void
    drawLine(net.minecraft.world.phys.Vec3 from, net.minecraft.world.phys.Vec3 to, int color, float lineWidth)
     
    static int
    How many draws are left of this frame's budget (MAX_DRAWS_PER_FRAME).
    static void
    emitClippedStrip(float sx, float sy, float sz, float ex, float ey, float ez, org.joml.Vector3f fwd, int color, float pxWidth, float pxToWorld)
    Emits a camera-facing anti-aliased quad strip with constant screen-pixel width, after clipping the segment against the near plane.
    static void
    emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int color)
    Emits a single filled quad into the no-depth-test filled batch.
    static void
    emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int c0, int c1, int c2, int c3)
    Emits a filled quad with a per-vertex color (for gradients) into the no-depth-test filled batch.
    static void
    emitFillQuadRelative(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, int color)
    Emits a filled quad using camera-relative float coordinates.
    static void
    emitLine(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
    Emits a single line segment into the no-depth-test line batch.
    static void
    emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
    Emits a single line segment into the depth-tested line batch.
    static void
    emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int startColor, int endColor, float lineWidth)
    Emits a depth-tested line segment whose color blends from startColor to endColor.
    static void
    emitLineRelative(float sx, float sy, float sz, float ex, float ey, float ez, int color, float lineWidth)
    Emits a line segment using camera-relative float coordinates.
    static void
    Flushes any pending draw batches and clears the render context.
    static void
    Immediately flushes the pending no-depth lines + filled batches without tearing down the render context.
    static net.minecraft.client.renderer.MultiBufferSource.BufferSource
    Returns the active buffer source for the current frame, or null outside a render pass.
    static double
    static double
    static double
    static boolean
    Returns true when draw calls should be skipped this frame.
    static boolean
    isInFrustum(net.minecraft.world.phys.AABB box)
    Returns true if the given world-space AABB is inside (or intersects) the current view frustum.
    static int
    withAlpha(int argb, int alpha)
     
    static org.joml.Vector3f
    worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera)
    Project a world position to GUI-scaled screen coordinates.
    static org.joml.Vector3f
    worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera, float minDepth)
    Project a world position to GUI-scaled screen coordinates, never giving up on a point at or behind the camera: its camera-space depth is clamped to at least minDepth (blocks) so it still lands somewhere on/around the screen.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STRIP_NEAR_PLANE

      public static final float STRIP_NEAR_PLANE
      Near-plane distance for manual strip clipping (matches vanilla).
      See Also:
    • lastFov

      public static float lastFov
      Last FOV captured from GameRenderer.renderLevel (degrees).
    • viewProjMatrix

      public static final org.joml.Matrix4f viewProjMatrix
      View-projection matrix for the current frame (proj * bob * view). Set by GameRendererMixin.
    • bobMatrix

      public static final org.joml.Matrix4f bobMatrix
      The combined bobHurt + bobView transform for the current frame. Applied to the projection matrix by vanilla so that the world "bobs" when walking. Custom renderers that bypass the GPU projection (e.g. worldToScreen(double, double, double, net.minecraft.client.Camera)) must account for this matrix to stay aligned with the bobbed world.

      Identity when view bobbing is disabled or suppressed.

  • Method Details

    • beginFrame

      public static void beginFrame()
      Called once per frame from GameRendererMixin before Render3DEvent is posted. Resets the draw budget and detects post-loading conditions, and registers Iris pipelines on first use.
    • isGizmosSuppressed

      public static boolean isGizmosSuppressed()
      Returns true when draw calls should be skipped this frame.
    • drawsLeft

      public static int drawsLeft()
      How many draws are left of this frame's budget (MAX_DRAWS_PER_FRAME).
    • countDraws

      public static void countDraws(int draws)
      Counts draws against this frame's budget: for geometry emitted directly (emitLine(double, double, double, double, double, double, int, float) and the like), which counts nothing by itself — a caller drawing a lot of it charges what it drew (a box outline, twelve segments, is one draw).
    • beginRender

      public static void beginRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource bufferSource, com.mojang.blaze3d.vertex.PoseStack poseStack, net.minecraft.client.Camera camera, net.minecraft.client.renderer.culling.Frustum frameFrustum)
      Begins the per-frame direct-draw context. Must be called before posting Render3DEvent and paired with endRender().
    • isInFrustum

      public static boolean isInFrustum(net.minecraft.world.phys.AABB box)
      Returns true if the given world-space AABB is inside (or intersects) the current view frustum. Always returns true when no frustum is set.
    • endRender

      public static void endRender()
      Flushes any pending draw batches and clears the render context.
    • flushPendingBatches

      public static void flushPendingBatches()
      Immediately flushes the pending no-depth lines + filled batches without tearing down the render context. Used by post-process pipelines that need draws to materialise against a specific FBO that's only bound for a short window.
    • drawBoxOutline

      public static void drawBoxOutline(net.minecraft.world.phys.AABB box, int color, float lineWidth)
    • drawBoxOutlineDepth

      public static void drawBoxOutlineDepth(net.minecraft.world.phys.AABB box, int color, float lineWidth)
    • drawBoxFill

      public static void drawBoxFill(net.minecraft.world.phys.AABB box, int color)
    • drawLine

      public static void drawLine(net.minecraft.world.phys.Vec3 from, net.minecraft.world.phys.Vec3 to, int color, float lineWidth)
    • getCamX

      public static double getCamX()
    • getCamY

      public static double getCamY()
    • getCamZ

      public static double getCamZ()
    • getBufferSource

      public static net.minecraft.client.renderer.MultiBufferSource.BufferSource getBufferSource()
      Returns the active buffer source for the current frame, or null outside a render pass.
    • emitFillQuad

      public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int color)
      Emits a single filled quad into the no-depth-test filled batch.
    • emitFillQuad

      public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int c0, int c1, int c2, int c3)
      Emits a filled quad with a per-vertex color (for gradients) into the no-depth-test filled batch.
    • emitFillQuadRelative

      public static void emitFillQuadRelative(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, int color)
      Emits a filled quad using camera-relative float coordinates. Use this when positions were already computed as (world - cam) in doubles and then cast to float, avoiding double precision loss.
    • emitLine

      public static void emitLine(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
      Emits a single line segment into the no-depth-test line batch.
    • emitLineDepth

      public static void emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
      Emits a single line segment into the depth-tested line batch.
    • emitLineDepth

      public static void emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int startColor, int endColor, float lineWidth)
      Emits a depth-tested line segment whose color blends from startColor to endColor.
    • emitLineRelative

      public static void emitLineRelative(float sx, float sy, float sz, float ex, float ey, float ez, int color, float lineWidth)
      Emits a line segment using camera-relative float coordinates. Use this when positions were already computed as (world - cam) in doubles and then cast to float, avoiding double precision loss.
    • emitClippedStrip

      public static void emitClippedStrip(float sx, float sy, float sz, float ex, float ey, float ez, org.joml.Vector3f fwd, int color, float pxWidth, float pxToWorld)
      Emits a camera-facing anti-aliased quad strip with constant screen-pixel width, after clipping the segment against the near plane.

      Unlike the MC line shader (which computes width from the normal's screen projection and degenerates when the line is view-aligned), this builds explicit billboard geometry whose width is derived from depth, guaranteeing constant rasterised width at any angle. The quad is widened by STRIP_AA_PAD pixels per side and the strip_aa shader fades edge coverage over the outer pixel.

      Parameters:
      fwd - unit camera-forward direction (camera-relative)
      pxWidth - desired width in screen pixels
      pxToWorld - pre-computed 2·tan(fov/2) / screenHeight
    • argb

      public static int argb(int r, int g, int b, int a)
    • withAlpha

      public static int withAlpha(int argb, int alpha)
    • worldToScreen

      public static org.joml.Vector3f worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera)
      Project a world position to GUI-scaled screen coordinates.
      Returns:
      a Vector3f with (screenX, screenY, cameraSpaceZ) or null if the point is behind the camera.
    • worldToScreen

      public static org.joml.Vector3f worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera, float minDepth)
      Project a world position to GUI-scaled screen coordinates, never giving up on a point at or behind the camera: its camera-space depth is clamped to at least minDepth (blocks) so it still lands somewhere on/around the screen. With minDepth <= 0 this behaves like worldToScreen(double, double, double, Camera) and returns null for points behind the camera.
      Returns:
      a Vector3f with (screenX, screenY, cameraSpaceZ), or null only when minDepth <= 0 and the point is behind the camera
    • clearDrawCaches

      public static void clearDrawCaches()
      Clears the direct-draw pipeline/type caches (called from RenderState.clearAllCaches).