nx_tex_sample.nx
buildroot/runtime/nx_tex_sample.nx
about
nx_tex_sample.nx -- UV texture sampling on Image (graphics).
Distinct from nx_texture.nx (Haralick GLCM + LBP texture
ANALYSIS for image classification). This file is texture
SAMPLING for rendering -- the GLSL texture2D / HLSL Sample /
Metal texture-access primitive. Completes the graphics minimum
stack (nx_raster + nx_zbuf + this).
Pure i64 substrate -- no FPU, no GPU. Substrate can now sample
textures with bilinear filtering + wrap modes on any backend
including Cortex-M3 with a framebuffer.
L3 composition (bits-up):
nx_image.Image (canonical pixel container, L1)
nx_loop.LoopVerdict (bounded loops)
===== UV convention =============================================
(u, v) in Q10 fixed-point representing [0, 1) UV space.
u_q10 = 0 -> left edge of texture
u_q10 = 1024 -> right edge (exclusive)
v_q10 = 0 -> top edge of texture
v_q10 = 1024 -> bottom edge (exclusive)
Q10 over Q14: bilinear weights need sub-pixel accuracy that 8-bit
can't give; Q14 is too tight for clean integer multiplication;
Q10 = sweet spot for the substrate's existing arithmetic.
===== Wrap modes (sealed enum) ==================================
NX_TEX_WRAP_CLAMP -- saturate to [0, W-1] / [0, H-1]
NX_TEX_WRAP_REPEAT -- modulo W / H (tile)
NX_TEX_WRAP_MIRROR -- ping-pong: every other tile is flipped
===== Filter modes ==============================================
NX_TEX_FILTER_NEAREST -- single texel lookup; fast, blocky
NX_TEX_FILTER_BILINEAR -- 4-tap weighted average; smooth
genealogy_id: catmull_smith_1980_texture_mapping +
dependencies 4 imports · 3 importers
imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_image.nx
imported by: nx_render_pass.nxnx_tex_sample_gate.nxnx_textured_tri.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 58 | const NX_TXS_Q10: nx_int = 1024 |
| 62 | const NX_TXS_WRAP_CLAMP: nx_int = 0 |
| 63 | const NX_TXS_WRAP_REPEAT: nx_int = 1 |
| 64 | const NX_TXS_WRAP_MIRROR: nx_int = 2 |
| 65 | const NX_TXS_WRAP_N: nx_int = 3 |
| 75 | const NX_TXS_FILTER_NEAREST: nx_int = 0 |
| 76 | const NX_TXS_FILTER_BILINEAR: nx_int = 1 |
| 77 | const NX_TXS_FILTER_N: nx_int = 2 |
| 87 | const NX_TXS_OK: nx_int = 0 |
| 88 | const NX_TXS_ERR_BAD_TEXTURE: nx_int = 1 |
| 89 | const NX_TXS_ERR_BAD_KIND: nx_int = 2 |
| 90 | const NX_TXS_N_VERDICTS: nx_int = 3 |
functions
| 67 | func nx_txs_wrap_is_valid(k: nx_int) -> nx_int called by 1: main |
| 79 | func nx_txs_filter_is_valid(k: nx_int) -> nx_int called by 1: main |
| 92 | func nx_txs_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 100 | func _txs_wrap_coord(x: nx_int, dim: nx_int, mode: nx_int) -> nx_int |
| 124 | func nx_txs_sample_nearest(tex: *Image, u_q10: nx_int, v_q10: nx_int, |
| 141 | func nx_txs_sample_bilinear(tex: *Image, u_q10: nx_int, v_q10: nx_int, |
| 180 | func nx_txs_sample(tex: *Image, u_q10: nx_int, v_q10: nx_int, |
| 198 | func main() -> i64 |