Class TexturedTriangle

Direct Known Subclasses:
LightmappedTriangle

public class TexturedTriangle extends AbstractCoordinateShape
A textured triangle renderer with perspective-correct texture mapping.

Quake-style subdivided perspective correction: (u/z, v/z, 1/z) are interpolated linearly in screen space and the exact texture coordinate is recovered with one reciprocal per subdivision interval, with affine stepping in between. This makes screen-size tessellation unnecessary — triangles of any size render with correct perspective.

See Also:
  • Field Details

    • PROF_TRIS

      public static final AtomicLong PROF_TRIS
      paintTriangle invocations.
    • PROF_BACKFACE

      public static final AtomicLong PROF_BACKFACE
      Triangles facing away (engine winding convention).
    • PROF_OFFY

      public static final AtomicLong PROF_OFFY
      Triangles discarded by vertical render-bounds clamp.
    • PROF_TINY

      public static final AtomicLong PROF_TINY
      Triangles with screen bounding box below 2x2 pixels.
    • PROF_SPANS

      public static final AtomicLong PROF_SPANS
      Scanline spans drawn.
    • PROF_PIXELS

      public static final AtomicLong PROF_PIXELS
      Pixel loop iterations across all spans.
  • Constructor Details

    • TexturedTriangle

      public TexturedTriangle(Vertex p1, Vertex p2, Vertex p3, Texture texture)
      Creates a textured triangle with the specified vertices and texture.
      Parameters:
      p1 - the first vertex (must have textureCoordinate set)
      p2 - the second vertex (must have textureCoordinate set)
      p3 - the third vertex (must have textureCoordinate set)
      texture - the texture to apply
    • TexturedTriangle

      protected TexturedTriangle(Texture texture)
      Constructor for flat-array-backed subclasses (MeshTriangle) that carry no Vertex objects and paint exclusively through paintFlat(RenderingContext, Texture, boolean, Point2D, Point2D, Point2D, Point2D, Point2D, Point2D, double, double, double, double, double), which computes the mipmap metric inline. totalTextureDistance is set to a neutral 1 — never read on that path.
      Parameters:
      texture - the texture the subclass paints with
  • Method Details

    • setPerspectiveCorrectionEnabled

      public static void setPerspectiveCorrectionEnabled(boolean enabled)
      Enables or disables perspective-correct texture mapping. When disabled, rendering falls back to plain affine mapping, which visibly warps textures on large on-screen triangles at steep angles.
      Parameters:
      enabled - true for perspective-correct mapping
    • isPerspectiveCorrectionEnabled

      public static boolean isPerspectiveCorrectionEnabled()
      Returns whether perspective-correct texture mapping is enabled.
      Returns:
      true when perspective correction is active
    • getTexture

      public Texture getTexture()
      Returns the current texture.
      Returns:
      the texture
    • setTexture

      public void setTexture(Texture texture)
      Atomically swaps the texture. Painters pick up the new texture at the next paint call; a triangle in flight finishes with the old one.
      Parameters:
      texture - the new texture
    • setGiShade

      public void setGiShade(float r, float g, float b)
      Stamps a uniform GI light triplet on this triangle (stage-1 preview): the span loops multiply every sampled texel by triplet / 255 until clearGiShade() is called.
      Parameters:
      r - red light units (255 = full)
      g - green light units
      b - blue light units
    • clearGiShade

      public void clearGiShade()
      Returns to painting the bare texture (stage-1 preview over).
    • setHaze

      public void setHaze(float mulR, float mulG, float mulB, float addR, float addG, float addB)
      Stamps this triangle's haze blend: the span loops compute texel * mul / 255 + add per channel — the attenuation half of the haze rides the light multiply that already exists, so the per-pixel price is one add per channel, no extra multiplication.
      Parameters:
      mulR - red shade multiplier including (1-f) (255 = full)
      mulG - green multiplier
      mulB - blue multiplier
      addR - red additive sky term (sky × f)
      addG - green additive term
      addB - blue additive term
    • clearHaze

      public void clearHaze()
      Returns to the haze-free span path (atmosphere off or too near).
    • profReset

      public static void profReset()
      Resets all profiling counters.
    • refreshTextureDistance

      protected final void refreshTextureDistance()
      Recomputes the mipmap-selection metric after texture coordinates are replaced post-construction (used by generated-UV subclasses like lightmapped triangles).
    • paint

      public void paint(RenderingContext renderBuffer)
      Description copied from class: AbstractCoordinateShape
      Paints this shape onto the rendering context's pixel buffer.

      This method is called after all shapes have been transformed and sorted by depth. Implementations should use the transformed screen-space coordinates from Vertex.transformedCoordinate(RenderingContext) to draw pixels.

      Specified by:
      paint in class AbstractCoordinateShape
      Parameters:
      renderBuffer - the rendering context containing the pixel buffer and graphics context
    • isBackfaceCullingEnabled

      public boolean isBackfaceCullingEnabled()
      Checks if backface culling is enabled for this triangle.
      Returns:
      true if backface culling is enabled
    • setBackfaceCulling

      public void setBackfaceCulling(boolean backfaceCulling)
      Enables or disables backface culling for this triangle.
      Parameters:
      backfaceCulling - true to enable backface culling