Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Show changes
Commits on Source (78)
Showing
with 117 additions and 28 deletions
......@@ -44,6 +44,9 @@ endif()
# configure everything to use the required dependencies
include(${vkcv_config}/Libraries.cmake)
# set the compile definitions aka preprocessor variables
add_compile_definitions(${vkcv_definitions})
# add modules as targets
add_subdirectory(modules)
......@@ -56,9 +59,6 @@ message("-- Flags: [ ${vkcv_flags} ]")
# set the compiler flags for the framework
set(CMAKE_CXX_FLAGS ${vkcv_flags})
# set the compile definitions aka preprocessor variables
add_compile_definitions(${vkcv_definitions})
# create VkCV framework as static library using all source files
add_library(vkcv STATIC ${vkcv_sources})
......
......@@ -10,6 +10,8 @@ if(NOT WIN32)
list(APPEND vkcv_flags -fopenmp)
endif()
list(APPEND vkcv_definitions _USE_MATH_DEFINES)
# some formatted printing
set(vkcv_config_msg " - Library: ")
......
......@@ -223,6 +223,11 @@ namespace vkcv
bool supportStorage = false,
bool supportColorAttachment = false);
[[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle);
[[nodiscard]]
const uint32_t getImageHeight(ImageHandle imageHandle);
/** TODO:
* @param setDescriptions
* @return
......
......@@ -4,9 +4,12 @@
namespace vkcv {
struct SampledImageDescriptorWrite {
inline SampledImageDescriptorWrite(uint32_t binding, ImageHandle image) : binding(binding), image(image) {};
inline SampledImageDescriptorWrite(uint32_t binding, ImageHandle image, uint32_t mipLevel = 0, bool useGeneralLayout = false)
: binding(binding), image(image), mipLevel(mipLevel), useGeneralLayout(useGeneralLayout) {};
uint32_t binding;
ImageHandle image;
uint32_t mipLevel;
bool useGeneralLayout;
};
struct StorageImageDescriptorWrite {
......@@ -38,8 +41,8 @@ namespace vkcv {
struct DescriptorWrites {
std::vector<SampledImageDescriptorWrite> sampledImageWrites;
std::vector<StorageImageDescriptorWrite> storageImageWrites;
std::vector<UniformBufferDescriptorWrite> uniformBufferWrites;
std::vector<StorageBufferDescriptorWrite> storageBufferWrites;
std::vector<SamplerDescriptorWrite> samplerWrites;
std::vector<UniformBufferDescriptorWrite> uniformBufferWrites;
std::vector<StorageBufferDescriptorWrite> storageBufferWrites;
std::vector<SamplerDescriptorWrite> samplerWrites;
};
}
\ No newline at end of file
#pragma once
#include <functional>
#include <mutex>
namespace vkcv {
......@@ -26,6 +27,7 @@ namespace vkcv {
private:
std::vector< event_function<T...> > m_functions;
uint32_t m_id_counter;
std::mutex m_mutex;
public:
......@@ -34,9 +36,13 @@ namespace vkcv {
* @param arguments of the given function
*/
void operator()(T... arguments) {
lock();
for (auto &function : this->m_functions) {
function.callback(arguments...);
}
}
unlock();
}
/**
......@@ -64,8 +70,26 @@ namespace vkcv {
this->m_functions.end()
);
}
/**
* locks the event so its function handles won't be called
*/
void lock() {
m_mutex.lock();
}
/**
* unlocks the event so its function handles can be called after locking
*/
void unlock() {
m_mutex.unlock();
}
event() = default;
explicit event(bool locked = false) {
if (locked) {
lock();
}
}
event(const event &other) = delete;
......
......@@ -42,8 +42,10 @@ namespace vkcv {
void generateMipChainImmediate();
void recordMipChainGeneration(const vkcv::CommandStreamHandle& cmdStream);
private:
ImageManager* const m_manager;
const ImageHandle m_handle;
// TODO: const qualifier removed, very hacky!!!
// Else you cannot recreate an image. Pls fix.
ImageManager* m_manager;
ImageHandle m_handle;
Image(ImageManager* manager, const ImageHandle& handle);
......
#pragma once
#include <iostream>
#include <stdio.h>
namespace vkcv {
......@@ -45,12 +45,12 @@ namespace vkcv {
char output_message [ \
VKCV_DEBUG_MESSAGE_LEN \
]; \
std::snprintf( \
snprintf( \
output_message, \
VKCV_DEBUG_MESSAGE_LEN, \
__VA_ARGS__ \
); \
std::fprintf( \
fprintf( \
getLogOutput(level), \
"[%s]: %s [%s, line %d: %s]\n", \
vkcv::getLogName(level), \
......
......@@ -7,6 +7,7 @@
#define NOMINMAX
#include <algorithm>
#include "Event.hpp"
struct GLFWwindow;
......@@ -23,8 +24,6 @@ namespace vkcv {
*/
explicit Window(GLFWwindow *window);
static GLFWwindow* createGLFWWindow(const char *windowTitle, int width, int height, bool resizable);
private:
/**
* mouse callback for moving the mouse on the screen
......@@ -42,6 +41,12 @@ namespace vkcv {
*/
static void onMouseButtonEvent(GLFWwindow *callbackWindow, int button, int action, int mods);
/**
* @brief A callback function for handling mouse scrolling events.
* @param[in] callbackWindow The window that received the event.
* @param[in] xoffset The extent of horizontal scrolling.
* @param[in] yoffset The extent of vertical scrolling.
*/
static void onMouseScrollEvent(GLFWwindow *callbackWindow, double xoffset, double yoffset);
/**
......@@ -69,6 +74,12 @@ namespace vkcv {
*/
static void onCharEvent(GLFWwindow *callbackWindow, unsigned int c);
/**
* @brief A callback function for gamepad input events.
* @param gamepadIndex The gamepad index.
*/
static void onGamepadEvent(int gamepadIndex);
public:
/**
* creates a GLFWwindow with the parameters in the function
......@@ -87,11 +98,6 @@ namespace vkcv {
[[nodiscard]]
bool isWindowOpen() const;
/**
* binds windowEvents to lambda events
*/
void initEvents();
/**
* polls all events on the GLFWwindow
*/
......@@ -106,6 +112,7 @@ namespace vkcv {
event< int, int > e_resize;
event< int, int, int, int > e_key;
event< unsigned int > e_char;
event< int > e_gamepad;
/**
* returns the current window
......@@ -152,4 +159,4 @@ namespace vkcv {
virtual ~Window();
};
}
\ No newline at end of file
}
# Add new modules here:
add_subdirectory(asset_loader)
add_subdirectory(material)
add_subdirectory(camera)
add_subdirectory(gui)
add_subdirectory(shader_compiler)
......
......@@ -38,3 +38,5 @@ target_include_directories(vkcv_asset_loader SYSTEM BEFORE PRIVATE ${vkcv_asset_
# add the own include directory for public headers
target_include_directories(vkcv_asset_loader BEFORE PUBLIC ${vkcv_asset_loader_include})
target_compile_definitions(vkcv_asset_loader PUBLIC ${vkcv_asset_loader_definitions})
if (EXISTS "${vkcv_asset_loader_lib_path}/stb")
list(APPEND vkcv_asset_loader_includes ${vkcv_asset_loader_lib}/stb)
list(APPEND vkcv_asset_loader_definitions STB_IMAGE_IMPLEMENTATION)
list(APPEND vkcv_asset_loader_definitions STBI_ONLY_JPEG)
list(APPEND vkcv_asset_loader_definitions STBI_ONLY_PNG)
else()
message(WARNING "STB is required..! Update the submodules!")
endif ()
......@@ -3,9 +3,6 @@
#include <string.h> // memcpy(3)
#include <stdlib.h> // calloc(3)
#include <fx/gltf.h>
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_JPEG
#define STBI_ONLY_PNG
#include <stb_image.h>
#include <vkcv/Logger.hpp>
#include <algorithm>
......
......@@ -36,3 +36,4 @@ target_include_directories(vkcv_camera SYSTEM BEFORE PRIVATE ${vkcv_camera_inclu
# add the own include directory for public headers
target_include_directories(vkcv_camera BEFORE PUBLIC ${vkcv_camera_include} ${vkcv_camera_includes})
target_compile_definitions(vkcv_camera PUBLIC ${vkcv_camera_definitions})
......@@ -4,11 +4,17 @@ find_package(glm QUIET)
if (glm_FOUND)
list(APPEND vkcv_camera_includes ${GLM_INCLUDE_DIRS})
list(APPEND vkcv_camera_libraries glm)
list(APPEND vkcv_camera_definitions GLM_DEPTH_ZERO_TO_ONE)
list(APPEND vkcv_camera_definitions GLM_FORCE_LEFT_HANDED)
else()
if (EXISTS "${vkcv_camera_lib_path}/glm")
add_subdirectory(${vkcv_camera_lib}/glm)
list(APPEND vkcv_camera_libraries glm)
list(APPEND vkcv_camera_definitions GLM_DEPTH_ZERO_TO_ONE)
list(APPEND vkcv_camera_definitions GLM_FORCE_LEFT_HANDED)
else()
message(WARNING "GLM is required..! Update the submodules!")
endif ()
......
#pragma once
#define GLM_DEPTH_ZERO_TO_ONE
#define GLM_FORCE_LEFT_HANDED
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>
......
......@@ -59,6 +59,14 @@ namespace vkcv::camera {
* @param[in] camera The camera object.
*/
virtual void mouseButtonCallback(int button, int action, int mods, Camera &camera) = 0;
/**
* @brief A callback function for gamepad input events.
* @param gamepadIndex The gamepad index.
* @param camera The camera object.
* @param frametime The current frametime.
*/
virtual void gamepadCallback(int gamepadIndex, Camera &camera, double frametime) = 0;
};
}
\ No newline at end of file
......@@ -30,6 +30,7 @@ namespace vkcv::camera {
event_handle<double, double> m_mouseScrollHandle;
event_handle<int, int, int> m_mouseButtonHandle;
event_handle<int, int> m_resizeHandle;
event_handle<int> m_gamepadHandle;
Window& m_window;
std::vector<Camera> m_cameras;
......@@ -42,6 +43,9 @@ namespace vkcv::camera {
double m_lastX;
double m_lastY;
double m_inputDelayTimer;
double m_frameTime;
/**
* @brief Binds the camera object to the window event handles.
*/
......@@ -86,6 +90,13 @@ namespace vkcv::camera {
* @param[in] height The new height of the window.
*/
void resizeCallback(int width, int height);
/**
* @brief A callback function for gamepad input events. Currently, inputs are handled only for the first
* connected gamepad!
* @param gamepadIndex The gamepad index.
*/
void gamepadCallback(int gamepadIndex);
/**
* @brief Gets a camera controller object of specified @p controllerType.
......
......@@ -17,6 +17,10 @@ namespace vkcv::camera {
bool m_left;
bool m_right;
float m_gamepadX;
float m_gamepadY;
float m_gamepadZ;
bool m_rotationActive;
float m_cameraSpeed;
......@@ -133,6 +137,14 @@ namespace vkcv::camera {
* @param[in] camera The camera object.
*/
void mouseButtonCallback(int button, int action, int mods, Camera &camera);
/**
* @brief A callback function for gamepad input events.
* @param gamepadIndex The gamepad index.
* @param camera The camera object.
* @param frametime The current frametime.
*/
void gamepadCallback(int gamepadIndex, Camera &camera, double frametime);
};
}
\ No newline at end of file
......@@ -95,6 +95,13 @@ namespace vkcv::camera {
*/
void mouseButtonCallback(int button, int action, int mods, Camera &camera);
/**
* @brief A callback function for gamepad input events.
* @param gamepadIndex The gamepad index.
* @param camera The camera object.
* @param frametime The current frametime.
*/
void gamepadCallback(int gamepadIndex, Camera &camera, double frametime);
};
}
\ No newline at end of file
#include "vkcv/camera/Camera.hpp"
#define _USE_MATH_DEFINES
#include <math.h>
namespace vkcv::camera {
......