SDL_TRY
This commit is contained in:
parent
9fc98d2caa
commit
056904fab3
@ -11,7 +11,6 @@ public:
|
||||
SDLException_(const std::string& _file, const std::string& _func, int line_n);
|
||||
};
|
||||
|
||||
#define SDL_TRY_ZERO(FUNC_CALL) if(FUNC_CALL != 0) throw SDLException();
|
||||
#define SDL_TRY_ONE(FUNC_CALL) if(FUNC_CALL != 1) throw SDLException();
|
||||
#define SDL_TRY(EXPR) if(EXPR) throw SDLException();
|
||||
|
||||
}
|
||||
@ -16,16 +16,16 @@ f32 GUI::getDPI(){
|
||||
}
|
||||
|
||||
void GUI::init(const char* window_title){
|
||||
SDL_TRY_ZERO(SDL_Init(SDL_INIT_VIDEO));
|
||||
SDL_TRY(SDL_Init(SDL_INIT_VIDEO));
|
||||
SDL_version v;
|
||||
SDL_GetVersion(&v);
|
||||
kprintf("SDL version: %u.%u.%u\n", v.major, v.minor, v.patch);
|
||||
// GL 3.0 + GLSL 130
|
||||
const char* glsl_version = "#version 130";
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0));
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE));
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3));
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0));
|
||||
|
||||
// From 2.0.18: Enable native IME.
|
||||
#ifdef SDL_HINT_IME_SHOW_UI
|
||||
@ -33,9 +33,9 @@ void GUI::init(const char* window_title){
|
||||
#endif
|
||||
|
||||
// Create window with graphics context
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1));
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
|
||||
SDL_TRY_ZERO( SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24));
|
||||
SDL_TRY( SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8));
|
||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(
|
||||
SDL_WINDOW_OPENGL |
|
||||
SDL_WINDOW_RESIZABLE |
|
||||
@ -48,8 +48,8 @@ void GUI::init(const char* window_title){
|
||||
gl_context = SDL_GL_CreateContext(sdl_window);
|
||||
if(gl_context == nullptr)
|
||||
throw SDLException();
|
||||
SDL_TRY_ZERO( SDL_GL_MakeCurrent(sdl_window, gl_context));
|
||||
SDL_TRY_ZERO( SDL_GL_SetSwapInterval(1)); // Enable vsync
|
||||
SDL_TRY( SDL_GL_MakeCurrent(sdl_window, gl_context));
|
||||
SDL_TRY( SDL_GL_SetSwapInterval(1)); // Enable vsync
|
||||
|
||||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
@ -88,7 +88,7 @@ void GUI::poll_events(u16& frame_updates_requested, bool wait){
|
||||
SDL_Event event;
|
||||
if(wait){
|
||||
// waits for first event in cpu-efficient way
|
||||
SDL_TRY_ONE(SDL_WaitEvent(&event));
|
||||
SDL_TRY(SDL_WaitEvent(&event) != 1);
|
||||
}
|
||||
// dont wait for event
|
||||
else if(!SDL_PollEvent(&event))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user