OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
Window.h
1// =====================================================================================================================
2// OpenShaderDesigner, an open source software utility to create materials and shaders.
3// Copyright (C) 2024 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef WINDOW_H
20#define WINDOW_H
21
22#include <SDL2/SDL.h>
23#include <glm/glm.hpp>
24#include <string>
25#include <Core/EventSystem.h>
26
27#include "open-cpp-utils/optional.h"
28
29namespace ocu = open_cpp_utils;
30
31namespace OpenShaderDesigner
32{
33
34BeginEvent(SDLEvent)
35 const SDL_Event sdl_event;
36
37 SDLEvent() : sdl_event() {}
38
39 explicit SDLEvent(const SDL_Event &event) : sdl_event(event) {}
40EndEvent
41
42
43BeginEvent(BeginFrame)
44EndEvent;
45
46BeginEvent(SDLEventsDone)
47EndEvent;
48
49BeginEvent(EndFrame)
50EndEvent;
51
52
53class Window
54{
55public:
56 enum class VSyncMode : int
57 {
58 DISABLED = 0,
59 ENABLED = 1,
60 ADAPTIVE = -1,
61 DEFAULT = DISABLED,
62 };
63
64 enum class FullscreenMode : int
65 {
66 WINDOWED = 0,
67 FULLSCREEN = SDL_WINDOW_FULLSCREEN,
68 FULLSCREEN_WINDOW = SDL_WINDOW_FULLSCREEN_DESKTOP,
69 };
70
72 {
73 struct
74 {
75 std::string Title;
76 } Application;
77
78 struct
79 {
80 FullscreenMode Fullscreen;
81 glm::ivec2 Resolution;
82 VSyncMode VSync;
83 bool HDR;
84 ocu::optional<int> Multisamples;
85 } Video;
86
88 : Application { "App" }
89 , Video { FullscreenMode::WINDOWED, glm::ivec2(1280, 720), VSyncMode::DISABLED, false }
90 { }
91 };
92
93 inline static const Configuration DefaultConfiguration;
94
95 explicit Window(const Configuration& config);
96 ~Window();
97
98 void HandleEvents();
99 void BeginFrame();
100 void EndFrame();
101
102 void Close() { Open_ = false; }
103 [[nodiscard]] bool IsOpen() const { return Open_; }
104
105 SDL_Window* GetHandle() { return Handle_; }
106 [[nodiscard]] const SDL_Window* GetHandle() const { return Handle_; }
107
108 SDL_GLContext GetContext() { return Context_; }
109 [[nodiscard]] const SDL_GLContext GetContext() const { return Context_; }
110
111 [[nodiscard]] glm::ivec2 Size() const { return Config_.Video.Resolution; }
112private:
113 Configuration Config_;
114 SDL_Window* Handle_;
115 SDL_GLContext Context_;
116 bool Open_;
117};
118
119}
120
121
122
123
124#endif //WINDOW_H
Definition Window.h:54