MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk_wrap.graphics.Sprite Class Reference

Public Member Functions

None __init__ (self, "App" app, str|Path|None image=None, *, int width=0, int height=0, str vertex_shader="", str fragment_shader="")
 A 2D image that can be queued for drawing each frame.
None close (self)
None draw (self, int x=0, int y=0, *, int|None width=None, int|None height=None, float scale=1.0, float rotation=0.0)
None enable_extended_uniforms (self)
None set_mouse (self, float x, float y, bool pressed=False)
None set_uniform (self, int index, float x, float y, float z, float w)
None shader_params (self, float first=0.0, float second=0.0, float third=0.0, float fourth=0.0)
None update (self, object pixels, int width, int height, *, int pitch=0)

Public Attributes

 native = None
 Create an image sprite or an empty dynamic texture.

Detailed Description

Definition at line 45 of file graphics.py.

Constructor & Destructor Documentation

◆ __init__()

None mxvk_wrap.graphics.Sprite.__init__ ( self,
"App" app,
str | Path | None image = None,
* ,
int width = 0,
int height = 0,
str vertex_shader = "",
str fragment_shader = "" )

A 2D image that can be queued for drawing each frame.

Definition at line 48 of file graphics.py.

48 def __init__(self, app: "App", image: str | Path | None = None, *, width: int = 0, height: int = 0, vertex_shader: str = "", fragment_shader: str = "") -> None:
49 ## @brief Create an image sprite or an empty dynamic texture.
50 ## @param app The owning application.
51 ## @param image Image file to load; omit for an empty sprite.
52 ## @param width Empty texture width.
53 ## @param height Empty texture height.
54 ## @param vertex_shader Optional vertex SPIR-V path.
55 ## @param fragment_shader Optional fragment SPIR-V path.
56 self.native = None
57 try:
58 if image is not None:
59 self.native = app.create_sprite(str(image), vertex_shader, fragment_shader)
60 elif width > 0 and height > 0:
61 self.native = app.create_sprite(width, height, vertex_shader, fragment_shader)
62 else:
63 raise ValueError("provide image or positive width and height")
64 except Exception:
65 self.native = None
66 _abort_failed_resource(app)
67 raise
68 app.add(self)
69

Member Function Documentation

◆ close()

None mxvk_wrap.graphics.Sprite.close ( self)

Definition at line 123 of file graphics.py.

123 def close(self) -> None:
124 ## @brief Drop this sprite's native handle before its app is released.
125 ## @details MXVK owns sprites through the window; releasing this Python
126 ## handle first prevents a Python/native reference cycle at shutdown.
127 self.native = None
128
129

◆ draw()

None mxvk_wrap.graphics.Sprite.draw ( self,
int x = 0,
int y = 0,
* ,
int | None width = None,
int | None height = None,
float scale = 1.0,
float rotation = 0.0 )

Definition at line 70 of file graphics.py.

70 def draw(self, x: int = 0, y: int = 0, *, width: int | None = None, height: int | None = None, scale: float = 1.0, rotation: float = 0.0) -> None:
71 ## @brief Queue this sprite for the current frame.
72 ## @param x Left pixel coordinate.
73 ## @param y Top pixel coordinate.
74 ## @param width Optional output width; requires @p height too.
75 ## @param height Optional output height; requires @p width too.
76 ## @param scale Uniform scale used when no output rectangle is supplied.
77 ## @param rotation Rotation in radians used when no output rectangle is supplied.
78 if width is not None or height is not None:
79 if width is None or height is None:
80 raise ValueError("width and height must be supplied together")
81 self.native.draw_rect(x, y, width, height)
82 elif rotation != 0.0:
83 self.native.draw_rotated(x, y, scale, scale, rotation)
84 elif scale != 1.0:
85 self.native.draw(x, y, scale, scale)
86 else:
87 self.native.draw(x, y)
88

◆ enable_extended_uniforms()

None mxvk_wrap.graphics.Sprite.enable_extended_uniforms ( self)

Definition at line 101 of file graphics.py.

101 def enable_extended_uniforms(self) -> None:
102 ## @brief Enable mouse and four-vector uniforms for a custom sprite shader.
103 self.native.enable_extended_ubo()
104

◆ set_mouse()

None mxvk_wrap.graphics.Sprite.set_mouse ( self,
float x,
float y,
bool pressed = False )

Definition at line 105 of file graphics.py.

105 def set_mouse(self, x: float, y: float, pressed: bool = False) -> None:
106 ## @brief Set mouse data consumed by an extended sprite shader.
107 ## @param x Mouse X coordinate in window pixels.
108 ## @param y Mouse Y coordinate in window pixels.
109 ## @param pressed Whether a mouse button is currently pressed.
110 self.native.set_mouse_state(x, y, 1.0 if pressed else 0.0)
111

◆ set_uniform()

None mxvk_wrap.graphics.Sprite.set_uniform ( self,
int index,
float x,
float y,
float z,
float w )

Definition at line 112 of file graphics.py.

112 def set_uniform(self, index: int, x: float, y: float, z: float, w: float) -> None:
113 ## @brief Set one of four generic vectors for an extended sprite shader.
114 ## @param index Vector index from zero through three.
115 ## @param x First component.
116 ## @param y Second component.
117 ## @param z Third component.
118 ## @param w Fourth component.
119 if index not in range(4):
120 raise ValueError("uniform index must be from 0 through 3")
121 getattr(self.native, f"set_uniform{index}")(x, y, z, w)
122

◆ shader_params()

None mxvk_wrap.graphics.Sprite.shader_params ( self,
float first = 0.0,
float second = 0.0,
float third = 0.0,
float fourth = 0.0 )

Definition at line 97 of file graphics.py.

97 def shader_params(self, first: float = 0.0, second: float = 0.0, third: float = 0.0, fourth: float = 0.0) -> None:
98 ## @brief Set the four generic shader parameters for this sprite.
99 self.native.set_shader_params(first, second, third, fourth)
100

◆ update()

None mxvk_wrap.graphics.Sprite.update ( self,
object pixels,
int width,
int height,
* ,
int pitch = 0 )

Definition at line 89 of file graphics.py.

89 def update(self, pixels: object, width: int, height: int, *, pitch: int = 0) -> None:
90 ## @brief Replace this sprite's pixels with a contiguous RGBA8 array.
91 ## @param pixels NumPy-compatible RGBA8 pixel array.
92 ## @param width Pixel width.
93 ## @param height Pixel height.
94 ## @param pitch Bytes per row; zero uses @c width * 4.
95 self.native.update_texture(pixels, width, height, pitch)
96

Member Data Documentation

◆ native

mxvk_wrap.graphics.Sprite.native = None

Create an image sprite or an empty dynamic texture.

Set one of four generic vectors for an extended sprite shader.

Parameters
appThe owning application.
imageImage file to load; omit for an empty sprite.
widthEmpty texture width.
heightEmpty texture height.
vertex_shaderOptional vertex SPIR-V path.
fragment_shaderOptional fragment SPIR-V path.
indexVector index from zero through three.
xFirst component.
ySecond component.
zThird component.
wFourth component.

Definition at line 56 of file graphics.py.


The documentation for this class was generated from the following file: