Compare commits
No commits in common. "6d48ac251cdce019ff4c7f36694a7b2c7a3096c0" and "eeb0dd8024431af19c90216b941b86580d3df464" have entirely different histories.
6d48ac251c
...
eeb0dd8024
5
.gitignore
vendored
5
.gitignore
vendored
@ -103,7 +103,4 @@ CMakeUserPresets.json
|
|||||||
# Other
|
# Other
|
||||||
.cache/
|
.cache/
|
||||||
.vscode/
|
.vscode/
|
||||||
build/
|
build/
|
||||||
|
|
||||||
.kdev4/
|
|
||||||
*.kdev4
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(vksdlproj VERSION 0.2.0 LANGUAGES C CXX)
|
project(vksdlproj VERSION 0.1.0 LANGUAGES C CXX)
|
||||||
|
|
||||||
SET(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
SET(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||||
set(EXE_NAME project)
|
set(EXE_NAME project)
|
||||||
@ -69,4 +69,4 @@ endif()
|
|||||||
# Linking
|
# Linking
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE SDL3::SDL3)
|
target_link_libraries(${EXE_NAME} PRIVATE SDL3::SDL3)
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE Vulkan::Vulkan)
|
target_link_libraries(${EXE_NAME} PRIVATE Vulkan::Vulkan)
|
||||||
target_link_libraries(${EXE_NAME} PRIVATE vk-bootstrap::vk-bootstrap)
|
target_link_libraries(${EXE_NAME} PRIVATE vk-bootstrap::vk-bootstrap)
|
||||||
@ -7,8 +7,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
const std::vector<const char*> validationLayers = {
|
const std::vector<const char*> validationLayers = {
|
||||||
@ -53,9 +51,6 @@ public:
|
|||||||
void init();
|
void init();
|
||||||
void loop();
|
void loop();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
inline bool minimized() { return mMinimized; }
|
|
||||||
inline void minimized(bool v) { mMinimized = v; }
|
|
||||||
inline void resized(bool v) { mResized = v; }
|
|
||||||
private:
|
private:
|
||||||
// SDL2
|
// SDL2
|
||||||
SDL_Window *mWin;
|
SDL_Window *mWin;
|
||||||
@ -64,7 +59,7 @@ private:
|
|||||||
// Not tied to library
|
// Not tied to library
|
||||||
uint32_t mWidth;
|
uint32_t mWidth;
|
||||||
uint32_t mHeight;
|
uint32_t mHeight;
|
||||||
// bool mActive = false;
|
bool mActive = false;
|
||||||
bool mResized = false;
|
bool mResized = false;
|
||||||
bool mMinimized = false;
|
bool mMinimized = false;
|
||||||
|
|
||||||
@ -143,4 +138,4 @@ private:
|
|||||||
|
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
92
src/main.cc
92
src/main.cc
@ -1,95 +1,19 @@
|
|||||||
#define SDL_MAIN_USE_CALLBACKS
|
|
||||||
#include <SDL3/SDL_main.h>
|
|
||||||
#include <SDL3/SDL_init.h>
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
|
|
||||||
#include "vulkanapp.hh"
|
#include "vulkanapp.hh"
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
constexpr uint32_t winInitWidth = 512;
|
int main() {
|
||||||
constexpr uint32_t winInitHeight = 512;
|
VulkanApp app(1024, 1024);
|
||||||
|
|
||||||
struct AppContext {
|
|
||||||
VulkanApp vkapp;
|
|
||||||
SDL_AppResult appQuit = SDL_APP_CONTINUE;
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL_AppResult SDL_Fail() {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Error: %s", SDL_GetError());
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) {
|
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
if(!SDL_Init(SDL_INIT_VIDEO))
|
|
||||||
return SDL_Fail();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
*appstate = new AppContext { .vkapp = VulkanApp(1024, 1024)};
|
app.init();
|
||||||
AppContext* app = static_cast<AppContext*>(*appstate);
|
app.loop();
|
||||||
app->vkapp.init();
|
app.cleanup();
|
||||||
} catch(const std::exception& except) {
|
} catch(const std::exception& except) {
|
||||||
fprintf(stderr, "Error! %s\n", except.what());
|
fprintf(stderr, "Error! %s\n", except.what());
|
||||||
|
|
||||||
return SDL_APP_FAILURE;
|
return 1;
|
||||||
}
|
|
||||||
return SDL_APP_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|
||||||
AppContext* app = static_cast<AppContext*>(appstate);
|
|
||||||
|
|
||||||
switch(event->type) {
|
|
||||||
case SDL_EVENT_QUIT:
|
|
||||||
app->appQuit = SDL_APP_SUCCESS;
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_WINDOW_RESIZED:
|
|
||||||
app->vkapp.resized(true);
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_WINDOW_MINIMIZED:
|
|
||||||
app->vkapp.minimized(true);
|
|
||||||
break;
|
|
||||||
case SDL_EVENT_WINDOW_RESTORED:
|
|
||||||
app->vkapp.minimized(false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_AppResult SDL_AppIterate(void *appstate) {
|
|
||||||
AppContext* app = static_cast<AppContext*>(appstate);
|
|
||||||
|
|
||||||
try {
|
|
||||||
app->vkapp.loop();
|
|
||||||
} catch(const std::exception& except) {
|
|
||||||
fprintf(stderr, "Error! %s\n", except.what());
|
|
||||||
|
|
||||||
return SDL_APP_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return app->appQuit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SDL_AppQuit(void *appstate, SDL_AppResult result) {
|
|
||||||
AppContext* app = static_cast<AppContext*>(appstate);
|
|
||||||
|
|
||||||
if(result == SDL_APP_FAILURE) {
|
|
||||||
fputs("Program failure, shutting down\n", stderr);
|
|
||||||
} else {
|
|
||||||
puts("Program shutting down, no errors.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(app) {
|
|
||||||
app->vkapp.cleanup();
|
|
||||||
|
|
||||||
delete app;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
@ -862,7 +862,31 @@ void VulkanApp::loop() {
|
|||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mMinimized) drawFrame();
|
mActive = true;
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while(mActive) {
|
||||||
|
while(SDL_PollEvent(&mEvent)) {
|
||||||
|
switch (mEvent.type) {
|
||||||
|
case SDL_EVENT_QUIT:
|
||||||
|
mActive = false;
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_WINDOW_RESIZED:
|
||||||
|
mResized = true;
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_WINDOW_MINIMIZED:
|
||||||
|
mMinimized = true;
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_WINDOW_RESTORED:
|
||||||
|
mMinimized = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!mMinimized) drawFrame();
|
||||||
|
}
|
||||||
|
|
||||||
vkDeviceWaitIdle(mLogicalDevice);
|
vkDeviceWaitIdle(mLogicalDevice);
|
||||||
}
|
}
|
||||||
@ -897,4 +921,7 @@ void VulkanApp::cleanup() {
|
|||||||
SDL_DestroyWindow(mWin);
|
SDL_DestroyWindow(mWin);
|
||||||
mWin = nullptr;
|
mWin = nullptr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
//SDL_Vulkan_UnloadLibrary();
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user