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.app.App Class Reference
Inheritance diagram for mxvk_wrap.app.App:

Public Member Functions

"App" __enter__ (self)
None __exit__ (self, *object _)
None __init__ (self, str title="MXVK", int width=1280, int height=720, *, bool fullscreen=False, bool vsync=True, bool validation=False, str|Path|None shader_directory=None)
 A simple callback-driven MXVK application.
Any add (self, Any resource)
None close (self)
None draw (self)
None draw_text (self, str text, int x, int y, Any font, Color color=Color(255, 255, 255, 255))
None event (self, mxvk.Event event)
None on_event (self, mxvk.Event event)
None proc (self)
None quit (self)
None run (self)
tuple[int, int]|None text_size (self, str text, Any font)

Protected Attributes

bool _closed = False
 Safely release managed objects and Vulkan window resources.
list _managed = []
 Safely release managed objects and Vulkan window resources.

Detailed Description

Definition at line 13 of file app.py.

Constructor & Destructor Documentation

◆ __init__()

None mxvk_wrap.app.App.__init__ ( self,
str title = "MXVK",
int width = 1280,
int height = 720,
* ,
bool fullscreen = False,
bool vsync = True,
bool validation = False,
str | Path | None shader_directory = None )

A simple callback-driven MXVK application.

Subclass this class and override draw and optionally on_event. Managed sprites and models are released before the window.

Definition at line 18 of file app.py.

18 def __init__(self, title: str = "MXVK", width: int = 1280, height: int = 720, *, fullscreen: bool = False, vsync: bool = True, validation: bool = False, shader_directory: str | Path | None = None) -> None:
19 ## @brief Create a Vulkan window with practical Python defaults.
20 ## @param title Text displayed in the window title bar.
21 ## @param width Initial window width in pixels.
22 ## @param height Initial window height in pixels.
23 ## @param fullscreen Start in fullscreen mode when true.
24 ## @param vsync Synchronize presentation with the display when true.
25 ## @param validation Enable Vulkan validation layers when true.
26 ## @param shader_directory Optional directory containing shared shaders.
27 if shader_directory is not None:
28 mxvk.set_default_shader_directory(str(shader_directory))
29 present_mode = mxvk.PresentModePreference.vsync if vsync else mxvk.PresentModePreference.low_latency
30 super().__init__(title, width, height, fullscreen, validation, present_mode, mxvk.RuntimeMode.windowed)
31 self._managed: list[Any] = []
32 self._closed = False
33

Member Function Documentation

◆ __enter__()

"App" mxvk_wrap.app.App.__enter__ ( self)

Definition at line 103 of file app.py.

103 def __enter__(self) -> "App":
104 ## @brief Enter a context manager owning this application.
105 return self
106

◆ __exit__()

None mxvk_wrap.app.App.__exit__ ( self,
*object _ )

Definition at line 107 of file app.py.

107 def __exit__(self, *_: object) -> None:
108 ## @brief Close the application when its context exits.
109 self.close()

◆ add()

Any mxvk_wrap.app.App.add ( self,
Any resource )

Definition at line 52 of file app.py.

52 def add(self, resource: Any) -> Any:
53 ## @brief Keep a wrapper resource alive for the application's lifetime.
54 ## @param resource A wrapper created for this application.
55 ## @return The supplied resource, for convenient inline use.
56 self._managed.append(resource)
57 return resource
58

◆ close()

None mxvk_wrap.app.App.close ( self)

Definition at line 88 of file app.py.

88 def close(self) -> None:
89 ## @brief Safely release managed objects and Vulkan window resources.
90 if self._closed:
91 return
92 self._closed = True
93 try:
94 self.wait_idle()
95 for resource in reversed(self._managed):
96 close = getattr(resource, "close", None)
97 if close is not None:
98 close()
99 finally:
100 self._managed.clear()
101 self.release()
102

◆ draw()

None mxvk_wrap.app.App.draw ( self)

Definition at line 34 of file app.py.

34 def draw(self) -> None:
35 ## @brief Draw one frame.
36 ## @details Override this method; queue sprite drawing here.
37 pass
38

◆ draw_text()

None mxvk_wrap.app.App.draw_text ( self,
str text,
int x,
int y,
Any font,
Color color = Color(255, 255, 255, 255) )

Definition at line 59 of file app.py.

59 def draw_text(self, text: str, x: int, y: int, font: Any, color: Color = Color(255, 255, 255, 255)) -> None:
60 ## @brief Queue text using a supplied font without changing the default font.
61 ## @param text Text to draw.
62 ## @param x Left pixel coordinate.
63 ## @param y Top pixel coordinate.
64 ## @param font A wrapper @c Font created from a font file and size.
65 ## @param color RGBA text color.
66 ## @details This calls MXVK's per-draw font overload and does not call
67 ## @c set_font, so existing default-font text remains unchanged.
68 self.print_text(text, x, y, color, font.native)
69

◆ event()

None mxvk_wrap.app.App.event ( self,
mxvk.Event event )

Definition at line 48 of file app.py.

48 def event(self, event: mxvk.Event) -> None:
49 ## @brief Native event-loop callback that forwards to @c on_event.
50 self.on_event(event)
51

◆ on_event()

None mxvk_wrap.app.App.on_event ( self,
mxvk.Event event )

Definition at line 39 of file app.py.

39 def on_event(self, event: mxvk.Event) -> None:
40 ## @brief Receive one SDL input event.
41 ## @param event Read-only MXVK event data.
42 pass
43

◆ proc()

None mxvk_wrap.app.App.proc ( self)

Definition at line 44 of file app.py.

44 def proc(self) -> None:
45 ## @brief Native render-loop callback that forwards to @c draw.
46 self.draw()
47

◆ quit()

None mxvk_wrap.app.App.quit ( self)

Definition at line 84 of file app.py.

84 def quit(self) -> None:
85 ## @brief Request that the render loop exit after the current frame.
86 self.request_exit()
87

◆ run()

None mxvk_wrap.app.App.run ( self)

Definition at line 77 of file app.py.

77 def run(self) -> None:
78 ## @brief Run until @c quit is called or the window is closed.
79 try:
80 self.loop()
81 finally:
82 self.close()
83

◆ text_size()

tuple[int, int] | None mxvk_wrap.app.App.text_size ( self,
str text,
Any font )

Definition at line 70 of file app.py.

70 def text_size(self, text: str, font: Any) -> tuple[int, int] | None:
71 ## @brief Measure text using a supplied font without changing the default font.
72 ## @param text Text to measure.
73 ## @param font A wrapper @c Font created from a font file and size.
74 ## @return Width and height in pixels, or @c None when measurement fails.
75 return self.get_text_dimensions(text, font.native)
76

Member Data Documentation

◆ _closed

bool mxvk_wrap.app.App._closed = False
protected

Safely release managed objects and Vulkan window resources.

Definition at line 32 of file app.py.

◆ _managed

mxvk_wrap.app.App._managed = []
protected

Safely release managed objects and Vulkan window resources.

Definition at line 31 of file app.py.


The documentation for this class was generated from the following file:
  • python-examples/mxvk_wrap/app.py