Skip to main content

ferroui_vulkan/
i_vulkan_render_target.rs

1use crate::VulkanImageInfo;
2use ferroui_base::platform::surfaces::IPlatformRenderSurfaceRenderTarget;
3use ferroui_base::PixelSize;
4use std::rc::Rc;
5
6/// The Vulkan render target of a surface.
7///
8/// The contract is implemented by this crate and by surfaces that provide
9/// their own render target.
10pub trait IVulkanRenderTarget: IPlatformRenderSurfaceRenderTarget {
11    /// Starts rendering a frame.
12    ///
13    /// # Panics
14    /// Panics when the image to render to cannot be created.
15    fn begin_draw(&self) -> Rc<dyn IVulkanRenderSession>;
16
17    /// Releases the render target.
18    fn dispose(&self);
19}
20
21/// One frame being rendered with Vulkan. Disposing the session presents the
22/// frame.
23pub trait IVulkanRenderSession {
24    /// The scaling from logical units to device pixels.
25    fn scaling(&self) -> f64;
26
27    /// The size of the image in device pixels.
28    fn size(&self) -> PixelSize;
29
30    /// Whether the first row of the image is its top row.
31    fn is_y_flipped(&self) -> bool;
32
33    /// The image to render to.
34    fn image_info(&self) -> VulkanImageInfo;
35
36    /// Whether the channels of the image are in the order red, green, blue,
37    /// alpha (and not blue, green, red, alpha).
38    fn is_rgba(&self) -> bool;
39
40    /// Finishes and presents the frame.
41    fn dispose(&self);
42}