9#ifndef __SGCT__ENGINE__H__
10#define __SGCT__ENGINE__H__
12#include <sgct/sgctexports.h>
57 std::optional<std::filesystem::path> path = std::nullopt);
71class SGCT_EXPORT Engine {
172 std::optional<std::pair<uint64_t, uint64_t>>
limits;
214 std::vector<std::byte> (*
encode)() =
nullptr;
218 void (*
decode)(
const std::vector<std::byte>&) =
nullptr;
251 void (*
drop)(
const std::vector<std::string_view>&) =
nullptr;
460 const std::vector<std::unique_ptr<Window>>&
windows()
const;
509 static Engine* _instance;
536 void frameLockPreStage();
542 void frameLockPostStage();
550 void waitForAllWindowsInSwapGroupToOpen();
553 void (*_preWindowFn)() =
nullptr;
556 void (*_initOpenGLFn)(GLFWwindow*) =
nullptr;
559 void (*_preSyncFn)() =
nullptr;
562 void (*_postSyncPreDrawFn)() =
nullptr;
568 void (*_draw2DFn)(
const RenderData&) =
nullptr;
571 void (*_postDrawFn)() =
nullptr;
574 void (*_cleanupFn)() =
nullptr;
578 float _nearClipPlane = 0.1f;
582 float _farClipPlane = 100.f;
588 double _statsPrevTimestamp = 0.0;
592 std::unique_ptr<StatisticsRenderer> _statisticsRenderer;
595 bool _shouldTakeScreenshot =
false;
598 bool _shouldTerminate =
false;
602 std::vector<int> _shouldTakeScreenshotIds;
606 std::unique_ptr<std::thread> _thread;
608 unsigned int _frameCounter = 0;
609 unsigned int _shotCounter = 0;
void exec()
This function starts the SGCT render loop in which the rendering, synchronization,...
const Settings & settings() const
unsigned int currentFrameNumber() const
Returns the number of the current frame.
void takeScreenshot(std::vector< int > windowIds=std::vector< int >())
Takes an RGBA screenshot and saves it as a PNG file.
float statsGraphScale() const
Returns the current scaling value used to render the statistics graphs if they are enabled.
bool isMaster() const
Returns if this Node is the master in a clustered environment.
void setScreenshotNumber(unsigned int number)
Sets the number that the next screenshot will recieve with the next call of takeScreenshot.
void(*)(const RenderData &) DrawFunction
Definition engine.h:73
void setCaptureFromBackBuffer(bool state)
Set if capture should capture warped from backbuffer instead of texture.
static void create(config::Cluster cluster, Callbacks callbacks, const Configuration &arg)
Creates the singleton Engine that is accessible through the Engine::instance function.
void resetScreenshotNumber()
Resets the screenshot number to 0.
vec2 statsGraphOffset() const
Returns the current offset value used to render the statistics graphics away from the center of the s...
void setStatsGraphOffset(vec2 offset)
Sets the new offet value for the statistics graph rendering.
Engine::DrawFunction drawFunction() const
This function returns the draw function to be used in internal classes that need to repeatedly call t...
StatisticsRenderer * statisticsRenderer()
const Node & thisNode() const
Returns a reference to the node that represents this computer.
const Statistics & statistics() const
Returns the Engine::Statistics object that contains all collected information about the frametimes,...
void setStatsGraphVisibility(bool value)
Determines whether the graph displaying the rendering stats is being displayed or not.
void terminate()
Signals to SGCT that the application should be terminated at the end of the next frame.
void setNearAndFarClippingPlanes(float nearClippingPlane, float farClippingPlane)
Set the near and far clipping planes.
void setStatsGraphScale(float scale)
Sets the new scaling value for the statistics graph rendering.
void setCapturePath(std::filesystem::path path)
Set capture/screenshot path used by SGCT.
unsigned int screenShotNumber() const
Returns the number the next screenshot will receive upon the next call of takeScreenshot.
const std::vector< std::unique_ptr< Window > > & windows() const
Returns a list of all windows for the current node.
void updateFrustums() const
This functions updates the frustum of all viewports.
float nearClipPlane() const
Returns the distance to the near clipping plane in meters.
Engine::DrawFunction draw2DFunction() const
static User & defaultUser()
Returns a pointer to the default user, i.e.
const Window * focusedWindow() const
Return the Window that currently has the focus.
static void destroy()
Destroys the singleton Engine instance that was created by Engine::create and that is accessible thro...
float farClipPlane() const
Returns the distance to the far clipping plane in meters.
static Engine & instance()
Returns the global Engine object that is created through the Engine::create function.
Definition statisticsrenderer.h:23
Helper class for setting user variables.
Definition user.h:24
Definition clustermanager.h:22
double time()
Returns the number of seconds since the program start.
Action
Definition actions.h:18
MouseButton
Definition mouse.h:18
Modifier
Definition modifiers.h:18
config::Cluster loadCluster(std::optional< std::filesystem::path > path=std::nullopt)
Loads the cluster information from the provided path.
Definition commandline.h:22
This struct holds all of the callback functions that can be used by the client library to be called d...
Definition engine.h:180
void(*) draw2D(const RenderData &)
This function is be called after overlays and post effects has been drawn and can used to render text...
Definition engine.h:203
void(*) dataTransferStatus(bool, int)
This function is called when the connection status changes.
Definition engine.h:230
void(*) cleanup()
This is called before all SGCT components will be destroyed.
Definition engine.h:210
void(*) drop(const std::vector< std::string_view > &)
Drop files to any window. All windows are connected to this callback.
Definition engine.h:251
void(*) keyboard(Key, Modifier, Action, int, Window *)
This function sets the keyboard callback (GLFW wrapper) for all windows.
Definition engine.h:236
void(*) dataTransferDecode(void *, int, int, int)
This function is called when a TCP message is received.
Definition engine.h:227
void(*) mouseScroll(double, double, Window *)
All windows are connected to this callback.
Definition engine.h:248
void(*) draw(const RenderData &)
This function draws the scene and could be called several times per frame as it's called once per vie...
Definition engine.h:199
std::vector< std::byte >(*) encode()
This function is called to encode all shared data that is sent to the connected nodes in a clustered ...
Definition engine.h:214
void(*) preWindow()
This function is called before the window is created (before OpenGL context is created).
Definition engine.h:184
void(*) decode(const std::vector< std::byte > &)
This function is called by decode all shared data sent to us from the master.
Definition engine.h:218
void(*) mouseButton(MouseButton, Modifier, Action, Window *)
This function sets the mouse button callback (GLFW wrapper) for all windows.
Definition engine.h:242
void(*) postDraw()
This function is called after the draw stage but before the OpenGL buffer swap.
Definition engine.h:206
void(*) externalDecode(const char *, int)
This function is called when a TCP message is received.
Definition engine.h:221
void(*) preSync()
This function is called before the synchronization stage.
Definition engine.h:192
void(*) externalStatus(bool)
This function is called when the connection status changes.
Definition engine.h:224
void(*) postSyncPreDraw()
This function is called once per frame after sync but before draw stage.
Definition engine.h:195
void(*) initOpenGL(GLFWwindow *)
This function is called once before the starting the render loop and after creation of the OpenGL con...
Definition engine.h:189
void(*) dataTransferAcknowledge(int, int)
This function is called when data is successfully sent.
Definition engine.h:233
void(*) character(unsigned int, int, Window *)
All windows are connected to this callback.
Definition engine.h:239
void(*) mousePos(double, double, Window *)
All windows are connected to this callback.
Definition engine.h:245
bool addWindowName
If set to true, the window name is added to screenshots.
Definition engine.h:163
std::optional< std::pair< uint64_t, uint64_t > > limits
Information about the screenshot limits.
Definition engine.h:172
int nCaptureThreads
Definition engine.h:157
std::string prefix
The prefix to be used for all screenshots.
Definition engine.h:166
bool addNodeName
If set to true, the node name is added to screenshots.
Definition engine.h:160
std::filesystem::path capturePath
The location where the screenshots are being saved.
Definition engine.h:154
float syncTimeout
The number of seconds that SGCT will wait for the master or clients to connect before aborting.
Definition engine.h:150
bool usePositionTexture
Definition engine.h:146
bool createDebugContext
Stores the configuration option whether the created OpenGL contexts should be debug contexts or regul...
Definition engine.h:126
bool captureBackBuffer
Get if capture should use backbuffer data or texture.
Definition engine.h:142
int8_t swapInterval
Sets the swap interval to be used by the application -1 = adaptive sync(Nvidia) 0 = vertical sync off...
Definition engine.h:133
bool useDepthTexture
Definition engine.h:144
bool useNormalTexture
Definition engine.h:145
bool printSyncMessage
If this is true, a log message is printed to the console while a client is waiting for the master to ...
Definition engine.h:138
Structure with all statistics gathered about different frametimes.
Definition engine.h:81
std::array< double, HistoryLength > loopTimeMin
The lowest time recorded for network communication between master and clients.
Definition engine.h:96
std::array< double, HistoryLength > syncTimes
The amount of time spend synchronizing the state between master and clients.
Definition engine.h:93
std::array< double, HistoryLength > frametimes
The times that contain the entire time spending processing the frames.
Definition engine.h:87
std::array< double, HistoryLength > drawTimes
The amount of time spend rendering the 2D and 3D components of the frame.
Definition engine.h:90
std::array< double, HistoryLength > loopTimeMax
The highest time recorded for network communication between master and clients.
Definition engine.h:99
static constexpr int HistoryLength
For how many frames are the history values collected before the oldest values are replaced.
Definition engine.h:84
Definition callbackdata.h:22