Source code for simvx.graphics.scene.draw_batch
"""Indirect draw buffer generation — vectorized with numpy."""
from __future__ import annotations
import logging
import numpy as np
from .._types import INDIRECT_DRAW_DTYPE
log = logging.getLogger(__name__)
__all__ = ["DrawBatch"]
[docs]
class DrawBatch:
"""Generates VkDrawIndexedIndirectCommand arrays from entity data."""
def __init__(self) -> None:
self.commands = np.zeros(0, dtype=INDIRECT_DRAW_DTYPE)
[docs]
def build(
self,
index_counts: np.ndarray,
first_indices: np.ndarray,
vertex_offsets: np.ndarray,
) -> np.ndarray:
"""Build the indirect draw buffer from per-mesh data (vectorized)."""
n = len(index_counts)
self.commands = np.zeros(n, dtype=INDIRECT_DRAW_DTYPE)
self.commands["index_count"] = index_counts
self.commands["instance_count"] = 1
self.commands["first_index"] = first_indices
self.commands["vertex_offset"] = vertex_offsets
self.commands["first_instance"] = np.arange(n, dtype=np.uint32)
return self.commands