Skip to content
Snippets Groups Projects
Commit 888eea8a authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

Merge branch '18-first-triangle' into 'develop'

Resolve "First Triangle"

Closes #18

See merge request !21
parents dfc1a650 87a081c8
No related branches found
No related tags found
1 merge request!21Resolve "First Triangle"
Pipeline #24866 passed
# IDE specific files
.project .project
.cproject .cproject
.vs/ .vs/
...@@ -5,6 +7,12 @@ ...@@ -5,6 +7,12 @@
.idea/ .idea/
.editorconfig .editorconfig
# build directories
build/ build/
cmake-build-debug/ cmake-build-debug/
cmake-build-release/ cmake-build-release/
# VS build files and binaries
*.exe
*.ilk
*.pdb
...@@ -12,6 +12,11 @@ if (CMAKE_BUILD_TYPE) ...@@ -12,6 +12,11 @@ if (CMAKE_BUILD_TYPE)
endif() endif()
message("-- Language: [ C++ " ${CMAKE_CXX_STANDARD} " ]") message("-- Language: [ C++ " ${CMAKE_CXX_STANDARD} " ]")
message("-- Compiler: [ " ${CMAKE_CXX_COMPILER_ID} " " ${CMAKE_CXX_COMPILER_VERSION} " ]")
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0"))
message(FATAL_ERROR "Upgrade your compiler! GCC 9.0+ is required!")
endif()
# setting up different paths # setting up different paths
set(vkcv_config ${PROJECT_SOURCE_DIR}/config) set(vkcv_config ${PROJECT_SOURCE_DIR}/config)
...@@ -36,17 +41,21 @@ if (vkcv_build_debug) ...@@ -36,17 +41,21 @@ if (vkcv_build_debug)
endif() endif()
endif() endif()
# add modules as targets
add_subdirectory(modules)
# add source files for compilation # add source files for compilation
include(${vkcv_config}/Sources.cmake) include(${vkcv_config}/Sources.cmake)
# configure everything to use the required dependencies # configure everything to use the required dependencies
include(${vkcv_config}/Libraries.cmake) include(${vkcv_config}/Libraries.cmake)
message("-- Libraries: [ ${vkcv_libraries} ]")
message("-- Flags: [ ${vkcv_flags} ]")
# set the compiler flags for the framework # set the compiler flags for the framework
set(CMAKE_CXX_FLAGS ${vkcv_flags}) set(CMAKE_CXX_FLAGS ${vkcv_flags})
message("-- Flags: [ ${CMAKE_CXX_FLAGS} ]")
# set the compile definitions aka preprocessor variables # set the compile definitions aka preprocessor variables
add_compile_definitions(${vkcv_definitions}) add_compile_definitions(${vkcv_definitions})
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
set(vkcv_config_lib ${vkcv_config}/lib) set(vkcv_config_lib ${vkcv_config}/lib)
set(vkcv_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_lib}) set(vkcv_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_lib})
if(NOT WIN32) if(NOT MSVC)
set(vkcv_libraries stdc++fs) set(vkcv_libraries stdc++fs)
# optimization for loading times # optimization for loading times
list(APPEND vkcv_flags -pthread) list(APPEND vkcv_flags -pthread)
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
*/ */
#include <memory> #include <memory>
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include "vkcv/Context.hpp" #include "vkcv/Context.hpp"
#include "vkcv/SwapChain.hpp" #include "vkcv/SwapChain.hpp"
#include "vkcv/Window.hpp" #include "vkcv/Window.hpp"
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "vkcv/PipelineConfig.hpp" #include "vkcv/PipelineConfig.hpp"
#include "CommandResources.hpp" #include "CommandResources.hpp"
#include "SyncResources.hpp" #include "SyncResources.hpp"
#include "Result.hpp"
#include "vkcv/QueueManager.hpp" #include "vkcv/QueueManager.hpp"
namespace vkcv namespace vkcv
...@@ -40,7 +41,7 @@ namespace vkcv ...@@ -40,7 +41,7 @@ namespace vkcv
// explicit destruction of default constructor // explicit destruction of default constructor
Core() = delete; Core() = delete;
uint32_t acquireSwapchainImage(); Result acquireSwapchainImage();
void destroyTemporaryFramebuffers(); void destroyTemporaryFramebuffers();
Context m_Context; Context m_Context;
......
#pragma once
namespace vkcv {
enum class Result {
SUCCESS = 0,
ERROR = 1
};
}
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
* @file src/vkcv/Window.hpp * @file src/vkcv/Window.hpp
* @brief Window class to handle a basic rendering surface and input * @brief Window class to handle a basic rendering surface and input
*/ */
#include <GLFW/glfw3.h>
#define NOMINMAX #define NOMINMAX
#include <algorithm> #include <algorithm>
struct GLFWwindow;
namespace vkcv { namespace vkcv {
class Window final { class Window final {
private: private:
GLFWwindow *m_window; GLFWwindow *m_window;
...@@ -88,4 +90,5 @@ namespace vkcv { ...@@ -88,4 +90,5 @@ namespace vkcv {
*/ */
virtual ~Window(); virtual ~Window();
}; };
} }
\ No newline at end of file
# Add new modules here:
add_subdirectory(testing)
cmake_minimum_required(VERSION 3.16)
project(vkcv_testing)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(vkcv_testing_source ${PROJECT_SOURCE_DIR}/src)
set(vkcv_testing_include ${PROJECT_SOURCE_DIR}/include)
set(vkcv_testing_sources
${vkcv_testing_include}/vkcv/testing/Test.hpp
${vkcv_testing_source}/vkcv/testing/Test.cpp
)
# adding source files to the project
add_library(vkcv_testing STATIC ${vkcv_testing_sources})
# add the own include directory for public headers
target_include_directories(vkcv_testing BEFORE PUBLIC ${vkcv_testing_include})
#pragma once
namespace vkcv::testing {
class Test {
private:
public:
void test(int test_value);
};
}
#include "vkcv/testing/Test.hpp"
namespace vkcv::testing {
void Test::test(int test_value) {
// TODO: this is an example
}
}
first_triangle
\ No newline at end of file
...@@ -5,14 +5,20 @@ project(first_triangle) ...@@ -5,14 +5,20 @@ project(first_triangle)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders/vert.spv DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/shaders) # this should fix the execution path to load local files from the project
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/shaders/frag.spv DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/shaders) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# adding source files to the project # adding source files to the project
add_executable(first_triangle src/main.cpp) add_executable(first_triangle src/main.cpp)
# this should fix the execution path to load local files from the project (for MSVC)
if(MSVC)
set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
# including headers of dependencies and the VkCV framework # including headers of dependencies and the VkCV framework
target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes}) target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include})
# linking with libraries from all dependencies and the VkCV framework # linking with libraries from all dependencies and the VkCV framework
target_link_libraries(first_triangle vkcv ${vkcv_libraries}) target_link_libraries(first_triangle vkcv ${vkcv_libraries} vkcv_testing)
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* @brief Handling of global states regarding dependencies * @brief Handling of global states regarding dependencies
*/ */
#include <GLFW/glfw3.h>
#include "vkcv/Core.hpp" #include "vkcv/Core.hpp"
#include "PassManager.hpp" #include "PassManager.hpp"
#include "PipelineManager.hpp" #include "PipelineManager.hpp"
...@@ -317,19 +319,31 @@ namespace vkcv ...@@ -317,19 +319,31 @@ namespace vkcv
return m_PassManager->createPass(config); return m_PassManager->createPass(config);
} }
uint32_t Core::acquireSwapchainImage() { Result Core::acquireSwapchainImage() {
uint32_t index; uint32_t imageIndex;
m_Context.getDevice().acquireNextImageKHR(m_swapchain.getSwapchain(), 0, nullptr,
m_SyncResources.swapchainImageAcquired, &index, {}); const auto& acquireResult = m_Context.getDevice().acquireNextImageKHR(
const uint64_t timeoutPeriodNs = 1000; // TODO: think if is adequate m_swapchain.getSwapchain(), std::numeric_limits<uint64_t>::max(), nullptr,
const auto& result = m_Context.getDevice().waitForFences(m_SyncResources.swapchainImageAcquired, true, timeoutPeriodNs); m_SyncResources.swapchainImageAcquired, &imageIndex, {}
);
if (acquireResult != vk::Result::eSuccess) {
return Result::ERROR;
}
const auto& result = m_Context.getDevice().waitForFences(
m_SyncResources.swapchainImageAcquired, true,
std::numeric_limits<uint64_t>::max()
);
m_Context.getDevice().resetFences(m_SyncResources.swapchainImageAcquired); m_Context.getDevice().resetFences(m_SyncResources.swapchainImageAcquired);
if (result == vk::Result::eTimeout) { if (result != vk::Result::eSuccess) {
index = std::numeric_limits<uint32_t>::max(); return Result::ERROR;
} }
return index; m_currentSwapchainImageIndex = imageIndex;
return Result::SUCCESS;
} }
void Core::destroyTemporaryFramebuffers() { void Core::destroyTemporaryFramebuffers() {
...@@ -340,12 +354,9 @@ namespace vkcv ...@@ -340,12 +354,9 @@ namespace vkcv
} }
void Core::beginFrame() { void Core::beginFrame() {
m_currentSwapchainImageIndex = acquireSwapchainImage(); if (acquireSwapchainImage() != Result::SUCCESS) {
return;
if (m_currentSwapchainImageIndex == std::numeric_limits<uint32_t>::max()) { }
std::cerr << "Drop frame!" << std::endl;
return;
}
m_Context.getDevice().waitIdle(); // FIMXE: this is a sin against graphics programming, but its getting late - Alex m_Context.getDevice().waitIdle(); // FIMXE: this is a sin against graphics programming, but its getting late - Alex
destroyTemporaryFramebuffers(); destroyTemporaryFramebuffers();
......
#include "vkcv/QueueManager.hpp"
#include <unordered_set> #include <unordered_set>
#include <limits>
#include "vkcv/QueueManager.hpp"
namespace vkcv { namespace vkcv {
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
* @brief Window class to handle a basic rendering surface and input * @brief Window class to handle a basic rendering surface and input
*/ */
#include "vkcv/Window.hpp" #include <GLFW/glfw3.h>
#include "vkcv/Window.hpp"
namespace vkcv { namespace vkcv {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment