SGCT master (487fac4)
Simple Graphics Cluster Toolkit
Loading...
Searching...
No Matches
window.h
Go to the documentation of this file.
1/*****************************************************************************************
2 * SGCT *
3 * Simple Graphics Cluster Toolkit *
4 * *
5 * Copyright (c) 2012-2026 *
6 * For conditions of distribution and use, see copyright notice in LICENSE.md *
7 ****************************************************************************************/
8
9#ifndef __SGCT__WINDOW__H__
10#define __SGCT__WINDOW__H__
11
12#include <sgct/sgctexports.h>
13
14#include <sgct/definitions.h>
16#include <sgct/screencapture.h>
17#include <sgct/shaderprogram.h>
18#include <sgct/viewport.h>
19#include <cmath>
20#include <cstddef>
21#include <cstdint>
22#include <filesystem>
23#include <memory>
24#include <optional>
25#include <string>
26#include <string_view>
27#include <vector>
28
29#ifdef SGCT_HAS_NDI
30#include <Processing.NDI.Lib.h>
31#include <Processing.NDI.Send.h>
32#include <Processing.NDI.Structs.h>
33#endif // SGCT_HAS_NDI
34
35struct GLFWwindow;
36
37#ifdef SGCT_HAS_SPOUT
38struct SPOUTLIBRARY;
39using SPOUTHANDLE = SPOUTLIBRARY*;
40#endif // SGCT_HAS_SPOUT
41
42namespace sgct {
43
44namespace config { struct Window; }
45
46class SGCT_EXPORT Window {
47public:
51 enum class StereoMode : uint8_t {
52 NoStereo = 0,
53 Active,
54 AnaglyphRedCyan,
55 AnaglyphAmberBlue,
56 AnaglyphRedCyanWimmer,
57 Checkerboard,
58 CheckerboardInverted,
59 VerticalInterlaced,
60 VerticalInterlacedInverted,
61 Dummy,
62 SideBySide,
63 SideBySideInverted,
64 TopBottom,
65 TopBottomInverted
66 };
67
69
74 static void initNvidiaSwapGroups();
75
80 static void setBarrier(bool state);
81 static bool isBarrierActive();
82 static bool isUsingSwapGroups();
83 static unsigned int swapGroupFrameNumber();
84
85 Window(const config::Window& window);
87
95 void openWindow(GLFWwindow* share, bool isLastWindow);
96
98
103
105
107
108 void update();
109
110 void draw();
111
113
117 void swapBuffers(bool takeScreenshot);
118
120
121 // Returns true if this window has any settings that require a fallback on an OpenGL
122 // compatibility profile
124
126 bool isOpenXREnabled() const;
127
132 vec2 scale() const;
133
137 float aspectRatio() const;
138
143
147 GLFWwindow* windowHandle() const;
148
149 void addViewport(std::unique_ptr<Viewport> vpPtr);
150 const std::vector<std::unique_ptr<Viewport>>& viewports() const;
151
152 void updateFrustums(float nearClip, float farClip);
153 void renderScreenQuad() const;
154
162
169
173 bool isWindowResized() const;
174
178 bool isFocused() const;
179
183 int id() const;
184
188 void setName(std::string name);
189
193 const std::string& name() const;
194
198 void setTags(std::vector<std::string> tags);
199
203 bool hasTag(std::string_view tag) const;
204
210 void setVisible(bool state);
211
215 bool isVisible() const;
216
221 void setRenderWhileHidden(bool state);
222
227
231 void setFullscreen(bool fullscreen);
232
236 void setAutoiconify(bool shouldAutoiconify);
237
241 void setFloating(bool floating);
242
246 void setTakeScreenshot(bool takeScreenshot);
247
251 void setWindowDecoration(bool state);
252
256 void setWindowResizable(bool state);
257
261 void setFixResolution(bool state);
262
266 bool isFixResolution() const;
267
268 void setHorizFieldOfView(float hFovDeg);
269
274
278 void setCallDraw2DFunction(bool state);
279
283 void setCallDraw3DFunction(bool state);
284
290
295
299 bool isStereo() const;
300
301
302 // @TODO: Remove this
303 unsigned int frameBufferTextureEye(Eye eye) const;
304
305private:
306 enum class TextureType { Color, Depth, Normal, Position };
307
308 Window(const Window&) = delete;
309 Window& operator=(const Window&) = delete;
310
314 void createTextures();
315 void generateTexture(unsigned int& id, TextureType type);
316
320 void resizeFBOs();
321
322 void destroyFBOs();
323
327 void createVBOs();
328 void loadShaders();
329 bool useRightEyeTexture() const;
330
338 void renderViewports(FrustumMode frustum, Eye eye) const;
339
346 void render2D(FrustumMode frustum) const;
347
359 void blitWindowViewport(const Window& prevWindow, const Viewport& viewport,
360 FrustumMode mode) const;
361
362 std::string _name;
363 std::vector<std::string> _tags;
364 int8_t _id = -1;
365
366 bool _hideMouseCursor;
367 bool _takeScreenshot;
368 bool _hasAlpha;
369 bool _hasCallDraw2DFunction;
370 bool _hasCallDraw3DFunction;
371 bool _isFullScreen;
372 bool _shouldAutoiconify;
373 bool _isFloating;
374 bool _shouldRenderWhileHidden;
375 uint8_t _nAASamples;
376 bool _useFXAA;
377 bool _isDecorated;
378 bool _isResizable;
379 bool _isMirrored;
380 int8_t _blitWindowId;
381 uint8_t _monitorIndex;
382 bool _mirrorX;
383 bool _mirrorY;
384 bool _noError;
385 bool _useOpenXR;
386 bool _isVisible;
387 bool _isIconified = false;
388 StereoMode _stereoMode;
389 std::optional<ivec2> _windowPos;
390 ivec2 _windowSize;
391 ivec2 _framebufferRes;
392
393 std::optional<ivec2> _pendingWindowSize;
394 bool _windowResChanged = false;
395 bool _hasFocus = false;
396 bool _useFixResolution = false;
397 bool _hasAnyMasks = false;
398 std::optional<ivec2> _pendingFramebufferRes;
399 GLFWwindow* _windowHandle = nullptr;
400 float _aspectRatio = 1.f;
401 vec2 _scale = vec2{ 0.f, 0.f };
402
403#ifdef SGCT_HAS_SPOUT
404 struct {
405 bool enabled;
406 std::string name;
407 SPOUTHANDLE handle = nullptr;
408 } _spout;
409#endif // SGCT_HAS_SPOUT
410
411#ifdef SGCT_HAS_NDI
412 struct {
413 NDIlib_send_instance_t handle = nullptr;
414 NDIlib_video_frame_v2_t videoFrame;
415 std::string name;
416 std::string groups;
417 unsigned int pingPongPbo[3] = { 0, 0, 0 };
418 int currentFrame = 0;
419 } _ndi;
420#endif // SGCT_HAS_NDI
421
422 const unsigned int _internalColorFormat;
423 const unsigned int _colorDataType;
424 const int _bytesPerColor = 4;
425
426 struct {
427 unsigned int leftEye = 0;
428 unsigned int rightEye = 0;
429 unsigned int depth = 0;
430 unsigned int intermediate = 0;
431 unsigned int normals = 0;
432 unsigned int positions = 0;
433 } _frameBufferTextures;
434
435 std::unique_ptr<ScreenCapture> _screenCaptureLeftOrMono;
436 std::unique_ptr<ScreenCapture> _screenCaptureRight;
437
438
439 unsigned int _vao = 0;
440 unsigned int _vbo = 0;
441
442 ShaderProgram _fboQuad;
443 ShaderProgram _overlay;
444 ShaderProgram _stereo;
445
446 struct FXAAShader {
447 ShaderProgram shader;
448 int sizeX = -1;
449 int sizeY = -1;
450 };
451 std::optional<FXAAShader> _fxaa;
452
453 std::vector<std::unique_ptr<Viewport>> _viewports;
454 std::unique_ptr<OffScreenBuffer> _finalFBO;
455
456 static GLFWwindow* _sharedHandle;
457 static bool _useSwapGroups;
458 static bool _isBarrierActive;
459
460 // ScalableMesh
461 struct {
462 void* sdk = nullptr;
463 std::filesystem::path path;
464 } _scalableMesh;
465};
466
468 const config::Window& window);
469
470} // namespace sgct
471
472#endif // __SGCT__WINDOW__H__
This class holds and manages viewportdata and calculates frustums.
Definition viewport.h:29
Definition window.h:46
bool needsCompatibilityProfile() const
static void initNvidiaSwapGroups()
Init Nvidia swap groups if supported by hardware.
void setHorizFieldOfView(float hFovDeg)
static bool isBarrierActive()
void renderScreenQuad() const
int id() const
void swapBuffers(bool takeScreenshot)
Swap previous data and current data.
GLFWwindow * windowHandle() const
void setCallDraw3DFunction(bool state)
Set if the specified Draw3D function pointer should be called for this window.
void setWindowDecoration(bool state)
Set if window borders should be visible.
bool isStereo() const
StereoMode
Different stereo modes used for rendering.
Definition window.h:51
float aspectRatio() const
unsigned int frameBufferTextureEye(Eye eye) const
void setName(std::string name)
Name this window.
static void resetSwapGroupFrameNumber()
Force a restore of the shared OpenGL context.
Window(const config::Window &window)
bool isFocused() const
void setAutoiconify(bool shouldAutoiconify)
Sets whether a full screen window should automatically iconify when losing focus.
void setFloating(bool floating)
Set if the window should float (be on top / topmost).
const std::vector< std::unique_ptr< Viewport > > & viewports() const
void makeOpenGLContextCurrent()
void initializeContextSpecific()
void setTags(std::vector< std::string > tags)
Tag this window.
ivec2 windowSize() const
bool isWindowResized() const
void setFixResolution(bool state)
Force the framebuffer to a fixed size which may be different from the window size.
void updateFrustums(float nearClip, float farClip)
void closeWindow()
void openWindow(GLFWwindow *share, bool isLastWindow)
This function is used to open the window.
const std::string & name() const
void setStereoMode(StereoMode sm)
Set the stereo mode.
void setTakeScreenshot(bool takeScreenshot)
Set if the window should participate in screenshot taking.
void addViewport(std::unique_ptr< Viewport > vpPtr)
vec2 scale() const
void updateResolutions()
static void setBarrier(bool state)
void setRenderWhileHidden(bool state)
Set if window should render while hidden.
ivec2 framebufferResolution() const
Get the dimensions of the final FBO.
void setWindowResizable(bool state)
Set if the window should be resizable.
bool isOpenXREnabled() const
void initialize()
Initialize window buffers such as textures, FBOs, VAOs, VBOs and PBOs.
void setFramebufferResolution(ivec2 resolution)
Sets the framebuffer resolution.
StereoMode stereoMode() const
bool isVisible() const
void renderFBOTexture()
bool hasTag(std::string_view tag) const
static void makeSharedContextCurrent()
static unsigned int swapGroupFrameNumber()
bool isRenderingWhileHidden() const
void setCallDraw2DFunction(bool state)
Set if the specified Draw2D function pointer should be called for this window.
float horizFieldOfViewDegrees() const
Get FOV of viewport[0].
void setFullscreen(bool fullscreen)
Set if fullscreen mode should be used.
bool shouldTakeScreenshot() const
void setVisible(bool state)
Set the visibility state of this window.
static bool isUsingSwapGroups()
bool isFixResolution() const
SPOUTLIBRARY * SPOUTHANDLE
Definition cubemap.h:27
Definition actions.h:16
Eye
Definition definitions.h:18
config::Window createScalableConfiguration(const config::Window::Scalable &scalable, const config::Window &window)
FrustumMode
Definition definitions.h:23
Definition config.h:360
Definition config.h:316
Definition math.h:17
Definition math.h:47