simvx.graphics.draw2d¶
Immediate-mode 2D drawing API for Vulkan backend.
Matches the SDL3 Renderer2D interface so 2D games work on both backends. Collects per-frame geometry into CPU buffers; Draw2DPass uploads and renders.
Module Contents¶
Classes¶
Vulkan-backed 2D drawing API matching SDL3 Renderer2D interface. |
Data¶
API¶
- simvx.graphics.draw2d.__all__¶
[‘Draw2D’, ‘UI_VERTEX_DTYPE’]
- simvx.graphics.draw2d.log¶
‘getLogger(…)’
- simvx.graphics.draw2d.UI_VERTEX_DTYPE¶
‘dtype(…)’
- class simvx.graphics.draw2d.Draw2D¶
Vulkan-backed 2D drawing API matching SDL3 Renderer2D interface.
- classmethod push_transform(a, b, c, d, tx, ty)¶
Push a 2D affine transform, composing with current.
- classmethod pop_transform()¶
Pop the last transform, restoring the previous one.
- classmethod push_identity()¶
Push current transform and reset to identity (for screen-space drawing).
- classmethod set_font(path: str | None = None, size: int = 64) None¶
Load an MSDF font atlas via the shared TextRenderer.
- classmethod set_color(r=255, g=255, b=255, a=255)¶
- classmethod fill_rect(pos, size_or_y=None, w=None, h=None)¶
- classmethod draw_rect(pos, size_or_y=None, w=None, h=None)¶
- classmethod draw_line(a, b_or_y=None, x2=None, y2=None)¶
- classmethod draw_lines(points, closed=True, color=None)¶
- classmethod draw_circle(center, radius_or_y=None, radius=None, segments=24)¶
- classmethod draw_text(text, pos, scale=1, color=None)¶
- classmethod text_width(text, scale=1)¶
- classmethod clear(r=0, g=0, b=0)¶
- classmethod present()¶
- classmethod push_clip(x: int, y: int, w: int, h: int)¶
Push a scissor clip rect. Content outside is not drawn.
Nested clips are intersected with the current clip.
- classmethod pop_clip()¶
Pop the last clip rect, restoring the previous one.
- classmethod new_layer()¶
Force a batch break so subsequent draws render on top of all prior geometry.
- classmethod fill_triangle(x1, y1, x2, y2, x3, y3)¶
Emit a single filled triangle.
- classmethod fill_quad(x1, y1, x2, y2, x3, y3, x4, y4)¶
Emit a filled quad from four arbitrary corners (two triangles).
- classmethod draw_thick_line(x1, y1, x2, y2, width=2.0)¶
Draw a thick line as a filled quad using perpendicular offsets.
- classmethod fill_circle(cx, cy, radius, segments=24)¶
Emit a filled circle as a triangle fan (indexed triangles).
- classmethod draw_thick_line_colored(x1, y1, x2, y2, width, color)¶
Set color (float 0-1 tuple) and draw_thick_line in one call.
- classmethod draw_filled_circle(cx, cy, radius, color, segments=24)¶
Set color and fill_circle in one call.
- classmethod draw_filled_triangle(x1, y1, x2, y2, x3, y3, color)¶
Set color and fill_triangle in one call.
- classmethod draw_filled_quad(x1, y1, x2, y2, x3, y3, x4, y4, color)¶
Set color and fill_quad in one call.
- classmethod draw_filled_rect(x, y, w, h, color)¶
Set color (float 0-1 tuple) and fill_rect in one call.
- classmethod draw_rect_colored(x, y, w, h, color)¶
Set color (float 0-1 tuple) and draw_rect in one call.
- classmethod draw_line_colored(x1, y1, x2, y2, color)¶
Set color (float 0-1 tuple) and draw_line in one call.
- classmethod draw_text_colored(text, x, y, scale=1, color=None)¶
Draw text with color (float 0-1 tuple) in one call.
- classmethod draw_texture(texture_id: int, x: float, y: float, w: float, h: float, color: tuple[float, ...] | None = None, rotation: float = 0.0)¶
Draw a textured quad at (x, y) with size (w, h).
Args: texture_id: Bindless texture index from TextureManager. x, y: Top-left position in screen pixels. w, h: Width and height in screen pixels. color: Optional RGBA tint (0.0-1.0 floats). Default white. rotation: Rotation in radians around the quad center.
- classmethod draw_texture_region(texture_id: int, x: float, y: float, w: float, h: float, u0: float = 0.0, v0: float = 0.0, u1: float = 1.0, v1: float = 1.0, color: tuple[float, ...] | None = None, rotation: float = 0.0)¶
Draw a sub-rectangle of a texture as a quad.
Args: texture_id: Bindless texture index. x, y: Top-left position in screen pixels. w, h: Width and height in screen pixels. u0, v0, u1, v1: UV coordinates for the source region (0-1). color: Optional RGBA tint (0.0-1.0 floats). Default white. rotation: Rotation in radians around the quad center.