MayaFlux 0.2.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 * "Last completed frame" semantics: the swapchain image whose in-flight
44 * fence has already signaled. Safe to call without stalling the render
45 * pipeline.
46 *
47 * Dimensions on the returned DataAccess (IMAGE_COLOR convention):
48 * [0] SPATIAL_Y — pixel_height
49 * [1] SPATIAL_X — pixel_width
50 * [2] CHANNEL — channel_count derived from format traits
51 *
52 * @param window Window whose surface is being read.
53 * @param x_offset Left edge of the pixel rectangle (inclusive).
54 * @param y_offset Top edge of the pixel rectangle (inclusive).
55 * @param pixel_width Width of the rectangle in pixels.
56 * @param pixel_height Height of the rectangle in pixels.
57 * @param out_variant Receives the typed pixel data. Left unchanged on
58 * failure.
59 * @return DataAccess wrapping out_variant with IMAGE_COLOR modality.
60 * Returns a default-constructed DataAccess on failure.
61 */
62MAYAFLUX_API DataAccess readback_region(
63 const std::shared_ptr<Core::Window>& window,
64 uint32_t x_offset,
65 uint32_t y_offset,
66 uint32_t pixel_width,
67 uint32_t pixel_height,
68 DataVariant& out_variant);
69
70/**
71 * @brief Query the current pixel dimensions of the window's swapchain.
72 * @param window Target window.
73 * @return {width, height} in pixels. Returns {0, 0} if the window is not
74 * registered with the graphics backend.
75 */
76MAYAFLUX_API std::pair<uint32_t, uint32_t> query_surface_extent(
77 const std::shared_ptr<Core::Window>& window);
78
79/**
80 * @brief Check whether a completed frame is currently available for readback.
81 * Returns false if the window has no registered swapchain or if the
82 * last in-flight fence has not yet signalled.
83 * @param window Target window.
84 * @return true if readback_region() can safely be called now.
85 */
86MAYAFLUX_API bool is_readback_available(
87 const std::shared_ptr<Core::Window>& window);
88
89} // 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:73
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)