Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
Chronos::Editor::EditorRenderer Class Reference

#include <editorRenderer.hpp>

Collaboration diagram for Chronos::Editor::EditorRenderer:

Public Member Functions

void init (Chronos::Engine::Device *device, GLFWwindow *window, Chronos::Engine::SwapChain *swapChain, VkInstance instance, VkSurfaceKHR surface)
 
void render (uint32_t currentFrame, uint32_t imageIndex, float bgColor[3])
 
void destroy ()
 
void update ()
 
void recreate ()
 
void changeMsaa ()
 
void cleanup ()
 
void renderAdditionalViewports ()
 

Public Attributes

Chronos::Engine::Devicedevice
 
Chronos::Engine::SwapChainswapChain
 
VkSurfaceKHR surface
 
GLFWwindow * window
 
VkCommandPool commandPool
 
VkDescriptorPool descriptorPool
 
std::vector< VkCommandBuffer > commandBuffers
 
std::vector< VkFramebuffer > framebuffers
 
VkRenderPass renderPass
 
void(* addElements )()
 

Detailed Description

Definition at line 28 of file editorRenderer.hpp.

Member Function Documentation

◆ changeMsaa()

void Chronos::Editor::EditorRenderer::changeMsaa ( )

Definition at line 198 of file editorRenderer.cpp.

199{
200 vkDestroyRenderPass(device->device, renderPass, nullptr);
202 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
203 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
204 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false, false, true);
205 recreate();
206}
Chronos::Engine::Device * device
Chronos::Engine::SwapChain * swapChain
VkDevice device
This is the logical device that is used by Vulkan.
Definition device.hpp:52
VkRenderPass createRenderPass(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkImageLayout initalLayout, VkImageLayout finalLayout, VkImageLayout msaaFinalLayout, bool msaa, bool clearFramebuffer, bool dependency)
Creates a render pass.
Definition helper.cpp:175

References Chronos::Engine::createRenderPass().

Here is the call graph for this function:

◆ cleanup()

void Chronos::Editor::EditorRenderer::cleanup ( )

Definition at line 172 of file editorRenderer.cpp.

173{
174 for (auto framebuffer : framebuffers)
175 vkDestroyFramebuffer(device->device, framebuffer, nullptr);
176 LOG(3, "EditorRenderer cleaned up")
177}
std::vector< VkFramebuffer > framebuffers
#define LOG(LEVEL, MESSAGE)
Definition logging.hpp:60

References LOG.

◆ destroy()

void Chronos::Editor::EditorRenderer::destroy ( )

Definition at line 126 of file editorRenderer.cpp.

127{
128 ImGui_ImplVulkan_Shutdown();
129 vkDestroyRenderPass(device->device, renderPass, nullptr);
130 for (auto framebuffer : framebuffers)
131 vkDestroyFramebuffer(device->device, framebuffer, nullptr);
132 vkDestroyCommandPool(device->device, commandPool, nullptr);
133 vkDestroyDescriptorPool(device->device, descriptorPool, nullptr);
134 LOG(3, "EditorRenderer destroyed")
135}

References LOG.

◆ init()

void Chronos::Editor::EditorRenderer::init ( Chronos::Engine::Device device,
GLFWwindow *  window,
Chronos::Engine::SwapChain swapChain,
VkInstance  instance,
VkSurfaceKHR  surface 
)

Definition at line 28 of file editorRenderer.cpp.

31{
32 this->device = device;
33 this->swapChain = swapChain;
34 this->surface = surface;
35 this->window = window;
36
38 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
39 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
40 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, false, false, true);
42 *device, *swapChain, renderPass, false);
43 // Setup Dear ImGui context
44 IMGUI_CHECKVERSION();
45 ImGui::CreateContext();
46 ImGuiIO& io = ImGui::GetIO();
47 (void)io;
48 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
49 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
50#ifdef WIN32
51 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
52 LOG(3, "Viewports enabled")
53#endif
54 ImGui::StyleColorsDark();
55
56 std::array<VkDescriptorPoolSize, 1> poolSizes {};
57 poolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
58 poolSizes[0].descriptorCount = static_cast<uint32_t>(MAX_FRAMES_IN_FLIGHT);
59
60 VkDescriptorPoolSize pool_sizes[]
61 = { { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 100 } };
62 VkDescriptorPoolCreateInfo pool_info = {};
63 pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
64 pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
65 pool_info.maxSets = 100;
66 pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
67 pool_info.pPoolSizes = pool_sizes;
68 vkCreateDescriptorPool(
69 device->device, &pool_info, nullptr, &descriptorPool);
70
71 ImGui_ImplGlfw_InitForVulkan(window, true);
72 ImGui_ImplVulkan_InitInfo init_info = {};
73 init_info.Instance = instance;
74 init_info.PhysicalDevice = device->physicalDevice;
75 init_info.Device = device->device;
76 init_info.QueueFamily
78 .graphicsFamily.value();
79 init_info.Queue = device->graphicsQueue;
80 init_info.PipelineCache = VK_NULL_HANDLE;
81 init_info.DescriptorPool = descriptorPool;
82 init_info.RenderPass = renderPass;
83 init_info.Allocator = nullptr;
84 init_info.MinImageCount = MAX_FRAMES_IN_FLIGHT;
85 init_info.ImageCount = MAX_FRAMES_IN_FLIGHT;
86 init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
87 init_info.CheckVkResultFn = nullptr; // add a fucntion to this
88 ImGui_ImplVulkan_Init(&init_info);
89
90 VkCommandPoolCreateInfo commandPoolCreateInfo = {};
91 commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
92 commandPoolCreateInfo.queueFamilyIndex
94 .graphicsFamily.value();
95 commandPoolCreateInfo.flags
96 = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
97
98 if (vkCreateCommandPool(
99 device->device, &commandPoolCreateInfo, nullptr, &commandPool)
100 != VK_SUCCESS) {
101 LOG(1, "Could not create graphics command pool")
102 throw std::runtime_error("Could not create graphics command pool");
103 }
104
105 VkCommandBuffer command_buffer
106 = Chronos::Engine::beginSingleTimeCommands(commandPool, device->device);
107 ImGui_ImplVulkan_CreateFontsTexture();
108 Chronos::Engine::endSingleTimeCommands(
109 &command_buffer, *device, commandPool);
110
111 commandBuffers.resize(swapChain->swapChainImageViews.size());
112 VkCommandBufferAllocateInfo allocInfo {};
113 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
114 allocInfo.commandPool = commandPool;
115 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
116 allocInfo.commandBufferCount = static_cast<uint32_t>(commandBuffers.size());
117 if (vkAllocateCommandBuffers(
118 device->device, &allocInfo, commandBuffers.data())
119 != VK_SUCCESS) {
120 LOG(1, "failed to allocate command buffers!")
121 throw std::runtime_error("failed to allocate command buffers!");
122 }
123 LOG(3, "EditorRenderer initialized")
124}
std::vector< VkCommandBuffer > commandBuffers
VkPhysicalDevice physicalDevice
This is the physical device that is used by Vulkan.
Definition device.hpp:60
VkQueue graphicsQueue
This is the queue that is used for graphics rendering.
Definition device.hpp:65
std::vector< VkFramebuffer > createFramebuffer(Chronos::Engine::Device device, Chronos::Engine::SwapChain swapChain, VkRenderPass renderPass, bool msaa)
Creates a set of framebuffers for use.
Definition helper.cpp:276
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface)
Gets the indices of the needed queue families.
Definition helper.cpp:126
std::optional< uint32_t > graphicsFamily
Definition helper.hpp:45
#define MAX_FRAMES_IN_FLIGHT
The number of frames in flight.

References Chronos::Engine::beginSingleTimeCommands(), commandBuffers, commandPool, Chronos::Engine::createFramebuffer(), Chronos::Engine::createRenderPass(), descriptorPool, device, Chronos::Engine::Device::device, Chronos::Engine::endSingleTimeCommands(), Chronos::Engine::findQueueFamilies(), framebuffers, Chronos::Engine::QueueFamilyIndices::graphicsFamily, Chronos::Engine::Device::graphicsQueue, LOG, MAX_FRAMES_IN_FLIGHT, Chronos::Engine::Device::physicalDevice, renderPass, surface, swapChain, Chronos::Engine::SwapChain::swapChainImageViews, and window.

Here is the call graph for this function:

◆ recreate()

void Chronos::Editor::EditorRenderer::recreate ( )

Definition at line 179 of file editorRenderer.cpp.

180{
181 cleanup();
183 *device, *swapChain, renderPass, false);
184 LOG(3, "EditorRenderer recreated")
185}

References Chronos::Engine::createFramebuffer(), and LOG.

Here is the call graph for this function:

◆ render()

void Chronos::Editor::EditorRenderer::render ( uint32_t  currentFrame,
uint32_t  imageIndex,
float  bgColor[3] 
)

Definition at line 147 of file editorRenderer.cpp.

149{
150 vkResetCommandBuffer(commandBuffers[currentFrame], 0);
151 VkCommandBufferBeginInfo beginInfo {};
152 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
153 VkClearValue clearColor
154 = { { { bgColor[0], bgColor[1], bgColor[2], 1.0f } } };
155 vkBeginCommandBuffer(commandBuffers[currentFrame], &beginInfo);
156 VkRenderPassBeginInfo info = {};
157 info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
158 info.renderPass = renderPass;
159 info.framebuffer = framebuffers[imageIndex];
160 info.renderArea.extent = swapChain->swapChainExtent;
161 info.clearValueCount = 1;
162 info.pClearValues = &clearColor;
163 vkCmdBeginRenderPass(
164 commandBuffers[currentFrame], &info, VK_SUBPASS_CONTENTS_INLINE);
165 ImGui_ImplVulkan_RenderDrawData(
166 ImGui::GetDrawData(), commandBuffers[currentFrame]);
167 vkCmdEndRenderPass(commandBuffers[currentFrame]);
168 vkEndCommandBuffer(commandBuffers[currentFrame]);
169 LOG(4, "EditorRenderer rendered")
170}
VkExtent2D swapChainExtent
Dimenisons of the current swapchain.

References LOG.

◆ renderAdditionalViewports()

void Chronos::Editor::EditorRenderer::renderAdditionalViewports ( )

Definition at line 187 of file editorRenderer.cpp.

188{
189#ifdef WIN32
190 if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
191 ImGui::UpdatePlatformWindows();
192 ImGui::RenderPlatformWindowsDefault();
193 }
194 LOG(4, "Rendered additional viewports")
195#endif
196}

References LOG.

◆ update()

void Chronos::Editor::EditorRenderer::update ( )

Definition at line 137 of file editorRenderer.cpp.

138{
139 ImGui_ImplVulkan_NewFrame();
140 ImGui_ImplGlfw_NewFrame();
141 ImGui::NewFrame();
142 this->addElements();
143 ImGui::Render();
144 LOG(4, "EditorRenderer updated")
145}

References addElements(), and LOG.

Here is the call graph for this function:

Member Data Documentation

◆ addElements

void(* Chronos::Editor::EditorRenderer::addElements) ()

Definition at line 52 of file editorRenderer.hpp.

◆ commandBuffers

std::vector<VkCommandBuffer> Chronos::Editor::EditorRenderer::commandBuffers

Definition at line 37 of file editorRenderer.hpp.

◆ commandPool

VkCommandPool Chronos::Editor::EditorRenderer::commandPool

Definition at line 35 of file editorRenderer.hpp.

◆ descriptorPool

VkDescriptorPool Chronos::Editor::EditorRenderer::descriptorPool

Definition at line 36 of file editorRenderer.hpp.

◆ device

Chronos::Engine::Device* Chronos::Editor::EditorRenderer::device

Definition at line 30 of file editorRenderer.hpp.

◆ framebuffers

std::vector<VkFramebuffer> Chronos::Editor::EditorRenderer::framebuffers

Definition at line 38 of file editorRenderer.hpp.

◆ renderPass

VkRenderPass Chronos::Editor::EditorRenderer::renderPass

Definition at line 39 of file editorRenderer.hpp.

◆ surface

VkSurfaceKHR Chronos::Editor::EditorRenderer::surface

Definition at line 32 of file editorRenderer.hpp.

◆ swapChain

Chronos::Engine::SwapChain* Chronos::Editor::EditorRenderer::swapChain

Definition at line 31 of file editorRenderer.hpp.

◆ window

GLFWwindow* Chronos::Editor::EditorRenderer::window

Definition at line 33 of file editorRenderer.hpp.


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