Adjust CMakeLists.txt and program so that it compiles and runs on windows
This commit is contained in:
parent
75e9921d45
commit
7daf540a9b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.cache/
|
||||
.vscode/
|
||||
build/
|
||||
thirdparty/SDL2
|
||||
|
||||
@ -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
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#include <exception>
|
||||
|
||||
int main() {
|
||||
VulkanApp app(640, 480);
|
||||
VulkanApp app(1024, 1024);
|
||||
|
||||
try {
|
||||
app.init();
|
||||
|
||||
@ -38,7 +38,13 @@ void DestroyDebugUtilsMessengerEXT(VkInstance instance,
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> 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<uint8_t> 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<VkExtensionProperties> 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<VkLayerProperties> 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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user