diff --git a/.gitignore b/.gitignore index 2994ef0..8aa0d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .cache/ .vscode/ build/ +thirdparty/SDL2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 25706cd..f7dc776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,17 @@ file(GLOB SHADERS ${SHADER_DIR}/*.vert ${SHADER_DIR}/*.rmiss ) -find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) +option(SDL2_NONSYSTEM "Use SDL2 from folder in source tree" OFF) + +if(SDL2_NONSYSTEM) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/SDL2 ${CMAKE_CURRENT_BINARY_DIR}/SDL2 EXCLUDE_FROM_ALL) +else() + find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) + if(WIN32) + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) + endif() +endif() + find_package(Vulkan REQUIRED COMPONENTS glslc) # Compile each shader @@ -39,14 +49,26 @@ endForeach() add_custom_target(shaders ALL DEPENDS ${SPV_SHADERS}) add_executable(${EXE_NAME} ${CMAKE_SOURCE_DIR}/src/main.cc ${PROGRAM_SOURCES} ${SHADERS}) + +set_target_properties(${EXE_NAME} + PROPERTIES + CXX_STANDARD 17 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS ON +) + target_include_directories(${EXE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) add_dependencies(${EXE_NAME} shaders) -if ( CMAKE_COMPILER_IS_GNUCC ) +if(CMAKE_COMPILER_IS_GNUCC) target_compile_options(${EXE_NAME} PRIVATE -Wall -Wextra) +elseif(MSVC) + target_compile_options(${EXE_NAME} PRIVATE /W4) endif() -if ( MSVC ) - target_compile_options(${EXE_NAME} PRIVATE /W4) + +# Windows specific +if(TARGET SDL2::SDL2main) + target_link_libraries(${EXE_NAME} PRIVATE SDL2::SDL2main) endif() # Linking diff --git a/src/main.cc b/src/main.cc index cdfd962..68402ec 100644 --- a/src/main.cc +++ b/src/main.cc @@ -3,7 +3,7 @@ #include int main() { - VulkanApp app(640, 480); + VulkanApp app(1024, 1024); try { app.init(); diff --git a/src/vulkanapp.cc b/src/vulkanapp.cc index efc0e3c..dc81759 100644 --- a/src/vulkanapp.cc +++ b/src/vulkanapp.cc @@ -38,7 +38,13 @@ void DestroyDebugUtilsMessengerEXT(VkInstance instance, } const std::vector readFile(const std::string& path) { - FILE *fd = fopen(path.c_str(), "rb"); + FILE *fd = nullptr; +#if _MSC_VER + fopen_s(&fd, path.c_str(), "rb"); +#else + fd = fopen(path.c_str(), "rb"); +#endif + long fileSize = 0; std::vector buf; @@ -709,8 +715,8 @@ void VulkanApp::createGraphicsPipeline() { VK_NULL_HANDLE, 1, &pipelineInfo, - nullptr, - &mGraphicsPipeline) != VK_SUCCESS) { + nullptr, + &mGraphicsPipeline) != VK_SUCCESS) { throw std::runtime_error("Could not create Vulkan graphics pipeline!"); } @@ -794,7 +800,7 @@ void VulkanApp::createSyncObjects() { } bool VulkanApp::checkDeviceExtensionSupport(VkPhysicalDevice device) { - uint32_t extensionCount; + uint32_t extensionCount = 0; vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); std::vector availableExtensions(extensionCount); @@ -810,7 +816,7 @@ bool VulkanApp::checkDeviceExtensionSupport(VkPhysicalDevice device) { } bool VulkanApp::checkValidationLayerSupport() { - uint32_t layerCount; + uint32_t layerCount = 0; vkEnumerateInstanceLayerProperties(&layerCount, nullptr); std::vector availableLayers(layerCount); @@ -861,8 +867,6 @@ void VulkanApp::loop() { mActive = true; - //SDL_Renderer *rend = SDL_CreateRenderer(mWin, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); - // Main loop while(mActive) { while(SDL_PollEvent(&mEvent)) { @@ -890,16 +894,10 @@ void VulkanApp::loop() { } } - //SDL_SetRenderDrawColor(rend, 255, 0, 0, 255); - //SDL_RenderClear(rend); - - //SDL_RenderPresent(rend); - if(!mMinimized) drawFrame(); } vkDeviceWaitIdle(mLogicalDevice); - //SDL_DestroyRenderer(rend); } void VulkanApp::cleanup() {