Compare commits

...

18 Commits

Author SHA1 Message Date
Ano-sys 6bc2ea1650 Added camera 2025-07-04 00:55:50 +02:00
t 318263051a Resize true, cursor disabled 2025-04-08 17:29:26 +02:00
Ano-sys 01d558539d Removed duplicate destroy of instance in cleanup 2025-04-08 17:18:23 +02:00
Ano-sys 9e325ed1c8 Found faulty line where width instead of height was set 2025-04-08 17:17:01 +02:00
t 76ea39b784 Camera and Movementhooks are implemented but Camerarotation is faulty 2025-04-07 23:01:58 +02:00
t ce8bc3a96b Implemented Maximal MSAA 2025-04-07 18:01:31 +02:00
t 2f485d11e6 Implemented Mipmaps 2025-04-07 17:31:34 +02:00
Ano-sys a4a1847f95 Now Models can be loaded 2025-04-06 00:36:45 +02:00
Ano-sys edc4931b67 Removed transitionImageLayout call in createDepthResources because renderPass takes care of this implicitly 2025-04-05 23:41:22 +02:00
Ano-sys b458f432ff Implemented Depth Buffering 2025-04-05 23:37:38 +02:00
Ano-sys 6d986f496e Image is projected onto the sqaure now 2025-04-05 15:04:30 +02:00
Ano-sys 881a43177e Example image of percy 2025-04-05 15:03:36 +02:00
Ano-sys 80012fc7e7 Implemented Sampler with Clamp to Edge (because I like this) and anisotrpic filtering to the graphics cards max 2025-04-05 14:40:32 +02:00
Ano-sys 45b362be82 Texture mapping functionallity implemented 2025-04-05 14:01:42 +02:00
Ano-sys b1c47589bc Added library requirements info at the top 2025-04-05 14:00:50 +02:00
Ano-sys 997e32f9bf Added entries to copy textures to cmake output dir 2025-04-05 14:00:19 +02:00
Ano-sys 71be91d2b1 Added set = 0 to layout for ubo 2025-04-04 18:05:35 +02:00
Ano-sys 3562c0308a Altered readme 2025-04-04 18:05:08 +02:00
13 changed files with 16985 additions and 149 deletions
+22 -9
View File
@@ -7,26 +7,41 @@ set(GLFW_USE_WAYLAND ON)
find_package(Vulkan REQUIRED) find_package(Vulkan REQUIRED)
find_package(glfw3 3.3 REQUIRED) find_package(glfw3 3.3 REQUIRED)
# Suche nach dem glslc Compiler
find_program(GLSLC glslc) find_program(GLSLC glslc)
if(NOT GLSLC) if(NOT GLSLC)
message(FATAL_ERROR "glslc compiler not found. Please install the Vulkan SDK.") message(FATAL_ERROR "glslc compiler not found. Please install the Vulkan SDK.")
endif() 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 file(GLOB SHADER_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert" "${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert"
"${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.frag" "${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.frag"
) )
set(SPIRV_SHADERS "")
foreach(SHADER ${SHADER_FILES}) foreach(SHADER ${SHADER_FILES})
# Dateiname extrahieren
get_filename_component(SHADER_NAME ${SHADER} NAME) 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") set(SPIRV "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.spv")
# Custom Command zum Kompilieren des Shaders
add_custom_command( add_custom_command(
OUTPUT ${SPIRV} OUTPUT ${SPIRV}
COMMAND ${GLSLC} ${SHADER} -o ${SPIRV} COMMAND ${GLSLC} ${SHADER} -o ${SPIRV}
@@ -37,17 +52,15 @@ foreach(SHADER ${SHADER_FILES})
list(APPEND SPIRV_SHADERS ${SPIRV}) list(APPEND SPIRV_SHADERS ${SPIRV})
endforeach() endforeach()
# Custom Target, das alle Shader kompiliert
add_custom_target(compile_shaders ALL DEPENDS ${SPIRV_SHADERS}) add_custom_target(compile_shaders ALL DEPENDS ${SPIRV_SHADERS})
# Das eigentliche Executable
add_executable(vulkan_test add_executable(vulkan_test
main.cpp main.cpp
vulkan/vulkan_app.cpp vulkan/vulkan_app.cpp
vulkan/vulkan_glfw_events.cpp
vulkan/vulkan_app.hpp vulkan/vulkan_app.hpp
) )
target_link_libraries(vulkan_test PRIVATE Vulkan::Vulkan glfw) 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) add_dependencies(vulkan_test compile_shaders)
+1 -1
View File
@@ -1,3 +1,3 @@
# Vulkan_TestApp # Vulkan_TestApp
Triangle Test App with Vulkan API strictly following documentation. Test App with Vulkan API strictly following documentation.
+2
View File
@@ -0,0 +1,2 @@
// Camera.cpp
#include "camera.hpp"
+71
View File
@@ -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));
}
};
}
+18 -3
View File
@@ -1,13 +1,28 @@
/**
* Required external Libraries:
* - Vulkan
* - glfw
* - glm
* - stb
* - tinyobjloader
*/
#define DEBUG 1 #define DEBUG 1
#include <iostream>
#include "vulkan/vulkan_app.hpp" #include "vulkan/vulkan_app.hpp"
int main(int argc, char **argv){ int main(int argc, char **argv){
std::cout << "Program path: " << argv[0] << std::endl; std::cout << "Program path: " << argv[0] << std::endl;
try{ try{
vapp::Vulkan app; 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){ catch(const std::exception& e){
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
@@ -15,4 +30,4 @@ int main(int argc, char **argv){
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
+16053
View File
File diff suppressed because it is too large Load Diff
+5 -1
View File
@@ -1,9 +1,13 @@
#version 450 #version 450
layout(location = 0) in vec3 fragColor; layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 0) out vec4 outColor; layout(location = 0) out vec4 outColor;
layout(binding = 1) uniform sampler2D texSampler;
void main(){ void main(){
outColor = vec4(fragColor, 1.0); // outColor = vec4(fragTexCoord, 0.0, 1.0);
outColor = texture(texSampler, fragTexCoord);
} }
+6 -20
View File
@@ -1,34 +1,20 @@
#version 450 #version 450
layout(binding = 0) uniform UniformBufferObject{ layout(set = 0, binding = 0) uniform UniformBufferObject{
mat4 model; mat4 model;
mat4 view; mat4 view;
mat4 proj; mat4 proj;
}ubo; }ubo;
layout(location = 0) in vec2 inPosition; layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor; layout(location = 1) in vec3 inColor;
layout(location = 2) in vec2 inTexCoord;
layout(location = 0) out vec3 fragColor; layout(location = 0) out vec3 fragColor;
layout(location = 1) out vec2 fragTexCoord;
/*
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)
);
*/
void main(){ void main(){
// gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0);
// fragColor = colors[gl_VertexIndex];
// gl_Position = vec4(inPosition, 0.0, 1.0);
gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 0.0, 1.0);
fragColor = inColor; 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

+637 -98
View File
File diff suppressed because it is too large Load Diff
+119 -17
View File
@@ -10,45 +10,50 @@
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES #define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
#include <iostream> #include <iostream>
#include <stdexcept>
#include <cstdlib>
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include <optional> #include <optional>
#include <set> #include <set>
#include <limits>
#include <algorithm>
#include <fstream> #include <fstream>
#include <array> #include <array>
#include <chrono> #include <chrono>
#include <unordered_map>
#include "../camera/camera.hpp"
namespace vapp{ namespace vapp{
// Change here for other presentMode // Change here for other presentMode
const VkPresentModeKHR WISHED_PRESENT_MODE = VK_PRESENT_MODE_MAILBOX_KHR; const VkPresentModeKHR WISHED_PRESENT_MODE = VK_PRESENT_MODE_MAILBOX_KHR;
struct Vertex{ struct Vertex{
glm::vec2 pos; glm::vec3 pos;
glm::vec3 color; glm::vec3 color;
glm::vec2 texCoord;
static VkVertexInputBindingDescription getBindingDescription(){ static VkVertexInputBindingDescription getBindingDescription(){
VkVertexInputBindingDescription bindingDescription{}; VkVertexInputBindingDescription bindingDescription{};
bindingDescription.binding = 0; bindingDescription.binding = 0;
bindingDescription.stride = sizeof(Vertex); bindingDescription.stride = sizeof(Vertex);
bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
return bindingDescription; return bindingDescription;
} }
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions(){ static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions(){
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions{}; std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions{};
attributeDescriptions[0].binding = 0; attributeDescriptions[0].binding = 0;
attributeDescriptions[0].location = 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[0].offset = offsetof(Vertex, pos);
attributeDescriptions[1].binding = 0; attributeDescriptions[1].binding = 0;
@@ -56,20 +61,38 @@ namespace vapp{
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT; attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[1].offset = offsetof(Vertex, color); 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; 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 = { const std::vector<Vertex> vertices = {
{{-0.5f, -0.5f}, {0.0f, 1.0f, 0.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, 1.0f}}, {{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.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.0f}, {1.0f, 1.0f}},
{{-0.5f, 0.5f}, {1.0f, 0.0f, 0.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 // uint16_t also possible -> change in vkCmdBindIndexBuffer also
const std::vector<uint32_t> indices = { 0, 1, 2, 2, 3, 0 }; const std::vector<uint32_t> indices = {
0, 1, 2, 2, 3, 0,
4, 5, 6, 6, 7, 4
};
*/
// END Remove // END Remove
struct UniformBufferObject{ struct UniformBufferObject{
@@ -99,7 +122,7 @@ namespace vapp{
class Vulkan{ class Vulkan{
private: private:
#pragma region Fields #pragma region PrivateFields
GLFWwindow *window; GLFWwindow *window;
uint32_t _width, _height; uint32_t _width, _height;
@@ -138,6 +161,8 @@ namespace vapp{
const int MAX_FRAMES_IN_FLIGHT = 2; const int MAX_FRAMES_IN_FLIGHT = 2;
uint32_t currentFrame = 0; uint32_t currentFrame = 0;
std::vector<Vertex> vertices;
std::vector<uint32_t> indices;
VkBuffer vertexBuffer; VkBuffer vertexBuffer;
VkDeviceMemory vertexBufferMemory; VkDeviceMemory vertexBufferMemory;
VkBuffer indexBuffer; VkBuffer indexBuffer;
@@ -149,10 +174,34 @@ namespace vapp{
VkDescriptorPool descriptorPool; VkDescriptorPool descriptorPool;
std::vector<VkDescriptorSet> descriptorSets; 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 endregion
#pragma region PrivateFunctions
bool checkValidationLayerSupport(); bool checkValidationLayerSupport();
std::vector<const char*> getRequiredExtensions(); std::vector<const char*> getRequiredExtensions();
VkSampleCountFlagBits getMaxUsableSampleCount();
void createInstance(); void createInstance();
void setupDebugMessenger(); void setupDebugMessenger();
@@ -172,11 +221,33 @@ namespace vapp{
void createGraphicsPipeline(); void createGraphicsPipeline();
VkShaderModule createShaderModule(const std::vector<char>& code); VkShaderModule createShaderModule(const std::vector<char>& code);
void createRenderPass(); void createRenderPass();
void createFrameBuffers(); void createFramebuffers();
void createCommandPool(); 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); 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 copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
void copyBufferOld(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
void loadModel();
void createVertexBuffer(); void createVertexBuffer();
void createIndexBuffer(); void createIndexBuffer();
void createUniformBuffers(); void createUniformBuffers();
@@ -193,8 +264,10 @@ namespace vapp{
void initVulkan(); void initVulkan();
void mainLoop(); void mainLoop();
void cleanup(); void cleanup();
#pragma endregion
public: public:
#pragma region PublicFields
#ifdef DEBUG #ifdef DEBUG
const bool enableValidationLayers = true; const bool enableValidationLayers = true;
#else #else
@@ -202,9 +275,38 @@ namespace vapp{
#endif #endif
bool framebufferResized = false; 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); void run(const char *windowName, const uint32_t width = 800, const uint32_t height = 600);
#pragma endregion
}; };
} // vapp } // 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 #endif //VULKAN_APP_H
+51
View File
@@ -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));
}
}