|
@@ -1,10 +1,13 @@
|
|
|
#include "platform.hpp"
|
|
#include "platform.hpp"
|
|
|
|
|
|
|
|
|
|
+#include <SDL3/SDL.h>
|
|
|
|
|
+
|
|
|
namespace saura {
|
|
namespace saura {
|
|
|
-Platform::Platform(std::shared_ptr<Window> window_ctx) {
|
|
|
|
|
- this->root_window_ctx = window_ctx;
|
|
|
|
|
|
|
|
|
|
- ui_ctx = std::make_unique<UI>(this->root_window_ctx);
|
|
|
|
|
|
|
+Platform *Platform::instance = nullptr;
|
|
|
|
|
+
|
|
|
|
|
+void Platform::init(void *window_handle) {
|
|
|
|
|
+ window_ctx = new (Window);
|
|
|
|
|
|
|
|
std::locale::global(std::locale("en_US.UTF-8"));
|
|
std::locale::global(std::locale("en_US.UTF-8"));
|
|
|
|
|
|
|
@@ -12,26 +15,20 @@ Platform::Platform(std::shared_ptr<Window> window_ctx) {
|
|
|
throw std::runtime_error("Failed SDL_Init!");
|
|
throw std::runtime_error("Failed SDL_Init!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this->root_window_ctx->renderer =
|
|
|
|
|
- SDL_CreateRenderer(this->root_window_ctx->handle, nullptr);
|
|
|
|
|
- if (this->root_window_ctx->renderer == nullptr) {
|
|
|
|
|
- throw std::runtime_error("Failed SDL_CreateRenderer!");
|
|
|
|
|
- }
|
|
|
|
|
- SDL_SetRenderVSync(this->root_window_ctx->renderer, SDL_RENDERER_VSYNC_DISABLED);
|
|
|
|
|
- SDL_SetWindowPosition(this->root_window_ctx->handle, SDL_WINDOWPOS_CENTERED,
|
|
|
|
|
- SDL_WINDOWPOS_CENTERED);
|
|
|
|
|
|
|
+ // GL 3.0 + GLSL 130
|
|
|
|
|
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
|
|
|
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
|
|
|
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
|
|
|
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
|
|
|
|
|
|
- ui_ctx->init();
|
|
|
|
|
|
|
+ SDL_PropertiesID props = SDL_CreateProperties();
|
|
|
|
|
+ SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER,
|
|
|
|
|
+ (Sint64)window_handle);
|
|
|
|
|
+ window_ctx->handle = SDL_CreateWindowWithProperties(props);
|
|
|
|
|
+ window_ctx->gl_ctx = SDL_GL_GetCurrentContext();
|
|
|
|
|
|
|
|
- SDL_ShowWindow(this->root_window_ctx->handle);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-Platform::~Platform() {
|
|
|
|
|
- ui_ctx->deinit();
|
|
|
|
|
-
|
|
|
|
|
- SDL_DestroyRenderer(this->root_window_ctx->renderer);
|
|
|
|
|
- SDL_DestroyWindow(this->root_window_ctx->handle);
|
|
|
|
|
- SDL_Quit();
|
|
|
|
|
|
|
+ ui_ctx = new (UI);
|
|
|
|
|
+ ui_ctx->init(window_ctx);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Platform::draw_begin() { this->ui_ctx->begin(); }
|
|
void Platform::draw_begin() { this->ui_ctx->begin(); }
|
|
@@ -40,9 +37,9 @@ void Platform::draw_end() { this->ui_ctx->end(); }
|
|
|
|
|
|
|
|
void Platform::update() {
|
|
void Platform::update() {
|
|
|
int w, h = 0;
|
|
int w, h = 0;
|
|
|
- SDL_GetWindowSize(this->root_window_ctx->handle, &w, &h);
|
|
|
|
|
- this->root_window_ctx->w = w;
|
|
|
|
|
- this->root_window_ctx->h = h;
|
|
|
|
|
|
|
+ SDL_GetWindowSize(this->window_ctx->handle, &w, &h);
|
|
|
|
|
+ this->window_ctx->w = w;
|
|
|
|
|
+ this->window_ctx->h = h;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool Platform::update_events() {
|
|
bool Platform::update_events() {
|
|
@@ -61,7 +58,7 @@ bool Platform::update_events() {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
|
|
case SDL_EVENT_WINDOW_CLOSE_REQUESTED: {
|
|
|
- if (event.window.windowID == SDL_GetWindowID(this->root_window_ctx->handle)) {
|
|
|
|
|
|
|
+ if (event.window.windowID == SDL_GetWindowID(this->window_ctx->handle)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -73,12 +70,12 @@ bool Platform::update_events() {
|
|
|
|
|
|
|
|
void Platform::sleep(double ms) { SDL_Delay((Uint32)ms * 1000); }
|
|
void Platform::sleep(double ms) { SDL_Delay((Uint32)ms * 1000); }
|
|
|
|
|
|
|
|
-int Platform::get_root_window_width() { return this->root_window_ctx->w; }
|
|
|
|
|
|
|
+int Platform::get_root_window_width() { return this->window_ctx->w; }
|
|
|
|
|
|
|
|
-int Platform::get_root_window_height() { return this->root_window_ctx->h; }
|
|
|
|
|
|
|
+int Platform::get_root_window_height() { return this->window_ctx->h; }
|
|
|
|
|
|
|
|
void Platform::set_root_window_title(std::string title) {
|
|
void Platform::set_root_window_title(std::string title) {
|
|
|
- SDL_SetWindowTitle(this->root_window_ctx.get()->handle, title.c_str());
|
|
|
|
|
|
|
+ SDL_SetWindowTitle(this->window_ctx->handle, title.c_str());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
double Platform::get_performance_frequency() {
|
|
double Platform::get_performance_frequency() {
|
|
@@ -118,4 +115,4 @@ fs::path Platform::get_home_config_path() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::string Platform::get_user_name() { return get_safe_getenv("USERNAME"); }
|
|
std::string Platform::get_user_name() { return get_safe_getenv("USERNAME"); }
|
|
|
-}
|
|
|
|
|
|
|
+} // namespace saura
|