OpenShaderDesigner 0.0.1
Loading...
Searching...
No Matches
Window.h
1// =====================================================================================================================
2// Copyright 2024 Medusa Slockbower
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// =====================================================================================================================
15
16#ifndef WINDOW_H
17#define WINDOW_H
18
19#include <SDL2/SDL.h>
20#include <glm/glm.hpp>
21#include <string>
22#include <Core/EventSystem.h>
23
24namespace OpenShaderDesigner
25{
26 BeginEvent(SDLEvent)
27 const SDL_Event sdl_event;
28
29 SDLEvent() : sdl_event() {}
30
31 explicit SDLEvent(const SDL_Event &event) : sdl_event(event) {}
32 EndEvent
33
34
35 BeginEvent(BeginFrame)
36 EndEvent;
37
38 BeginEvent(SDLEventsDone)
39 EndEvent;
40
41 BeginEvent(EndFrame)
42 EndEvent;
43
44
45 class Window
46 {
47 public:
48 enum class VSyncMode : int
49 {
50 DISABLED = 0,
51 ENABLED = 1,
52 ADAPTIVE = -1,
53 DEFAULT = DISABLED,
54 };
55
56 enum class FullscreenMode : int
57 {
58 WINDOWED = 0,
59 FULLSCREEN = SDL_WINDOW_FULLSCREEN,
60 FULLSCREEN_WINDOW = SDL_WINDOW_FULLSCREEN_DESKTOP,
61 };
62
64 {
65 struct
66 {
67 std::string Title;
68 } Application;
69
70 struct
71 {
72 FullscreenMode Fullscreen;
73 glm::ivec2 Resolution;
74 VSyncMode VSync;
75 bool HDR;
76 } Video;
77
79 : Application { "App" }
80 , Video { FullscreenMode::WINDOWED, glm::ivec2(1280, 720), VSyncMode::DISABLED, false }
81 { }
82 };
83
84 inline static const Configuration DefaultConfiguration;
85
86 explicit Window(const Configuration& config);
87 ~Window();
88
89 void HandleEvents();
90 void BeginFrame();
91 void EndFrame();
92
93 void Close() { Open = false; }
94 [[nodiscard]] bool IsOpen() const { return Open; }
95
96 SDL_Window* GetHandle() { return Handle; }
97 [[nodiscard]] const SDL_Window* GetHandle() const { return Handle; }
98
99 SDL_GLContext GetContext() { return Context; }
100 [[nodiscard]] const SDL_GLContext GetContext() const { return Context; }
101
102 [[nodiscard]] glm::ivec2 Size() const { return Config.Video.Resolution; }
103 private:
104 Configuration Config;
105 SDL_Window* Handle;
106 SDL_GLContext Context;
107 bool Open;
108 };
109}
110
111
112
113
114#endif //WINDOW_H
Definition Window.h:46