Source code for simvx.graphics.draw2d_ops
"""Ordered op record for Draw2D.
Every Draw2D submission (fill, line, text, textured quad) appends a single
``Op`` to ``Draw2D._ops``. Draw2DPass walks that list in order and coalesces
adjacent same-(kind, clip, tex_id) ops into one GPU draw, so submission order
is the GPU order. This is the canonical 2D ordering contract; there is no
other mechanism.
Verts are stored as raw 8-float tuples ``(x, y, u, v, r, g, b, a)`` and
indices as raw ``int`` lists; the pass concatenates per-run and builds the
structured numpy buffer once at upload time. Carrying numpy arrays on every
op was hot in the bullet-hell HUD workload (1000+ rects/frame).
Reserved fields (``material_id``, ``blend_mode``) are not used today: they
mark where per-call ShaderMaterial and BlendMode extensions land without
re-shaping callers.
"""
from enum import IntEnum
from typing import NamedTuple
__all__ = ["OpKind", "Op"]
[docs]
class OpKind(IntEnum):
FILL = 0 # fill pipeline, indexed triangles
LINE = 1 # line pipeline, non-indexed line list
TEXT = 2 # MSDF text pipeline, indexed triangles
TEX = 3 # textured-quad pipeline, indexed triangles, bindless tex_id
[docs]
class Op(NamedTuple):
kind: OpKind
clip: tuple[int, int, int, int] | None
verts: list[tuple] # 8-float tuples: (x, y, u, v, r, g, b, a)
indices: list[int] | None # None for LINE (non-indexed)
tex_id: int # -1 for non-TEX; bindless slot for TEX