|
Rehti MMORPG
1.0.0
Rehti MMORPG is a free and open source MMORPG game.
|
Graphics object manager manages different types of objects that have memory and can be drawn. More...
#include <GraphicsObjectManager.hpp>

Classes | |
| struct | CommandUnit |
| Command unit represents everything needed to allocate, submit, record and execute commands. More... | |
Public Member Functions | |
| GraphicsObjectManager (VkInstance instance, VkPhysicalDevice gpu, VkDevice logDevice, VkQueue graphicsQueue, std::shared_mutex &graphicsMutex, uint32_t graphicsQueueFamily, const uint32_t frameCount) | |
| Creates a graphics object manager. More... | |
| ~GraphicsObjectManager () | |
| Destructor. More... | |
| void | addTransferQueueFamilyAccess (const uint32_t transferQueueFamily, VkQueue transferQueue) |
| Adds the given transfer queue to the manager. More... | |
| bool | addCharacter (int characterID, const std::vector< CharacterVertex > &vertices, const std::vector< uint32_t > &indices, ImageData &texture, glm::mat4 transformation, glm::mat4 bindPose[MAX_BONES], VkSampler imgSampler, PhongMaterial material=PhongMaterial::getDefaultMaterial()) |
| Adds a character to the buffer manager with the given parameters. More... | |
| bool | addGameObject (int objectId, const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, ImageData &texture, glm::mat4 transformation, VkSampler imgSampler, PhongMaterial material=PhongMaterial::getDefaultMaterial()) |
| Adds a game object to the buffer manager. More... | |
| bool | addTestObject (int id, const std::vector< SimpleVertex > &vertices, const std::vector< uint32_t > &indices, glm::mat4 transformation) |
| Adds a test object to the buffer manager. More... | |
| bool | addArea (const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices, std::array< ImageData, 6 > textures, VkSampler texSampler) |
| Adds an area object to the buffer manager. More... | |
| bool | cleanResources (int id, ObjectType type) |
| Cleans resources of the given id, if they exists. More... | |
| void | updateTestObject (int id, const void *srcData, uint32_t frame) |
| Updates test object data. More... | |
| void | updateObjectDescriptor (int id, const void *srcData, uint32_t frame) |
| Updates the object descriptor with the given data. More... | |
| void | updateCharacterDescriptor (int id, const void *transformSrcData, const void *boneSrcData, uint32_t frame) |
| VkDescriptorSet | getSunDescriptorSet (uint32_t frame) const |
| Returns the descriptor set of the sun for the given frame. More... | |
| VkDescriptorSetLayout | getSunLayout () const |
| Returns the descriptor set layout of the sun. More... | |
| void | updateSunDescriptor (const void *srcData, uint32_t frame) |
| Updates the sun descriptor with the given data. More... | |
| void | updateCameraDescriptor (const void *srcData, uint32_t frame) |
| Updates the camera descriptor with the given data. More... | |
| AllocatedImage | createDepthImage (uint32_t width, uint32_t height, VkFormat depthFormat) |
| Creates a depth image. More... | |
| void | destroyImage (AllocatedImage image) |
| Interface for destroying an image That is owned by the user of this class. More... | |
| void | transitionDepthImageLayout (AllocatedImage depthImage, VkFormat depthFormat, VkImageLayout srcLayout, VkImageLayout dstLayout) |
| Transitions the given image to the given layout using graphics queue. More... | |
| VkImageView | createImageView (VkImage image, VkFormat format, VkImageAspectFlags aspectFlags=VK_IMAGE_ASPECT_COLOR_BIT) |
| Creates an image view for the given image and format. More... | |
| CombinedImage | createCombinedImage (uint32_t width, uint32_t height, VkFormat format) |
| Creates an image for the given data and stores the memory to this class. More... | |
| void | copyBuffer (AllocatedBuffer allocBuffer, const void *srcData) |
| Copies the given data to the given buffer. More... | |
| void | copyImage (AllocatedImage allocImage, const ImageData &srcData) |
| Copies the given data to the given image. More... | |
| VkDescriptorSetLayout | getLayout (ObjectType type) const |
| Returns the descriptor set layout for the given object type. More... | |
| uint32_t | getLayoutCount (ObjectType type) const |
| Returns the number of descriptor layouts of the given type. Currently not a very useful function. However, it might be useful in the future. More... | |
| std::vector< DrawableObject > | getDrawableObjects (ObjectType type, uint32_t frame) const |
| Returns drawable objects of the given type. More... | |
Private Member Functions | |
| AllocatedBuffer | createBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VmaAllocationInfo &info, VmaMemoryUsage memUsage=VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags=0, VkMemoryPropertyFlags requiredFlags=0, VkMemoryPropertyFlags preferredFlags=0) |
| Creates a buffer with the given parameters. More... | |
| AllocatedBuffer | createBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VmaMemoryUsage memUsage=VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags=0, VkMemoryPropertyFlags requiredFlags=0, VkMemoryPropertyFlags preferredFlags=0) |
| AllocatedImage | createImage (uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling=VK_IMAGE_TILING_OPTIMAL, VkImageUsageFlags usage=VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, VmaMemoryUsage memUsage=VMA_MEMORY_USAGE_AUTO, VmaAllocationCreateFlags vmaCreationFlags=0, VkMemoryPropertyFlags requiredFlags=0, VkMemoryPropertyFlags preferredFlags=0) |
| Creates an allocated image. The standard parameters make it easy to create a texture image on the GPU. More specific use cases must be specified through the parameters. More... | |
| void | createDescriptorBuilder () |
| Initializes the descriptorBuilder member. More... | |
| uint32_t | getQueueFamilyCount () |
| Returns number of queue families. More... | |
| VkSharingMode | getSharingMode () |
| Returns the sharing mode of created resources. More... | |
| VkCommandBuffer | startCommandBuffer (bool preferTransfer) |
| Allocates and begins a command buffer. More... | |
| bool | endCommandBuffer (VkCommandBuffer commandBuffer, VkFence fence=VK_NULL_HANDLE) |
| Submits the given command buffer to be executed on the gpu. More... | |
| void | transitionImageLayout (VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, VkCommandBuffer commandBuffer, VkImageAspectFlags aspectFlags=VK_IMAGE_ASPECT_COLOR_BIT, std::pair< uint32_t, uint32_t > srcAndDstQueueFamilies={VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED}) |
| Records image layout transition barrier to the given command buffer. More... | |
| std::pair< uint32_t, uint32_t > | getQueueTransitionFamilies () |
| Queue families should be transferred, if the resources are using multiple queues, and the sharingmode is exclusive, or the desired stage is available only to another queue. todo could be updated in the future. More... | |
| bool | getPipelineAndAccessFlags (VkImageLayout srcLayout, VkImageLayout dstLayout, std::pair< VkAccessFlags, VkAccessFlags > &srcAndDstAccessMasks, std::pair< VkPipelineStageFlags, VkPipelineStageFlags > &srcAndDstStages) |
| Fills access masks and pipeline stages when given source and destination layouts for an image. More... | |
| AllocatedBuffer | createStagingBuffer (VkDeviceSize size, VmaAllocationInfo &allocInfo) |
| Helper for creating a staging buffer. More... | |
| void | createSun () |
| Creates necessary memory allocations and mappings for a sun. More... | |
Private Attributes | |
| VkDevice | logDeviceM |
| VmaAllocator | allocatorM |
| VkDeviceSize | minOffsetM |
| Minimum offset alignment for uniform buffers. More... | |
| std::shared_mutex & | graphicsQueueMutexM |
| CommandUnit | graphicsCommandUnitM |
| std::optional< CommandUnit > | transferCommandUnitM |
| std::optional< CommandUnit > | activeCommandUnitM |
| std::unique_ptr< DescriptorBuilder > | pBuilderM |
| std::unordered_map< int, CharacterObject > | characterObjectsM |
| std::unordered_map< int, GameObject > | gameObjectsM |
| std::unordered_map< int, TestObject > | testObjectsM |
| std::vector< AreaObject > | areaObjectsM |
| LightObject | sunM |
| VkDescriptorSetLayout | sunLayoutM |
| std::vector< CombinedImage > | allocatedImagesM |
| uint32_t | frameCountM |
| std::array< VkDescriptorSetLayout, OBJECT_TYPE_COUNT > | descriptorSetLayoutsM |
Graphics object manager manages different types of objects that have memory and can be drawn.
| GraphicsObjectManager::GraphicsObjectManager | ( | VkInstance | instance, |
| VkPhysicalDevice | gpu, | ||
| VkDevice | logDevice, | ||
| VkQueue | graphicsQueue, | ||
| std::shared_mutex & | graphicsMutex, | ||
| uint32_t | graphicsQueueFamily, | ||
| const uint32_t | frameCount | ||
| ) |
Creates a graphics object manager.
| instance | is a Vulkan instance. |
| gpu | is the physical device. |
| logDevice | is the logical device. |
| graphicsQueue | is the queue for graphics operations. |
| graphicsMutex | is a mutex for graphics operations. |
| graphicsQueueFamily | is the family index of the graphics queue. |
| frameCount | is the number of frames. |
| GraphicsObjectManager::~GraphicsObjectManager | ( | ) |
Destructor.
| bool GraphicsObjectManager::addArea | ( | const std::vector< Vertex > & | vertices, |
| const std::vector< uint32_t > & | indices, | ||
| std::array< ImageData, 6 > | textures, | ||
| VkSampler | texSampler | ||
| ) |
Adds an area object to the buffer manager.
| vertices | of the area |
| indices | of the area |
| textures | of the area |

| bool GraphicsObjectManager::addCharacter | ( | int | characterID, |
| const std::vector< CharacterVertex > & | vertices, | ||
| const std::vector< uint32_t > & | indices, | ||
| ImageData & | texture, | ||
| glm::mat4 | transformation, | ||
| glm::mat4 | bindPose[MAX_BONES], | ||
| VkSampler | imgSampler, | ||
| PhongMaterial | material = PhongMaterial::getDefaultMaterial() |
||
| ) |
Adds a character to the buffer manager with the given parameters.
| characterID | is the id of the character |
| vertices | of the character |
| indices | of the character |
| texture | of the character |
| transformation | to be applied to the character |
| bindPose | is the bind pose bone data of the character |
| imgSampler | is the sampler for the texture of the character |

| bool GraphicsObjectManager::addGameObject | ( | int | objectId, |
| const std::vector< Vertex > & | vertices, | ||
| const std::vector< uint32_t > & | indices, | ||
| ImageData & | texture, | ||
| glm::mat4 | transformation, | ||
| VkSampler | imgSampler, | ||
| PhongMaterial | material = PhongMaterial::getDefaultMaterial() |
||
| ) |
Adds a game object to the buffer manager.
| objectId | |
| vertices | of the object |
| indices | of the points making up triangles |
| texture | of the object |
| transformation | to be applied to the object |
| imgSampler | is the sampler for the texture of the gameobject |

| bool GraphicsObjectManager::addTestObject | ( | int | id, |
| const std::vector< SimpleVertex > & | vertices, | ||
| const std::vector< uint32_t > & | indices, | ||
| glm::mat4 | transformation | ||
| ) |
Adds a test object to the buffer manager.
| id | of the object |
| vertices | |
| indices | |
| transformation |

| void GraphicsObjectManager::addTransferQueueFamilyAccess | ( | const uint32_t | transferQueueFamily, |
| VkQueue | transferQueue | ||
| ) |
Adds the given transfer queue to the manager.
| transferQueueFamily | is the family index of the transfer queue. |
| transferQueue | is the transfer queue. |
| bool GraphicsObjectManager::cleanResources | ( | int | id, |
| ObjectType | type | ||
| ) |
Cleans resources of the given id, if they exists.
| id | is the id of the object. |
| type | is the type of the object. |
| void GraphicsObjectManager::copyBuffer | ( | AllocatedBuffer | allocBuffer, |
| const void * | srcData | ||
| ) |
Copies the given data to the given buffer.
| allocBuffer | is the buffer to which the data is copied. |
| srcData | is the source data. |


| void GraphicsObjectManager::copyImage | ( | AllocatedImage | allocImage, |
| const ImageData & | srcData | ||
| ) |
Copies the given data to the given image.
| allocImage | is the image to copy to. |
| srcData | is the source image data. |


|
private |
Creates a buffer with the given parameters.
| size | is the size of the buffer in bytes. |
| usage | is the usage of the buffer. |
| info | is the allocation info of the buffer to be filled. |
| memUsage | is the memory usage of the buffer. |
| vmaCreationFlags | are the flags for the creation of the buffer. |
| requiredFlags | are the required memory property flags. |
| preferredFlags | are the preferred memory property flags. |


|
private |

| CombinedImage GraphicsObjectManager::createCombinedImage | ( | uint32_t | width, |
| uint32_t | height, | ||
| VkFormat | format | ||
| ) |
Creates an image for the given data and stores the memory to this class.
| data | of the image |

| AllocatedImage GraphicsObjectManager::createDepthImage | ( | uint32_t | width, |
| uint32_t | height, | ||
| VkFormat | depthFormat | ||
| ) |
Creates a depth image.
| width | is the width of the image. |
| height | is the height of the image. |
| depthFormat | is the format of the depth image. |

|
private |
Initializes the descriptorBuilder member.
|
private |
Creates an allocated image. The standard parameters make it easy to create a texture image on the GPU. More specific use cases must be specified through the parameters.
| width | The width of the image. |
| height | The height of the image. |
| format | The format of the image. |
| tiling | The tiling of the image. |
| usage | The usage of the image. |
| memUsage | The VMA memory usage of the image. |
| vmaCreationFlags | The VMA creation flags of the image. |
| requiredFlags | The required memory property flags. |
| preferredFlags | The preferred memory property flags. |

| VkImageView GraphicsObjectManager::createImageView | ( | VkImage | image, |
| VkFormat | format, | ||
| VkImageAspectFlags | aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT |
||
| ) |
Creates an image view for the given image and format.
| image | The image for which to create a view. |
| format | The format of the image view. |

|
private |
Helper for creating a staging buffer.
| size | of the staging buffer |
| allocInfo | to be filled |


|
private |
Creates necessary memory allocations and mappings for a sun.

| void GraphicsObjectManager::destroyImage | ( | AllocatedImage | image | ) |
Interface for destroying an image That is owned by the user of this class.
| image |
|
private |
Submits the given command buffer to be executed on the gpu.
| commandBuffer | to end |
| fence | to set signal. |

| std::vector< DrawableObject > GraphicsObjectManager::getDrawableObjects | ( | ObjectType | type, |
| uint32_t | frame | ||
| ) | const |
Returns drawable objects of the given type.
| type | of object desired for drawing |
| VkDescriptorSetLayout GraphicsObjectManager::getLayout | ( | ObjectType | type | ) | const |
Returns the descriptor set layout for the given object type.
| type |
| uint32_t GraphicsObjectManager::getLayoutCount | ( | ObjectType | type | ) | const |
Returns the number of descriptor layouts of the given type. Currently not a very useful function. However, it might be useful in the future.
| type | of object to be queried for. |
|
private |
Fills access masks and pipeline stages when given source and destination layouts for an image.
| srcLayout | of the image |
| dstLayout | of the image |
| srcAndDstAccessMasks | to be filled |
| srcAndDstStages | to be filled |

|
private |
Returns number of queue families.

|
private |
Queue families should be transferred, if the resources are using multiple queues, and the sharingmode is exclusive, or the desired stage is available only to another queue. todo could be updated in the future.
|
private |
Returns the sharing mode of created resources.
| id | of the object |

| VkDescriptorSet GraphicsObjectManager::getSunDescriptorSet | ( | uint32_t | frame | ) | const |
Returns the descriptor set of the sun for the given frame.
| frame | to get the descriptor set for. |
| VkDescriptorSetLayout GraphicsObjectManager::getSunLayout | ( | ) | const |
Returns the descriptor set layout of the sun.
|
private |
Allocates and begins a command buffer.
| preferTransfer | indicates if the transfer unit should be used. |


| void GraphicsObjectManager::transitionDepthImageLayout | ( | AllocatedImage | depthImage, |
| VkFormat | depthFormat, | ||
| VkImageLayout | srcLayout, | ||
| VkImageLayout | dstLayout | ||
| ) |
Transitions the given image to the given layout using graphics queue.
| depthImage | |
| depthFormat | |
| srcLayout | |
| dstLayout |

|
private |
Records image layout transition barrier to the given command buffer.
| image | to transition |
| format | of the image |
| oldLayout | of the image |
| newLayout | of the image |
| commandBuffer | to record the transition to |
| srcQueueFamilyIndex | & dstQueueFamilyIndex of the source family. Use the default value if you do not want to change queue ownership |


| void GraphicsObjectManager::updateCameraDescriptor | ( | const void * | srcData, |
| uint32_t | frame | ||
| ) |
Updates the camera descriptor with the given data.
| srcData | is the data to be copied |
| frame | is the frame of the update |
| void GraphicsObjectManager::updateCharacterDescriptor | ( | int | id, |
| const void * | transformSrcData, | ||
| const void * | boneSrcData, | ||
| uint32_t | frame | ||
| ) |
| id | of the character |
| transformSrcData | is the transformation data to be copied to the buffer (4x4 matrix) |
| boneSrcData | is the bone data to be copied (list of matrixes) |
| frame | is the frame of the update |
| void GraphicsObjectManager::updateObjectDescriptor | ( | int | id, |
| const void * | srcData, | ||
| uint32_t | frame | ||
| ) |
Updates the object descriptor with the given data.
| id | of the object to update |
| srcData | is the data to be copied to the buffer (4x4 matrix) |
| frame | is the frame of the update |
| void GraphicsObjectManager::updateSunDescriptor | ( | const void * | srcData, |
| uint32_t | frame | ||
| ) |
Updates the sun descriptor with the given data.
| srcData | is the data to be copied |
| frame | is the frame of the update |
| void GraphicsObjectManager::updateTestObject | ( | int | id, |
| const void * | srcData, | ||
| uint32_t | frame | ||
| ) |
Updates test object data.
| id | is the ID of the object. |
| srcData | is the source data. |
| frame | is the frame number. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Minimum offset alignment for uniform buffers.
|
private |
|
private |
|
private |
|
private |
|
private |