#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 | dispatchCompute (VkCommandBuffer cmdBuffer, VkImageView inputView, VkImageView outputView, uint32_t width, uint32_t height) |
| Dispatch the compute effect between two full-frame images. | |
| 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 | enableComputeShader (const std::string &path, uint32_t localSizeX, uint32_t localSizeY, uint32_t localSizeZ=1) |
| Build a compute image-effect pipeline for this sprite. | |
| void | enableExtendedUBO () |
| Allocate and initialise the extended uniform buffer object. | |
| void | enableHistoryTexture (uint32_t width, uint32_t height, uint32_t layers) |
| Allocate a shader-readable RGBA history texture array. | |
| void | enableInstancing (uint32_t maxInstances, const std::string &instanceVertShaderPath, const std::string &instanceFragShaderPath) |
| Enable GPU instancing for this sprite type. | |
| uint32_t | enableSpectrumHistoryTexture (uint32_t bins, uint32_t layers) |
| Allocate a shader-readable FFT spectrum-history array. | |
| void | enableSpectrumTexture (uint32_t bins) |
| Allocate a shader-readable 1-D floating-point spectrum texture. | |
| bool | getEffectsEnabled () const |
| int | getHeight () const |
| uint32_t | getHistoryHead () const |
| uint32_t | getHistoryLayerCount () const |
| VkPipeline | getPipeline () const |
| VkPipelineLayout | getPipelineLayout () const |
| uint32_t | getSpectrumBinCount () const |
| uint32_t | getSpectrumHistoryHead () const |
| uint32_t | getSpectrumHistoryLayerCount () const |
| int | getWidth () const |
| bool | hasComputePipeline () 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 | setAudioBands (float low, float mid, float high, float reserved=0.0f) |
| Upload audio frequency-band energy to the extended UBO. | |
| 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 | setCustomUniforms (const std::vector< float > &values) |
| Upload ordered custom float values to the extended UBO. | |
| 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 | shareHistoryTexture (const VK_Sprite &source) |
| Bind another sprite's history array without taking ownership. | |
| void | updateHistoryTexture (const void *pixels, int width, int height, int pitch=0) |
| Upload one RGBA frame into the next history layer. | |
| void | updateSpectrumHistoryTexture (const float *magnitudes, uint32_t bins) |
| Upload one FFT spectrum into the next history layer. | |
| void | updateSpectrumTexture (const float *magnitudes, uint32_t bins) |
| Replace the current floating-point spectrum data. | |
| 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. | |
Static Public Attributes | |
| static constexpr std::size_t | MAX_CUSTOM_UNIFORMS = 64 |
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 2762 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::clearQueue | ( | ) |
Discard all pending draw commands without rendering.
Definition at line 2868 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 1739 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::dispatchCompute | ( | VkCommandBuffer | cmdBuffer, |
| VkImageView | inputView, | ||
| VkImageView | outputView, | ||
| uint32_t | width, | ||
| uint32_t | height ) |
Dispatch the compute effect between two full-frame images.
Definition at line 1617 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 2691 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 2695 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 2699 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 2710 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::enableComputeShader | ( | const std::string & | path, |
| uint32_t | localSizeX, | ||
| uint32_t | localSizeY, | ||
| uint32_t | localSizeZ = 1 ) |
Build a compute image-effect pipeline for this sprite.
Compute shaders use the extended sprite descriptor ABI: binding 0 is the sampled input image, binding 1 is SpriteExtended, optional history/audio textures remain at bindings 2-4, and binding 5 is a write-only RGBA8 storage image.
Definition at line 1588 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::enableExtendedUBO | ( | ) |
Allocate and initialise the extended uniform buffer object.
Definition at line 176 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::enableHistoryTexture | ( | uint32_t | width, |
| uint32_t | height, | ||
| uint32_t | layers ) |
Allocate a shader-readable RGBA history texture array.
Enables extended descriptors and exposes the array as a combined image sampler at set 0, binding 2. Replaces any previously allocated history texture. The texture is initialized to transparent black.
| width | Width of every history layer in pixels. |
| height | Height of every history layer in pixels. |
| layers | Number of layers in the circular history buffer. |
| mxvk::Exception | when any dimension is zero. |
Definition at line 222 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 1167 of file mxvk_sprite.cpp.
| uint32_t mxvk::VK_Sprite::enableSpectrumHistoryTexture | ( | uint32_t | bins, |
| uint32_t | layers ) |
Allocate a shader-readable FFT spectrum-history array.
Enables extended descriptors and exposes the history as a combined image sampler at set 0, binding 4. The R32_SFLOAT 1-D array is initialized to zero and uses a circular write head.
| bins | Number of frequency bins in every history layer. |
| layers | Requested number of history layers. The active GPU's maximum image-array-layer limit is applied automatically. |
| mxvk::Exception | when either requested dimension is zero. |
Definition at line 546 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::enableSpectrumTexture | ( | uint32_t | bins | ) |
Allocate a shader-readable 1-D floating-point spectrum texture.
Enables extended descriptors and exposes the texture as a combined image sampler at set 0, binding 3. The texture is initialized to zero.
| bins | Number of R32_SFLOAT frequency bins. |
| mxvk::Exception | when bins is zero. |
Definition at line 431 of file mxvk_sprite.cpp.
|
inline |
true if shader effects are enabled. Definition at line 169 of file mxvk_sprite.hpp.
|
inline |
Definition at line 193 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 385 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 388 of file mxvk_sprite.hpp.
|
inline |
Definition at line 252 of file mxvk_sprite.hpp.
|
inline |
Definition at line 254 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 409 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 435 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 438 of file mxvk_sprite.hpp.
|
inline |
Definition at line 191 of file mxvk_sprite.hpp.
|
inlinenodiscard |
Definition at line 240 of file mxvk_sprite.hpp.
|
inline |
true if a custom pipeline has been built. Definition at line 250 of file mxvk_sprite.hpp.
|
inline |
true if the extended UBO is active. Definition at line 280 of file mxvk_sprite.hpp.
|
inline |
true if GPU instancing is active. Definition at line 274 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 1698 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 1708 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 2769 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::rebuildInstancedPipeline | ( | ) |
Destroy and recreate the instanced graphics pipeline.
Definition at line 1659 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::rebuildPipeline | ( | ) |
Destroy and recreate the custom graphics pipeline.
Definition at line 1504 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 2775 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::setAudioBands | ( | float | low, |
| float | mid, | ||
| float | high, | ||
| float | reserved = 0.0f ) |
Upload audio frequency-band energy to the extended UBO.
The values are appended after the custom-uniform array to preserve the existing SpriteExtended prefix and custom-uniform offsets.
| low | Energy below 300 Hz. |
| mid | Energy from 300 through 3000 Hz. |
| high | Energy above 3000 Hz. |
| reserved | Reserved channel. |
Definition at line 205 of file mxvk_sprite.cpp.
|
inline |
Assign dynamic-rendering color attachment format used to build pipelines.
Definition at line 206 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.
| void mxvk::VK_Sprite::setCustomUniforms | ( | const std::vector< float > & | values | ) |
Upload ordered custom float values to the extended UBO.
Custom shaders can append vec4 custom_uniforms[16] after u3 in their binding-1 SpriteExtended block. Value N is available at custom_uniforms[N/4][N%4]. Existing shaders that use only the original SpriteExtended prefix remain compatible.
| values | Up to MAX_CUSTOM_UNIFORMS values. Unused slots are zeroed. |
| mxvk::Exception | when too many values are supplied. |
Definition at line 209 of file mxvk_sprite.cpp.
|
inline |
Assign dynamic-rendering depth attachment format used to build pipelines.
Definition at line 208 of file mxvk_sprite.hpp.
|
inline |
Assign an external descriptor-set layout.
Definition at line 202 of file mxvk_sprite.hpp.
|
inline |
Enable or disable the custom fragment shader effects.
| enabled | true to enable effects. |
Definition at line 166 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::setExternalTexture | ( | VkImageView | image_view, |
| int | width, | ||
| int | height ) |
Definition at line 2723 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 1511 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 185 of file mxvk_sprite.cpp.
|
inline |
Use the shared pipeline cache for custom/instanced pipeline creation.
Definition at line 216 of file mxvk_sprite.hpp.
|
inline |
Assign the render pass used to build the custom pipeline.
Definition at line 204 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 2719 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 189 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 193 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 197 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 201 of file mxvk_sprite.cpp.
|
inline |
Override the vertex shader path (used when rebuilding the pipeline).
Definition at line 224 of file mxvk_sprite.hpp.
| void mxvk::VK_Sprite::shareHistoryTexture | ( | const VK_Sprite & | source | ) |
Bind another sprite's history array without taking ownership.
The source sprite must outlive this sprite. This is intended for post-processing passes which read one shared input history ring. No image, memory, or image view is allocated or freed by this sprite.
| source | Sprite which owns an enabled history texture. |
| mxvk::Exception | when the source has no history texture or belongs to a different Vulkan device. |
Definition at line 313 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::updateHistoryTexture | ( | const void * | pixels, |
| int | width, | ||
| int | height, | ||
| int | pitch = 0 ) |
Upload one RGBA frame into the next history layer.
The write head advances after a successful upload. Input dimensions must match those passed to enableHistoryTexture().
| pixels | RGBA8 source pixels. |
| width | Source width in pixels. |
| height | Source height in pixels. |
| pitch | Source row stride in bytes, or zero for tightly packed data. |
| mxvk::Exception | for null data, invalid dimensions, or an inactive cache. |
Definition at line 345 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::updateSpectrumHistoryTexture | ( | const float * | magnitudes, |
| uint32_t | bins ) |
Upload one FFT spectrum into the next history layer.
| magnitudes | Pointer to bins frequency magnitudes. |
| bins | Number of values; must match the configured history. |
Definition at line 623 of file mxvk_sprite.cpp.
| void mxvk::VK_Sprite::updateSpectrumTexture | ( | const float * | magnitudes, |
| uint32_t | bins ) |
Replace the current floating-point spectrum data.
| magnitudes | Pointer to bins frequency magnitudes. |
| bins | Number of values; must match enableSpectrumTexture(). |
Definition at line 479 of file mxvk_sprite.cpp.
| 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 1864 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 1816 of file mxvk_sprite.cpp.
|
staticconstexpr |
Definition at line 58 of file mxvk_sprite.hpp.
| VkSampler mxvk::VK_Sprite::spriteSampler = VK_NULL_HANDLE |
Texture sampler.
Definition at line 261 of file mxvk_sprite.hpp.