Compare commits
23 Commits
24a6e0086b
..
camera
| Author | SHA1 | Date | |
|---|---|---|---|
| 6bc2ea1650 | |||
| 318263051a | |||
| 01d558539d | |||
| 9e325ed1c8 | |||
| 76ea39b784 | |||
| ce8bc3a96b | |||
| 2f485d11e6 | |||
| a4a1847f95 | |||
| edc4931b67 | |||
| b458f432ff | |||
| 6d986f496e | |||
| 881a43177e | |||
| 80012fc7e7 | |||
| 45b362be82 | |||
| b1c47589bc | |||
| 997e32f9bf | |||
| 71be91d2b1 | |||
| 3562c0308a | |||
| 49d32224af | |||
| cf88fecf08 | |||
| 8e0234c1fb | |||
| e2e84eb42c | |||
| aa91619805 |
+22
-9
@@ -7,26 +7,41 @@ set(GLFW_USE_WAYLAND ON)
|
||||
find_package(Vulkan REQUIRED)
|
||||
find_package(glfw3 3.3 REQUIRED)
|
||||
|
||||
# Suche nach dem glslc Compiler
|
||||
find_program(GLSLC glslc)
|
||||
if(NOT GLSLC)
|
||||
message(FATAL_ERROR "glslc compiler not found. Please install the Vulkan SDK.")
|
||||
endif()
|
||||
|
||||
# Alle Shader-Dateien im Verzeichnis ./shaders sammeln
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/textures)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/models)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/shaders)
|
||||
|
||||
# Copy textures into cmake output
|
||||
file(GLOB TEXTURE_FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/textures/*"
|
||||
)
|
||||
foreach(TEXTURE ${TEXTURE_FILES})
|
||||
file(COPY ${TEXTURE_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/textures/")
|
||||
endforeach()
|
||||
|
||||
# Copy models into cmake output
|
||||
file(GLOB MODEL_FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/models/*"
|
||||
)
|
||||
foreach(MODEL ${MODEL_FILES})
|
||||
file(COPY ${MODEL_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/models/")
|
||||
endforeach()
|
||||
|
||||
# Copy shaders into cmake output
|
||||
file(GLOB SHADER_FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.frag"
|
||||
)
|
||||
|
||||
set(SPIRV_SHADERS "")
|
||||
foreach(SHADER ${SHADER_FILES})
|
||||
# Dateiname extrahieren
|
||||
get_filename_component(SHADER_NAME ${SHADER} NAME)
|
||||
# Zielpfad für die kompilierten Shader im Build-Verzeichnis
|
||||
set(SPIRV "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.spv")
|
||||
|
||||
# Custom Command zum Kompilieren des Shaders
|
||||
add_custom_command(
|
||||
OUTPUT ${SPIRV}
|
||||
COMMAND ${GLSLC} ${SHADER} -o ${SPIRV}
|
||||
@@ -37,17 +52,15 @@ foreach(SHADER ${SHADER_FILES})
|
||||
list(APPEND SPIRV_SHADERS ${SPIRV})
|
||||
endforeach()
|
||||
|
||||
# Custom Target, das alle Shader kompiliert
|
||||
add_custom_target(compile_shaders ALL DEPENDS ${SPIRV_SHADERS})
|
||||
|
||||
# Das eigentliche Executable
|
||||
add_executable(vulkan_test
|
||||
main.cpp
|
||||
vulkan/vulkan_app.cpp
|
||||
vulkan/vulkan_glfw_events.cpp
|
||||
vulkan/vulkan_app.hpp
|
||||
)
|
||||
|
||||
target_link_libraries(vulkan_test PRIVATE Vulkan::Vulkan glfw)
|
||||
|
||||
# Sicherstellen, dass die Shader vor dem Bauen des Executables kompiliert werden
|
||||
add_dependencies(vulkan_test compile_shaders)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# Vulkan_TestApp
|
||||
|
||||
Triangle Test App with Vulkan API strictly following documentation.
|
||||
Test App with Vulkan API strictly following documentation.
|
||||
@@ -0,0 +1,2 @@
|
||||
// Camera.cpp
|
||||
#include "camera.hpp"
|
||||
@@ -0,0 +1,71 @@
|
||||
// Camera.hpp
|
||||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace vapp{
|
||||
enum Camera_Movement{
|
||||
FORWARD,
|
||||
BACKWARD,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
UP,
|
||||
DOWN,
|
||||
};
|
||||
|
||||
class Camera{
|
||||
public:
|
||||
float Yaw = -90.0f, Pitch = 0.0f;
|
||||
float MovementSpeed = 2.5f;
|
||||
float MouseSensitivity = 0.1f;
|
||||
float Zoom = 45.0f;
|
||||
|
||||
glm::vec3 Position, Front, Up, Right, WorldUp;
|
||||
|
||||
Camera(glm::vec3 pos = {0, 0, 3}, glm::vec3 up = {0, 1, 0})
|
||||
: Position(pos), WorldUp(up), Front({0, 0, -1}){ updateCameraVectors(); }
|
||||
|
||||
glm::mat4 GetViewMatrix(){
|
||||
return glm::lookAt(Position, Position + Front, Up);
|
||||
}
|
||||
|
||||
void ProcessKeyboard(Camera_Movement dir, float dt){
|
||||
float v = MovementSpeed * dt;
|
||||
if(dir == FORWARD) Position += Front * v;
|
||||
if(dir == BACKWARD) Position -= Front * v;
|
||||
if(dir == LEFT) Position -= Right * v;
|
||||
if(dir == RIGHT) Position += Right * v;
|
||||
if(dir == UP) Position += Up * v;
|
||||
if(dir == DOWN) Position -= Up * v;
|
||||
}
|
||||
|
||||
void ProcessMouseMovement(float xoff, float yoff, bool constrainPitch = true){
|
||||
xoff *= MouseSensitivity;
|
||||
yoff *= MouseSensitivity;
|
||||
Yaw += xoff;
|
||||
Pitch += yoff;
|
||||
if(constrainPitch){
|
||||
if(Pitch > 89.0f) Pitch = 89.0f;
|
||||
if(Pitch < -89.0f) Pitch = -89.0f;
|
||||
}
|
||||
updateCameraVectors();
|
||||
}
|
||||
|
||||
void ProcessMouseScroll(float yoff){
|
||||
Zoom -= yoff;
|
||||
if(Zoom < 1.0f) Zoom = 1.0f;
|
||||
if(Zoom > 45.0f) Zoom = 45.0f;
|
||||
}
|
||||
|
||||
private:
|
||||
void updateCameraVectors(){
|
||||
glm::vec3 f;
|
||||
f.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
f.y = sin(glm::radians(Pitch));
|
||||
f.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Front = glm::normalize(f);
|
||||
Right = glm::normalize(glm::cross(Front, WorldUp));
|
||||
Up = glm::normalize(glm::cross(Right, Front));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,12 +1,28 @@
|
||||
/**
|
||||
* Required external Libraries:
|
||||
* - Vulkan
|
||||
* - glfw
|
||||
* - glm
|
||||
* - stb
|
||||
* - tinyobjloader
|
||||
*/
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
#include <iostream>
|
||||
#include "vulkan/vulkan_app.hpp"
|
||||
|
||||
int main(){
|
||||
int main(int argc, char **argv){
|
||||
std::cout << "Program path: " << argv[0] << std::endl;
|
||||
try{
|
||||
vapp::Vulkan app;
|
||||
app.run("Vulkan", 1200, 900);
|
||||
|
||||
// app.MODEL_PATH = "models/SMG_Observatory/objects/AstroBaseA.obj";
|
||||
// app.TEXTURE_PATH = "models/SMG_Observatory/objects/AstroBaseA.png";
|
||||
|
||||
app.MODEL_PATH = "models/viking_room.obj";
|
||||
app.TEXTURE_PATH = "textures/viking_room.png";
|
||||
|
||||
app.run("Vulkan", 800, 800);
|
||||
}
|
||||
catch(const std::exception& e){
|
||||
std::cerr << e.what() << std::endl;
|
||||
@@ -14,4 +30,4 @@ int main(){
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+16053
File diff suppressed because it is too large
Load Diff
+5
-1
@@ -1,9 +1,13 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 1) in vec2 fragTexCoord;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(binding = 1) uniform sampler2D texSampler;
|
||||
|
||||
void main(){
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
// outColor = vec4(fragTexCoord, 0.0, 1.0);
|
||||
outColor = texture(texSampler, fragTexCoord);
|
||||
}
|
||||
|
||||
+11
-18
@@ -1,27 +1,20 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 inPosition;
|
||||
layout(set = 0, binding = 0) uniform UniformBufferObject{
|
||||
mat4 model;
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
}ubo;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in vec2 inTexCoord;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
|
||||
/*
|
||||
vec2 positions[3] = vec2[](
|
||||
vec2(0.0, -0.5),
|
||||
vec2(0.5, 0.5),
|
||||
vec2(-0.5, 0.5)
|
||||
);
|
||||
|
||||
vec3 colors[3] = vec3[](
|
||||
vec3(0.0, 1.0, 1.0),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec3(0.0, 0.0, 1.0)
|
||||
);
|
||||
*/
|
||||
layout(location = 1) out vec2 fragTexCoord;
|
||||
|
||||
void main(){
|
||||
// gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
|
||||
// fragColor = colors[gl_VertexIndex];
|
||||
gl_Position = vec4(inPosition, 0.0, 1.0);
|
||||
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
|
||||
fragColor = inColor;
|
||||
fragTexCoord = inTexCoord;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 940 KiB |
+764
-72
File diff suppressed because it is too large
Load Diff
+150
-16
@@ -8,42 +8,52 @@
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#define GLM_FORCE_RADIANS
|
||||
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
|
||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/hash.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <glm/glm.hpp>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../camera/camera.hpp"
|
||||
|
||||
namespace vapp{
|
||||
// Change here for other presentMode
|
||||
const VkPresentModeKHR WISHED_PRESENT_MODE = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
|
||||
struct Vertex{
|
||||
glm::vec2 pos;
|
||||
glm::vec3 pos;
|
||||
glm::vec3 color;
|
||||
glm::vec2 texCoord;
|
||||
|
||||
static VkVertexInputBindingDescription getBindingDescription(){
|
||||
VkVertexInputBindingDescription bindingDescription{};
|
||||
|
||||
bindingDescription.binding = 0;
|
||||
bindingDescription.stride = sizeof(Vertex);
|
||||
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
||||
|
||||
return bindingDescription;
|
||||
}
|
||||
|
||||
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions(){
|
||||
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{};
|
||||
static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions(){
|
||||
std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
|
||||
|
||||
attributeDescriptions[0].binding = 0;
|
||||
attributeDescriptions[0].location = 0;
|
||||
attributeDescriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
|
||||
attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[0].offset = offsetof(Vertex, pos);
|
||||
|
||||
attributeDescriptions[1].binding = 0;
|
||||
@@ -51,15 +61,44 @@ namespace vapp{
|
||||
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
||||
attributeDescriptions[1].offset = offsetof(Vertex, color);
|
||||
|
||||
attributeDescriptions[2].binding = 0;
|
||||
attributeDescriptions[2].location = 2;
|
||||
attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
|
||||
attributeDescriptions[2].offset = offsetof(Vertex, texCoord);
|
||||
|
||||
return attributeDescriptions;
|
||||
}
|
||||
|
||||
bool operator==(const Vertex& other) const{
|
||||
return pos == other.pos && color == other.color && texCoord == other.texCoord;
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Remove
|
||||
/*
|
||||
const std::vector<Vertex> vertices = {
|
||||
{{0.0f, -0.5f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f}, {0.0f, 1.0f, 0.0f}},
|
||||
{{-0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}}
|
||||
{{-0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
|
||||
{{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
|
||||
{{-0.5f, 0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
|
||||
|
||||
{{-0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
|
||||
{{0.5f, -0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
|
||||
{{0.5f, 0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
|
||||
{{-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}}
|
||||
};
|
||||
|
||||
// uint16_t also possible -> change in vkCmdBindIndexBuffer also
|
||||
const std::vector<uint32_t> indices = {
|
||||
0, 1, 2, 2, 3, 0,
|
||||
4, 5, 6, 6, 7, 4
|
||||
};
|
||||
*/
|
||||
// END Remove
|
||||
|
||||
struct UniformBufferObject{
|
||||
alignas(16) glm::mat4 model;
|
||||
alignas(16) glm::mat4 view;
|
||||
alignas(16) glm::mat4 proj;
|
||||
};
|
||||
|
||||
struct QueueFamilyIndices{
|
||||
@@ -83,7 +122,7 @@ namespace vapp{
|
||||
|
||||
class Vulkan{
|
||||
private:
|
||||
#pragma region Fields
|
||||
#pragma region PrivateFields
|
||||
GLFWwindow *window;
|
||||
uint32_t _width, _height;
|
||||
|
||||
@@ -106,6 +145,7 @@ namespace vapp{
|
||||
std::vector<VkImageView> swapChainImageViews;
|
||||
|
||||
VkRenderPass renderPass;
|
||||
VkDescriptorSetLayout descriptorSetLayout;
|
||||
VkPipelineLayout pipelineLayout;
|
||||
|
||||
VkPipeline graphicsPipeline;
|
||||
@@ -121,12 +161,47 @@ namespace vapp{
|
||||
const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
uint32_t currentFrame = 0;
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
VkBuffer vertexBuffer;
|
||||
VkDeviceMemory vertexBufferMemory;
|
||||
VkBuffer indexBuffer;
|
||||
VkDeviceMemory indexBufferMemory;
|
||||
|
||||
std::vector<VkBuffer> uniformBuffers;
|
||||
std::vector<VkDeviceMemory> uniformBuffersMemory;
|
||||
std::vector<void*> uniformBuffersMapped;
|
||||
|
||||
VkDescriptorPool descriptorPool;
|
||||
std::vector<VkDescriptorSet> descriptorSets;
|
||||
|
||||
int32_t mipLevels;
|
||||
VkImage textureImage;
|
||||
VkDeviceMemory textureImageMemory;
|
||||
|
||||
VkImageView textureImageView;
|
||||
VkSampler textureSampler;
|
||||
|
||||
VkImage depthImage;
|
||||
VkDeviceMemory depthImageMemory;
|
||||
VkImageView depthImageView;
|
||||
|
||||
VkImage colorImage;
|
||||
VkDeviceMemory colorImageMemory;
|
||||
VkImageView colorImageView;
|
||||
|
||||
#pragma region GLFWFunctions
|
||||
static void mouseCallback(GLFWwindow *win, double xpos, double ypos);
|
||||
static void scrollCallback(GLFWwindow *win, double xoffset, double yoffset);
|
||||
void processInput();
|
||||
static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
|
||||
#pragma endregion
|
||||
|
||||
#pragma endregion
|
||||
#pragma region PrivateFunctions
|
||||
bool checkValidationLayerSupport();
|
||||
std::vector<const char*> getRequiredExtensions();
|
||||
VkSampleCountFlagBits getMaxUsableSampleCount();
|
||||
|
||||
void createInstance();
|
||||
void setupDebugMessenger();
|
||||
@@ -142,18 +217,46 @@ namespace vapp{
|
||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||
void createSwapChain();
|
||||
void createImageViews();
|
||||
void createDescriptorSetLayout();
|
||||
void createGraphicsPipeline();
|
||||
VkShaderModule createShaderModule(const std::vector<char>& code);
|
||||
void createRenderPass();
|
||||
void createFrameBuffers();
|
||||
void createFramebuffers();
|
||||
void createCommandPool();
|
||||
VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates, VkImageTiling tiling,
|
||||
VkFormatFeatureFlags features);
|
||||
VkFormat findDepthFormat();
|
||||
void createColorResources();
|
||||
void createDepthResources();
|
||||
VkCommandBuffer beginSingleTimeCommands();
|
||||
void endSingleTimeCommands(VkCommandBuffer commandBuffer);
|
||||
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout,
|
||||
uint32_t mipLevels);
|
||||
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);
|
||||
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 generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight,
|
||||
uint32_t mipLevels);
|
||||
void createTextureImage();
|
||||
VkImageView createImageView(VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels);
|
||||
void createTextureImageView();
|
||||
void createTextureSampler();
|
||||
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
||||
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory);
|
||||
void createBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
|
||||
VkBuffer& buffer, VkDeviceMemory& bufferMemory);
|
||||
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
|
||||
void copyBufferOld(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
|
||||
void loadModel();
|
||||
void createVertexBuffer();
|
||||
void createIndexBuffer();
|
||||
void createUniformBuffers();
|
||||
void createDescriptorPool();
|
||||
void createDescriptorSets();
|
||||
void createCommandBuffers();
|
||||
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);
|
||||
void createSyncObjects();
|
||||
void updateUniformBuffer(uint32_t currentFrame);
|
||||
void drawFrame();
|
||||
void cleanupSwapChain();
|
||||
void recreateSwapChain();
|
||||
@@ -161,8 +264,10 @@ namespace vapp{
|
||||
void initVulkan();
|
||||
void mainLoop();
|
||||
void cleanup();
|
||||
#pragma endregion
|
||||
|
||||
public:
|
||||
#pragma region PublicFields
|
||||
#ifdef DEBUG
|
||||
const bool enableValidationLayers = true;
|
||||
#else
|
||||
@@ -170,9 +275,38 @@ namespace vapp{
|
||||
#endif
|
||||
|
||||
bool framebufferResized = false;
|
||||
std::string MODEL_PATH;
|
||||
std::string TEXTURE_PATH;
|
||||
|
||||
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
|
||||
Camera camera;
|
||||
float yaw = -90.0f;
|
||||
float pitch = 0.0f;
|
||||
float lastX = 0.0f, lastY = 0.0f;
|
||||
bool firstMouse = true;
|
||||
float deltaTime = 0.0f, lastFrame = 0.0f;
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(2.0f, 2.0f, 2.0f);
|
||||
glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
glm::vec3 cameraUp = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
#pragma endregion
|
||||
|
||||
#pragma region PublicFunctions
|
||||
void run(const char *windowName, const uint32_t width = 800, const uint32_t height = 600);
|
||||
#pragma endregion
|
||||
};
|
||||
} // vapp
|
||||
|
||||
namespace std{
|
||||
template <>
|
||||
struct hash<vapp::Vertex>{
|
||||
size_t operator()(vapp::Vertex const& vertex) const{
|
||||
return ((hash<glm::vec3>()(vertex.pos) ^
|
||||
(hash<glm::vec3>()(vertex.color) << 1)) >> 1) ^
|
||||
(hash<glm::vec2>()(vertex.texCoord) << 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //VULKAN_APP_H
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "vulkan_app.hpp"
|
||||
|
||||
namespace vapp{
|
||||
void Vulkan::processInput(){
|
||||
float currentFrame = static_cast<float>(glfwGetTime());
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(FORWARD, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(BACKWARD, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(LEFT, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(RIGHT, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(UP, deltaTime);
|
||||
if(glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
|
||||
camera.ProcessKeyboard(DOWN, deltaTime);
|
||||
}
|
||||
|
||||
void Vulkan::keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods){
|
||||
Vulkan *app = static_cast<Vulkan*>(glfwGetWindowUserPointer(window));
|
||||
if(key == GLFW_KEY_LEFT_SHIFT){
|
||||
if(action == GLFW_PRESS)
|
||||
app->camera.MovementSpeed = 5.0f;
|
||||
else if(action == GLFW_RELEASE)
|
||||
app->camera.MovementSpeed = 2.5f;
|
||||
}
|
||||
}
|
||||
|
||||
void Vulkan::mouseCallback(GLFWwindow *window, double xpos, double ypos){
|
||||
auto app = static_cast<Vulkan*>(glfwGetWindowUserPointer(window));
|
||||
if(app->firstMouse){
|
||||
app->lastX = xpos;
|
||||
app->lastY = ypos;
|
||||
app->firstMouse = false;
|
||||
}
|
||||
float xoff = xpos - app->lastX;
|
||||
float yoff = app->lastY - ypos;
|
||||
app->lastX = xpos;
|
||||
app->lastY = ypos;
|
||||
app->camera.ProcessMouseMovement(xoff, yoff);
|
||||
}
|
||||
|
||||
void Vulkan::scrollCallback(GLFWwindow *window, double /*x*/, double yoffset){
|
||||
Vulkan *app = static_cast<Vulkan*>(glfwGetWindowUserPointer(window));
|
||||
app->camera.ProcessMouseScroll(static_cast<float>(yoffset));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user