libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
mx::VKWindow Class Referenceabstract

Primary Vulkan rendering window and device management class. More...

#include <vk.hpp>

Collaboration diagram for mx::VKWindow:
[legend]

Public Member Functions

 VKWindow ()=default
 VKWindow (const std::string &title, int width, int height, bool full=false, bool valid=true)
 Create and fully initialise the Vulkan window.
virtual ~VKWindow ()
 Virtual destructor — subclasses should call cleanup().
 VKWindow (const VKWindow &)=delete
VKWindow & operator= (const VKWindow &)=delete
 VKWindow (VKWindow &&)=delete
VKWindow & operator= (VKWindow &&)=delete
void initWindow (const std::string &title, int width, int height, bool full=false)
 Open the SDL2 window (called automatically by constructor).
void setFont (const std::string &font, const int size=24)
 Set the font used for printText().
virtual void initVulkan ()
 Initialise all Vulkan objects (overridable).
void createVertexBuffer ()
 Create and upload the vertex buffer.
void setPath (const std::string &path)
 Set the asset root directory.
void loop ()
 Run the blocking event/render loop.
virtual void proc ()
 Process one event/render iteration (overridable).
virtual void cleanup ()
 Free all Vulkan resources (overridable).
virtual void event (SDL_Event &e)=0
 Handle an SDL event (pure virtual).
virtual void draw ()
 Record rendering commands for the current frame (overridable).
virtual void onResize ()
 Called when the window is resized (optional override).
virtual bool shouldRender3D ()
 Control whether 3-D geometry is rendered this frame.
void createGraphicsPipeline ()
 (Re)create the graphics pipeline.
VkShaderModule createShaderModule (const std::vector< char > &code)
 Compile a SPIR-V shader module.
void quit ()
 Post a quit event to stop the loop.
void setFullScreen (const bool full)
 Toggle fullscreen mode.
void updateTexture (SDL_Surface *newSurface)
 Replace the primary texture from an SDL_Surface.
void updateTexture (void *pixels, VkDeviceSize imageSize)
 Replace the primary texture from a raw pixel buffer.
void printText (const std::string &text, int x, int y, const SDL_Color &col)
 Queue a text string for rendering at a screen position.
void clearTextQueue ()
 Clear all pending text-render entries.
bool getTextDimensions (const std::string &text, int &width, int &height)
 Measure a text string without rendering it.
VKSprite * createSprite (const std::string &pngPath, const std::string &vertexShader, const std::string &fragmentShaderPath="")
 Create a sprite from a PNG file.
VKSprite * createSprite (SDL_Surface *surface, const std::string &vertexShader, const std::string &fragmentShaderPath="")
 Create a sprite from an SDL_Surface.
VKSprite * createSprite (int width, int height, const std::string &vertexShader="", const std::string &fragmentShaderPath="")
 Create a blank sprite of the given dimensions.
int getWidth () const
int getHeight () const
void resizeWindow (int width, int height)
 Resize the SDL window and recreate the swapchain.
bool enableControllerInput ()
 Enable joystick and game controller subsystems on demand.
bool controllerInputEnabled () const
void setWireFrame (bool enable)
 Enable or disable wireframe rendering.
bool getWireFrame () const
VkPhysicalDevice getPhysicalDevice () const
VkDevice getDevice () const
VkQueue getGraphicsQueue () const
VkCommandPool getCommandPool () const

Public Attributes

int w = 0
 Current window width.
int h = 0
 Current window height.
mxUtil util
 Asset path and utility helpers.

Protected Member Functions

void createDescriptorSetLayout ()
 Create the main descriptor set layout (UBO + sampler).
void createDepthResources ()
 Create depth buffer image, memory, and view.
VkFormat findSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
 Find a supported VkFormat from the candidate list.
VkFormat findDepthFormat ()
 Select a depth buffer format supported by the physical device.
void createInstance ()
 Create the Vulkan instance and enable extensions/layers.
void createSurface ()
 Create the Vulkan surface from the SDL window.
void pickPhysicalDevice ()
 Enumerate GPUs and select the most suitable physical device.
void createLogicalDevice ()
 Create the logical device and retrieve queue handles.
void createUniformBuffers ()
 Allocate per-frame uniform buffers and map them persistently.
virtual void createSwapChain ()
 Create (or recreate) the swapchain and associated images (overridable).
void createImageViews ()
 Create image views for every swapchain image.
void createRenderPass ()
 Create the main render pass with colour and depth attachments.
void createFramebuffers ()
 Create framebuffers for each swapchain image view.
void createCommandPool ()
 Create the graphics command pool.
void createCommandBuffers ()
 Allocate per-frame command buffers from the command pool.
void createSyncObjects ()
 Create semaphores and fences for frame synchronisation.
virtual void cleanupSwapChain ()
 Destroy swapchain-dependent resources before recreation (overridable).
QueueFamilyIndices findQueueFamilies (VkPhysicalDevice device)
 Find queue families supporting graphics and presentation.
VkSurfaceFormatKHR chooseSwapSurfaceFormat (const std::vector< VkSurfaceFormatKHR > &availableFormats)
 Choose the best surface format from available options.
VkPresentModeKHR chooseSwapPresentMode (const std::vector< VkPresentModeKHR > &availablePresentModes)
 Choose the best present mode (prefers mailbox, falls back to FIFO).
VkExtent2D chooseSwapExtent (const VkSurfaceCapabilitiesKHR &capabilities)
 Determine the swapchain image extent from surface capabilities.
bool isDeviceSuitable (VkPhysicalDevice device)
 Check whether a physical device meets all application requirements.
SwapChainSupportDetails querySwapChainSupport (VkPhysicalDevice device)
 Query swapchain support details for a physical device.
void createBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
 Allocate a Vulkan buffer with the given usage and memory properties.
uint32_t findMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties)
 Find a device memory type matching the filter and property flags.
void copyBuffer (VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size)
 Copy data between two Vulkan buffers via a one-shot command.
void createTextureImage (SDL_Surface *surfacex)
 Create a Vulkan texture image from an SDL surface.
void createImage (uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory)
 Create a Vulkan image with the specified parameters.
void transitionImageLayout (VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout)
 Transition an image between two layouts using a pipeline barrier.
void copyBufferToImage (VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
 Copy a staging buffer into a Vulkan image.
VkCommandBuffer beginSingleTimeCommands ()
 Begin a one-shot command buffer for transfer operations.
void endSingleTimeCommands (VkCommandBuffer commandBuffer)
 End and submit a one-shot command buffer, then wait for completion.
void createTextureImageView ()
 Create the image view for the primary texture.
VkImageView createImageView (VkImage image, VkFormat format, VkImageAspectFlags aspectFlags)
 Create an image view with specified format and aspect flags.
void createTextureSampler ()
 Create the texture sampler with default filter/addressing modes.
void createDescriptorPool ()
 Create the main descriptor pool.
void createDescriptorSets ()
 Allocate main descriptor sets from the pool.
void updateDescriptorSets ()
 Write updated bindings into existing descriptor sets.
void recreateSwapChain ()
 Tear down and rebuild the swapchain and all dependent resources.
void setupTextureImage (uint32_t w, uint32_t h)
 Allocate a blank texture image of the given dimensions.
void createTextDescriptorSetLayout ()
 Create the descriptor set layout for text rendering.
void createTextPipeline ()
 Create the pipeline for text rendering.
void createTextDescriptorPool ()
 Create the descriptor pool for text rendering.
void createSpriteDescriptorSetLayout ()
 Create the descriptor set layout for sprite rendering.
void createSpritePipeline ()
 Create the pipeline for sprite rendering.
void createSpriteDescriptorPool ()
 Create the descriptor pool for sprite rendering.

Protected Attributes

bool active = true
 true while the event loop should keep running.
bool inputControllersInitialized = false
 Whether joystick/controller input is enabled.
bool enableValidation = true
 Enable Vulkan validation layers.
std::string font = "font.ttf"
 Path to the current TTF font.
int font_size = 24
 Current font point size.
VkInstance instance = VK_NULL_HANDLE
 Vulkan instance.
VkSurfaceKHR surface = VK_NULL_HANDLE
 Window surface.
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE
 Selected GPU.
VkDevice device = VK_NULL_HANDLE
 Logical device.
VkQueue graphicsQueue = VK_NULL_HANDLE
 Graphics submission queue.
VkQueue presentQueue = VK_NULL_HANDLE
 Presentation queue.
VkDescriptorSetLayout descriptorSetLayout
 Main descriptor set layout.
VkSwapchainKHR swapChain = VK_NULL_HANDLE
 Active swapchain.
std::vector< VkImage > swapChainImages
 Swapchain image handles.
VkFormat swapChainImageFormat
 Colour format of swapchain images.
VkExtent2D swapChainExtent
 Swapchain pixel dimensions.
std::vector< VkImageView > swapChainImageViews
 Image views into swapchain images.
std::vector< VkBuffer > uniformBuffers
 Per-frame uniform buffers.
std::vector< VkDeviceMemory > uniformBuffersMemory
 Memory for per-frame UBOs.
std::vector< void * > uniformBuffersMapped
 Persistently mapped UBO pointers.
VkRenderPass renderPass = VK_NULL_HANDLE
 Main render pass.
VkPipelineLayout pipelineLayout = VK_NULL_HANDLE
 Pipeline layout for the main pass.
VkPipeline graphicsPipeline = VK_NULL_HANDLE
 Filled-polygon graphics pipeline.
VkPipeline graphicsPipelineMatrix = VK_NULL_HANDLE
 3-D matrix-enabled graphics pipeline.
VkPolygonMode currentPolygonMode = VK_POLYGON_MODE_FILL
 Current polygon fill mode.
bool useWireFrame = false
 Wireframe rendering toggle.
bool supportsWireFrame = false
 Whether the device supports wireframe.
std::vector< VkFramebuffer > swapChainFramebuffers
 Framebuffers for each swapchain image.
VkCommandPool commandPool = VK_NULL_HANDLE
 Command pool for graphics commands.
std::vector< VkCommandBuffer > commandBuffers
 Per-frame command buffers.
VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE
 Signals when a swapchain image is acquired.
VkSemaphore renderFinishedSemaphore = VK_NULL_HANDLE
 Signals when rendering is complete.
VkFence inFlightFence = VK_NULL_HANDLE
 CPU–GPU frame synchronisation fence.
VkBuffer vertexBuffer = VK_NULL_HANDLE
 Full-screen quad vertex buffer.
VkDeviceMemory vertexBufferMemory = VK_NULL_HANDLE
 Memory for the vertex buffer.
VkBuffer indexBuffer = VK_NULL_HANDLE
 Full-screen quad index buffer.
VkDeviceMemory indexBufferMemory = VK_NULL_HANDLE
 Memory for the index buffer.
uint32_t indexCount = 0
 Number of indices in the quad.
VkImage textureImage = VK_NULL_HANDLE
 Primary texture image.
VkDeviceMemory textureImageMemory = VK_NULL_HANDLE
 Memory for the primary texture.
VkImageView textureImageView = VK_NULL_HANDLE
 View into the primary texture.
VkImageLayout textureImageLayout = VK_IMAGE_LAYOUT_UNDEFINED
 Current layout of the primary texture.
VkSampler textureSampler = VK_NULL_HANDLE
 Sampler for the primary texture.
VkDescriptorPool descriptorPool = VK_NULL_HANDLE
 Main descriptor pool.
std::vector< VkDescriptorSet > descriptorSets
 Per-frame descriptor sets.
VkImage depthImage = VK_NULL_HANDLE
 Depth/stencil image.
VkDeviceMemory depthImageMemory = VK_NULL_HANDLE
 Memory for the depth image.
VkImageView depthImageView = VK_NULL_HANDLE
 View into the depth image.
VkFormat depthFormat = VK_FORMAT_D32_SFLOAT
 Format used for the depth buffer.
float cameraDistance = 3.0f
 Default camera distance from origin.
std::unique_ptr< VKText > textRenderer
 Text rendering subsystem.
VkPipeline textPipeline = VK_NULL_HANDLE
 Pipeline for text rendering.
VkPipelineLayout textPipelineLayout = VK_NULL_HANDLE
 Pipeline layout for text rendering.
VkDescriptorPool textDescriptorPool = VK_NULL_HANDLE
 Descriptor pool for text.
VkDescriptorSetLayout textDescriptorSetLayout = VK_NULL_HANDLE
 Descriptor layout for text.
std::vector< std::unique_ptr< VKSprite > > sprites
 Owned sprite instances.
VkPipeline spritePipeline = VK_NULL_HANDLE
 Pipeline for sprite rendering.
VkPipelineLayout spritePipelineLayout = VK_NULL_HANDLE
 Pipeline layout for sprites.
VkDescriptorPool spriteDescriptorPool = VK_NULL_HANDLE
 Descriptor pool for sprites.
VkDescriptorSetLayout spriteDescriptorSetLayout = VK_NULL_HANDLE
 Descriptor layout for sprites.
VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE
 Vulkan debug messenger (validation layers).
uint32_t width
uint32_t height
 Internal width/height tracking.
SDL_Window * window = nullptr
 SDL window handle.
SDL_Surface * surface_img = nullptr
 Cached SDL surface for texture uploads.

Friends

class VKAbstractModel

Detailed Description

Primary Vulkan rendering window and device management class.

Encapsulates the full Vulkan initialisation sequence: instance, surface, physical and logical device selection, swap chain creation, render pass, descriptor sets, command buffers, and synchronisation. Derived classes implement event() and optionally override draw(), initVulkan(), and cleanup() to add application-specific rendering.

Built-in support for:

  • 2-D text rendering via VKText
  • Sprite rendering via VKSprite
  • Texture upload (SDL_Surface or raw pixels)
  • Wireframe toggle

Definition at line 126 of file vk.hpp.

Constructor & Destructor Documentation

◆ VKWindow() [1/4]

mx::VKWindow::VKWindow ( )
default

References height, and width.

Referenced by operator=(), operator=(), VKWindow(), and VKWindow().

◆ VKWindow() [2/4]

mx::VKWindow::VKWindow ( const std::string & title,
int width,
int height,
bool full = false,
bool valid = true )

Create and fully initialise the Vulkan window.

Parameters
titleWindow title string.
widthWidth in pixels.
heightHeight in pixels.
fullStart fullscreen if true.
validEnable Vulkan validation layers if true.

Definition at line 10 of file vk.cpp.

References enableValidation, height, initWindow(), and width.

◆ ~VKWindow()

virtual mx::VKWindow::~VKWindow ( )
inlinevirtual

Virtual destructor — subclasses should call cleanup().

Definition at line 141 of file vk.hpp.

◆ VKWindow() [3/4]

mx::VKWindow::VKWindow ( const VKWindow & )
delete

References VKWindow().

◆ VKWindow() [4/4]

mx::VKWindow::VKWindow ( VKWindow && )
delete

References VKWindow().

Member Function Documentation

◆ beginSingleTimeCommands()

VkCommandBuffer mx::VKWindow::beginSingleTimeCommands ( )
protected

Begin a one-shot command buffer for transfer operations.

Definition at line 1147 of file vk.cpp.

References commandPool, device, and VK_CHECK_RESULT.

Referenced by copyBufferToImage(), and transitionImageLayout().

◆ chooseSwapExtent()

VkExtent2D mx::VKWindow::chooseSwapExtent ( const VkSurfaceCapabilitiesKHR & capabilities)
protected

Determine the swapchain image extent from surface capabilities.

Parameters
capabilitiesCurrent surface capabilities.
Returns
Chosen extent in pixels.

Definition at line 221 of file vk.cpp.

References h, and w.

Referenced by createSwapChain().

◆ chooseSwapPresentMode()

VkPresentModeKHR mx::VKWindow::chooseSwapPresentMode ( const std::vector< VkPresentModeKHR > & availablePresentModes)
protected

Choose the best present mode (prefers mailbox, falls back to FIFO).

Parameters
availablePresentModesCandidate modes.
Returns
Selected presentation mode.

Definition at line 212 of file vk.cpp.

Referenced by createSwapChain().

◆ chooseSwapSurfaceFormat()

VkSurfaceFormatKHR mx::VKWindow::chooseSwapSurfaceFormat ( const std::vector< VkSurfaceFormatKHR > & availableFormats)
protected

Choose the best surface format from available options.

Parameters
availableFormatsCandidate formats.
Returns
Selected surface format.

Definition at line 199 of file vk.cpp.

Referenced by createSwapChain().

◆ cleanup()

◆ cleanupSwapChain()

void mx::VKWindow::cleanupSwapChain ( )
protectedvirtual

Destroy swapchain-dependent resources before recreation (overridable).

Definition at line 704 of file vk.cpp.

References commandBuffers, commandPool, depthImage, depthImageMemory, depthImageView, device, graphicsPipeline, graphicsPipelineMatrix, pipelineLayout, renderPass, swapChain, swapChainFramebuffers, and swapChainImageViews.

Referenced by cleanup(), and recreateSwapChain().

◆ clearTextQueue()

void mx::VKWindow::clearTextQueue ( )

Clear all pending text-render entries.

Definition at line 2086 of file vk.cpp.

References textRenderer.

Referenced by draw().

◆ controllerInputEnabled()

bool mx::VKWindow::controllerInputEnabled ( ) const
inline
Returns
true if controller input subsystem was enabled.

Definition at line 313 of file vk.hpp.

References inputControllersInitialized.

◆ copyBuffer()

void mx::VKWindow::copyBuffer ( VkBuffer srcBuffer,
VkBuffer dstBuffer,
VkDeviceSize size )
protected

Copy data between two Vulkan buffers via a one-shot command.

Parameters
srcBufferSource buffer.
dstBufferDestination buffer.
sizeNumber of bytes to copy.

Definition at line 904 of file vk.cpp.

References commandPool, device, graphicsQueue, and VK_CHECK_RESULT.

Referenced by createVertexBuffer().

◆ copyBufferToImage()

void mx::VKWindow::copyBufferToImage ( VkBuffer buffer,
VkImage image,
uint32_t width,
uint32_t height )
protected

Copy a staging buffer into a Vulkan image.

Parameters
bufferSource buffer.
imageDestination image.
widthImage width.
heightImage height.

Definition at line 1117 of file vk.cpp.

References beginSingleTimeCommands(), endSingleTimeCommands(), height, and width.

Referenced by createTextureImage(), mx::VKAbstractModel::loadModelTextures(), mx::VKAbstractModel::loadModelTexturesFromMTL(), and updateTexture().

◆ createBuffer()

void mx::VKWindow::createBuffer ( VkDeviceSize size,
VkBufferUsageFlags usage,
VkMemoryPropertyFlags properties,
VkBuffer & buffer,
VkDeviceMemory & bufferMemory )
protected

Allocate a Vulkan buffer with the given usage and memory properties.

Parameters
sizeBuffer size in bytes.
usageVulkan buffer usage flags.
propertiesRequired memory property flags.
bufferOutput buffer handle.
bufferMemoryOutput device memory handle.

Definition at line 872 of file vk.cpp.

References device, and findMemoryType().

Referenced by createTextureImage(), createUniformBuffers(), createVertexBuffer(), mx::VKAbstractModel::load(), mx::VKAbstractModel::loadInstance(), mx::VKAbstractModel::loadModelTextures(), mx::VKAbstractModel::loadModelTexturesFromMTL(), mx::VKAbstractModel::resize(), and updateTexture().

◆ createCommandBuffers()

void mx::VKWindow::createCommandBuffers ( )
protected

Allocate per-frame command buffers from the command pool.

Definition at line 674 of file vk.cpp.

References commandBuffers, commandPool, device, and swapChainFramebuffers.

Referenced by initVulkan(), and recreateSwapChain().

◆ createCommandPool()

void mx::VKWindow::createCommandPool ( )
protected

Create the graphics command pool.

Definition at line 663 of file vk.cpp.

References commandPool, device, findQueueFamilies(), mx::QueueFamilyIndices::graphicsFamily, and physicalDevice.

Referenced by initVulkan().

◆ createDepthResources()

void mx::VKWindow::createDepthResources ( )
protected

Create depth buffer image, memory, and view.

Definition at line 792 of file vk.cpp.

References createImage(), createImageView(), depthFormat, depthImage, depthImageMemory, depthImageView, findDepthFormat(), and swapChainExtent.

Referenced by initVulkan(), and recreateSwapChain().

◆ createDescriptorPool()

void mx::VKWindow::createDescriptorPool ( )
protected

Create the main descriptor pool.

Definition at line 1228 of file vk.cpp.

References descriptorPool, device, instance, and swapChainImages.

Referenced by initVulkan().

◆ createDescriptorSetLayout()

void mx::VKWindow::createDescriptorSetLayout ( )
protected

Create the main descriptor set layout (UBO + sampler).

Definition at line 101 of file vk.cpp.

References descriptorSetLayout, and device.

Referenced by initVulkan().

◆ createDescriptorSets()

void mx::VKWindow::createDescriptorSets ( )
protected

Allocate main descriptor sets from the pool.

Definition at line 1254 of file vk.cpp.

References descriptorPool, descriptorSetLayout, descriptorSets, device, instance, swapChainImages, textureImageView, textureSampler, and uniformBuffers.

Referenced by initVulkan().

◆ createFramebuffers()

void mx::VKWindow::createFramebuffers ( )
protected

Create framebuffers for each swapchain image view.

Definition at line 642 of file vk.cpp.

References depthImageView, device, renderPass, swapChainExtent, swapChainFramebuffers, and swapChainImageViews.

Referenced by initVulkan(), and recreateSwapChain().

◆ createGraphicsPipeline()

void mx::VKWindow::createGraphicsPipeline ( )

◆ createImage()

void mx::VKWindow::createImage ( uint32_t width,
uint32_t height,
VkFormat format,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkMemoryPropertyFlags properties,
VkImage & image,
VkDeviceMemory & imageMemory )
protected

Create a Vulkan image with the specified parameters.

Parameters
widthImage width in pixels.
heightImage height in pixels.
formatPixel format.
tilingTiling arrangement.
usageImage usage flags.
propertiesMemory property flags.
imageOutput image handle.
imageMemoryOutput device memory handle.

Definition at line 995 of file vk.cpp.

References device, findMemoryType(), height, and width.

Referenced by createDepthResources(), createTextureImage(), mx::VKAbstractModel::loadModelTextures(), mx::VKAbstractModel::loadModelTexturesFromMTL(), and setupTextureImage().

◆ createImageView()

VkImageView mx::VKWindow::createImageView ( VkImage image,
VkFormat format,
VkImageAspectFlags aspectFlags )
protected

Create an image view with specified format and aspect flags.

Parameters
imageSource image.
formatView format.
aspectFlagsAspect mask (colour, depth, etc.).
Returns
Created VkImageView.

Definition at line 1184 of file vk.cpp.

References device.

Referenced by createDepthResources(), createTextureImageView(), mx::VKAbstractModel::loadModelTextures(), and mx::VKAbstractModel::loadModelTexturesFromMTL().

◆ createImageViews()

void mx::VKWindow::createImageViews ( )
protected

Create image views for every swapchain image.

Definition at line 559 of file vk.cpp.

References device, swapChainImageFormat, swapChainImages, and swapChainImageViews.

Referenced by initVulkan(), and recreateSwapChain().

◆ createInstance()

void mx::VKWindow::createInstance ( )
protected

Create the Vulkan instance and enable extensions/layers.

Definition at line 260 of file vk.cpp.

References mx::debugCallback(), debugMessenger, enableValidation, instance, VK_CHECK_RESULT, and window.

Referenced by initVulkan().

◆ createLogicalDevice()

void mx::VKWindow::createLogicalDevice ( )
protected

Create the logical device and retrieve queue handles.

Definition at line 435 of file vk.cpp.

References device, findQueueFamilies(), mx::QueueFamilyIndices::graphicsFamily, graphicsQueue, physicalDevice, mx::QueueFamilyIndices::presentFamily, presentQueue, and supportsWireFrame.

Referenced by initVulkan().

◆ createRenderPass()

void mx::VKWindow::createRenderPass ( )
protected

Create the main render pass with colour and depth attachments.

Definition at line 582 of file vk.cpp.

References depthFormat, device, renderPass, and swapChainImageFormat.

Referenced by initVulkan(), and recreateSwapChain().

◆ createShaderModule()

VkShaderModule mx::VKWindow::createShaderModule ( const std::vector< char > & code)

Compile a SPIR-V shader module.

Parameters
codeByte vector of SPIR-V code.
Returns
VkShaderModule handle.

Definition at line 162 of file vk.cpp.

References device.

Referenced by createGraphicsPipeline(), mx::VKAbstractModel::createModelPipeline(), createSpritePipeline(), and createTextPipeline().

◆ createSprite() [1/3]

VKSprite * mx::VKWindow::createSprite ( const std::string & pngPath,
const std::string & vertexShader,
const std::string & fragmentShaderPath = "" )

Create a sprite from a PNG file.

Parameters
pngPathPath to the PNG image.
vertexShaderVertex shader file path.
fragmentShaderPathFragment shader file path (empty = default).
Returns
Pointer to the created VKSprite (owned by this window).

Definition at line 1840 of file vk.cpp.

References commandPool, createSpriteDescriptorPool(), createSpriteDescriptorSetLayout(), createSpritePipeline(), device, graphicsQueue, physicalDevice, renderPass, spriteDescriptorSetLayout, spritePipeline, and sprites.

◆ createSprite() [2/3]

VKSprite * mx::VKWindow::createSprite ( int width,
int height,
const std::string & vertexShader = "",
const std::string & fragmentShaderPath = "" )

Create a blank sprite of the given dimensions.

Parameters
widthPixel width.
heightPixel height.
vertexShaderVertex shader file path.
fragmentShaderPathFragment shader file path.
Returns
Pointer to the created VKSprite.

Definition at line 1881 of file vk.cpp.

References commandPool, createSpriteDescriptorPool(), createSpriteDescriptorSetLayout(), createSpritePipeline(), device, graphicsQueue, height, physicalDevice, renderPass, spriteDescriptorSetLayout, spritePipeline, sprites, and width.

◆ createSprite() [3/3]

VKSprite * mx::VKWindow::createSprite ( SDL_Surface * surface,
const std::string & vertexShader,
const std::string & fragmentShaderPath = "" )

Create a sprite from an SDL_Surface.

Parameters
surfaceSource surface.
vertexShaderVertex shader file path.
fragmentShaderPathFragment shader file path.
Returns
Pointer to the created VKSprite.

Definition at line 1861 of file vk.cpp.

References commandPool, createSpriteDescriptorPool(), createSpriteDescriptorSetLayout(), createSpritePipeline(), device, graphicsQueue, physicalDevice, renderPass, spriteDescriptorSetLayout, spritePipeline, sprites, and surface.

◆ createSpriteDescriptorPool()

void mx::VKWindow::createSpriteDescriptorPool ( )
protected

Create the descriptor pool for sprite rendering.

Definition at line 2065 of file vk.cpp.

References device, spriteDescriptorPool, and VK_CHECK_RESULT.

Referenced by createSprite(), createSprite(), and createSprite().

◆ createSpriteDescriptorSetLayout()

void mx::VKWindow::createSpriteDescriptorSetLayout ( )
protected

Create the descriptor set layout for sprite rendering.

Definition at line 1901 of file vk.cpp.

References device, spriteDescriptorSetLayout, and VK_CHECK_RESULT.

Referenced by createSprite(), createSprite(), and createSprite().

◆ createSpritePipeline()

void mx::VKWindow::createSpritePipeline ( )
protected

◆ createSurface()

void mx::VKWindow::createSurface ( )
protected

Create the Vulkan surface from the SDL window.

Definition at line 365 of file vk.cpp.

References instance, surface, and window.

Referenced by initVulkan().

◆ createSwapChain()

◆ createSyncObjects()

void mx::VKWindow::createSyncObjects ( )
protected

Create semaphores and fences for frame synchronisation.

Definition at line 689 of file vk.cpp.

References device, imageAvailableSemaphore, inFlightFence, and renderFinishedSemaphore.

Referenced by initVulkan().

◆ createTextDescriptorPool()

void mx::VKWindow::createTextDescriptorPool ( )
protected

Create the descriptor pool for text rendering.

Definition at line 2283 of file vk.cpp.

References device, swapChainImages, textDescriptorPool, and VK_CHECK_RESULT.

Referenced by initVulkan().

◆ createTextDescriptorSetLayout()

void mx::VKWindow::createTextDescriptorSetLayout ( )
protected

Create the descriptor set layout for text rendering.

Definition at line 2101 of file vk.cpp.

References device, textDescriptorSetLayout, and VK_CHECK_RESULT.

Referenced by initVulkan().

◆ createTextPipeline()

void mx::VKWindow::createTextPipeline ( )
protected

Create the pipeline for text rendering.

Definition at line 2117 of file vk.cpp.

References createShaderModule(), device, mx::readFile(), renderPass, swapChainExtent, textDescriptorSetLayout, textPipeline, textPipelineLayout, util, and VK_CHECK_RESULT.

Referenced by initVulkan(), and recreateSwapChain().

◆ createTextureImage()

void mx::VKWindow::createTextureImage ( SDL_Surface * surfacex)
protected

Create a Vulkan texture image from an SDL surface.

Parameters
surfacexSource surface (RGBA).

Definition at line 937 of file vk.cpp.

References copyBufferToImage(), createBuffer(), createImage(), device, height, surface, textureImage, textureImageLayout, textureImageMemory, textureImageView, transitionImageLayout(), VK_CHECK_RESULT, and width.

◆ createTextureImageView()

void mx::VKWindow::createTextureImageView ( )
protected

Create the image view for the primary texture.

Definition at line 1180 of file vk.cpp.

References createImageView(), textureImage, and textureImageView.

Referenced by initVulkan().

◆ createTextureSampler()

void mx::VKWindow::createTextureSampler ( )
protected

Create the texture sampler with default filter/addressing modes.

Definition at line 1207 of file vk.cpp.

References device, and textureSampler.

Referenced by initVulkan().

◆ createUniformBuffers()

void mx::VKWindow::createUniformBuffers ( )
protected

Allocate per-frame uniform buffers and map them persistently.

Definition at line 1333 of file vk.cpp.

References createBuffer(), device, swapChainImages, uniformBuffers, uniformBuffersMapped, uniformBuffersMemory, and VK_CHECK_RESULT.

Referenced by initVulkan().

◆ createVertexBuffer()

void mx::VKWindow::createVertexBuffer ( )

Create and upload the vertex buffer.

Definition at line 811 of file vk.cpp.

References copyBuffer(), createBuffer(), device, indexBuffer, indexBufferMemory, indexCount, vertexBuffer, and vertexBufferMemory.

Referenced by initVulkan(), and recreateSwapChain().

◆ draw()

void mx::VKWindow::draw ( )
virtual

Record rendering commands for the current frame (overridable).

The default implementation draws the main textured quad and updates the uniform buffer.

Definition at line 1531 of file vk.cpp.

References clearTextQueue(), commandBuffers, device, graphicsQueue, imageAvailableSemaphore, presentQueue, recreateSwapChain(), renderFinishedSemaphore, renderPass, spritePipeline, spritePipelineLayout, sprites, swapChain, swapChainExtent, swapChainFramebuffers, textPipeline, textPipelineLayout, textRenderer, and VK_CHECK_RESULT.

Referenced by loop().

◆ enableControllerInput()

bool mx::VKWindow::enableControllerInput ( )

Enable joystick and game controller subsystems on demand.

Returns
true if controller input is ready, false on failure.

Definition at line 43 of file vk.cpp.

References inputControllersInitialized.

◆ endSingleTimeCommands()

void mx::VKWindow::endSingleTimeCommands ( VkCommandBuffer commandBuffer)
protected

End and submit a one-shot command buffer, then wait for completion.

Definition at line 1166 of file vk.cpp.

References commandPool, device, graphicsQueue, and VK_CHECK_RESULT.

Referenced by copyBufferToImage(), and transitionImageLayout().

◆ event()

virtual void mx::VKWindow::event ( SDL_Event & e)
pure virtual

Handle an SDL event (pure virtual).

Parameters
eSDL event to process.

Referenced by loop().

◆ findDepthFormat()

VkFormat mx::VKWindow::findDepthFormat ( )
protected

Select a depth buffer format supported by the physical device.

Definition at line 784 of file vk.cpp.

References findSupportedFormat().

Referenced by createDepthResources().

◆ findMemoryType()

uint32_t mx::VKWindow::findMemoryType ( uint32_t typeFilter,
VkMemoryPropertyFlags properties )
protected

Find a device memory type matching the filter and property flags.

Parameters
typeFilterBit mask of acceptable memory types.
propertiesRequired memory property flags.
Returns
Memory type index.

Definition at line 893 of file vk.cpp.

References physicalDevice.

Referenced by createBuffer(), and createImage().

◆ findQueueFamilies()

QueueFamilyIndices mx::VKWindow::findQueueFamilies ( VkPhysicalDevice device)
protected

Find queue families supporting graphics and presentation.

Parameters
devicePhysical device to query.
Returns
Populated QueueFamilyIndices.

Definition at line 174 of file vk.cpp.

References device, mx::QueueFamilyIndices::graphicsFamily, mx::QueueFamilyIndices::isComplete(), mx::QueueFamilyIndices::presentFamily, and surface.

Referenced by createCommandPool(), createLogicalDevice(), createSwapChain(), and isDeviceSuitable().

◆ findSupportedFormat()

VkFormat mx::VKWindow::findSupportedFormat ( const std::vector< VkFormat > & candidates,
VkImageTiling tiling,
VkFormatFeatureFlags features )
protected

Find a supported VkFormat from the candidate list.

Parameters
candidatesOrdered list of preferred formats.
tilingRequired tiling mode.
featuresRequired format feature flags.
Returns
First candidate that satisfies the requirements.

Definition at line 771 of file vk.cpp.

References physicalDevice.

Referenced by findDepthFormat().

◆ getCommandPool()

VkCommandPool mx::VKWindow::getCommandPool ( ) const
inline
Returns
Vulkan command pool handle.

Definition at line 329 of file vk.hpp.

References commandPool.

Referenced by mx::VKAbstractModel::load().

◆ getDevice()

◆ getGraphicsQueue()

VkQueue mx::VKWindow::getGraphicsQueue ( ) const
inline
Returns
Vulkan graphics queue handle.

Definition at line 327 of file vk.hpp.

References graphicsQueue.

Referenced by mx::VKAbstractModel::load().

◆ getHeight()

int mx::VKWindow::getHeight ( ) const
inline
Returns
Current window height.

Definition at line 297 of file vk.hpp.

References h.

◆ getPhysicalDevice()

VkPhysicalDevice mx::VKWindow::getPhysicalDevice ( ) const
inline
Returns
Vulkan physical device handle.

Definition at line 323 of file vk.hpp.

References physicalDevice.

Referenced by mx::VKAbstractModel::load().

◆ getTextDimensions()

bool mx::VKWindow::getTextDimensions ( const std::string & text,
int & width,
int & height )

Measure a text string without rendering it.

Parameters
textString to measure.
widthOutput: pixel width.
heightOutput: pixel height.
Returns
true if measurement succeeded.

Definition at line 2092 of file vk.cpp.

References height, textRenderer, and width.

◆ getWidth()

int mx::VKWindow::getWidth ( ) const
inline
Returns
Current window width.

Definition at line 295 of file vk.hpp.

References w.

◆ getWireFrame()

bool mx::VKWindow::getWireFrame ( ) const
inline
Returns
true if wireframe mode is active.

Definition at line 321 of file vk.hpp.

References useWireFrame.

◆ initVulkan()

◆ initWindow()

void mx::VKWindow::initWindow ( const std::string & title,
int width,
int height,
bool full = false )

Open the SDL2 window (called automatically by constructor).

Parameters
titleTitle string.
widthWidth.
heightHeight.
fullFullscreen flag.

Definition at line 15 of file vk.cpp.

References h, height, w, width, and window.

Referenced by VKWindow().

◆ isDeviceSuitable()

bool mx::VKWindow::isDeviceSuitable ( VkPhysicalDevice device)
protected

Check whether a physical device meets all application requirements.

Parameters
deviceCandidate physical device.
Returns
true if the device is suitable.

Definition at line 134 of file vk.cpp.

References device, findQueueFamilies(), mx::SwapChainSupportDetails::formats, mx::QueueFamilyIndices::isComplete(), mx::SwapChainSupportDetails::presentModes, and querySwapChainSupport().

Referenced by pickPhysicalDevice().

◆ loop()

void mx::VKWindow::loop ( )

Run the blocking event/render loop.

Definition at line 234 of file vk.cpp.

References active, draw(), event(), and proc().

◆ onResize()

virtual void mx::VKWindow::onResize ( )
inlinevirtual

Called when the window is resized (optional override).

Definition at line 201 of file vk.hpp.

Referenced by recreateSwapChain().

◆ operator=() [1/2]

VKWindow & mx::VKWindow::operator= ( const VKWindow & )
delete

References VKWindow().

◆ operator=() [2/2]

VKWindow & mx::VKWindow::operator= ( VKWindow && )
delete

References VKWindow().

◆ pickPhysicalDevice()

void mx::VKWindow::pickPhysicalDevice ( )
protected

Enumerate GPUs and select the most suitable physical device.

Definition at line 391 of file vk.cpp.

References instance, isDeviceSuitable(), and physicalDevice.

Referenced by initVulkan().

◆ printText()

void mx::VKWindow::printText ( const std::string & text,
int x,
int y,
const SDL_Color & col )

Queue a text string for rendering at a screen position.

Parameters
textString to display.
xX position in pixels.
yY position in pixels.
colText colour.

Definition at line 2080 of file vk.cpp.

References textRenderer.

◆ proc()

void mx::VKWindow::proc ( )
virtual

Process one event/render iteration (overridable).

Definition at line 244 of file vk.cpp.

Referenced by loop().

◆ querySwapChainSupport()

SwapChainSupportDetails mx::VKWindow::querySwapChainSupport ( VkPhysicalDevice device)
protected

Query swapchain support details for a physical device.

Parameters
devicePhysical device to query.
Returns
Populated SwapChainSupportDetails.

Definition at line 371 of file vk.cpp.

References mx::SwapChainSupportDetails::capabilities, device, mx::SwapChainSupportDetails::formats, mx::SwapChainSupportDetails::presentModes, and surface.

Referenced by createSwapChain(), and isDeviceSuitable().

◆ quit()

void mx::VKWindow::quit ( )

Post a quit event to stop the loop.

Definition at line 31 of file vk.cpp.

References active.

◆ recreateSwapChain()

◆ resizeWindow()

void mx::VKWindow::resizeWindow ( int width,
int height )

Resize the SDL window and recreate the swapchain.

Parameters
widthNew width.
heightNew height.

Definition at line 2297 of file vk.cpp.

References device, h, height, recreateSwapChain(), w, width, and window.

◆ setFont()

void mx::VKWindow::setFont ( const std::string & font,
const int size = 24 )

Set the font used for printText().

Parameters
fontPath to the TTF font file.
sizePoint size.

Definition at line 35 of file vk.cpp.

References font, font_size, textRenderer, and util.

◆ setFullScreen()

void mx::VKWindow::setFullScreen ( const bool full)

Toggle fullscreen mode.

Parameters
fulltrue for fullscreen.

Definition at line 1781 of file vk.cpp.

References device, h, recreateSwapChain(), w, and window.

◆ setPath()

void mx::VKWindow::setPath ( const std::string & path)

Set the asset root directory.

Parameters
pathAsset directory path.

Definition at line 130 of file vk.cpp.

References util.

◆ setupTextureImage()

void mx::VKWindow::setupTextureImage ( uint32_t w,
uint32_t h )
protected

Allocate a blank texture image of the given dimensions.

Parameters
wWidth in pixels.
hHeight in pixels.

Definition at line 1075 of file vk.cpp.

References createImage(), device, h, height, textureImage, textureImageLayout, textureImageMemory, transitionImageLayout(), w, and width.

Referenced by initVulkan().

◆ setWireFrame()

void mx::VKWindow::setWireFrame ( bool enable)
inline

Enable or disable wireframe rendering.

Parameters
enabletrue to draw in wireframe.

Definition at line 319 of file vk.hpp.

References useWireFrame.

◆ shouldRender3D()

virtual bool mx::VKWindow::shouldRender3D ( )
inlinevirtual

Control whether 3-D geometry is rendered this frame.

Returns
true (default) to submit the 3-D render pass.

Definition at line 207 of file vk.hpp.

◆ transitionImageLayout()

void mx::VKWindow::transitionImageLayout ( VkImage image,
VkFormat format,
VkImageLayout oldLayout,
VkImageLayout newLayout )
protected

Transition an image between two layouts using a pipeline barrier.

Parameters
imageTarget image.
formatImage format (used for aspect flag selection).
oldLayoutCurrent layout.
newLayoutDesired layout.

Definition at line 1026 of file vk.cpp.

References beginSingleTimeCommands(), and endSingleTimeCommands().

Referenced by createTextureImage(), mx::VKAbstractModel::loadModelTextures(), mx::VKAbstractModel::loadModelTexturesFromMTL(), setupTextureImage(), and updateTexture().

◆ updateDescriptorSets()

void mx::VKWindow::updateDescriptorSets ( )
protected

Write updated bindings into existing descriptor sets.

Definition at line 1313 of file vk.cpp.

References descriptorSets, device, swapChainImages, textureImageView, and textureSampler.

◆ updateTexture() [1/2]

void mx::VKWindow::updateTexture ( SDL_Surface * newSurface)

Replace the primary texture from an SDL_Surface.

Parameters
newSurfaceSource surface (not consumed).

Definition at line 96 of file vk.cpp.

References updateTexture().

Referenced by updateTexture().

◆ updateTexture() [2/2]

void mx::VKWindow::updateTexture ( void * pixels,
VkDeviceSize imageSize )

Replace the primary texture from a raw pixel buffer.

Parameters
pixelsPointer to RGBA data.
imageSizeSize of the data in bytes.

Definition at line 1092 of file vk.cpp.

References copyBufferToImage(), createBuffer(), device, height, textureImage, textureImageLayout, transitionImageLayout(), VK_CHECK_RESULT, and width.

◆ VKAbstractModel

friend class VKAbstractModel
friend

Definition at line 147 of file vk.hpp.

References font, height, VKAbstractModel, and width.

Referenced by VKAbstractModel.

Member Data Documentation

◆ active

bool mx::VKWindow::active = true
protected

true while the event loop should keep running.

Definition at line 331 of file vk.hpp.

Referenced by loop(), and quit().

◆ cameraDistance

float mx::VKWindow::cameraDistance = 3.0f
protected

Default camera distance from origin.

Definition at line 389 of file vk.hpp.

◆ commandBuffers

std::vector<VkCommandBuffer> mx::VKWindow::commandBuffers
protected

Per-frame command buffers.

Definition at line 363 of file vk.hpp.

Referenced by cleanupSwapChain(), createCommandBuffers(), and draw().

◆ commandPool

VkCommandPool mx::VKWindow::commandPool = VK_NULL_HANDLE
protected

◆ currentPolygonMode

VkPolygonMode mx::VKWindow::currentPolygonMode = VK_POLYGON_MODE_FILL
protected

Current polygon fill mode.

Definition at line 357 of file vk.hpp.

◆ debugMessenger

VkDebugUtilsMessengerEXT mx::VKWindow::debugMessenger = VK_NULL_HANDLE
protected

Vulkan debug messenger (validation layers).

Definition at line 402 of file vk.hpp.

Referenced by cleanup(), and createInstance().

◆ depthFormat

VkFormat mx::VKWindow::depthFormat = VK_FORMAT_D32_SFLOAT
protected

Format used for the depth buffer.

Definition at line 387 of file vk.hpp.

Referenced by createDepthResources(), and createRenderPass().

◆ depthImage

VkImage mx::VKWindow::depthImage = VK_NULL_HANDLE
protected

Depth/stencil image.

Definition at line 384 of file vk.hpp.

Referenced by cleanupSwapChain(), and createDepthResources().

◆ depthImageMemory

VkDeviceMemory mx::VKWindow::depthImageMemory = VK_NULL_HANDLE
protected

Memory for the depth image.

Definition at line 385 of file vk.hpp.

Referenced by cleanupSwapChain(), and createDepthResources().

◆ depthImageView

VkImageView mx::VKWindow::depthImageView = VK_NULL_HANDLE
protected

View into the depth image.

Definition at line 386 of file vk.hpp.

Referenced by cleanupSwapChain(), createDepthResources(), and createFramebuffers().

◆ descriptorPool

VkDescriptorPool mx::VKWindow::descriptorPool = VK_NULL_HANDLE
protected

Main descriptor pool.

Definition at line 381 of file vk.hpp.

Referenced by cleanup(), createDescriptorPool(), and createDescriptorSets().

◆ descriptorSetLayout

VkDescriptorSetLayout mx::VKWindow::descriptorSetLayout
protected

◆ descriptorSets

std::vector<VkDescriptorSet> mx::VKWindow::descriptorSets
protected

Per-frame descriptor sets.

Definition at line 382 of file vk.hpp.

Referenced by createDescriptorSets(), and updateDescriptorSets().

◆ device

◆ enableValidation

bool mx::VKWindow::enableValidation = true
protected

Enable Vulkan validation layers.

Definition at line 333 of file vk.hpp.

Referenced by cleanup(), createInstance(), and VKWindow().

◆ font

std::string mx::VKWindow::font = "font.ttf"
protected

Path to the current TTF font.

Definition at line 334 of file vk.hpp.

Referenced by initVulkan(), setFont(), and VKAbstractModel.

◆ font_size

int mx::VKWindow::font_size = 24
protected

Current font point size.

Definition at line 335 of file vk.hpp.

Referenced by initVulkan(), and setFont().

◆ graphicsPipeline

VkPipeline mx::VKWindow::graphicsPipeline = VK_NULL_HANDLE
protected

Filled-polygon graphics pipeline.

Definition at line 355 of file vk.hpp.

Referenced by cleanupSwapChain(), and createGraphicsPipeline().

◆ graphicsPipelineMatrix

VkPipeline mx::VKWindow::graphicsPipelineMatrix = VK_NULL_HANDLE
protected

3-D matrix-enabled graphics pipeline.

Definition at line 356 of file vk.hpp.

Referenced by cleanupSwapChain(), and createGraphicsPipeline().

◆ graphicsQueue

VkQueue mx::VKWindow::graphicsQueue = VK_NULL_HANDLE
protected

◆ h

int mx::VKWindow::h = 0

◆ height

uint32_t mx::VKWindow::height
protected

◆ imageAvailableSemaphore

VkSemaphore mx::VKWindow::imageAvailableSemaphore = VK_NULL_HANDLE
protected

Signals when a swapchain image is acquired.

Definition at line 365 of file vk.hpp.

Referenced by cleanup(), createSyncObjects(), and draw().

◆ indexBuffer

VkBuffer mx::VKWindow::indexBuffer = VK_NULL_HANDLE
protected

Full-screen quad index buffer.

Definition at line 371 of file vk.hpp.

Referenced by cleanup(), and createVertexBuffer().

◆ indexBufferMemory

VkDeviceMemory mx::VKWindow::indexBufferMemory = VK_NULL_HANDLE
protected

Memory for the index buffer.

Definition at line 372 of file vk.hpp.

Referenced by cleanup(), and createVertexBuffer().

◆ indexCount

uint32_t mx::VKWindow::indexCount = 0
protected

Number of indices in the quad.

Definition at line 373 of file vk.hpp.

Referenced by createVertexBuffer().

◆ inFlightFence

VkFence mx::VKWindow::inFlightFence = VK_NULL_HANDLE
protected

CPU–GPU frame synchronisation fence.

Definition at line 367 of file vk.hpp.

Referenced by cleanup(), and createSyncObjects().

◆ inputControllersInitialized

bool mx::VKWindow::inputControllersInitialized = false
protected

Whether joystick/controller input is enabled.

Definition at line 332 of file vk.hpp.

Referenced by cleanup(), controllerInputEnabled(), and enableControllerInput().

◆ instance

VkInstance mx::VKWindow::instance = VK_NULL_HANDLE
protected

Vulkan instance.

Definition at line 336 of file vk.hpp.

Referenced by cleanup(), createDescriptorPool(), createDescriptorSets(), createInstance(), createSurface(), and pickPhysicalDevice().

◆ physicalDevice

VkPhysicalDevice mx::VKWindow::physicalDevice = VK_NULL_HANDLE
protected

◆ pipelineLayout

VkPipelineLayout mx::VKWindow::pipelineLayout = VK_NULL_HANDLE
protected

Pipeline layout for the main pass.

Definition at line 354 of file vk.hpp.

Referenced by cleanup(), cleanupSwapChain(), createGraphicsPipeline(), and mx::VKAbstractModel::createModelPipeline().

◆ presentQueue

VkQueue mx::VKWindow::presentQueue = VK_NULL_HANDLE
protected

Presentation queue.

Definition at line 341 of file vk.hpp.

Referenced by createLogicalDevice(), and draw().

◆ renderFinishedSemaphore

VkSemaphore mx::VKWindow::renderFinishedSemaphore = VK_NULL_HANDLE
protected

Signals when rendering is complete.

Definition at line 366 of file vk.hpp.

Referenced by cleanup(), createSyncObjects(), and draw().

◆ renderPass

◆ spriteDescriptorPool

VkDescriptorPool mx::VKWindow::spriteDescriptorPool = VK_NULL_HANDLE
protected

Descriptor pool for sprites.

Definition at line 400 of file vk.hpp.

Referenced by cleanup(), and createSpriteDescriptorPool().

◆ spriteDescriptorSetLayout

VkDescriptorSetLayout mx::VKWindow::spriteDescriptorSetLayout = VK_NULL_HANDLE
protected

Descriptor layout for sprites.

Definition at line 401 of file vk.hpp.

Referenced by cleanup(), createSprite(), createSprite(), createSprite(), createSpriteDescriptorSetLayout(), createSpritePipeline(), and recreateSwapChain().

◆ spritePipeline

VkPipeline mx::VKWindow::spritePipeline = VK_NULL_HANDLE
protected

Pipeline for sprite rendering.

Definition at line 398 of file vk.hpp.

Referenced by cleanup(), createSprite(), createSprite(), createSprite(), createSpritePipeline(), draw(), and recreateSwapChain().

◆ spritePipelineLayout

VkPipelineLayout mx::VKWindow::spritePipelineLayout = VK_NULL_HANDLE
protected

Pipeline layout for sprites.

Definition at line 399 of file vk.hpp.

Referenced by cleanup(), createSpritePipeline(), draw(), and recreateSwapChain().

◆ sprites

std::vector<std::unique_ptr<VKSprite> > mx::VKWindow::sprites
protected

Owned sprite instances.

Definition at line 397 of file vk.hpp.

Referenced by cleanup(), createSprite(), createSprite(), createSprite(), draw(), and recreateSwapChain().

◆ supportsWireFrame

bool mx::VKWindow::supportsWireFrame = false
protected

Whether the device supports wireframe.

Definition at line 359 of file vk.hpp.

Referenced by createGraphicsPipeline(), and createLogicalDevice().

◆ surface

VkSurfaceKHR mx::VKWindow::surface = VK_NULL_HANDLE
protected

◆ surface_img

SDL_Surface* mx::VKWindow::surface_img = nullptr
protected

Cached SDL surface for texture uploads.

Definition at line 419 of file vk.hpp.

◆ swapChain

VkSwapchainKHR mx::VKWindow::swapChain = VK_NULL_HANDLE
protected

Active swapchain.

Definition at line 344 of file vk.hpp.

Referenced by cleanupSwapChain(), createSwapChain(), and draw().

◆ swapChainExtent

VkExtent2D mx::VKWindow::swapChainExtent
protected

Swapchain pixel dimensions.

Definition at line 347 of file vk.hpp.

Referenced by createDepthResources(), createFramebuffers(), createGraphicsPipeline(), createSwapChain(), createTextPipeline(), and draw().

◆ swapChainFramebuffers

std::vector<VkFramebuffer> mx::VKWindow::swapChainFramebuffers
protected

Framebuffers for each swapchain image.

Definition at line 360 of file vk.hpp.

Referenced by cleanupSwapChain(), createCommandBuffers(), createFramebuffers(), and draw().

◆ swapChainImageFormat

VkFormat mx::VKWindow::swapChainImageFormat
protected

Colour format of swapchain images.

Definition at line 346 of file vk.hpp.

Referenced by createImageViews(), createRenderPass(), and createSwapChain().

◆ swapChainImages

◆ swapChainImageViews

std::vector<VkImageView> mx::VKWindow::swapChainImageViews
protected

Image views into swapchain images.

Definition at line 348 of file vk.hpp.

Referenced by cleanupSwapChain(), createFramebuffers(), and createImageViews().

◆ textDescriptorPool

VkDescriptorPool mx::VKWindow::textDescriptorPool = VK_NULL_HANDLE
protected

Descriptor pool for text.

Definition at line 394 of file vk.hpp.

Referenced by cleanup(), and createTextDescriptorPool().

◆ textDescriptorSetLayout

VkDescriptorSetLayout mx::VKWindow::textDescriptorSetLayout = VK_NULL_HANDLE
protected

Descriptor layout for text.

Definition at line 395 of file vk.hpp.

Referenced by cleanup(), createTextDescriptorSetLayout(), createTextPipeline(), and initVulkan().

◆ textPipeline

VkPipeline mx::VKWindow::textPipeline = VK_NULL_HANDLE
protected

Pipeline for text rendering.

Definition at line 392 of file vk.hpp.

Referenced by cleanup(), createTextPipeline(), and draw().

◆ textPipelineLayout

VkPipelineLayout mx::VKWindow::textPipelineLayout = VK_NULL_HANDLE
protected

Pipeline layout for text rendering.

Definition at line 393 of file vk.hpp.

Referenced by cleanup(), createTextPipeline(), and draw().

◆ textRenderer

std::unique_ptr<VKText> mx::VKWindow::textRenderer
protected

Text rendering subsystem.

Definition at line 391 of file vk.hpp.

Referenced by cleanup(), clearTextQueue(), draw(), getTextDimensions(), initVulkan(), printText(), and setFont().

◆ textureImage

VkImage mx::VKWindow::textureImage = VK_NULL_HANDLE
protected

Primary texture image.

Definition at line 375 of file vk.hpp.

Referenced by cleanup(), createTextureImage(), createTextureImageView(), setupTextureImage(), and updateTexture().

◆ textureImageLayout

VkImageLayout mx::VKWindow::textureImageLayout = VK_IMAGE_LAYOUT_UNDEFINED
protected

Current layout of the primary texture.

Definition at line 378 of file vk.hpp.

Referenced by createTextureImage(), setupTextureImage(), and updateTexture().

◆ textureImageMemory

VkDeviceMemory mx::VKWindow::textureImageMemory = VK_NULL_HANDLE
protected

Memory for the primary texture.

Definition at line 376 of file vk.hpp.

Referenced by cleanup(), createTextureImage(), and setupTextureImage().

◆ textureImageView

VkImageView mx::VKWindow::textureImageView = VK_NULL_HANDLE
protected

View into the primary texture.

Definition at line 377 of file vk.hpp.

Referenced by cleanup(), createDescriptorSets(), createTextureImage(), createTextureImageView(), and updateDescriptorSets().

◆ textureSampler

VkSampler mx::VKWindow::textureSampler = VK_NULL_HANDLE
protected

Sampler for the primary texture.

Definition at line 379 of file vk.hpp.

Referenced by cleanup(), createDescriptorSets(), mx::VKAbstractModel::createModelDescriptorSets(), createTextureSampler(), and updateDescriptorSets().

◆ uniformBuffers

std::vector<VkBuffer> mx::VKWindow::uniformBuffers
protected

Per-frame uniform buffers.

Definition at line 349 of file vk.hpp.

Referenced by cleanup(), createDescriptorSets(), and createUniformBuffers().

◆ uniformBuffersMapped

std::vector<void*> mx::VKWindow::uniformBuffersMapped
protected

Persistently mapped UBO pointers.

Definition at line 351 of file vk.hpp.

Referenced by cleanup(), and createUniformBuffers().

◆ uniformBuffersMemory

std::vector<VkDeviceMemory> mx::VKWindow::uniformBuffersMemory
protected

Memory for per-frame UBOs.

Definition at line 350 of file vk.hpp.

Referenced by cleanup(), and createUniformBuffers().

◆ useWireFrame

bool mx::VKWindow::useWireFrame = false
protected

Wireframe rendering toggle.

Definition at line 358 of file vk.hpp.

Referenced by getWireFrame(), and setWireFrame().

◆ util

mxUtil mx::VKWindow::util

Asset path and utility helpers.

Definition at line 221 of file vk.hpp.

Referenced by createGraphicsPipeline(), createSpritePipeline(), createTextPipeline(), initVulkan(), setFont(), and setPath().

◆ vertexBuffer

VkBuffer mx::VKWindow::vertexBuffer = VK_NULL_HANDLE
protected

Full-screen quad vertex buffer.

Definition at line 369 of file vk.hpp.

Referenced by cleanup(), and createVertexBuffer().

◆ vertexBufferMemory

VkDeviceMemory mx::VKWindow::vertexBufferMemory = VK_NULL_HANDLE
protected

Memory for the vertex buffer.

Definition at line 370 of file vk.hpp.

Referenced by cleanup(), and createVertexBuffer().

◆ w

int mx::VKWindow::w = 0

◆ width

◆ window

SDL_Window* mx::VKWindow::window = nullptr
protected

SDL window handle.

Definition at line 418 of file vk.hpp.

Referenced by cleanup(), createInstance(), createSurface(), initWindow(), recreateSwapChain(), resizeWindow(), and setFullScreen().


The documentation for this class was generated from the following files: