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

Vulkan 2-D sprite with texture, custom shader, and instancing support. More...

#include <vk_sprite.hpp>

Collaboration diagram for mx::VKSprite:
[legend]

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_

Detailed Description

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.

Constructor & Destructor Documentation

◆ VKSprite() [1/3]

mx::VKSprite::VKSprite ( VkDevice device,
VkPhysicalDevice physicalDevice,
VkQueue graphicsQueue,
VkCommandPool commandPool )

Construct and record Vulkan context handles.

Parameters
deviceLogical device.
physicalDevicePhysical device.
graphicsQueueGraphics queue.
commandPoolCommand 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().

◆ ~VKSprite()

◆ VKSprite() [2/3]

mx::VKSprite::VKSprite ( const VKSprite & )
delete

References VKSprite().

◆ VKSprite() [3/3]

mx::VKSprite::VKSprite ( VKSprite && )
delete

References VKSprite().

Member Function Documentation

◆ beginSingleTimeCommands()

VkCommandBuffer mx::VKSprite::beginSingleTimeCommands ( )
private

Definition at line 1345 of file vk_sprite.cpp.

References commandPool, device, and VK_CHECK_RESULT.

Referenced by copyBufferToImage(), and transitionImageLayout().

◆ clearQueue()

void mx::VKSprite::clearQueue ( )

Discard all pending draw commands without rendering.

Definition at line 1192 of file vk_sprite.cpp.

References drawQueue.

◆ convertToRGBA()

SDL_Surface * mx::VKSprite::convertToRGBA ( SDL_Surface * surface)
private

Definition at line 1427 of file vk_sprite.cpp.

Referenced by loadSprite(), and updateTexture().

◆ copyBufferToImage()

void mx::VKSprite::copyBufferToImage ( VkBuffer buffer,
VkImage image,
uint32_t width,
uint32_t height )
private

Definition at line 1326 of file vk_sprite.cpp.

References beginSingleTimeCommands(), and endSingleTimeCommands().

Referenced by createEmptySprite(), and createSpriteTexture().

◆ createBuffer()

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

◆ createCustomPipeline()

◆ createDescriptorPool()

void mx::VKSprite::createDescriptorPool ( )
private

◆ createDescriptorSet()

VkDescriptorSet mx::VKSprite::createDescriptorSet ( VkImageView imageView)
private

◆ createEmptySprite()

void mx::VKSprite::createEmptySprite ( int width,
int height,
const std::string & vertexShaderPath = "",
const std::string & fragmentShaderPath = "" )

◆ createExtendedDescriptorSet()

void mx::VKSprite::createExtendedDescriptorSet ( )
private

◆ createExtendedDescriptorSetLayout()

void mx::VKSprite::createExtendedDescriptorSetLayout ( )
private

◆ createExtendedUBO()

void mx::VKSprite::createExtendedUBO ( )
private

◆ createImage()

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

Definition at line 1378 of file vk_sprite.cpp.

References device, findMemoryType(), and VK_CHECK_RESULT.

Referenced by createEmptySprite(), and createSpriteTexture().

◆ createImageView()

VkImageView mx::VKSprite::createImageView ( VkImage image,
VkFormat format )
private

Definition at line 1410 of file vk_sprite.cpp.

References device, and VK_CHECK_RESULT.

Referenced by createEmptySprite(), and createSpriteTexture().

◆ createInstancedPipeline()

void mx::VKSprite::createInstancedPipeline ( const std::string & vertPath,
const std::string & fragPath )
private

◆ createQuadBuffer()

void mx::VKSprite::createQuadBuffer ( )
private

◆ createSampler()

void mx::VKSprite::createSampler ( )
private

Definition at line 1043 of file vk_sprite.cpp.

References device, spriteSampler, and VK_CHECK_RESULT.

Referenced by createEmptySprite(), and loadSprite().

◆ createShaderModule()

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

◆ createSpriteTexture()

void mx::VKSprite::createSpriteTexture ( SDL_Surface * surface)
private

◆ createStagingResources()

◆ destroyExtendedUBO()

◆ destroyInstanceResources()

void mx::VKSprite::destroyInstanceResources ( )
private

◆ destroySpriteResources()

◆ destroyStagingResources()

◆ drawSprite() [1/3]

void mx::VKSprite::drawSprite ( int x,
int y )

Queue a draw at the given pixel position.

Parameters
xDestination X.
yDestination Y.

Definition at line 1068 of file vk_sprite.cpp.

References drawSpriteRect(), spriteHeight, and spriteWidth.

◆ drawSprite() [2/3]

void mx::VKSprite::drawSprite ( int x,
int y,
float scaleX,
float scaleY )

Queue a scaled draw.

Parameters
xDestination X.
yDestination Y.
scaleXHorizontal scale factor.
scaleYVertical scale factor.

Definition at line 1072 of file vk_sprite.cpp.

References drawSpriteRect(), spriteHeight, and spriteWidth.

◆ drawSprite() [3/3]

void mx::VKSprite::drawSprite ( int x,
int y,
float scaleX,
float scaleY,
float rotation )

Queue a scaled and rotated draw.

Parameters
xDestination X.
yDestination Y.
scaleXHorizontal scale.
scaleYVertical scale.
rotationClockwise rotation in degrees.

Definition at line 1076 of file vk_sprite.cpp.

References drawSpriteRect(), spriteHeight, and spriteWidth.

◆ drawSpriteRect()

void mx::VKSprite::drawSpriteRect ( int x,
int y,
int w,
int h )

Queue a draw into an explicit destination rectangle.

Parameters
x,y,w,hDestination rectangle.

Definition at line 1080 of file vk_sprite.cpp.

References drawQueue, shaderParams, and spriteLoaded.

Referenced by drawSprite(), drawSprite(), and drawSprite().

◆ enableExtendedUBO()

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().

◆ enableInstancing()

void mx::VKSprite::enableInstancing ( uint32_t maxInstances,
const std::string & instanceVertShaderPath,
const std::string & instanceFragShaderPath )

Enable GPU instancing for this sprite type.

Parameters
maxInstancesMaximum simultaneous instances.
instanceVertShaderPathVertex shader supporting instancing.
instanceFragShaderPathFragment shader.

Definition at line 387 of file vk_sprite.cpp.

References createInstancedPipeline(), createQuadBuffer(), descriptorSetLayout, ensureInstanceBuffer(), instanceFragPath_, instanceVertPath_, instancingEnabled, and renderPass.

◆ endSingleTimeCommands()

void mx::VKSprite::endSingleTimeCommands ( VkCommandBuffer commandBuffer)
private

Definition at line 1364 of file vk_sprite.cpp.

References commandPool, device, graphicsQueue, and VK_CHECK_RESULT.

Referenced by copyBufferToImage(), and transitionImageLayout().

◆ ensureInstanceBuffer()

void mx::VKSprite::ensureInstanceBuffer ( uint32_t count)
private

◆ findMemoryType()

uint32_t mx::VKSprite::findMemoryType ( uint32_t typeFilter,
VkMemoryPropertyFlags properties )
private

Definition at line 1271 of file vk_sprite.cpp.

References physicalDevice.

Referenced by createBuffer(), and createImage().

◆ getEffectsEnabled()

bool mx::VKSprite::getEffectsEnabled ( ) const
inline
Returns
true if shader effects are enabled.

Definition at line 158 of file vk_sprite.hpp.

References effectsEnabled.

◆ getHeight()

int mx::VKSprite::getHeight ( ) const
inline
Returns
Sprite texture height in pixels.

Definition at line 176 of file vk_sprite.hpp.

References spriteHeight.

◆ getPipeline()

VkPipeline mx::VKSprite::getPipeline ( ) const
inline
Returns
The custom VkPipeline handle (may be VK_NULL_HANDLE).

Definition at line 188 of file vk_sprite.hpp.

References customPipeline.

◆ getPipelineLayout()

VkPipelineLayout mx::VKSprite::getPipelineLayout ( ) const
inline
Returns
The custom pipeline layout handle.

Definition at line 190 of file vk_sprite.hpp.

References customPipelineLayout.

◆ getWidth()

int mx::VKSprite::getWidth ( ) const
inline
Returns
Sprite texture width in pixels.

Definition at line 174 of file vk_sprite.hpp.

References spriteWidth.

◆ hasOwnPipeline()

bool mx::VKSprite::hasOwnPipeline ( ) const
inline
Returns
true if a custom pipeline has been built.

Definition at line 186 of file vk_sprite.hpp.

References customPipeline.

◆ isExtendedUBOEnabled()

bool mx::VKSprite::isExtendedUBOEnabled ( ) const
inline
Returns
true if the extended UBO is active.

Definition at line 216 of file vk_sprite.hpp.

References extendedUBOEnabled.

◆ isInstancingEnabled()

bool mx::VKSprite::isInstancingEnabled ( ) const
inline
Returns
true if GPU instancing is active.

Definition at line 210 of file vk_sprite.hpp.

References instancingEnabled.

◆ loadSprite() [1/2]

void mx::VKSprite::loadSprite ( const std::string & pngPath,
const std::string & fragmentShaderPath = "" )

Load sprite texture from a PNG file.

Parameters
pngPathPath to the PNG file.
fragmentShaderPathOptional custom fragment shader (SPIR-V .spv).

Definition at line 744 of file vk_sprite.cpp.

References png::LoadPNG(), and loadSprite().

Referenced by loadSprite().

◆ loadSprite() [2/2]

void mx::VKSprite::loadSprite ( SDL_Surface * surface,
const std::string & fragmentShaderPath = "" )

Load sprite texture from an SDL_Surface.

Parameters
surfaceSource surface (not consumed).
fragmentShaderPathOptional 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.

◆ operator=() [1/2]

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

References VKSprite().

◆ operator=() [2/2]

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

References vertexShaderPath, and VKSprite().

◆ readShaderFile()

std::vector< char > mx::VKSprite::readShaderFile ( const std::string & filename)
private

◆ rebuildInstancedPipeline()

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.

◆ rebuildPipeline()

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().

◆ renderSprites()

void mx::VKSprite::renderSprites ( VkCommandBuffer cmdBuffer,
VkPipelineLayout pipelineLayout,
uint32_t screenWidth,
uint32_t screenHeight )

◆ setDescriptorSetLayout()

void mx::VKSprite::setDescriptorSetLayout ( VkDescriptorSetLayout layout)
inline

Assign an external descriptor-set layout.

Definition at line 179 of file vk_sprite.hpp.

References descriptorSetLayout.

◆ setEffectsEnabled()

void mx::VKSprite::setEffectsEnabled ( bool enabled)
inline

Enable or disable the custom fragment shader effects.

Parameters
enabledtrue to enable effects.

Definition at line 155 of file vk_sprite.hpp.

References effectsEnabled.

◆ setMouseState()

void mx::VKSprite::setMouseState ( float mx,
float my,
float pressed,
float reserved = 0.0f )

Upload mouse state to the extended UBO.

Parameters
mxMouse X (normalised or pixels).
myMouse Y.
pressedMouse button state.
reservedReserved channel.

Definition at line 125 of file vk_sprite.cpp.

References extendedUBOData.

◆ setRenderPass()

void mx::VKSprite::setRenderPass ( VkRenderPass rp)
inline

Assign the render pass used to build the custom pipeline.

Definition at line 181 of file vk_sprite.hpp.

References renderPass.

◆ setShaderParams()

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.

Parameters
p1,p2,p3,p4Parameter values packed into a vec4.

Definition at line 1089 of file vk_sprite.cpp.

References shaderParams.

◆ setUniform0()

void mx::VKSprite::setUniform0 ( float x,
float y,
float z,
float w )

Upload user uniform 0 to the extended UBO.

Parameters
x,y,z,wComponents.

Definition at line 129 of file vk_sprite.cpp.

References extendedUBOData.

◆ setUniform1()

void mx::VKSprite::setUniform1 ( float x,
float y,
float z,
float w )

Upload user uniform 1 to the extended UBO.

Parameters
x,y,z,wComponents.

Definition at line 133 of file vk_sprite.cpp.

References extendedUBOData.

◆ setUniform2()

void mx::VKSprite::setUniform2 ( float x,
float y,
float z,
float w )

Upload user uniform 2 to the extended UBO.

Parameters
x,y,z,wComponents.

Definition at line 137 of file vk_sprite.cpp.

References extendedUBOData.

◆ setUniform3()

void mx::VKSprite::setUniform3 ( float x,
float y,
float z,
float w )

Upload user uniform 3 to the extended UBO.

Parameters
x,y,z,wComponents.

Definition at line 141 of file vk_sprite.cpp.

References extendedUBOData.

◆ setVertexShaderPath()

void mx::VKSprite::setVertexShaderPath ( const std::string & path)
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().

◆ transitionImageLayout()

void mx::VKSprite::transitionImageLayout ( VkImage image,
VkImageLayout oldLayout,
VkImageLayout newLayout )
private

Definition at line 1284 of file vk_sprite.cpp.

References beginSingleTimeCommands(), and endSingleTimeCommands().

Referenced by createEmptySprite(), and createSpriteTexture().

◆ updateExtendedUBO()

void mx::VKSprite::updateExtendedUBO ( )
private

Definition at line 154 of file vk_sprite.cpp.

References extendedUBOData, extendedUBOEnabled, and extendedUBOMapped.

Referenced by renderSprites().

◆ updateSpriteTexture()

void mx::VKSprite::updateSpriteTexture ( const void * pixels,
uint32_t width,
uint32_t height )
private

◆ updateTexture() [1/2]

void mx::VKSprite::updateTexture ( const void * pixels,
int width,
int height,
int pitch = 0 )

Replace the sprite texture from a raw pixel buffer.

Parameters
pixelsPointer to RGBA data.
widthBuffer width.
heightBuffer height.
pitchRow 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.

◆ updateTexture() [2/2]

void mx::VKSprite::updateTexture ( SDL_Surface * surface)

Member Data Documentation

◆ commandPool

VkCommandPool mx::VKSprite::commandPool = VK_NULL_HANDLE
private

◆ customPipeline

VkPipeline mx::VKSprite::customPipeline = VK_NULL_HANDLE
private

◆ customPipelineLayout

VkPipelineLayout mx::VKSprite::customPipelineLayout = VK_NULL_HANDLE
private

◆ descriptorPool

VkDescriptorPool mx::VKSprite::descriptorPool = VK_NULL_HANDLE
private

◆ descriptorSet

VkDescriptorSet mx::VKSprite::descriptorSet = VK_NULL_HANDLE
private

Definition at line 278 of file vk_sprite.hpp.

Referenced by destroySpriteResources(), renderSprites(), updateTexture(), and updateTexture().

◆ descriptorSetLayout

VkDescriptorSetLayout mx::VKSprite::descriptorSetLayout = VK_NULL_HANDLE
private

◆ device

◆ drawQueue

std::vector<SpriteDrawCmd> mx::VKSprite::drawQueue
private

Definition at line 261 of file vk_sprite.hpp.

Referenced by clearQueue(), drawSpriteRect(), renderSprites(), and ~VKSprite().

◆ effectsEnabled

bool mx::VKSprite::effectsEnabled = true
private

Definition at line 260 of file vk_sprite.hpp.

Referenced by getEffectsEnabled(), renderSprites(), and setEffectsEnabled().

◆ extendedDescriptorPool

VkDescriptorPool mx::VKSprite::extendedDescriptorPool = VK_NULL_HANDLE
private

◆ extendedDescriptorSet

VkDescriptorSet mx::VKSprite::extendedDescriptorSet = VK_NULL_HANDLE
private

◆ extendedDescriptorSetLayout

VkDescriptorSetLayout mx::VKSprite::extendedDescriptorSetLayout = VK_NULL_HANDLE
private

◆ extendedUBOBuffer

VkBuffer mx::VKSprite::extendedUBOBuffer = VK_NULL_HANDLE
private

◆ extendedUBOData

SpriteExtendedUBO mx::VKSprite::extendedUBOData {}
private

◆ extendedUBOEnabled

bool mx::VKSprite::extendedUBOEnabled = false
private

◆ extendedUBOMapped

void* mx::VKSprite::extendedUBOMapped = nullptr
private

Definition at line 322 of file vk_sprite.hpp.

Referenced by createExtendedUBO(), destroyExtendedUBO(), and updateExtendedUBO().

◆ extendedUBOMemory

VkDeviceMemory mx::VKSprite::extendedUBOMemory = VK_NULL_HANDLE
private

Definition at line 321 of file vk_sprite.hpp.

Referenced by createExtendedUBO(), and destroyExtendedUBO().

◆ fragmentShaderModule

VkShaderModule mx::VKSprite::fragmentShaderModule = VK_NULL_HANDLE
private

◆ graphicsQueue

VkQueue mx::VKSprite::graphicsQueue = VK_NULL_HANDLE
private

Definition at line 249 of file vk_sprite.hpp.

Referenced by endSingleTimeCommands(), updateSpriteTexture(), and VKSprite().

◆ hasCustomShader

bool mx::VKSprite::hasCustomShader = false
private

◆ instanceBuffer

VkBuffer mx::VKSprite::instanceBuffer = VK_NULL_HANDLE
private

Definition at line 337 of file vk_sprite.hpp.

Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().

◆ instanceBufferCapacity

uint32_t mx::VKSprite::instanceBufferCapacity = 0
private

Definition at line 340 of file vk_sprite.hpp.

Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().

◆ instanceBufferMapped

void* mx::VKSprite::instanceBufferMapped = nullptr
private

Definition at line 339 of file vk_sprite.hpp.

Referenced by destroyInstanceResources(), ensureInstanceBuffer(), and renderSprites().

◆ instanceBufferMemory

VkDeviceMemory mx::VKSprite::instanceBufferMemory = VK_NULL_HANDLE
private

Definition at line 338 of file vk_sprite.hpp.

Referenced by destroyInstanceResources(), and ensureInstanceBuffer().

◆ instancedPipeline

VkPipeline mx::VKSprite::instancedPipeline = VK_NULL_HANDLE
private

Definition at line 342 of file vk_sprite.hpp.

Referenced by createInstancedPipeline(), destroyInstanceResources(), and renderSprites().

◆ instancedPipelineLayout

VkPipelineLayout mx::VKSprite::instancedPipelineLayout = VK_NULL_HANDLE
private

Definition at line 343 of file vk_sprite.hpp.

Referenced by createInstancedPipeline(), destroyInstanceResources(), and renderSprites().

◆ instanceFragPath_

std::string mx::VKSprite::instanceFragPath_
private

Definition at line 345 of file vk_sprite.hpp.

Referenced by enableInstancing(), and rebuildInstancedPipeline().

◆ instanceVertPath_

std::string mx::VKSprite::instanceVertPath_
private

Definition at line 344 of file vk_sprite.hpp.

Referenced by enableInstancing(), and rebuildInstancedPipeline().

◆ instancingEnabled

bool mx::VKSprite::instancingEnabled = false
private

◆ ownExtendedDescriptorSetLayout

bool mx::VKSprite::ownExtendedDescriptorSetLayout = false
private

Definition at line 326 of file vk_sprite.hpp.

Referenced by createExtendedDescriptorSetLayout(), and destroyExtendedUBO().

◆ persistentStagingBuffer

VkBuffer mx::VKSprite::persistentStagingBuffer = VK_NULL_HANDLE
private

◆ persistentStagingMapped

void* mx::VKSprite::persistentStagingMapped = nullptr
private

◆ persistentStagingMemory

VkDeviceMemory mx::VKSprite::persistentStagingMemory = VK_NULL_HANDLE
private

Definition at line 284 of file vk_sprite.hpp.

Referenced by createStagingResources(), and destroyStagingResources().

◆ persistentStagingSize

VkDeviceSize mx::VKSprite::persistentStagingSize = 0
private

Definition at line 286 of file vk_sprite.hpp.

Referenced by createStagingResources(), and destroyStagingResources().

◆ physicalDevice

VkPhysicalDevice mx::VKSprite::physicalDevice = VK_NULL_HANDLE
private

Definition at line 248 of file vk_sprite.hpp.

Referenced by findMemoryType(), and VKSprite().

◆ quadBufferCreated

bool mx::VKSprite::quadBufferCreated = false
private

Definition at line 273 of file vk_sprite.hpp.

Referenced by createQuadBuffer(), and renderSprites().

◆ quadIndexBuffer

VkBuffer mx::VKSprite::quadIndexBuffer = VK_NULL_HANDLE
private

Definition at line 271 of file vk_sprite.hpp.

Referenced by createQuadBuffer(), renderSprites(), and ~VKSprite().

◆ quadIndexBufferMemory

VkDeviceMemory mx::VKSprite::quadIndexBufferMemory = VK_NULL_HANDLE
private

Definition at line 272 of file vk_sprite.hpp.

Referenced by createQuadBuffer(), and ~VKSprite().

◆ quadVertexBuffer

VkBuffer mx::VKSprite::quadVertexBuffer = VK_NULL_HANDLE
private

Definition at line 269 of file vk_sprite.hpp.

Referenced by createQuadBuffer(), renderSprites(), and ~VKSprite().

◆ quadVertexBufferMemory

VkDeviceMemory mx::VKSprite::quadVertexBufferMemory = VK_NULL_HANDLE
private

Definition at line 270 of file vk_sprite.hpp.

Referenced by createQuadBuffer(), and ~VKSprite().

◆ renderPass

VkRenderPass mx::VKSprite::renderPass = VK_NULL_HANDLE
private

◆ shaderParams

glm::vec4 mx::VKSprite::shaderParams = glm::vec4(0.0f)
private

Definition at line 259 of file vk_sprite.hpp.

Referenced by drawSpriteRect(), and setShaderParams().

◆ spriteHeight

int mx::VKSprite::spriteHeight = 0
private

◆ spriteImage

VkImage mx::VKSprite::spriteImage = VK_NULL_HANDLE
private

◆ spriteImageMemory

VkDeviceMemory mx::VKSprite::spriteImageMemory = VK_NULL_HANDLE
private

◆ spriteImageView

VkImageView mx::VKSprite::spriteImageView = VK_NULL_HANDLE
private

◆ spriteLoaded

bool mx::VKSprite::spriteLoaded = false
private

◆ spriteSampler

VkSampler mx::VKSprite::spriteSampler = VK_NULL_HANDLE

◆ spriteWidth

int mx::VKSprite::spriteWidth = 0
private

◆ stagingResourcesCreated

bool mx::VKSprite::stagingResourcesCreated = false
private

◆ uploadCmdBuffer

VkCommandBuffer mx::VKSprite::uploadCmdBuffer = VK_NULL_HANDLE
private

◆ uploadFence

VkFence mx::VKSprite::uploadFence = VK_NULL_HANDLE
private

◆ vertexShaderPath

std::string mx::VKSprite::vertexShaderPath
private

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