16 StencilWindow(
const std::string &path,
int width,
int height,
bool fullscreen,
bool enable_vsync)
18 shader_root((path.empty() ? std::string(STENCIL_ASSET_DIR) : path) +
"/data") {
23 if (
device != VK_NULL_HANDLE) {
36 stencil->prepare_for_rendering(cmd);
41 VkRenderingAttachmentInfo &stencil_attachment,
42 [[maybe_unused]] uint32_t image_index)
override {
43 depth_attachment.imageView = VK_NULL_HANDLE;
45 stencil->configure_attachment(stencil_attachment);
50 if (!stencil || !stencil->valid()) {
54 const auto now = std::chrono::steady_clock::now();
55 const float elapsed = std::chrono::duration<float>(now - start_time).count();
57 const float aspect = current_extent.height > 0U
58 ?
static_cast<float>(current_extent.width) /
static_cast<float>(current_extent.height)
64 .phase = elapsed * 0.35f,
67 stencil->draw_mask(cmd, push);
68 stencil->draw_content(cmd, push);
72 void ensure_stencil() {
74 if (current_extent.width == 0U || current_extent.height == 0U) {
79 stencil = std::make_unique<mxvk::VK_Stencil>();
86 current_extent,
getSwapchainFormat(), VK_FORMAT_UNDEFINED,
getPipelineCache(), shader_root +
"/fullscreen.vert.spv", shader_root +
"/mandala_mask.frag.spv", shader_root +
"/content_fullscreen.vert.spv", shader_root +
"/stencil_fill.frag.spv");
88 stencil->resize(current_extent);
92 std::string shader_root;
93 std::chrono::steady_clock::time_point start_time{std::chrono::steady_clock::now()};
94 std::unique_ptr<mxvk::VK_Stencil> stencil{};
98int main(
int argc,
char **argv) {
104 std::cerr << std::format(
"mxvk: Exception: {}\n", e.
text());
107 std::cerr << std::format(
"mxvk: Argument Exception: {}\n", e.
text());
Lightweight, header-only, template command-line argument parser.
Arguments proc_args(int &argc, char **argv)
Parse standard libmx2 command-line options from main()'s argv.
Exception thrown by Argz::proc() on unrecognised or malformed options.
void onPrepareFrameRendering(VkCommandBuffer cmd, uint32_t image_index) override
Record resource transitions that must happen before dynamic rendering begins.
StencilWindow(const std::string &path, int width, int height, bool fullscreen, bool enable_vsync)
void onConfigureDepthStencilAttachments(VkRenderingAttachmentInfo &depth_attachment, VkRenderingAttachmentInfo &stencil_attachment, uint32_t image_index) override
Allow derived classes to customize depth/stencil attachments for the main dynamic rendering pass.
void onSwapchainAboutToRecreate() override
Called right before swapchain-dependent resources are recreated.
void onRecordCustomRendering(VkCommandBuffer cmd, uint32_t image_index) override
Optional hook for derived classes to record extra draw commands.
~StencilWindow() override
void initialize(const VulkanContext &context, VkExtent2D extent, VkFormat color_format, VkFormat depth_format, VkPipelineCache pipeline_cache, const std::string &mask_vertex_shader, const std::string &mask_fragment_shader, const std::string &content_vertex_shader, const std::string &content_fragment_shader)
Create the stencil attachment and fullscreen mask/content pipelines.
Main Vulkan window wrapper for MXVK.
VkExtent2D getSwapchainExtent() const noexcept
Get the current swapchain extent.
void loop()
Run the main event/render loop.
VkDevice getDevice() const noexcept
Get the Vulkan logical device handle.
VkQueue getGraphicsQueue() const noexcept
Get the graphics queue handle.
VkCommandPool getCommandPool() const noexcept
Get the command pool used for graphics/upload work.
void setClearColor(float r, float g, float b, float a=1.0f)
Set the per-frame color attachment clear color.
VK_Window()=default
Construct an empty window object.
VkPipelineCache getPipelineCache() const noexcept
Get the persistent Vulkan pipeline cache used by framework pipelines.
VkPhysicalDevice getPhysicalDevice() const noexcept
Get the Vulkan physical device handle.
VkFormat getSwapchainFormat() const noexcept
Get the swapchain color format.
Reusable dynamic-rendering stencil image and fullscreen stencil pipelines.
Utilities for loading and saving PNG images.
Plain data structure returned by proc_args() with all common libmx2 CLI options.
bool fullscreen
Whether fullscreen mode was requested.
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
int height
Viewport height in pixels (default: 720).
std::string path
Asset root; proc_args() defaults it to the executable directory.
int width
Viewport width in pixels (default: 1280).
Push-constant payload shared by the mask and content shaders.
Minimal Vulkan handles required by MXVK resource helpers.