some refactoring, add props and fix scissors

This commit is contained in:
Igor Stepanov 2025-10-07 16:36:15 +03:00
parent fddf810daf
commit f631382dbd
3 changed files with 20 additions and 7 deletions

View file

@ -146,7 +146,8 @@ window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept {
return; return;
} }
SDL_WindowFlags flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; SDL_WindowFlags flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE |
SDL_WINDOW_HIGH_PIXEL_DENSITY;
if (settings->fullscreen.get()) { if (settings->fullscreen.get()) {
flags |= SDL_WINDOW_FULLSCREEN; flags |= SDL_WINDOW_FULLSCREEN;
@ -185,6 +186,13 @@ window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept {
// SDL_GL_SetAttribute(SDL_WINDOW_ALLOW_HIGHDPI, false); // SDL_GL_SetAttribute(SDL_WINDOW_ALLOW_HIGHDPI, false);
#endif #endif
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, settings->samples.get()); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, settings->samples.get());
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
context = SDL_GL_CreateContext(window); context = SDL_GL_CreateContext(window);
if (!context) { if (!context) {
@ -203,6 +211,10 @@ window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept {
isSuccessfull = false; isSuccessfull = false;
return; return;
} }
float scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
logger.info() << "monitor content scale: " << scale;
} }
window_sdl::~window_sdl() { window_sdl::~window_sdl() {
if (window) { if (window) {
@ -215,10 +227,11 @@ window_sdl::~window_sdl() {
} }
} }
void window_sdl::swapBuffers() const noexcept { void window_sdl::swapBuffers() noexcept {
if (!SDL_GL_SwapWindow(window)) [[unlikely]] { // C++20 needed if (!SDL_GL_SwapWindow(window)) [[unlikely]] { // C++20 needed
logger.error() << "Cant swap buffer: " << SDL_GetError(); logger.error() << "Cant swap buffer: " << SDL_GetError();
} }
resetScissor();
} }
bool window_sdl::isMaximized() const { bool window_sdl::isMaximized() const {
return (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) != 0; return (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) != 0;

View file

@ -15,7 +15,7 @@ public:
window_sdl &operator=(const window_sdl &) = delete; window_sdl &operator=(const window_sdl &) = delete;
window_sdl &operator=(window_sdl &&) = default; window_sdl &operator=(window_sdl &&) = default;
void swapBuffers() const noexcept override; void swapBuffers() noexcept override;
bool isMaximized() const override; bool isMaximized() const override;
bool isFocused() const override; bool isFocused() const override;
@ -51,9 +51,9 @@ private:
bool toClose = false; bool toClose = false;
bool fullscreen = false; bool fullscreen = false;
SDL_Window *window; SDL_Window *window = nullptr;
SDL_GLContext context; SDL_GLContext context = nullptr;
std::stack<glm::vec4> scissorStack; std::stack<glm::vec4> scissorStack;
glm::vec4 scissorArea; glm::vec4 scissorArea {};
}; };

View file

@ -12,7 +12,7 @@ struct DisplaySettings;
class Window { class Window {
public: public:
virtual ~Window() = default; virtual ~Window() = default;
virtual void swapBuffers() const noexcept = 0; virtual void swapBuffers() noexcept = 0;
virtual bool isMaximized() const = 0; virtual bool isMaximized() const = 0;
virtual bool isFocused() const = 0; virtual bool isFocused() const = 0;