|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
Vulkan 2-D sprite with texture, custom shader, and instancing support. More...
#include <vk_sprite.hpp>
Classes | |
| struct | SpriteVertex |
| struct | SpriteDrawCmd |
| struct | SpriteExtendedUBO |
| struct | SpriteInstanceData |
Public Member Functions | |
| VKSprite (VkDevice device, VkPhysicalDevice physicalDevice, VkQueue graphicsQueue, VkCommandPool commandPool) | |
| Construct and record Vulkan context handles. | |
| ~VKSprite () | |
| Destructor — frees all Vulkan resources. | |
| VKSprite (const VKSprite &)=delete | |
| VKSprite & | operator= (const VKSprite &)=delete |
| VKSprite (VKSprite &&)=delete | |
| VKSprite & | operator= (VKSprite &&)=delete |
| void | loadSprite (const std::string &pngPath, const std::string &fragmentShaderPath="") |
| Load sprite texture from a PNG file. | |
| void | loadSprite (SDL_Surface *surface, const std::string &fragmentShaderPath="") |
| Load sprite texture from an SDL_Surface. | |
| void | createEmptySprite (int width, int height, const std::string &vertexShaderPath="", const std::string &fragmentShaderPath="") |
| Create a blank (un-initialised) sprite texture. | |
| void | drawSprite (int x, int y) |
| Queue a draw at the given pixel position. | |
| void | drawSprite (int x, int y, float scaleX, float scaleY) |
| Queue a scaled draw. | |
| void | drawSprite (int x, int y, float scaleX, float scaleY, float rotation) |
| Queue a scaled and rotated draw. | |
| void | drawSpriteRect (int x, int y, int w, int h) |
| Queue a draw into an explicit destination rectangle. | |
| void | updateTexture (SDL_Surface *surface) |
| Replace the sprite texture from an SDL_Surface. | |
| void | updateTexture (const void *pixels, int width, int height, int pitch=0) |
| Replace the sprite texture from a raw pixel buffer. | |
| void | setShaderParams (float p1=0.0f, float p2=0.0f, float p3=0.0f, float p4=0.0f) |
| Set up to four custom shader float parameters. | |
| void | setEffectsEnabled (bool enabled) |
| Enable or disable the custom fragment shader effects. | |
| bool | getEffectsEnabled () const |
| void | renderSprites (VkCommandBuffer cmdBuffer, VkPipelineLayout pipelineLayout, uint32_t screenWidth, uint32_t screenHeight) |
| Record all queued draw commands into the given command buffer. | |
| void | clearQueue () |
| Discard all pending draw commands without rendering. | |
| int | getWidth () const |
| int | getHeight () const |
| void | setDescriptorSetLayout (VkDescriptorSetLayout layout) |
| Assign an external descriptor-set layout. | |
| void | setRenderPass (VkRenderPass rp) |
| Assign the render pass used to build the custom pipeline. | |
| void | setVertexShaderPath (const std::string &path) |
| Override the vertex shader path (used when rebuilding the pipeline). | |
| bool | hasOwnPipeline () const |
| VkPipeline | getPipeline () const |
| VkPipelineLayout | getPipelineLayout () const |
| void | rebuildPipeline () |
| Destroy and recreate the custom graphics pipeline. | |
| void | rebuildInstancedPipeline () |
| Destroy and recreate the instanced graphics pipeline. | |
| void | enableInstancing (uint32_t maxInstances, const std::string &instanceVertShaderPath, const std::string &instanceFragShaderPath) |
| Enable GPU instancing for this sprite type. | |
| bool | isInstancingEnabled () const |
| void | enableExtendedUBO () |
| Allocate and initialise the extended uniform buffer object. | |
| bool | isExtendedUBOEnabled () const |
| void | setMouseState (float mx, float my, float pressed, float reserved=0.0f) |
| Upload mouse state to the extended UBO. | |
| void | setUniform0 (float x, float y, float z, float w) |
| Upload user uniform 0 to the extended UBO. | |
| void | setUniform1 (float x, float y, float z, float w) |
| Upload user uniform 1 to the extended UBO. | |
| void | setUniform2 (float x, float y, float z, float w) |
| Upload user uniform 2 to the extended UBO. | |
| void | setUniform3 (float x, float y, float z, float w) |
| Upload user uniform 3 to the extended UBO. | |
Public Attributes | |
| VkSampler | spriteSampler = VK_NULL_HANDLE |
| Texture sampler. | |
Private Member Functions | |
| void | createCustomPipeline () |
| void | createQuadBuffer () |
| void | createDescriptorPool () |
| VkDescriptorSet | createDescriptorSet (VkImageView imageView) |
| void | destroySpriteResources () |
| void | createStagingResources (VkDeviceSize size) |
| void | destroyStagingResources () |
| void | createBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) |
| uint32_t | findMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties) |
| void | copyBufferToImage (VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) |
| VkCommandBuffer | beginSingleTimeCommands () |
| void | endSingleTimeCommands (VkCommandBuffer commandBuffer) |
| void | transitionImageLayout (VkImage image, VkImageLayout oldLayout, VkImageLayout newLayout) |
| void | createImage (uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory) |
| VkImageView | createImageView (VkImage image, VkFormat format) |
| void | createSampler () |
| SDL_Surface * | convertToRGBA (SDL_Surface *surface) |
| void | createSpriteTexture (SDL_Surface *surface) |
| void | updateSpriteTexture (const void *pixels, uint32_t width, uint32_t height) |
| VkShaderModule | createShaderModule (const std::vector< char > &code) |
| std::vector< char > | readShaderFile (const std::string &filename) |
| void | createExtendedUBO () |
| void | updateExtendedUBO () |
| void | createExtendedDescriptorSetLayout () |
| void | createExtendedDescriptorSet () |
| void | destroyExtendedUBO () |
| void | createInstancedPipeline (const std::string &vertPath, const std::string &fragPath) |
| void | ensureInstanceBuffer (uint32_t count) |
| void | destroyInstanceResources () |
Private Attributes | |
| VkDevice | device = VK_NULL_HANDLE |
| VkPhysicalDevice | physicalDevice = VK_NULL_HANDLE |
| VkQueue | graphicsQueue = VK_NULL_HANDLE |
| VkCommandPool | commandPool = VK_NULL_HANDLE |
| VkImage | spriteImage = VK_NULL_HANDLE |
| VkDeviceMemory | spriteImageMemory = VK_NULL_HANDLE |
| VkImageView | spriteImageView = VK_NULL_HANDLE |
| int | spriteWidth = 0 |
| int | spriteHeight = 0 |
| bool | spriteLoaded = false |
| VkShaderModule | fragmentShaderModule = VK_NULL_HANDLE |
| bool | hasCustomShader = false |
| glm::vec4 | shaderParams = glm::vec4(0.0f) |
| bool | effectsEnabled = true |
| std::vector< SpriteDrawCmd > | drawQueue |
| VkPipeline | customPipeline = VK_NULL_HANDLE |
| VkPipelineLayout | customPipelineLayout = VK_NULL_HANDLE |
| VkRenderPass | renderPass = VK_NULL_HANDLE |
| std::string | vertexShaderPath |
| VkBuffer | quadVertexBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | quadVertexBufferMemory = VK_NULL_HANDLE |
| VkBuffer | quadIndexBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | quadIndexBufferMemory = VK_NULL_HANDLE |
| bool | quadBufferCreated = false |
| VkDescriptorPool | descriptorPool = VK_NULL_HANDLE |
| VkDescriptorSetLayout | descriptorSetLayout = VK_NULL_HANDLE |
| VkDescriptorSet | descriptorSet = VK_NULL_HANDLE |
| VkBuffer | persistentStagingBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | persistentStagingMemory = VK_NULL_HANDLE |
| void * | persistentStagingMapped = nullptr |
| VkDeviceSize | persistentStagingSize = 0 |
| VkFence | uploadFence = VK_NULL_HANDLE |
| VkCommandBuffer | uploadCmdBuffer = VK_NULL_HANDLE |
| bool | stagingResourcesCreated = false |
| bool | extendedUBOEnabled = false |
| SpriteExtendedUBO | extendedUBOData {} |
| VkBuffer | extendedUBOBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | extendedUBOMemory = VK_NULL_HANDLE |
| void * | extendedUBOMapped = nullptr |
| VkDescriptorSetLayout | extendedDescriptorSetLayout = VK_NULL_HANDLE |
| VkDescriptorPool | extendedDescriptorPool = VK_NULL_HANDLE |
| VkDescriptorSet | extendedDescriptorSet = VK_NULL_HANDLE |
| bool | ownExtendedDescriptorSetLayout = false |
| VkBuffer | instanceBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | instanceBufferMemory = VK_NULL_HANDLE |
| void * | instanceBufferMapped = nullptr |
| uint32_t | instanceBufferCapacity = 0 |
| bool | instancingEnabled = false |
| VkPipeline | instancedPipeline = VK_NULL_HANDLE |
| VkPipelineLayout | instancedPipelineLayout = VK_NULL_HANDLE |
| std::string | instanceVertPath_ |
| std::string | instanceFragPath_ |
Vulkan 2-D sprite with texture, custom shader, and instancing support.
Allocates and manages all Vulkan resources required to render one sprite type: image, sampler, descriptor set, vertex/index buffers, and an optional custom pipeline. Multiple draw commands are batched into a queue and submitted together in renderSprites().
Definition at line 55 of file vk_sprite.hpp.
| mx::VKSprite::VKSprite | ( | VkDevice | device, |
| VkPhysicalDevice | physicalDevice, | ||
| VkQueue | graphicsQueue, | ||
| VkCommandPool | commandPool ) |
Construct and record Vulkan context handles.
| device | Logical device. |
| physicalDevice | Physical device. |
| graphicsQueue | Graphics queue. |
| commandPool | Command pool for staging operations. |
Definition at line 10 of file vk_sprite.cpp.
References commandPool, device, graphicsQueue, and physicalDevice.
Referenced by operator=(), operator=(), VKSprite(), and VKSprite().
| mx::VKSprite::~VKSprite | ( | ) |
Destructor — frees all Vulkan resources.
Definition at line 14 of file vk_sprite.cpp.
References customPipeline, customPipelineLayout, descriptorPool, destroyExtendedUBO(), destroyInstanceResources(), destroyStagingResources(), device, drawQueue, fragmentShaderModule, quadIndexBuffer, quadIndexBufferMemory, quadVertexBuffer, quadVertexBufferMemory, spriteImage, spriteImageMemory, spriteImageView, and spriteSampler.
|
delete |
References VKSprite().
|
delete |
References VKSprite().
|
private |
Definition at line 1345 of file vk_sprite.cpp.
References commandPool, device, and VK_CHECK_RESULT.
Referenced by copyBufferToImage(), and transitionImageLayout().
| void mx::VKSprite::clearQueue | ( | ) |
Discard all pending draw commands without rendering.
Definition at line 1192 of file vk_sprite.cpp.
References drawQueue.
|
private |
Definition at line 1427 of file vk_sprite.cpp.
Referenced by loadSprite(), and updateTexture().
|
private |
Definition at line 1326 of file vk_sprite.cpp.
References beginSingleTimeCommands(), and endSingleTimeCommands().
Referenced by createEmptySprite(), and createSpriteTexture().
|
private |
Definition at line 1248 of file vk_sprite.cpp.
References device, findMemoryType(), and VK_CHECK_RESULT.
Referenced by createEmptySprite(), createExtendedUBO(), createQuadBuffer(), createSpriteTexture(), createStagingResources(), and ensureInstanceBuffer().
|
private |
Definition at line 557 of file vk_sprite.cpp.
References createShaderModule(), customPipeline, customPipelineLayout, descriptorSetLayout, device, extendedDescriptorSetLayout, extendedUBOEnabled, fragmentShaderModule, hasCustomShader, readShaderFile(), renderPass, vertexShaderPath, and VK_CHECK_RESULT.
Referenced by createEmptySprite(), loadSprite(), and rebuildPipeline().
|
private |
Definition at line 1196 of file vk_sprite.cpp.
References descriptorPool, device, and VK_CHECK_RESULT.
Referenced by createDescriptorSet(), createEmptySprite(), updateTexture(), and updateTexture().
|
private |
Definition at line 1211 of file vk_sprite.cpp.
References createDescriptorPool(), descriptorPool, descriptorSetLayout, device, spriteSampler, and VK_CHECK_RESULT.
Referenced by renderSprites().
| void mx::VKSprite::createEmptySprite | ( | int | width, |
| int | height, | ||
| const std::string & | vertexShaderPath = "", | ||
| const std::string & | fragmentShaderPath = "" ) |
Create a blank (un-initialised) sprite texture.
| width | Pixel width. |
| height | Pixel height. |
| vertexShaderPath | Optional vertex shader. |
| fragmentShaderPath | Optional fragment shader. |
Definition at line 782 of file vk_sprite.cpp.
References copyBufferToImage(), createBuffer(), createCustomPipeline(), createDescriptorPool(), createImage(), createImageView(), createQuadBuffer(), createSampler(), createShaderModule(), createStagingResources(), descriptorSetLayout, destroySpriteResources(), device, fragmentShaderModule, hasCustomShader, readShaderFile(), renderPass, setVertexShaderPath(), spriteHeight, spriteImage, spriteImageMemory, spriteImageView, spriteLoaded, spriteWidth, transitionImageLayout(), vertexShaderPath, and VK_CHECK_RESULT.
|
private |
Definition at line 185 of file vk_sprite.cpp.
References device, extendedDescriptorPool, extendedDescriptorSet, extendedDescriptorSetLayout, extendedUBOBuffer, spriteImageView, spriteSampler, and VK_CHECK_RESULT.
Referenced by renderSprites().
|
private |
Definition at line 159 of file vk_sprite.cpp.
References device, extendedDescriptorSetLayout, ownExtendedDescriptorSetLayout, and VK_CHECK_RESULT.
Referenced by enableExtendedUBO().
|
private |
Definition at line 145 of file vk_sprite.cpp.
References createBuffer(), device, extendedUBOBuffer, extendedUBOMapped, extendedUBOMemory, and VK_CHECK_RESULT.
Referenced by enableExtendedUBO().
|
private |
Definition at line 1378 of file vk_sprite.cpp.
References device, findMemoryType(), and VK_CHECK_RESULT.
Referenced by createEmptySprite(), and createSpriteTexture().
|
private |
Definition at line 1410 of file vk_sprite.cpp.
References device, and VK_CHECK_RESULT.
Referenced by createEmptySprite(), and createSpriteTexture().
|
private |
Definition at line 401 of file vk_sprite.cpp.
References createShaderModule(), descriptorSetLayout, device, instancedPipeline, instancedPipelineLayout, readShaderFile(), renderPass, and VK_CHECK_RESULT.
Referenced by enableInstancing(), and rebuildInstancedPipeline().
|
private |
Definition at line 711 of file vk_sprite.cpp.
References createBuffer(), device, quadBufferCreated, quadIndexBuffer, quadIndexBufferMemory, quadVertexBuffer, quadVertexBufferMemory, and VK_CHECK_RESULT.
Referenced by createEmptySprite(), enableInstancing(), and loadSprite().
|
private |
Definition at line 1043 of file vk_sprite.cpp.
References device, spriteSampler, and VK_CHECK_RESULT.
Referenced by createEmptySprite(), and loadSprite().
|
private |
Definition at line 1450 of file vk_sprite.cpp.
References device, and VK_CHECK_RESULT.
Referenced by createCustomPipeline(), createEmptySprite(), createInstancedPipeline(), and loadSprite().
|
private |
Definition at line 1015 of file vk_sprite.cpp.
References copyBufferToImage(), createBuffer(), createImage(), createImageView(), device, spriteImage, spriteImageMemory, spriteImageView, transitionImageLayout(), and VK_CHECK_RESULT.
Referenced by loadSprite(), updateTexture(), and updateTexture().
|
private |
Definition at line 271 of file vk_sprite.cpp.
References commandPool, createBuffer(), destroyStagingResources(), device, persistentStagingBuffer, persistentStagingMapped, persistentStagingMemory, persistentStagingSize, stagingResourcesCreated, uploadCmdBuffer, uploadFence, and VK_CHECK_RESULT.
Referenced by createEmptySprite(), and updateSpriteTexture().
|
private |
Definition at line 247 of file vk_sprite.cpp.
References device, extendedDescriptorPool, extendedDescriptorSet, extendedDescriptorSetLayout, extendedUBOBuffer, extendedUBOEnabled, extendedUBOMapped, extendedUBOMemory, and ownExtendedDescriptorSetLayout.
Referenced by ~VKSprite().
|
private |
Definition at line 341 of file vk_sprite.cpp.
References device, instanceBuffer, instanceBufferCapacity, instanceBufferMapped, instanceBufferMemory, instancedPipeline, instancedPipelineLayout, and instancingEnabled.
Referenced by ~VKSprite().
|
private |
Definition at line 62 of file vk_sprite.cpp.
References customPipeline, customPipelineLayout, descriptorPool, descriptorSet, destroyStagingResources(), device, extendedDescriptorPool, extendedDescriptorSet, fragmentShaderModule, hasCustomShader, spriteImage, spriteImageMemory, spriteImageView, spriteLoaded, and spriteSampler.
Referenced by createEmptySprite(), and loadSprite().
|
private |
Definition at line 317 of file vk_sprite.cpp.
References commandPool, device, persistentStagingBuffer, persistentStagingMapped, persistentStagingMemory, persistentStagingSize, stagingResourcesCreated, uploadCmdBuffer, and uploadFence.
Referenced by createStagingResources(), destroySpriteResources(), and ~VKSprite().
| void mx::VKSprite::drawSprite | ( | int | x, |
| int | y ) |
Queue a draw at the given pixel position.
| x | Destination X. |
| y | Destination Y. |
Definition at line 1068 of file vk_sprite.cpp.
References drawSpriteRect(), spriteHeight, and spriteWidth.
| void mx::VKSprite::drawSprite | ( | int | x, |
| int | y, | ||
| float | scaleX, | ||
| float | scaleY ) |
Queue a scaled draw.
| x | Destination X. |
| y | Destination Y. |
| scaleX | Horizontal scale factor. |
| scaleY | Vertical scale factor. |
Definition at line 1072 of file vk_sprite.cpp.
References drawSpriteRect(), spriteHeight, and spriteWidth.
| void mx::VKSprite::drawSprite | ( | int | x, |
| int | y, | ||
| float | scaleX, | ||
| float | scaleY, | ||
| float | rotation ) |
Queue a scaled and rotated draw.
| x | Destination X. |
| y | Destination Y. |
| scaleX | Horizontal scale. |
| scaleY | Vertical scale. |
| rotation | Clockwise rotation in degrees. |
Definition at line 1076 of file vk_sprite.cpp.
References drawSpriteRect(), spriteHeight, and spriteWidth.
| void mx::VKSprite::drawSpriteRect | ( | int | x, |
| int | y, | ||
| int | w, | ||
| int | h ) |
Queue a draw into an explicit destination rectangle.
| x,y,w,h | Destination rectangle. |
Definition at line 1080 of file vk_sprite.cpp.
References drawQueue, shaderParams, and spriteLoaded.
Referenced by drawSprite(), drawSprite(), and drawSprite().
| void mx::VKSprite::enableExtendedUBO | ( | ) |
Allocate and initialise the extended uniform buffer object.
Definition at line 117 of file vk_sprite.cpp.
References createExtendedDescriptorSetLayout(), createExtendedUBO(), extendedUBOEnabled, and rebuildPipeline().
| void mx::VKSprite::enableInstancing | ( | uint32_t | maxInstances, |
| const std::string & | instanceVertShaderPath, | ||
| const std::string & | instanceFragShaderPath ) |
Enable GPU instancing for this sprite type.
| maxInstances | Maximum simultaneous instances. |
| instanceVertShaderPath | Vertex shader supporting instancing. |
| instanceFragShaderPath | Fragment shader. |
Definition at line 387 of file vk_sprite.cpp.
References createInstancedPipeline(), createQuadBuffer(), descriptorSetLayout, ensureInstanceBuffer(), instanceFragPath_, instanceVertPath_, instancingEnabled, and renderPass.
|
private |
Definition at line 1364 of file vk_sprite.cpp.
References commandPool, device, graphicsQueue, and VK_CHECK_RESULT.
Referenced by copyBufferToImage(), and transitionImageLayout().
|
private |
Definition at line 364 of file vk_sprite.cpp.
References createBuffer(), device, instanceBuffer, instanceBufferCapacity, instanceBufferMapped, instanceBufferMemory, and VK_CHECK_RESULT.
Referenced by enableInstancing(), and renderSprites().
|
private |
Definition at line 1271 of file vk_sprite.cpp.
References physicalDevice.
Referenced by createBuffer(), and createImage().
|
inline |
true if shader effects are enabled. Definition at line 158 of file vk_sprite.hpp.
References effectsEnabled.
|
inline |
Definition at line 176 of file vk_sprite.hpp.
References spriteHeight.
|
inline |
Definition at line 188 of file vk_sprite.hpp.
References customPipeline.
|
inline |
Definition at line 190 of file vk_sprite.hpp.
References customPipelineLayout.
|
inline |
Definition at line 174 of file vk_sprite.hpp.
References spriteWidth.
|
inline |
true if a custom pipeline has been built. Definition at line 186 of file vk_sprite.hpp.
References customPipeline.
|
inline |
true if the extended UBO is active. Definition at line 216 of file vk_sprite.hpp.
References extendedUBOEnabled.
|
inline |
true if GPU instancing is active. Definition at line 210 of file vk_sprite.hpp.
References instancingEnabled.
| void mx::VKSprite::loadSprite | ( | const std::string & | pngPath, |
| const std::string & | fragmentShaderPath = "" ) |
Load sprite texture from a PNG file.
| pngPath | Path to the PNG file. |
| fragmentShaderPath | Optional custom fragment shader (SPIR-V .spv). |
Definition at line 744 of file vk_sprite.cpp.
References png::LoadPNG(), and loadSprite().
Referenced by loadSprite().
| void mx::VKSprite::loadSprite | ( | SDL_Surface * | surface, |
| const std::string & | fragmentShaderPath = "" ) |
Load sprite texture from an SDL_Surface.
| surface | Source surface (not consumed). |
| fragmentShaderPath | Optional custom fragment shader. |
Definition at line 753 of file vk_sprite.cpp.
References convertToRGBA(), createCustomPipeline(), createQuadBuffer(), createSampler(), createShaderModule(), createSpriteTexture(), descriptorSetLayout, destroySpriteResources(), fragmentShaderModule, hasCustomShader, readShaderFile(), renderPass, spriteHeight, spriteImage, spriteLoaded, and spriteWidth.
References VKSprite().
References vertexShaderPath, and VKSprite().
|
private |
Definition at line 1435 of file vk_sprite.cpp.
Referenced by createCustomPipeline(), createEmptySprite(), createInstancedPipeline(), and loadSprite().
| void mx::VKSprite::rebuildInstancedPipeline | ( | ) |
Destroy and recreate the instanced graphics pipeline.
Definition at line 706 of file vk_sprite.cpp.
References createInstancedPipeline(), instanceFragPath_, instanceVertPath_, and instancingEnabled.
| void mx::VKSprite::rebuildPipeline | ( | ) |
Destroy and recreate the custom graphics pipeline.
Definition at line 701 of file vk_sprite.cpp.
References createCustomPipeline(), fragmentShaderModule, and hasCustomShader.
Referenced by enableExtendedUBO().
| void mx::VKSprite::renderSprites | ( | VkCommandBuffer | cmdBuffer, |
| VkPipelineLayout | pipelineLayout, | ||
| uint32_t | screenWidth, | ||
| uint32_t | screenHeight ) |
Record all queued draw commands into the given command buffer.
| cmdBuffer | Active command buffer. |
| pipelineLayout | Pipeline layout for push constants/descriptors. |
| screenWidth | Current viewport width. |
| screenHeight | Current viewport height. |
Definition at line 1093 of file vk_sprite.cpp.
References createDescriptorSet(), createExtendedDescriptorSet(), customPipeline, customPipelineLayout, descriptorSet, drawQueue, effectsEnabled, ensureInstanceBuffer(), extendedDescriptorSet, extendedUBOEnabled, instanceBuffer, instanceBufferCapacity, instanceBufferMapped, instancedPipeline, instancedPipelineLayout, instancingEnabled, mx::VKSprite::SpriteInstanceData::params, mx::VKSprite::SpriteInstanceData::posX, mx::VKSprite::SpriteInstanceData::posY, quadBufferCreated, quadIndexBuffer, quadVertexBuffer, mx::VKSprite::SpriteInstanceData::sizeH, mx::VKSprite::SpriteInstanceData::sizeW, spriteImageView, spriteLoaded, and updateExtendedUBO().
|
inline |
Assign an external descriptor-set layout.
Definition at line 179 of file vk_sprite.hpp.
References descriptorSetLayout.
|
inline |
Enable or disable the custom fragment shader effects.
| enabled | true to enable effects. |
Definition at line 155 of file vk_sprite.hpp.
References effectsEnabled.
| void mx::VKSprite::setMouseState | ( | float | mx, |
| float | my, | ||
| float | pressed, | ||
| float | reserved = 0.0f ) |
Upload mouse state to the extended UBO.
| mx | Mouse X (normalised or pixels). |
| my | Mouse Y. |
| pressed | Mouse button state. |
| reserved | Reserved channel. |
Definition at line 125 of file vk_sprite.cpp.
References extendedUBOData.
|
inline |
Assign the render pass used to build the custom pipeline.
Definition at line 181 of file vk_sprite.hpp.
References renderPass.
| void mx::VKSprite::setShaderParams | ( | float | p1 = 0.0f, |
| float | p2 = 0.0f, | ||
| float | p3 = 0.0f, | ||
| float | p4 = 0.0f ) |
Set up to four custom shader float parameters.
| p1,p2,p3,p4 | Parameter values packed into a vec4. |
Definition at line 1089 of file vk_sprite.cpp.
References shaderParams.
| void mx::VKSprite::setUniform0 | ( | float | x, |
| float | y, | ||
| float | z, | ||
| float | w ) |
Upload user uniform 0 to the extended UBO.
| x,y,z,w | Components. |
Definition at line 129 of file vk_sprite.cpp.
References extendedUBOData.
| void mx::VKSprite::setUniform1 | ( | float | x, |
| float | y, | ||
| float | z, | ||
| float | w ) |
Upload user uniform 1 to the extended UBO.
| x,y,z,w | Components. |
Definition at line 133 of file vk_sprite.cpp.
References extendedUBOData.
| void mx::VKSprite::setUniform2 | ( | float | x, |
| float | y, | ||
| float | z, | ||
| float | w ) |
Upload user uniform 2 to the extended UBO.
| x,y,z,w | Components. |
Definition at line 137 of file vk_sprite.cpp.
References extendedUBOData.
| void mx::VKSprite::setUniform3 | ( | float | x, |
| float | y, | ||
| float | z, | ||
| float | w ) |
Upload user uniform 3 to the extended UBO.
| x,y,z,w | Components. |
Definition at line 141 of file vk_sprite.cpp.
References extendedUBOData.
|
inline |
Override the vertex shader path (used when rebuilding the pipeline).
Definition at line 183 of file vk_sprite.hpp.
References vertexShaderPath.
Referenced by createEmptySprite().
|
private |
Definition at line 1284 of file vk_sprite.cpp.
References beginSingleTimeCommands(), and endSingleTimeCommands().
Referenced by createEmptySprite(), and createSpriteTexture().
|
private |
Definition at line 154 of file vk_sprite.cpp.
References extendedUBOData, extendedUBOEnabled, and extendedUBOMapped.
Referenced by renderSprites().
|
private |
Definition at line 957 of file vk_sprite.cpp.
References createStagingResources(), device, graphicsQueue, persistentStagingBuffer, persistentStagingMapped, spriteImage, uploadCmdBuffer, uploadFence, and VK_CHECK_RESULT.
Referenced by updateTexture(), and updateTexture().
| void mx::VKSprite::updateTexture | ( | const void * | pixels, |
| int | width, | ||
| int | height, | ||
| int | pitch = 0 ) |
Replace the sprite texture from a raw pixel buffer.
| pixels | Pointer to RGBA data. |
| width | Buffer width. |
| height | Buffer height. |
| pitch | Row stride in bytes (0 = auto). |
Definition at line 887 of file vk_sprite.cpp.
References createDescriptorPool(), createSpriteTexture(), descriptorPool, descriptorSet, device, extendedDescriptorPool, extendedDescriptorSet, spriteHeight, spriteImage, spriteImageMemory, spriteImageView, spriteLoaded, spriteWidth, stagingResourcesCreated, updateSpriteTexture(), and uploadFence.
| void mx::VKSprite::updateTexture | ( | SDL_Surface * | surface | ) |
Replace the sprite texture from an SDL_Surface.
| surface | New surface (not consumed). |
Definition at line 840 of file vk_sprite.cpp.
References convertToRGBA(), createDescriptorPool(), createSpriteTexture(), descriptorPool, descriptorSet, device, extendedDescriptorPool, extendedDescriptorSet, spriteHeight, spriteImage, spriteImageMemory, spriteImageView, spriteLoaded, spriteWidth, stagingResourcesCreated, updateSpriteTexture(), and uploadFence.
|
private |
Definition at line 250 of file vk_sprite.hpp.
Referenced by beginSingleTimeCommands(), createStagingResources(), destroyStagingResources(), endSingleTimeCommands(), and VKSprite().
|
private |
Definition at line 263 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), destroySpriteResources(), getPipeline(), hasOwnPipeline(), renderSprites(), and ~VKSprite().
|
private |
Definition at line 264 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), destroySpriteResources(), getPipelineLayout(), renderSprites(), and ~VKSprite().
|
private |
Definition at line 276 of file vk_sprite.hpp.
Referenced by createDescriptorPool(), createDescriptorSet(), destroySpriteResources(), updateTexture(), updateTexture(), and ~VKSprite().
|
private |
Definition at line 278 of file vk_sprite.hpp.
Referenced by destroySpriteResources(), renderSprites(), updateTexture(), and updateTexture().
|
private |
Definition at line 277 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createDescriptorSet(), createEmptySprite(), createInstancedPipeline(), enableInstancing(), loadSprite(), and setDescriptorSetLayout().
|
private |
Definition at line 247 of file vk_sprite.hpp.
Referenced by beginSingleTimeCommands(), createBuffer(), createCustomPipeline(), createDescriptorPool(), createDescriptorSet(), createEmptySprite(), createExtendedDescriptorSet(), createExtendedDescriptorSetLayout(), createExtendedUBO(), createImage(), createImageView(), createInstancedPipeline(), createQuadBuffer(), createSampler(), createShaderModule(), createSpriteTexture(), createStagingResources(), destroyExtendedUBO(), destroyInstanceResources(), destroySpriteResources(), destroyStagingResources(), endSingleTimeCommands(), ensureInstanceBuffer(), updateSpriteTexture(), updateTexture(), updateTexture(), VKSprite(), and ~VKSprite().
|
private |
Definition at line 261 of file vk_sprite.hpp.
Referenced by clearQueue(), drawSpriteRect(), renderSprites(), and ~VKSprite().
|
private |
Definition at line 260 of file vk_sprite.hpp.
Referenced by getEffectsEnabled(), renderSprites(), and setEffectsEnabled().
|
private |
Definition at line 324 of file vk_sprite.hpp.
Referenced by createExtendedDescriptorSet(), destroyExtendedUBO(), destroySpriteResources(), updateTexture(), and updateTexture().
|
private |
Definition at line 325 of file vk_sprite.hpp.
Referenced by createExtendedDescriptorSet(), destroyExtendedUBO(), destroySpriteResources(), renderSprites(), updateTexture(), and updateTexture().
|
private |
Definition at line 323 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createExtendedDescriptorSet(), createExtendedDescriptorSetLayout(), and destroyExtendedUBO().
|
private |
Definition at line 320 of file vk_sprite.hpp.
Referenced by createExtendedDescriptorSet(), createExtendedUBO(), and destroyExtendedUBO().
|
private |
Definition at line 319 of file vk_sprite.hpp.
Referenced by setMouseState(), setUniform0(), setUniform1(), setUniform2(), setUniform3(), and updateExtendedUBO().
|
private |
Definition at line 318 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), destroyExtendedUBO(), enableExtendedUBO(), isExtendedUBOEnabled(), renderSprites(), and updateExtendedUBO().
|
private |
Definition at line 322 of file vk_sprite.hpp.
Referenced by createExtendedUBO(), destroyExtendedUBO(), and updateExtendedUBO().
|
private |
Definition at line 321 of file vk_sprite.hpp.
Referenced by createExtendedUBO(), and destroyExtendedUBO().
|
private |
Definition at line 257 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createEmptySprite(), destroySpriteResources(), loadSprite(), rebuildPipeline(), and ~VKSprite().
|
private |
Definition at line 249 of file vk_sprite.hpp.
Referenced by endSingleTimeCommands(), updateSpriteTexture(), and VKSprite().
|
private |
Definition at line 258 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createEmptySprite(), destroySpriteResources(), loadSprite(), and rebuildPipeline().
|
private |
Definition at line 337 of file vk_sprite.hpp.
Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().
|
private |
Definition at line 340 of file vk_sprite.hpp.
Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().
|
private |
Definition at line 339 of file vk_sprite.hpp.
Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().
|
private |
Definition at line 338 of file vk_sprite.hpp.
Referenced by destroyInstanceResources(), and ensureInstanceBuffer().
|
private |
Definition at line 342 of file vk_sprite.hpp.
Referenced by createInstancedPipeline(), destroyInstanceResources(), and renderSprites().
|
private |
Definition at line 343 of file vk_sprite.hpp.
Referenced by createInstancedPipeline(), destroyInstanceResources(), and renderSprites().
|
private |
Definition at line 345 of file vk_sprite.hpp.
Referenced by enableInstancing(), and rebuildInstancedPipeline().
|
private |
Definition at line 344 of file vk_sprite.hpp.
Referenced by enableInstancing(), and rebuildInstancedPipeline().
|
private |
Definition at line 341 of file vk_sprite.hpp.
Referenced by destroyInstanceResources(), enableInstancing(), isInstancingEnabled(), rebuildInstancedPipeline(), and renderSprites().
|
private |
Definition at line 326 of file vk_sprite.hpp.
Referenced by createExtendedDescriptorSetLayout(), and destroyExtendedUBO().
|
private |
Definition at line 283 of file vk_sprite.hpp.
Referenced by createStagingResources(), destroyStagingResources(), and updateSpriteTexture().
|
private |
Definition at line 285 of file vk_sprite.hpp.
Referenced by createStagingResources(), destroyStagingResources(), and updateSpriteTexture().
|
private |
Definition at line 284 of file vk_sprite.hpp.
Referenced by createStagingResources(), and destroyStagingResources().
|
private |
Definition at line 286 of file vk_sprite.hpp.
Referenced by createStagingResources(), and destroyStagingResources().
|
private |
Definition at line 248 of file vk_sprite.hpp.
Referenced by findMemoryType(), and VKSprite().
|
private |
Definition at line 273 of file vk_sprite.hpp.
Referenced by createQuadBuffer(), and renderSprites().
|
private |
Definition at line 271 of file vk_sprite.hpp.
Referenced by createQuadBuffer(), renderSprites(), and ~VKSprite().
|
private |
Definition at line 272 of file vk_sprite.hpp.
Referenced by createQuadBuffer(), and ~VKSprite().
|
private |
Definition at line 269 of file vk_sprite.hpp.
Referenced by createQuadBuffer(), renderSprites(), and ~VKSprite().
|
private |
Definition at line 270 of file vk_sprite.hpp.
Referenced by createQuadBuffer(), and ~VKSprite().
|
private |
Definition at line 265 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createEmptySprite(), createInstancedPipeline(), enableInstancing(), loadSprite(), and setRenderPass().
|
private |
Definition at line 259 of file vk_sprite.hpp.
Referenced by drawSpriteRect(), and setShaderParams().
|
private |
Definition at line 255 of file vk_sprite.hpp.
Referenced by createEmptySprite(), drawSprite(), drawSprite(), drawSprite(), getHeight(), loadSprite(), updateTexture(), and updateTexture().
|
private |
Definition at line 251 of file vk_sprite.hpp.
Referenced by createEmptySprite(), createSpriteTexture(), destroySpriteResources(), loadSprite(), updateSpriteTexture(), updateTexture(), updateTexture(), and ~VKSprite().
|
private |
Definition at line 252 of file vk_sprite.hpp.
Referenced by createEmptySprite(), createSpriteTexture(), destroySpriteResources(), updateTexture(), updateTexture(), and ~VKSprite().
|
private |
Definition at line 253 of file vk_sprite.hpp.
Referenced by createEmptySprite(), createExtendedDescriptorSet(), createSpriteTexture(), destroySpriteResources(), renderSprites(), updateTexture(), updateTexture(), and ~VKSprite().
|
private |
Definition at line 256 of file vk_sprite.hpp.
Referenced by createEmptySprite(), destroySpriteResources(), drawSpriteRect(), loadSprite(), renderSprites(), updateTexture(), and updateTexture().
| VkSampler mx::VKSprite::spriteSampler = VK_NULL_HANDLE |
Texture sampler.
Definition at line 197 of file vk_sprite.hpp.
Referenced by createDescriptorSet(), createExtendedDescriptorSet(), createSampler(), destroySpriteResources(), and ~VKSprite().
|
private |
Definition at line 254 of file vk_sprite.hpp.
Referenced by createEmptySprite(), drawSprite(), drawSprite(), drawSprite(), getWidth(), loadSprite(), updateTexture(), and updateTexture().
|
private |
Definition at line 289 of file vk_sprite.hpp.
Referenced by createStagingResources(), destroyStagingResources(), updateTexture(), and updateTexture().
|
private |
Definition at line 288 of file vk_sprite.hpp.
Referenced by createStagingResources(), destroyStagingResources(), and updateSpriteTexture().
|
private |
Definition at line 287 of file vk_sprite.hpp.
Referenced by createStagingResources(), destroyStagingResources(), updateSpriteTexture(), updateTexture(), and updateTexture().
|
private |
Definition at line 266 of file vk_sprite.hpp.
Referenced by createCustomPipeline(), createEmptySprite(), operator=(), and setVertexShaderPath().