MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SurfaceUtils.hpp
Go to the documentation of this file.
1#pragma once
2
4
7
8namespace MayaFlux::Core {
9class Window;
10}
11
12namespace MayaFlux::Kakshya {
13
14/**
15 * @brief Query the actual vk::Format in use by the window's live swapchain,
16 * translated back to the MayaFlux surface format enum.
17 *
18 * This is the ground truth for readback allocation — it reflects what the
19 * driver actually negotiated, which may differ from the value requested in
20 * GlobalGraphicsConfig when the preferred format was unavailable.
21 *
22 * @param window Target window.
23 * @return Actual surface format. Returns B8G8R8A8_SRGB if the window has
24 * no registered swapchain.
25 */
27 const std::shared_ptr<Core::Window>& window);
28
29/**
30 * @brief Read a pixel rectangle from the last completed swapchain frame into
31 * a DataVariant whose element type matches the live swapchain format.
32 *
33 * Format -> DataVariant mapping:
34 * B8G8R8A8_SRGB / R8G8B8A8_SRGB / B8G8R8A8_UNORM / R8G8B8A8_UNORM
35 * -> std::vector<uint8_t> (4 bytes/pixel)
36 * R16G16B16A16_SFLOAT
37 * -> std::vector<uint16_t> (8 bytes/pixel, raw half-float bits)
38 * A2B10G10R10_UNORM
39 * -> std::vector<uint32_t> (4 bytes/pixel, packed word)
40 * R32G32B32A32_SFLOAT
41 * -> std::vector<float> (16 bytes/pixel)
42 *
43 * The rectangle is cropped host-side from the full surface published by the
44 * per-window readback thread. The data is one frame late relative to the
45 * current render, not synchronously captured at call time. No GPU work and
46 * no staging buffer: the function reads the cached frame, validates the
47 * region against the swapchain extent, and copies the rows out. Safe to call
48 * without stalling the render pipeline. Returns failure if no frame has been
49 * captured yet or the region exceeds the surface bounds.
50 *
51 * Dimensions on the returned DataAccess (IMAGE_COLOR convention):
52 * [0] SPATIAL_Y - pixel_height
53 * [1] SPATIAL_X - pixel_width
54 * [2] CHANNEL - channel_count derived from format traits
55 *
56 * @param window Window whose surface is being read.
57 * @param x_offset Left edge of the pixel rectangle (inclusive).
58 * @param y_offset Top edge of the pixel rectangle (inclusive).
59 * @param pixel_width Width of the rectangle in pixels.
60 * @param pixel_height Height of the rectangle in pixels.
61 * @param out_variant Receives the typed pixel data. Left unchanged on
62 * failure.
63 * @return DataAccess wrapping out_variant with IMAGE_COLOR modality.
64 * Returns a default-constructed DataAccess on failure.
65 */
66MAYAFLUX_API DataAccess readback_region(
67 const std::shared_ptr<Core::Window>& window,
68 uint32_t x_offset,
69 uint32_t y_offset,
70 uint32_t pixel_width,
71 uint32_t pixel_height,
72 DataVariant& out_variant);
73
74/**
75 * @brief Query the current pixel dimensions of the window's swapchain.
76 * @param window Target window.
77 * @return {width, height} in pixels. Returns {0, 0} if the window is not
78 * registered with the graphics backend.
79 */
80MAYAFLUX_API std::pair<uint32_t, uint32_t> query_surface_extent(
81 const std::shared_ptr<Core::Window>& window);
82
83/**
84 * @brief Check whether a completed frame is currently available for readback.
85 * Returns false if the window has no registered swapchain or if the
86 * last in-flight fence has not yet signalled.
87 * @param window Target window.
88 * @return true if readback_region() can safely be called now.
89 */
90MAYAFLUX_API bool is_readback_available(
91 const std::shared_ptr<Core::Window>& window);
92
93} // namespace MayaFlux::Kakshya
bool is_readback_available(const std::shared_ptr< Core::Window > &window)
Check whether a completed frame is currently available for readback.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:76
std::pair< uint32_t, uint32_t > query_surface_extent(const std::shared_ptr< Core::Window > &window)
Query the current pixel dimensions of the window's swapchain.
DataAccess readback_region(const std::shared_ptr< Core::Window > &window, uint32_t x_offset, uint32_t y_offset, uint32_t pixel_width, uint32_t pixel_height, DataVariant &out_variant)
Read a pixel rectangle from the last completed swapchain frame into a DataVariant whose element type ...
Core::GraphicsSurfaceInfo::SurfaceFormat query_surface_format(const std::shared_ptr< Core::Window > &window)
Query the actual vk::Format in use by the window's live swapchain, translated back to the MayaFlux su...
SurfaceFormat
Default pixel format for window surfaces (Vulkan-compatible)