21 flatVase.
model = model;
28 smoothVase.
model = model;
40 std::vector<glm::vec3> lightColors{
49 for (std::size_t i = 0; i < lightColors.size(); i++)
52 pointLight.
color = lightColors[i];
53 auto rotateLight = rotate(glm::mat4(1.F), (
static_cast<float>(i) * glm::two_pi<float>()) /
static_cast<float>(lightColors.size()), {0.F, -1.F, 0.F});
73 std::chrono::duration<float> deltaTime{};
74 float frameTime = NAN;
77 std::chrono::time_point<std::chrono::system_clock> newTime;
78 std::chrono::time_point<std::chrono::system_clock> currentTime = std::chrono::high_resolution_clock::now();
82 RenderSystem renderSystem(m_device, m_renderer.getSwapChainRenderPass(), globalSetLayout->getDescriptorSetLayout());
83 PointLightSystem pointLightSystem(m_device, m_renderer.getSwapChainRenderPass(), globalSetLayout->getDescriptorSetLayout());
85 for (
auto & uboBuffer : uboBuffers)
87 uboBuffer = std::make_unique<Buffer>(m_device,
sizeof(
GlobalUbo), 1, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
90 for (std::size_t i = 0; i < globalDescriptorSets.size(); i++) {
91 VkDescriptorBufferInfo bufferInfo = uboBuffers[i]->descriptorInfo();
94 camera.setViewTarget(glm::vec3(-1.F, -2.F, -2.F), glm::vec3(0.F, 0.F, 2.5F));
97 while (glfwWindowShouldClose(m_window.getGLFWindow()) == 0)
101 newTime = std::chrono::high_resolution_clock::now();
102 deltaTime = newTime - currentTime;
103 currentTime = newTime;
104 frameTime = deltaTime.count();
105 frameCounter.update(frameTime);
107 cameraController.moveInPlaneXZ(m_window.getGLFWindow(), frameTime, viewerObject);
109 camera.setPerspectiveProjection(glm::radians(50.0F), m_renderer.getAspectRatio(), 0.1F, 100.F);
111 if (VkCommandBuffer_T *commandBuffer = m_renderer.beginFrame())
113 frameIndex = (m_renderer.getFrameIndex());
114 FrameInfo frameInfo{frameIndex, frameTime, commandBuffer, camera, globalDescriptorSets[
static_cast<unsigned long>(frameIndex)], m_objects};
116 ubo.projection = camera.getProjection();
117 ubo.view = camera.getView();
118 ubo.inverseView = camera.getInverseView();
120 uboBuffers[
static_cast<unsigned long>(frameIndex)]->writeToBuffer(&ubo);
121 uboBuffers[
static_cast<unsigned long>(frameIndex)]->flush();
123 m_renderer.beginSwapChainRenderPass(commandBuffer);
125 pointLightSystem.
render(frameInfo);
127 m_renderer.endFrame();
130 vkDeviceWaitIdle(m_device.device());
135 VkApplicationInfo appInfo{};
136 appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
137 appInfo.pApplicationName =
"VEngine App";
138 appInfo.applicationVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
139 appInfo.pEngineName =
"VEngine";
140 appInfo.engineVersion = VK_MAKE_API_VERSION(0, 1, 0, 0);
141 appInfo.apiVersion = VK_API_VERSION_1_0;
142 VkInstanceCreateInfo createInfo{};
143 createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
144 createInfo.pApplicationInfo = &appInfo;
145 uint32_t glfwExtensionCount = 0;
146 const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
147 createInfo.enabledExtensionCount = glfwExtensionCount;
148 createInfo.ppEnabledExtensionNames = glfwExtensions;
150 if (vkCreateInstance(&createInfo,
nullptr, &m_instance) != VK_SUCCESS)
152 throw std::runtime_error(
"Failed to create Vulkan instance");