18 [[nodiscard]]
bool run() {
20 return readback_verified;
26 if (processed_frames > MAX_FRAME_COUNT) {
27 std::cerr <<
"headless example: timed out waiting for readback\n";
32 void onFrameReadback(std::vector<std::uint8_t> &rgba_pixels, uint32_t width, uint32_t height)
override {
33 if (readback_verified) {
36 const bool dimensions_match = width == WIDTH && height == HEIGHT;
37 const bool pixels_available = rgba_pixels.size() ==
static_cast<size_t>(WIDTH) * HEIGHT * 4U;
38 if (!dimensions_match || !pixels_available) {
39 std::cerr <<
"headless example: invalid frame readback\n";
44 const size_t center = (
static_cast<size_t>(HEIGHT / 2U) * WIDTH + WIDTH / 2U) * 4U;
45 const bool color_matches = rgba_pixels[center] >= 30U && rgba_pixels[center] <= 34U && rgba_pixels[center + 1U] >= 62U && rgba_pixels[center + 1U] <= 66U && rgba_pixels[center + 2U] >= 126U && rgba_pixels[center + 2U] <= 130U;
47 std::cerr <<
"headless example: clear-color readback mismatch\n";
52 readback_verified =
true;
53 std::cout <<
"headless example: surface-free RGBA readback verified " << width <<
'x' << height <<
'\n';
58 static constexpr uint32_t WIDTH = 320;
59 static constexpr uint32_t HEIGHT = 180;
60 static constexpr uint32_t MAX_FRAME_COUNT = 8;
61 uint32_t processed_frames = 0;
62 bool readback_verified =
false;
69 return app.
run() ? 0 : 1;
71 std::cerr <<
"headless example: " << ex.
text() <<
'\n';
72 }
catch (
const std::exception &ex) {
73 std::cerr <<
"headless example: " << ex.what() <<
'\n';
void proc() override
Execute one processing/update step.
void onFrameReadback(std::vector< std::uint8_t > &rgba_pixels, uint32_t width, uint32_t height) override
Receive one tightly packed RGBA8 copy of the rendered frame.
Main Vulkan window wrapper for MXVK.
void loop()
Run the main event/render loop.
void setClearColor(float r, float g, float b, float a=1.0f)
Set the per-frame color attachment clear color.
void exit()
Request loop termination.
void setFrameReadbackEnabled(bool enabled) noexcept
Enable or disable readback of each rendered swapchain frame.
VK_Window()=default
Construct an empty window object.
void setEnableScreenshot(bool enabled) noexcept
Enable or disable F10 screenshot capture.
Utilities for loading and saving PNG images.