| 1 | #pragma once |
| 2 | |
| 3 | #if defined(_WIN64) |
| 4 | #define VK_USE_PLATFORM_WIN32_KHR |
| 5 | #elif defined(__APPLE__) |
| 6 | #define VK_USE_PLATFORM_METAL_EXT |
| 7 | #else |
| 8 | #define VK_USE_PLATFORM_XCB_KHR |
| 9 | #endif |
| 10 | #define GLFW_INCLUDE_VULKAN |
| 11 | #include <GLFW/glfw3.h> |
| 12 | |
| 13 | #if defined(_WIN64) |
| 14 | #define GLFW_EXPOSE_NATIVE_WIN32 |
| 15 | #elif defined(__APPLE__) |
| 16 | #define GLFW_EXPOSE_NATIVE_COCOA |
| 17 | #else |
| 18 | #define GLFW_EXPOSE_NATIVE_X11 |
| 19 | #endif |
| 20 | #include <GLFW/glfw3native.h> |
| 21 | |
| 22 | #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 |
| 23 | #include <vulkan/vulkan.hpp> |
| 24 | #pragma endregion |
| 25 | |
| 26 | #define GLM_FORCE_RADIANS |
| 27 | #include <glm/glm.hpp> |
| 28 | #include <glm/gtc/matrix_transform.hpp> |
| 29 | |
| 30 | struct Vertex { |
| 31 | glm::vec2 pos; |
| 32 | glm::vec3 col; |
| 33 | glm::vec2 texCoord; |
| 34 | |
| 35 | static vk::VertexInputBindingDescription getBindingDescription() { |
| 36 | vk::VertexInputBindingDescription desc; |
| 37 | desc.binding = 0; |
| 38 | desc.stride = sizeof(Vertex); |
| 39 | desc.inputRate = vk::VertexInputRate::eVertex; |
| 40 | return desc; |
| 41 | } |
| 42 | |
| 43 | static std::array<vk::VertexInputAttributeDescription, 3> getAttributeDescriptions() { |
| 44 | std::array<vk::VertexInputAttributeDescription, 3> descs; |
| 45 | { |
| 46 | vk::VertexInputAttributeDescription desc; |
| 47 | desc.location = 0; |
| 48 | desc.binding = 0; |
| 49 | desc.format = vk::Format::eR32G32Sfloat; |
| 50 | desc.offset = offsetof(Vertex, pos); |
| 51 | descs[0] = desc; |
| 52 | } |
| 53 | { |
| 54 | vk::VertexInputAttributeDescription desc; |
| 55 | desc.location = 1; |
| 56 | desc.binding = 0; |
| 57 | desc.format = vk::Format::eR32G32B32Sfloat; |
| 58 | desc.offset = offsetof(Vertex, col); |
| 59 | descs[1] = desc; |
| 60 | } |
| 61 | { |
| 62 | vk::VertexInputAttributeDescription desc; |
| 63 | desc.location = 2; |
| 64 | desc.binding = 0; |
| 65 | desc.format = vk::Format::eR32G32Sfloat; |
| 66 | desc.offset = offsetof(Vertex, texCoord); |
| 67 | descs[2] = desc; |
| 68 | } |
| 69 | |
| 70 | return descs; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | inline const std::vector<Vertex> vertices = { |
| 75 | {{ -0.5f, -0.5f }, { 1.f, 0.f, 0.f }, { 1.f, 0.f }}, |
| 76 | {{ 0.5f, -0.5f }, { 0.f, 1.f, 0.f }, { 0.f, 0.f }}, |
| 77 | {{ 0.5f, 0.5f }, { 0.f, 0.f, 1.f }, { 0.f, 1.f }}, |
| 78 | {{ -0.5f, 0.5f }, { 1.f, 1.f, 0.f }, { 1.f, 1.f }}, |
| 79 | }; |
| 80 | |
| 81 | inline const std::vector<uint16_t> indices = { |
| 82 | 0, 1, 2, |
| 83 | 2, 3, 0, |
| 84 | }; |
| 85 | |
| 86 | struct UniformBufferObject { |
| 87 | alignas(16) glm::mat4 model; |
| 88 | alignas(16) glm::mat4 view; |
| 89 | alignas(16) glm::mat4 proj; |
| 90 | }; |