Avara3D 0.2.0
C++ API reference
Window.h
1//
2// GLFWWindow.h
3// avara3d
4//
5// Created by Morgan Davis on 4/16/2024.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_RENDER_CONTEXT_GLFWWINDOW_H
10#define AVARA3D_RENDER_CONTEXT_GLFWWINDOW_H
11
12#include <memory>
13#include <string>
14
15#include "a3d/render/context/RenderContext.h"
16
17struct GLFWwindow;
18
19namespace a3d {
20
21 class Camera;
22 class Color;
23 class DesktopInputContext;
24 class Image;
25 class Node;
26 class Renderer;
27 class Scene;
28
36 class Window : public RenderContext {
37
38 public:
39 // [Public Static Member Functions]
40
42 static std::unique_ptr<DesktopInputContext> InputContext();
43
44 // [Public Lifecycle Functions]
45
56 bool fullScreen,
57 bool enableHighDPI = true,
59
60 Window(const Window& other) = delete;
61 Window& operator=(const Window& other) = delete;
62
63 Window(Window&&) = delete;
64 Window& operator=(Window&&) = delete;
65
66 ~Window() override;
67
68 // [Public Member Functions]
69
75 void open();
76
78 void close();
79
81 bool isOpen() const;
82
84 std::string title() const;
85
87 void title(const std::string& title);
88
91
93 void size(const math::uvec2& size);
94
97
99 void position(const math::uvec2& pos);
100
102 void center();
103
105 bool hidden() const;
106
108 void hidden(bool hidden);
109
111 bool cursorCaptured() const;
112
119 void cursorCaptured(bool captured);
120
122 bool cursorHidden() const;
123
126
128 bool highDPIEnabled() const;
129
130 // [Public RenderContext Member Functions]
131
133 bool vSyncEnabled() const override;
134
141 void vSyncEnabled(bool enabled) override;
142
143 // [RenderContext Internal Member Functions]
144
145 void pollEvents() override;
146
147 void beginFrame(const Scene& scene) override;
148 void endFrame(const Scene& scene) override;
149
150 void swapBuffers() override;
151
152 math::uvec2 viewportLogicalSize() const override;
153 math::uvec2 framebufferSize() const override;
154
155 unsigned defaultFramebuffer() const override;
156
157 // [Internal Member Functions]
158
159 void inputContext(DesktopInputContext* inputContext);
160 GLFWwindow* glfwWindow() const; // remove?
161
162 // [Internal Static Member Functions]
163
164 static void Destroy(GLFWwindow* window);
165
166 private:
167 // [Private Static Member Functions]
168
169 static void GLFWCursorPositionCallback(GLFWwindow* glfwWindow, double xPos, double yPos);
170 static void GLFWMouseButtonCallback(GLFWwindow* glfwWindow, int button, int action, int mods);
171 static void GLFWScrollWheelCallback(GLFWwindow* glfwWindow, double xOffset, double yOffset);
172 static void GLFWKeyCallback(GLFWwindow* glfwWindow, int key, int scanCode, int action, int mods);
173 static void GLFWWindowFocusCallback(GLFWwindow* glfwWindow, int focused);
174 static Window* WindowFromGLFWwindow(GLFWwindow* glfwWindow);
175 static DesktopInputContext* InputContextFromGLFWWindow(GLFWwindow* glfwWindow);
176
177 // [Private Member Functions]
178
179 void registerGLFWCallbacks();
180 void unregisterGLFWCallbacks();
181
182 // [Private Types]
183
184 struct DestroyGLFWWindow {
185 void operator()(GLFWwindow* window) {
186 Destroy(window);
187 }
188 };
189
190 // [Private Member Variables]
191
192 std::unique_ptr<GLFWwindow, DestroyGLFWWindow> _glfwWindow;
193 bool _vSyncEnabled;
194 bool _cursorCaptured;
195 bool _cursorHidden;
196 bool _open;
197 bool _hidden;
198 bool _highDPIEnabled;
199 DesktopInputContext* _inputContext;
200 };
201
202}
203
204#endif // AVARA3D_RENDER_CONTEXT_GLFWWINDOW_H
Exposes keyboard, pointer-button, pointer-motion, and scroll state.
Abstract rendering destination used by VisualWorld.
Definition: RenderContext.h:34
Antialiasing antialiasing() const
Returns the antialiasing mode selected when the rendering target was created.
Antialiasing
Selects multisample antialiasing requested for the rendering target.
Definition: RenderContext.h:40
@ None
No multisample antialiasing.
Owns a scene graph and the worlds used to simulate and render it.
Definition: Scene.h:44
RenderContext for interactive desktop and web rendering.
Definition: Window.h:36
Window(const math::uvec2 &size, bool fullScreen, bool enableHighDPI=true, Antialiasing antialiasing=Antialiasing::None)
Creates a rendering window and its rendering resources.
bool cursorHidden() const
Returns whether the pointer is requested to be hidden when not captured.
void open()
Shows the window and begins accepting normal window callbacks.
void hidden(bool hidden)
Shows or hides the window.
void title(const std::string &title)
Sets the window title.
void cursorHidden(bool hidden)
Shows or hides the pointer when pointer capture is disabled.
bool cursorCaptured() const
Returns whether pointer input is captured by the window.
bool hidden() const
Returns whether the window is explicitly hidden.
void vSyncEnabled(bool enabled) override
Enables or disables vertical synchronization when supported.
void center()
Centers the window on its current monitor when supported by the platform.
void position(const math::uvec2 &pos)
Sets the window position in screen coordinates.
static std::unique_ptr< DesktopInputContext > InputContext()
Creates the DesktopInputContext implementation used by Window.
bool isOpen() const
Returns whether the Window has been opened and not subsequently closed.
std::string title() const
Returns the window title; web builds currently return an empty string.
math::uvec2 size() const
Returns the window size in platform window coordinates.
void cursorCaptured(bool captured)
Captures or releases pointer input.
bool vSyncEnabled() const override
Returns whether vertical synchronization is enabled.
math::uvec2 position() const
Returns the window position in screen coordinates.
void size(const math::uvec2 &size)
Sets the window size in platform window coordinates.
void close()
Closes the window and releases pointer capture.
bool highDPIEnabled() const
Returns whether high-DPI rendering was requested when the Window was created.