scop
a small 3D object loader
Loading...
Searching...
No Matches
VulkanApp.hpp
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* VulkanApp.hpp :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rbourgea <rbourgea@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/01/09 08:57:56 by rbourgea #+# #+# */
9/* Updated: 2024/04/13 15:12:16 by rbourgea ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#ifndef VULKAN_APP_HPP
14#define VULKAN_APP_HPP
15
16#define GLFW_INCLUDE_VULKAN
17#include <GLFW/glfw3.h>
18
19#include <unordered_map>
20#include <filesystem>
21#include <algorithm>
22#include <stdexcept>
23#include <optional>
24#include <iostream>
25#include <fstream>
26#include <cstring>
27#include <cstdlib>
28#include <cstdint>
29#include <sstream>
30#include <iomanip>
31#include <vector>
32#include <chrono>
33#include <limits>
34#include <array>
35#include <set>
36
37#define MATH_FORCE_DEPTH_ZERO_TO_ONE
38#include "Math.hpp"
39#include "Image.hpp"
40
41inline const char* TITLE = "scop";
42const uint32_t WIDTH = 800;
43const uint32_t HEIGHT = 600;
44
46
47const std::vector<const char*> validationLayers = {
48 "VK_LAYER_KHRONOS_validation",
49#ifdef __linux__
50 "VK_LAYER_MESA_overlay", // display fps
51#endif
52};
53
54const std::vector<const char*> deviceExtensions = {
55 VK_KHR_SWAPCHAIN_EXTENSION_NAME
56};
57
58#ifdef DEBUG
59 constexpr bool debugMode = true;
60#else
61 constexpr bool debugMode = false;
62#endif
63
64VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger);
65void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
66
68 std::optional<uint32_t> graphicsFamily;
69 std::optional<uint32_t> presentFamily;
70
71 bool isComplete() {
72 return graphicsFamily.has_value() && presentFamily.has_value();
73 }
74};
75
77 VkSurfaceCapabilitiesKHR capabilities;
78 std::vector<VkSurfaceFormatKHR> formats;
79 std::vector<VkPresentModeKHR> presentModes;
80};
81
87
94
95struct Vertex {
102 float dissolveTexture{1.0};
103
104 std::string material_name;
106
107 static VkVertexInputBindingDescription getBindingDescription() {
108 VkVertexInputBindingDescription bindingDescription{};
109 bindingDescription.binding = 0;
110 bindingDescription.stride = sizeof(Vertex);
111 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
112
113 return bindingDescription;
114 }
115
116 static std::array<VkVertexInputAttributeDescription, 7> getAttributeDescriptions() {
117 std::array<VkVertexInputAttributeDescription, 7> attributeDescriptions{};
118
119 attributeDescriptions[0].binding = 0;
120 attributeDescriptions[0].location = 0;
121 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
122 attributeDescriptions[0].offset = offsetof(Vertex, pos);
123
124 attributeDescriptions[1].binding = 0;
125 attributeDescriptions[1].location = 1;
126 attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
127 attributeDescriptions[1].offset = offsetof(Vertex, color);
128
129 attributeDescriptions[2].binding = 0;
130 attributeDescriptions[2].location = 2;
131 attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
132 attributeDescriptions[2].offset = offsetof(Vertex, texCoord);
133
134 attributeDescriptions[3].binding = 0;
135 attributeDescriptions[3].location = 3;
136 attributeDescriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT;
137 attributeDescriptions[3].offset = offsetof(Vertex, ambientColor);
138
139 attributeDescriptions[4].binding = 0;
140 attributeDescriptions[4].location = 4;
141 attributeDescriptions[4].format = VK_FORMAT_R32G32B32_SFLOAT;
142 attributeDescriptions[4].offset = offsetof(Vertex, specularColor);
143
144 attributeDescriptions[5].binding = 0;
145 attributeDescriptions[5].location = 5;
146 attributeDescriptions[5].format = VK_FORMAT_R32_SFLOAT;
147 attributeDescriptions[5].offset = offsetof(Vertex, dissolveFactor);
148
149 attributeDescriptions[6].binding = 0;
150 attributeDescriptions[6].location = 6;
151 attributeDescriptions[6].format = VK_FORMAT_R32_SFLOAT;
152 attributeDescriptions[6].offset = offsetof(Vertex, dissolveTexture);
153
154 return attributeDescriptions;
155 }
156};
157
159 alignas(16) mat4 model;
160 alignas(16) mat4 view;
161 alignas(16) mat4 proj;
162};
163
164// const std::vector<Vertex> vertices = {
165// {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
166// {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
167// {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
168// {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}
169// };
170
171// const std::vector<uint32_t> indices = {
172// 0, 1, 2, 2, 3, 0
173// };
174
175// const std::vector<Vertex> vertices = {
176// {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
177// {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
178// {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
179// {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}},
180
181// {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}},
182// {{0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
183// {{0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}},
184// {{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}}
185// };
186
187// const std::vector<uint32_t> indices = {
188// 0, 1, 2, 2, 3, 0,
189// 4, 5, 6, 6, 7, 4
190// };
191
193public:
194 void run(const std::string& objFile1);
195
196private:
197 GLFWwindow* window;
198
200 vec3(5.0f, 0.0f, 5.0f),
201 vec3(0.0f, 0.0f, 0.0f),
202 vec3(0.0f, 1.0f, 0.0f)
203 };
204
207
208 // Bounding Box
210
211 double lastMouseX = 0.0;
212 double lastMouseY = 0.0;
213 bool mouseDrag = false;
214 bool disable_textures = false;
215 bool transition_over = true;
216
225
227
228 std::vector<Vertex> vertices;
229 std::vector<uint32_t> indices;
230
231 VkInstance instance;
232 VkDebugUtilsMessengerEXT debugMessenger;
233 VkSurfaceKHR surface;
234
235 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
236 VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
237 VkDevice device;
238
241
242 VkSwapchainKHR swapChain;
243 std::vector<VkImage> swapChainImages;
245 VkExtent2D swapChainExtent;
246 std::vector<VkImageView> swapChainImageViews;
247 std::vector<VkFramebuffer> swapChainFramebuffers;
248
249 VkRenderPass renderPass;
250 VkDescriptorSetLayout descriptorSetLayout;
251 VkPipelineLayout pipelineLayout;
253
254 VkImage depthImage;
255 VkDeviceMemory depthImageMemory;
256 VkImageView depthImageView;
257
258 uint32_t mipLevels;
260 VkDeviceMemory textureImageMemory;
261 VkImageView textureImageView;
262 VkSampler textureSampler;
263
264 VkBuffer vertexBuffer;
265 VkDeviceMemory vertexBufferMemory;
266 VkBuffer indexBuffer;
267 VkDeviceMemory indexBufferMemory;
268
269 std::vector<VkBuffer> uniformBuffers;
270 std::vector<VkDeviceMemory> uniformBuffersMemory;
271 std::vector<void*> uniformBuffersMapped;
272
273 VkDescriptorPool descriptorPool;
274 std::vector<VkDescriptorSet> descriptorSets;
275
276 VkCommandPool commandPool;
277 std::vector<VkCommandBuffer> commandBuffers;
278
279 VkImage colorImage;
280 VkDeviceMemory colorImageMemory;
281 VkImageView colorImageView;
282
283 std::vector<VkSemaphore> imageAvailableSemaphores;
284 std::vector<VkSemaphore> renderFinishedSemaphores;
285 std::vector<VkFence> inFlightFences;
286 size_t currentFrame = 0;
287
288 bool framebufferResized = false;
289
290 VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
291
292 /* ================================= **
293 ** Vulkan initialization **
294 ** File: VulkanInit.cpp **
295 ** ================================= */
296 void initWindow();
297 void initVulkan();
298 void mainLoop();
299
301 std::vector<const char*> getRequiredExtensions();
302 void createInstance();
303 void createSurface();
304
305 bool checkDeviceExtensionSupport(VkPhysicalDevice device);
306 bool isDeviceSuitable(VkPhysicalDevice device);
307 void pickPhysicalDevice();
308 void createLogicalDevice();
309
310 VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes);
311 VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
313 void createSwapChain();
314 void recreateSwapChain();
315
316 /* ================================= **
317 ** Vulkan cleaning **
318 ** File: VulkanClean.cpp **
319 ** ================================= */
320 void cleanup();
321 void cleanupSwapChain();
322 void cleanupVertexBuffer();
323
324 /* ================================= **
325 ** Vulkan debug logs **
326 ** File: VulkanDebug.cpp **
327 ** ================================= */
328 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
329 void setupDebugMessenger();
330
331 /* ================================= **
332 ** Vulkan graphics pipeline **
333 ** File: VulkanPipeline.cpp **
334 ** ================================= */
335 void createRenderPass();
336 VkShaderModule createShaderModule(const std::vector<char>& code);
340 void updateUniformBuffer(uint32_t currentImage);
343
344 /* ================================= **
345 ** Vulkan render **
346 ** File: VulkanRender.cpp **
347 ** ================================= */
348 void createFramebuffers();
349 void createCommandPool();
351 void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);
352 void createSyncObjects();
353 void drawFrame();
354 VkCommandBuffer beginSingleTimeCommands();
355 void endSingleTimeCommands(VkCommandBuffer commandBuffer);
358
359 /* ================================= **
360 ** Vertex buffers **
361 ** File: VulkanVertex.cpp **
362 ** ================================= */
363 void createVertexBuffer();
364 void updateVertexBuffer();
365 uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
366 void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer& buffer, VkDeviceMemory& bufferMemory);
367 void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
368
369 /* ================================= **
370 ** Index buffers **
371 ** File: VulkanIndex.cpp **
372 ** ================================= */
373 void createIndexBuffer();
374
375 /* ================================= **
376 ** Images and Textures **
377 ** File: VulkanTexture.cpp **
378 ** ================================= */
379 void createTextureImage();
380 void generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels);
381 void createImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory);
382 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels);
383 void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);
384 void createImageViews();
385 VkSampleCountFlagBits getMaxUsableSampleCount();
387 VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels);
389 VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling, VkFormatFeatureFlags features);
390 VkFormat findDepthFormat();
391 bool hasStencilComponent(VkFormat format);
392
393 /* ================================= **
394 ** Parsing files **
395 ** File: Parsing.cpp **
396 ** ================================= */
397 void parseObjFile(const std::string& filename);
398 void parseMtlFile(const std::string& objFilePath, const std::string& mtlFilename);
399 static std::vector<char> readFile(const std::string& filename);
400
401 static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
402 (void)scancode;
403 auto app = reinterpret_cast<VulkanApp*>(glfwGetWindowUserPointer(window));
404
405 if ((action == GLFW_PRESS || action == GLFW_REPEAT) && !(mods & GLFW_MOD_SHIFT)) {
406 switch (key) {
407 // CameraView Center
408 case GLFW_KEY_UP:
409 app->cameraView.center += vec3(0, 1, 0);
410 break;
411 case GLFW_KEY_DOWN:
412 app->cameraView.center += vec3(0, -1, 0);
413 break;
414 case GLFW_KEY_LEFT:
415 app->cameraView.center += vec3(0, 0, 1);
416 break;
417 case GLFW_KEY_RIGHT:
418 app->cameraView.center += vec3(0, 0, -1);
419 break;
420 // Position X, Y, Z
421 case GLFW_KEY_1:
422 app->positionModel += vec3(1.0f, 0.0f, 0.0f);
423 break;
424 case GLFW_KEY_2:
425 app->positionModel += vec3(0.0f, 1.0f, 0.0f);
426 break;
427 case GLFW_KEY_3:
428 app->positionModel += vec3(0.0f, 0.0f, 1.0f);
429 break;
430 // Rotation X, Y, Z
431 case GLFW_KEY_4:
432 app->rotationModel += vec3(1.0f, 0.0f, 0.0f);
433 break;
434 case GLFW_KEY_5:
435 app->rotationModel += vec3(0.0f, 1.0f, 0.0f);
436 break;
437 case GLFW_KEY_6:
438 app->rotationModel += vec3(0.0f, 0.0f, 1.0f);
439 break;
440 // RESET
441 case GLFW_KEY_SPACE:
442 app->positionModel = vec3(0.0f, 0.0f, 0.0f);
443 app->rotationModel = vec3(0.0f, 0.0f, 0.0f);
444 app->cameraView.center = vec3(0.0f, 0.0f, 0.0f);
445 break;
446 // Black Color
447 case GLFW_KEY_0:
448 for (auto& vertex : app->vertices) {
449 if (app->colorMode == NONE)
450 vertex.original_color = vertex.color;
451 vertex.color = vec3(0, 0, 0);
452 }
453 app->colorMode = BLACK;
454 app->updateVertexBuffer();
455 break;
456 // RGB COLORS
457 case GLFW_KEY_R:
458 for (auto& vertex : app->vertices) {
459 if (app->colorMode == NONE)
460 vertex.original_color = vertex.color;
461 vertex.color = vec3(1, 0.3, 0.3);
462 }
463 app->updateVertexBuffer();
464 app->colorMode = RED;
465 break;
466 case GLFW_KEY_G:
467 for (auto& vertex : app->vertices) {
468 if (app->colorMode == NONE)
469 vertex.original_color = vertex.color;
470 vertex.color = vec3(0.3, 1, 0.3);
471 }
472 app->colorMode = GREEN;
473 app->updateVertexBuffer();
474 break;
475 case GLFW_KEY_B:
476 for (auto& vertex : app->vertices) {
477 if (app->colorMode == NONE)
478 vertex.original_color = vertex.color;
479 vertex.color = vec3(0.3, 0.3, 1);
480 }
481 app->colorMode = BLUE;
482 app->updateVertexBuffer();
483 break;
484 case GLFW_KEY_D:
485 app->enableDarkMode();
486 app->updateVertexBuffer();
487 break;
488 case GLFW_KEY_M:
489 app->disable_textures = !app->disable_textures;
490 app->transition_over = false;
491 break;
492 case GLFW_KEY_N:
493 if (app->colorMode != NONE) {
494 app->colorMode = NONE;
495
496 for (auto& vertex : app->vertices) {
497 vertex.color = vertex.original_color;
498 }
499 app->updateVertexBuffer();
500 }
501 break;
502 case GLFW_KEY_T:
503 if (app->topology == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) {
504 app->topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
505 } else if (app->topology == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) {
506 app->topology = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
507 } else {
508 app->topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
509 }
510 vkDestroyPipeline(app->device, app->graphicsPipeline, nullptr);
511 app->createGraphicsPipeline();
512 break;
513 default:
514 break;
515 }
516 } else if ((action == GLFW_PRESS || action == GLFW_REPEAT) && (mods & GLFW_MOD_SHIFT)) {
517 switch (key) {
518 // Position X, Y, Z
519 case GLFW_KEY_1:
520 app->positionModel += vec3(-1.0f, 0.0f, 0.0f);
521 break;
522 case GLFW_KEY_2:
523 app->positionModel += vec3(0.0f, -1.0f, 0.0f);
524 break;
525 case GLFW_KEY_3:
526 app->positionModel += vec3(0.0f, 0.0f, -1.0f);
527 break;
528 // Rotation X, Y, Z
529 case GLFW_KEY_4:
530 app->rotationModel += vec3(-1.0f, 0.0f, 0.0f);
531 break;
532 case GLFW_KEY_5:
533 app->rotationModel += vec3(0.0f, -1.0f, 0.0f);
534 break;
535 case GLFW_KEY_6:
536 app->rotationModel += vec3(0.0f, 0.0f, -1.0f);
537 break;
538 default:
539 break;
540 }
541 }
542 }
543
544 static void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods) {
545 (void)mods;
546 VulkanApp* app = reinterpret_cast<VulkanApp*>(glfwGetWindowUserPointer(window));
547
548 if (button == GLFW_MOUSE_BUTTON_LEFT) {
549 if (action == GLFW_PRESS) {
550 app->mouseDrag = true;
551 glfwGetCursorPos(window, &app->lastMouseX, &app->lastMouseY);
552 } else if (action == GLFW_RELEASE) {
553 app->mouseDrag = false;
554 }
555 }
556 }
557
558 static void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
559 VulkanApp* app = reinterpret_cast<VulkanApp*>(glfwGetWindowUserPointer(window));
560
561 if (app->mouseDrag) {
562 float deltaX = static_cast<float>(xpos - app->lastMouseX);
563 float deltaY = static_cast<float>(ypos - app->lastMouseY);
564
565 app->rotationModel.x += deltaY * -0.1f;
566 app->rotationModel.y += deltaX * -0.1f;
567
568 app->lastMouseX = xpos;
569 app->lastMouseY = ypos;
570 }
571 }
572
575
576 uint32_t queueFamilyCount = 0;
577 vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);
578
579 std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
580 vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());
581
582 int i = 0;
583 for (const auto& queueFamily : queueFamilies) {
584 if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
585 indices.graphicsFamily = i;
586 }
587
588 VkBool32 presentSupport = false;
589 vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
590
591 if (presentSupport) {
592 indices.presentFamily = i;
593 }
594
595 if (indices.isComplete()) {
596 break;
597 }
598
599 i++;
600 }
601
602 return indices;
603 }
604
605 static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData) {
606 (void)messageSeverity;
607 (void)messageType;
608 (void)pUserData;
609 std::cerr << "- Validation layer: " << pCallbackData->pMessage << std::endl;
610 return VK_FALSE;
611 }
612
613 static void framebufferResizeCallback(GLFWwindow* window, int width, int height) {
614 (void)width;
615 (void)height;
616 auto app = reinterpret_cast<VulkanApp*>(glfwGetWindowUserPointer(window));
617 app->framebufferResized = true;
618 }
619
620 void transitionTextures();
621 void enableDarkMode();
622};
623
624#endif
const uint32_t WIDTH
Definition VulkanApp.hpp:42
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks *pAllocator)
const int MAX_FRAMES_IN_FLIGHT
Definition VulkanApp.hpp:45
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pDebugMessenger)
const std::vector< const char * > validationLayers
Definition VulkanApp.hpp:47
constexpr bool debugMode
Definition VulkanApp.hpp:61
const std::vector< const char * > deviceExtensions
Definition VulkanApp.hpp:54
const uint32_t HEIGHT
Definition VulkanApp.hpp:43
const char * TITLE
Definition VulkanApp.hpp:41
static std::vector< char > readFile(const std::string &filename)
Definition Parsing.cpp:258
void createCommandPool()
void createDescriptorSets()
std::vector< uint32_t > indices
void createDepthResources()
GLFWwindow * window
uint32_t mipLevels
Camera cameraView
VkSampleCountFlagBits msaaSamples
VkDevice device
void createVertexBuffer()
void createGraphicsPipeline()
static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device)
VkImageView textureImageView
void createImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image, VkDeviceMemory &imageMemory)
void updateVertexBuffer()
std::vector< VkDeviceMemory > uniformBuffersMemory
VkPhysicalDevice physicalDevice
void createColorResources()
bool mouseDrag
VkQueue presentQueue
VkFormat findSupportedFormat(const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
void createSwapChain()
void drawFrame()
void recreateSwapChain()
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size)
void cleanupVertexBuffer()
std::vector< VkSemaphore > renderFinishedSemaphores
VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels)
VkBuffer indexBuffer
void createTextureImageView()
void cleanupSwapChain()
VkRenderPass renderPass
static void cursorPosCallback(GLFWwindow *window, double xpos, double ypos)
VkSurfaceKHR surface
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties)
bool checkValidationLayerSupport()
VkSampler textureSampler
VkShaderModule createShaderModule(const std::vector< char > &code)
VkImage textureImage
VkDeviceMemory textureImageMemory
vec3 modelCentroid
VkQueue graphicsQueue
std::vector< VkImage > swapChainImages
VkDeviceMemory colorImageMemory
VkPresentModeKHR chooseSwapPresentMode(const std::vector< VkPresentModeKHR > &availablePresentModes)
void run(const std::string &objFile1)
ColorMode colorMode
std::vector< VkFence > inFlightFences
std::vector< VkCommandBuffer > commandBuffers
VkPipelineLayout pipelineLayout
void pickPhysicalDevice()
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory)
std::vector< VkFramebuffer > swapChainFramebuffers
void createDescriptorSetLayout()
void transitionTextures()
VkExtent2D swapChainExtent
VkPipeline graphicsPipeline
std::vector< VkSemaphore > imageAvailableSemaphores
VkDescriptorPool descriptorPool
static void framebufferResizeCallback(GLFWwindow *window, int width, int height)
void createInstance()
vec3 rotationModel
VkImage colorImage
std::vector< VkBuffer > uniformBuffers
void createTextureImage()
void parseMtlFile(const std::string &objFilePath, const std::string &mtlFilename)
Definition Parsing.cpp:172
void setupDebugMessenger()
VkInstance instance
bool hasStencilComponent(VkFormat format)
std::vector< const char * > getRequiredExtensions()
void createIndexBuffer()
void parseObjFile(const std::string &filename)
Definition Parsing.cpp:15
bool checkDeviceExtensionSupport(VkPhysicalDevice device)
VkDeviceMemory indexBufferMemory
void createImageViews()
VkBuffer vertexBuffer
VkDebugUtilsMessengerEXT debugMessenger
bool isDeviceSuitable(VkPhysicalDevice device)
bool framebufferResized
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height)
void enableDarkMode()
VkCommandBuffer beginSingleTimeCommands()
VkDeviceMemory vertexBufferMemory
void initWindow()
VkImage depthImage
VkDeviceMemory depthImageMemory
VkFormat findDepthFormat()
void createCommandBuffers()
void initVulkan()
void cleanup()
VkPrimitiveTopology topology
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
VkCommandPool commandPool
VkImageView colorImageView
double lastMouseX
void createUniformBuffers()
double lastMouseY
std::vector< VkDescriptorSet > descriptorSets
VkImageView depthImageView
void endSingleTimeCommands(VkCommandBuffer commandBuffer)
void createSyncObjects()
void createLogicalDevice()
void createFramebuffers()
void createTextureSampler()
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels)
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device)
std::vector< Vertex > vertices
void mainLoop()
std::vector< void * > uniformBuffersMapped
std::vector< VkImageView > swapChainImageViews
void generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels)
void createDescriptorPool()
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities)
void updateUniformBuffer(uint32_t currentImage)
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex)
bool disable_textures
void createRenderPass()
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
vec3 positionModel
VkSwapchainKHR swapChain
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
bool transition_over
VkDescriptorSetLayout descriptorSetLayout
VkFormat swapChainImageFormat
size_t currentFrame
void createSurface()
VkSampleCountFlagBits getMaxUsableSampleCount()
Definition Math.hpp:172
Definition Math.hpp:19
Definition Math.hpp:65
float x
Definition Math.hpp:67
float y
Definition Math.hpp:67
vec3 center
Definition VulkanApp.hpp:84
vec3 eye
Definition VulkanApp.hpp:83
vec3 up
Definition VulkanApp.hpp:85
vec3 diffuse
Definition VulkanApp.hpp:90
float dissolve
Definition VulkanApp.hpp:92
vec3 ambient
Definition VulkanApp.hpp:89
vec3 specular
Definition VulkanApp.hpp:91
std::optional< uint32_t > graphicsFamily
Definition VulkanApp.hpp:68
std::optional< uint32_t > presentFamily
Definition VulkanApp.hpp:69
std::vector< VkSurfaceFormatKHR > formats
Definition VulkanApp.hpp:78
VkSurfaceCapabilitiesKHR capabilities
Definition VulkanApp.hpp:77
std::vector< VkPresentModeKHR > presentModes
Definition VulkanApp.hpp:79
vec3 color
Definition VulkanApp.hpp:97
vec3 ambientColor
Definition VulkanApp.hpp:99
vec2 texCoord
Definition VulkanApp.hpp:98
float dissolveTexture
vec3 specularColor
float dissolveFactor
std::string material_name
static VkVertexInputBindingDescription getBindingDescription()
static std::array< VkVertexInputAttributeDescription, 7 > getAttributeDescriptions()
vec3 pos
Definition VulkanApp.hpp:96
vec3 original_color