31 const std::unordered_map<std::string, std::shared_ptr<Model>> modelCache =
ModelFactory::loadAll(m_device,
"assets/models/");
32 const std::shared_ptr<Texture> defaultTexture = m_sceneManager.getTextureDefault();
37 modelCache.at(
"assets/models/quad.obj"),
40 .translation = {0.F, .5F, 0.F},
41 .scale = {3.F, 1.F, 3.F},
42 .rotation = {0.F, 0.F, 0.F}
49 modelCache.at(
"assets/models/smooth_vase.obj"),
52 .translation = {.5F, .5F, 0.F},
53 .scale = {3.F, 1.5F, 3.F},
54 .rotation = {0.F, 0.F, 0.F}
60 modelCache.at(
"assets/models/flat_vase.obj"),
63 .translation = {-.5F, .5F, 0.F},
64 .scale = {3.F, 1.5F, 3.F},
65 .rotation = {0.F, 0.F, 0.F}
68 for (std::size_t i = 0; i < lightColors.size(); i++)
71 const glm::mat4 rotateLight = rotate(
73 static_cast<float>(i) * glm::two_pi<float>() / 6.0F,
77 .translation = glm::vec3(rotateLight * glm::vec4(-1.F, -1.F, -1.F, 1.F)),
78 .scale = { 0.1F, 0.0F, 0.0F },
79 .rotation = { 0.F, 0.F, 0.F }},
91 VkCommandBuffer_T *commandBuffer =
nullptr;
92 VkDescriptorBufferInfo bufferInfo{};
93 float frameTime = 0.0F;
94 unsigned long frameIndex = 0;
95 const std::unique_ptr globalSetLayout(
DescriptorSetLayout::Builder(m_device).addBinding(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_ALL_GRAPHICS).build());
98 const ObjectRenderSystem objectRenderSystem(m_device, m_renderer.getSwapChainRenderPass(), globalSetLayout->getDescriptorSetLayout());
99 const PointLightRenderSystem pointLightRenderSystem(m_device, m_renderer.getSwapChainRenderPass(), globalSetLayout->getDescriptorSetLayout());
101 for (
auto& uboBuffer : uboBuffers)
103 uboBuffer = std::make_unique<Buffer>(m_device,
sizeof(
GlobalUbo), 1, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
106 for (std::size_t i = 0; i < globalDescriptorSets.size(); i++) {
107 bufferInfo = uboBuffers[i]->descriptorInfo();
111 while (m_state !=
EXIT)
115 eventManager.handleEvents(m_window.getGLFWindow(), &m_state, m_camera, m_gui, frameTime);
116 commandBuffer = m_renderer.beginFrame();
118 m_camera.setViewXYZ(m_camera.transform.translation, m_camera.transform.rotation);
119 m_camera.setPerspectiveProjection(m_renderer.getAspectRatio());
121 if (commandBuffer !=
nullptr) {
122 frameIndex = m_renderer.getFrameIndex();
123 m_framePools[frameIndex]->resetPool();
126 .frameTime=frameTime,
127 .commandBuffer=commandBuffer,
129 .globalDescriptorSet=globalDescriptorSets[frameIndex],
130 .frameDescriptorPool=*m_framePools[frameIndex],
131 .objects=m_sceneManager.getObjects(),
132 .lights=m_sceneManager.getLights()
134 ubo.projection=m_camera.getProjection();
135 ubo.view=m_camera.getView();
136 ubo.inverseView=m_camera.getInverseView();
137 m_sceneManager.updateBuffer(ubo, frameIndex, frameTime);
138 uboBuffers.at(frameIndex)->writeToBuffer(&ubo);
139 uboBuffers.at(frameIndex)->flush();
140 m_renderer.beginSwapChainRenderPass(frameInfo.commandBuffer);
141 objectRenderSystem.
render(frameInfo);
142 pointLightRenderSystem.
render(frameInfo);
144 if (m_gui.getState() !=
HIDDEN) {
149 m_device.getPhysicalDevice(),
151 { .deltaTimeMS=clock.getDeltaTimeMS(), .fps=clock.getFPS() }
155 m_renderer.endSwapChainRenderPass(commandBuffer);
156 m_renderer.endFrame();
157 commandBuffer =
nullptr;
159 if (m_sceneManager.getDestroyState()) {
160 vkDeviceWaitIdle(m_device.device());
161 m_sceneManager.destroyEntity(m_gui.getObjectsToRemove(), m_gui.getLightsToRemove());
164 vkDeviceWaitIdle(m_device.device());