libdonut 2.3.6
Application framework for cross-platform game development in C++20
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#ifndef DONUT_GRAPHICS_WINDOW_HPP
2#define DONUT_GRAPHICS_WINDOW_HPP
3
7#include <donut/math.hpp>
8
9#include <cstdint> // std::uint32_t
10
11namespace donut::graphics {
12
23 const char* title = "Application";
24
33 ivec2 size{800, 600};
34
38 bool resizable = true;
39
43 bool fullscreen = false;
44
60 bool vSync = false;
61
75 int msaaLevel = 0;
76};
77
81class Window {
82public:
91 explicit Window(const WindowOptions& options);
92
94 ~Window() = default;
95
97 Window(const Window&) = delete;
98
100 Window(Window&&) = delete;
101
103 Window& operator=(const Window&) = delete;
104
106 Window& operator=(Window&&) = delete;
107
112 void present();
113
122 void setTitle(const char* title);
123
135 void setSize(ivec2 size);
136
144 void setResizable(bool resizable);
145
153 void setFullscreen(bool fullscreen);
154
162 void setVSync(bool vSync);
163
171 [[nodiscard]] bool isScreenKeyboardShown() const noexcept;
172
178 [[nodiscard]] bool isFullscreen() const noexcept;
179
188 [[nodiscard]] ivec2 getSize() const noexcept;
189
198 [[nodiscard]] ivec2 getDrawableSize() const noexcept;
199
205 [[nodiscard]] std::uint32_t getId() const;
206
213 [[nodiscard]] Framebuffer& getFramebuffer();
214
215private:
216 struct VideoContext {
217 VideoContext();
218 ~VideoContext();
219
220 VideoContext(const VideoContext&) = delete;
221 VideoContext(VideoContext&&) = delete;
222 VideoContext& operator=(const VideoContext&) = delete;
223 VideoContext& operator=(VideoContext&&) = delete;
224 };
225
226 struct WindowDeleter {
227 void operator()(void* handle) const noexcept;
228 };
229
230 struct GLContextDeleter {
231 void operator()(void* handle) const noexcept;
232 };
233
234 [[no_unique_address]] VideoContext videoContext{};
235 UniqueHandle<void*, WindowDeleter> window{};
236 UniqueHandle<void*, GLContextDeleter> glContext{};
237 Framebuffer framebuffer{Handle{}};
238};
239
240} // namespace donut::graphics
241
242#endif
Unique resource handle with exclusive ownership of a GPU framebuffer.
Definition Framebuffer.hpp:15
Graphical window that can be rendered to.
Definition Window.hpp:81
std::uint32_t getId() const
Get a unique identifier for this window.
void setVSync(bool vSync)
Enable or disable vertical synchronization for the window.
~Window()=default
Destructor.
void setResizable(bool resizable)
Set whether to allow the window to be resized by the user or not.
ivec2 getDrawableSize() const noexcept
Get the drawable size of the window.
ivec2 getSize() const noexcept
Get the size of the window.
Window(const WindowOptions &options)
Create a new window.
void present()
Swap the window's front and back buffers, showing what has been rendered to the framebuffer since the...
bool isScreenKeyboardShown() const noexcept
Check if the screen keyboard is currently open.
Window & operator=(const Window &)=delete
Copying a window is not allowed, since it manages global state.
void setFullscreen(bool fullscreen)
Set the fullscreen state of the window.
Window(Window &&)=delete
Moving a window is not allowed, since it manages global state.
bool isFullscreen() const noexcept
Check if the window is currently in fullscreen mode.
Window & operator=(Window &&)=delete
Moving a window is not allowed, since it manages global state.
void setSize(ivec2 size)
Set the size of the window.
Framebuffer & getFramebuffer()
Get the Framebuffer for rendering to this window.
Window(const Window &)=delete
Copying a window is not allowed, since it manages global state.
void setTitle(const char *title)
Set the displayed title of the window.
Definition Buffer.hpp:7
std::uint32_t Handle
Generic GPU resource handle.
Definition Handle.hpp:11
Configuration options for a Window.
Definition Window.hpp:16
bool fullscreen
Whether the window should start in fullscreen mode or not.
Definition Window.hpp:43
bool vSync
Whether the window should use vertical synchronization or not.
Definition Window.hpp:60
const char * title
Non-owning pointer to a null-terminated UTF-8 string of the displayed title of the window.
Definition Window.hpp:23
ivec2 size
The desired size of the window, in screen coordinates (typically pixels).
Definition Window.hpp:33
int msaaLevel
Number of samples used for multisample anti-aliasing (MSAA) when rendering a pixel to the window via ...
Definition Window.hpp:75
bool resizable
Whether the user should be allowed to resize the window or not.
Definition Window.hpp:38