Gfx GX Fn GXGetLightAttnK - wowjinxy/libPorpoise GitHub Wiki

GXGetLightAttnK

  • Category: Lighting
  • Matrix Status: Implemented
  • Matrix Notes: Verified distance attenuation getter reads k0/k1/k2 from light object state.
  • Matrix Link: Gfx-GX-API-Matrix

Official SDK (Reference)

  • Manual page: reference/man/gfx/gx/Lighting/GXGetLightAttnK.html
  • Reference source: reference/gx/GXLight.c (GXGetLightAttnK)
  • SDK behavior:
    • Signature: void GXGetLightAttnK(GXLightObj* lt_obj, f32* k0, f32* k1, f32* k2) (manual) / const GXLightObj* in reference source.
    • Reads distance attenuation coefficients (k[0..2]) from the provided light object.
    • Getter only; no GX/XF register writes.
    • SDK debug path validates input assumptions, then writes all three outputs.

libPorpoise Implementation

  • Public API declaration: include/dolphin/gx/GXGet.h
  • Runtime implementation: src/gx/pc_gx.c (GXGetLightAttnK)
  • Behavior:
    • Casts light object to internal layout and returns k0/k1/k2.
    • Performs per-output null checks (k0/k1/k2) before writing.
    • Does not mutate GX renderer state.

SDK vs Porpoise Diff

  • Signature parity:
    • SDK manual: GXLightObj*; SDK source uses const GXLightObj*.
    • Porpoise header: GXLightObj*; runtime uses internal void* and read-only access.
  • Behavioral parity:
    • SDK: returns distance attenuation coefficients from light object storage.
    • Porpoise: same coefficient mapping (k0/k1/k2).
  • Known divergence:
    • SDK-style code assumes non-null outputs; Porpoise fail-soft allows null output pointers (skips those writes).
    • SDK debug path asserts on invalid inputs; Porpoise does not assert in this getter path.

Validation Checklist

  • GX demo coverage checked
  • Pikmin usage path checked
  • Matrix status updated if needed
  • Notes updated with concrete file/function references

Working Notes

  • Reference implementation writes all three outputs directly from obj->k[0..2].
  • Porpoise mapping is direct and consistent with light-object layout used by init/load light paths.