#include <mxvk/include/mxvk/mxvk_sprite.hpp>
Public Member Functions | |
| void | clearExternalTextureDescriptors () |
| void | clearQueue () |
| Discard all pending draw commands without rendering. | |
| 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 | enableExtendedUBO () |
| Allocate and initialise the extended uniform buffer object. | |
| void | enableInstancing (uint32_t maxInstances, const std::string &instanceVertShaderPath, const std::string &instanceFragShaderPath) |
| Enable GPU instancing for this sprite type. | |
| bool | getEffectsEnabled () const |
| int | getHeight () const |
| VkPipeline | getPipeline () const |
| VkPipelineLayout | getPipelineLayout () const |
| int | getWidth () const |
| bool | hasOwnPipeline () const |
| bool | isExtendedUBOEnabled () const |
| bool | isInstancingEnabled () const |
| 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. | |
| VK_Sprite & | operator= (const VK_Sprite &)=delete |
| VK_Sprite & | operator= (VK_Sprite &&)=delete |
| void | prepareForRendering (VkCommandBuffer cmdBuffer) |
| Record texture barriers that must happen before dynamic rendering begins. | |
| void | rebuildInstancedPipeline () |
| Destroy and recreate the instanced graphics pipeline. | |
| void | rebuildPipeline () |
| Destroy and recreate the custom graphics pipeline. | |
| void | releaseUploadResources () |
| Release upload/staging resources tied to the current command pool. | |
| void | renderSprites (VkCommandBuffer cmdBuffer, VkPipelineLayout pipelineLayout, uint32_t screenWidth, uint32_t screenHeight) |
| Record all queued draw commands into the given command buffer. | |
| void | setColorAttachmentFormat (VkFormat format) |
| Assign dynamic-rendering color attachment format used to build pipelines. | |
| void | setCommandPool (VkCommandPool pool) |
| Rebind the command pool used for upload/staging operations. | |
| void | setDepthAttachmentFormat (VkFormat format) |
| Assign dynamic-rendering depth attachment format used to build pipelines. | |
| void | setDescriptorSetLayout (VkDescriptorSetLayout layout) |
| Assign an external descriptor-set layout. | |
| void | setEffectsEnabled (bool enabled) |
| Enable or disable the custom fragment shader effects. | |
| void | setExternalTexture (VkImageView image_view, int width, int height) |
| void | setFragmentShaderPath (const std::string &path) |
| Replace the fragment shader path and rebuild the custom pipeline. | |
| void | setMouseState (float mx, float my, float pressed, float reserved=0.0f) |
| Upload mouse state to the extended UBO. | |
| void | setPipelineCache (VkPipelineCache cache) |
| Use the shared pipeline cache for custom/instanced pipeline creation. | |
| void | setRenderPass (VkRenderPass rp) |
| Assign the render pass used to build the custom pipeline. | |
| 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 | setTextureFilter (VkFilter filter) |
| Select the hardware filter used when scaling this sprite. | |
| 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. | |
| void | setVertexShaderPath (const std::string &path) |
| Override the vertex shader path (used when rebuilding the pipeline). | |
| void | updateTexture (const void *pixels, int width, int height, int pitch=0) |
| Replace the sprite texture from a raw pixel buffer. | |
| void | updateTexture (SDL_Surface *surface) |
| Replace the sprite texture from an SDL_Surface. | |
| VK_Sprite (const VK_Sprite &)=delete | |
| VK_Sprite (VK_Sprite &&)=delete | |
| VK_Sprite (VkDevice device, VkPhysicalDevice physicalDevice, VkQueue graphicsQueue, VkCommandPool commandPool) | |
| Construct and record Vulkan context handles. | |
| ~VK_Sprite () | |
| Destructor — frees all Vulkan resources. | |
Public Attributes | |
| VkSampler | spriteSampler = VK_NULL_HANDLE |
| Texture sampler. | |
Definition at line 56 of file mxvk_sprite.hpp.
| mxvk::VK_Sprite::VK_Sprite | ( | 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 18 of file mxvk_sprite.cpp.
| mxvk::VK_Sprite::~VK_Sprite | ( | ) |
Destructor — frees all Vulkan resources.
Definition at line 58 of file mxvk_sprite.cpp.
|
delete |
|
delete |
| void mxvk::VK_Sprite::clearExternalTextureDescriptors | ( | ) |
Definition at line 1712 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::clearQueue | ( | ) |
Discard all pending draw commands without rendering.
Definition at line 1818 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 911 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::drawSprite | ( | int | x, |
| int | y ) |
Queue a draw at the given pixel position.
| x | Destination X. |
| y | Destination Y. |
Definition at line 1641 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 1645 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 1649 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 1660 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::enableExtendedUBO | ( | ) |
Allocate and initialise the extended uniform buffer object.
Definition at line 165 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 453 of file mxvk_sprite.cpp.
|
inline |
true if shader effects are enabled. Definition at line 167 of file mxvk_sprite.hpp.
|
inline |
Definition at line 191 of file mxvk_sprite.hpp.
|
inline |
Definition at line 229 of file mxvk_sprite.hpp.
|
inline |
Definition at line 231 of file mxvk_sprite.hpp.
|
inline |
Definition at line 189 of file mxvk_sprite.hpp.
|
inline |
true if a custom pipeline has been built. Definition at line 227 of file mxvk_sprite.hpp.
|
inline |
true if the extended UBO is active. Definition at line 257 of file mxvk_sprite.hpp.
|
inline |
true if GPU instancing is active. Definition at line 251 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::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 870 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 880 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::prepareForRendering | ( | VkCommandBuffer | cmdBuffer | ) |
Record texture barriers that must happen before dynamic rendering begins.
| cmdBuffer | Command buffer currently being recorded outside a rendering instance. |
Definition at line 1719 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::rebuildInstancedPipeline | ( | ) |
Destroy and recreate the instanced graphics pipeline.
Definition at line 831 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::rebuildPipeline | ( | ) |
Destroy and recreate the custom graphics pipeline.
Definition at line 790 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::releaseUploadResources | ( | ) |
Release upload/staging resources tied to the current command pool.
Call this before destroying or recreating the command pool.
Definition at line 23 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 1725 of file mxvk_sprite.cpp.
|
inline |
Assign dynamic-rendering color attachment format used to build pipelines.
Definition at line 204 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::setCommandPool | ( | VkCommandPool | pool | ) |
Rebind the command pool used for upload/staging operations.
Any in-flight upload resources tied to the previous pool are released first.
Definition at line 27 of file mxvk_sprite.cpp.
|
inline |
Assign dynamic-rendering depth attachment format used to build pipelines.
Definition at line 206 of file mxvk_sprite.hpp.
|
inline |
Assign an external descriptor-set layout.
Definition at line 200 of file mxvk_sprite.hpp.
|
inline |
Enable or disable the custom fragment shader effects.
| enabled | true to enable effects. |
Definition at line 164 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::setExternalTexture | ( | VkImageView | image_view, |
| int | width, | ||
| int | height ) |
Definition at line 1673 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::setFragmentShaderPath | ( | const std::string & | path | ) |
Replace the fragment shader path and rebuild the custom pipeline.
Definition at line 797 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 174 of file mxvk_sprite.cpp.
|
inline |
Use the shared pipeline cache for custom/instanced pipeline creation.
Definition at line 214 of file mxvk_sprite.hpp.
|
inline |
Assign the render pass used to build the custom pipeline.
Definition at line 202 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::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 1669 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::setTextureFilter | ( | VkFilter | filter | ) |
Select the hardware filter used when scaling this sprite.
| filter | VK_FILTER_NEAREST for sharp pixels or VK_FILTER_LINEAR for smoothing. |
Definition at line 38 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 178 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 182 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 186 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::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 190 of file mxvk_sprite.cpp.
|
inline |
Override the vertex shader path (used when rebuilding the pipeline).
Definition at line 222 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::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 1033 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::updateTexture | ( | SDL_Surface * | surface | ) |
Replace the sprite texture from an SDL_Surface.
| surface | New surface (not consumed). |
Definition at line 985 of file mxvk_sprite.cpp.
| VkSampler mxvk::VK_Sprite::spriteSampler = VK_NULL_HANDLE |
Texture sampler.
Definition at line 238 of file mxvk_sprite.hpp.