Chronos 0.0
A advanced 2D rendering and animation system
|
Class for creating a text object for rendering text. More...
#include <text.hpp>
Public Member Functions | |
void | init (Chronos::Engine::Device *device, VkCommandPool commandPool, Chronos::Engine::SwapChain *swapChain, VkSampler textureSampler, VkRenderPass *renderPass, Chronos::Engine::FontTypes fontStyle) |
Initializes the font object and creates the necessary objects. | |
void | destroy () override |
Destroys the font object and frees the memory. | |
void | clear () |
Clears the text stored in the font object. | |
void | render (uint32_t currentFrame, uint32_t imageIndex, float bgColor[3], VkViewport &viewport, VkRect2D &scissor, std::vector< VkCommandBuffer > &commandBuffers) override |
Records the commands needed for rendering the text . | |
void | update (uint32_t currentFrame) override |
Updates the attributes(like position, color, etc) of the text. | |
![]() | |
void | init (Chronos::Engine::Device *device, VkCommandPool commandPool, SwapChain *swapChain, VkSampler textureSampler, VkRenderPass *renderPass, ObjectType objectType, unsigned char *vertShaderCode, int vertShaderCodeSize, unsigned char *fragShaderCode, int fragShaderCodeSize) |
Initializes the object. | |
void | recreateGraphicsPipeline () |
Recreates the graphics pipeline for the object. | |
Public Attributes | |
VkBuffer | vertexBuffer |
The vertices of each character used for rendering. | |
uint32_t | numLetters |
The total number of letters to render. | |
Chronos::Engine::TextParams | params |
Various parameters of the text that are set by the user. | |
![]() | |
VkPipeline | graphicsPipeline |
VkPipelineLayout | pipelineLayout |
std::vector< VkDescriptorSet > | descriptorSets |
Chronos::Engine::ObjectType | objectType |
Private Member Functions | |
void | createDescriptorSets () override |
Creates the descriptor sets needed for rendering the text. | |
std::vector< VkDescriptorType > | getDescriptorTypes () override |
Gets the descriptor types needed for rendering the text. | |
std::vector< VkShaderStageFlagBits > | getDescriptorStages () override |
Gets the descriptor stages in which the descriptor sets are used. | |
PipelineAttributes | getPipelineAttributes () override |
Returns the pipeline attributes that are set for the graphics pipeline. | |
void | updateBuffer () |
Updates the buffer with the new text. | |
Private Attributes | |
stb_fontchar | stbFontData [STB_FONT_consolas_24_latin1_NUM_CHARS] |
uint32_t | maxTextLength = 2048 |
Maximum number of characters that can be rendered. | |
VkDeviceMemory | vertexBufferMemory |
The vertex buffer memory. | |
Chronos::Engine::Texture | fontTexture |
std::vector< Chronos::Engine::ColorBuffer > | colorBuffers |
uint32_t | firstChar = 'a' |
FontTypes | fontStyle |
glm::vec4 * | mappedMemory |
unsigned char(* | fontpixels )[256] |
Additional Inherited Members | |
![]() | |
void | createGraphicsPipeline () |
Creates the graphics pipeline for the object. | |
void | createDescriptorPool () |
Creates the Vulkan descriptor pool for the object. | |
void | createDescriptorSetLayout () |
Creates the Vulkan descriptor set layout for the object. | |
![]() | |
Chronos::Engine::Device * | device |
Chronos::Engine::SwapChain * | swapChain |
VkCommandPool | commandPool |
VkSampler | textureSampler |
VkRenderPass * | renderPass |
VkDescriptorSetLayout | descriptorSetLayout |
VkDescriptorPool | descriptorPool |
std::vector< Chronos::Engine::UniformBuffer > | uniformBuffers |
Class for creating a text object for rendering text.
We can choose from a lot of fonts and sizes. There are many available.
For rendering text in vulkan, we need a bunch of setup and objects. It is also a very complex process. This class handles this process and abstracts this complex process into a simple class with simple methods that can be used for rendering text.
The way the test is rendered is by creating a texture atlas. This is a texture that contains all the characters in the font. This texture is then used to render the text. The text is rendered by creating a rectangle for each character and then rendering it.
This class is not meant to be directly used, but instead to be used by the
class. That will handle the creation and destruction of the font object, along with any updates needed.
void Chronos::Engine::Text::clear | ( | ) |
Clears the text stored in the font object.
Used for resetting the text stored in the font object.
Definition at line 296 of file text.cpp.
|
overrideprivatevirtual |
Creates the descriptor sets needed for rendering the text.
This function is used to create the descriptor sets needed for rendering the text. The descriptor sets contain information about the texture sampler and the uniform buffer.
Implements Chronos::Engine::Object.
Definition at line 94 of file text.cpp.
References MAX_FRAMES_IN_FLIGHT.
|
overridevirtual |
Destroys the font object and frees the memory.
This destroys all the vulkan related objects related to this class and frees memory.
Implements Chronos::Engine::Object.
Definition at line 210 of file text.cpp.
References Chronos::Engine::Object::destroy(), and MAX_FRAMES_IN_FLIGHT.
|
overrideprivatevirtual |
Gets the descriptor stages in which the descriptor sets are used.
Implements Chronos::Engine::Object.
Definition at line 88 of file text.cpp.
|
overrideprivatevirtual |
Gets the descriptor types needed for rendering the text.
Implements Chronos::Engine::Object.
Definition at line 80 of file text.cpp.
|
overrideprivatevirtual |
Returns the pipeline attributes that are set for the graphics pipeline.
Implements Chronos::Engine::Object.
Definition at line 160 of file text.cpp.
References Chronos::Engine::PipelineAttributes::attributeDescriptions, Chronos::Engine::PipelineAttributes::bindingDescriptions, Chronos::Engine::PipelineAttributes::colorBlendAttachment, Chronos::Engine::PipelineAttributes::frontFace, and Chronos::Engine::PipelineAttributes::topology.
void Chronos::Engine::Text::init | ( | Chronos::Engine::Device * | device, |
VkCommandPool | commandPool, | ||
Chronos::Engine::SwapChain * | swapChain, | ||
VkSampler | textureSampler, | ||
VkRenderPass * | renderPass, | ||
Chronos::Engine::FontTypes | fontStyle | ||
) |
Initializes the font object and creates the necessary objects.
device | The device to use for creating the objects. |
commandPool | The command pool to use for rendering |
swapChain | The swapchain to use for rendering |
textureSampler | The texture sampler to use for fonts |
renderPass | The renderpass to use for rendering |
fontStyle | The font style to use for rendering |
Definition at line 28 of file text.cpp.
References colorBuffers, Chronos::Engine::Object::commandPool, Chronos::Engine::Texture::create(), Chronos::Engine::createBuffer(), Chronos::Engine::Object::device, Chronos::Engine::FontTypes::firstChar, firstChar, Chronos::Engine::FontTypes::fontHeight, fontpixels, fontStyle, fontTexture, Chronos::Engine::FontTypes::fontWidth, Chronos::Engine::FontTypes::getFontData, Chronos::Engine::Object::init(), MAX_FRAMES_IN_FLIGHT, maxTextLength, Chronos::Engine::Object::renderPass, stbFontData, Chronos::Engine::Object::swapChain, Chronos::Engine::Object::textureSampler, Chronos::Engine::TypeText, vertexBuffer, and vertexBufferMemory.
|
overridevirtual |
Records the commands needed for rendering the text .
When this function is called, it records the commands that are needed for rendering the text stored in this class.
currentFrame | The current frame number to render to. |
imageIndex | The index of the framebuffer associated with the current frame |
bgColor | The background color to use for rendering the text. |
Implements Chronos::Engine::Object.
Definition at line 319 of file text.cpp.
|
overridevirtual |
Updates the attributes(like position, color, etc) of the text.
This function is used to update the attributes of the text. It is called by the FontManager
class. It does this by updating the uniform buffer.
Implements Chronos::Engine::Object.
Definition at line 310 of file text.cpp.
|
private |
Updates the buffer with the new text.
Definition at line 222 of file text.cpp.
|
private |
|
private |
|
private |
|
private |
|
private |
uint32_t Chronos::Engine::Text::numLetters |
Chronos::Engine::TextParams Chronos::Engine::Text::params |
|
private |
VkBuffer Chronos::Engine::Text::vertexBuffer |
|
private |