Line |
Branch |
Exec |
Source |
1 |
|
|
#ifndef NO_GRAPHICS |
2 |
|
|
#pragma once |
3 |
|
|
|
4 |
|
|
// Preserve order |
5 |
|
|
// clang-format off |
6 |
|
|
#include <GL/glew.h> |
7 |
|
|
#include <GLFW/glfw3.h> |
8 |
|
|
// clang-format on |
9 |
|
|
|
10 |
|
|
#include <chrono> |
11 |
|
|
#include <map> |
12 |
|
|
#include <string> |
13 |
|
|
|
14 |
|
|
#include "camera.hpp" |
15 |
|
|
#include "shader.hpp" |
16 |
|
|
#include "simulation.hpp" |
17 |
|
|
#include "system.hpp" |
18 |
|
|
|
19 |
|
|
/** |
20 |
|
|
* Having only static members, this class is a singleton, i.e. it can only be |
21 |
|
|
* instanciated once. It manages the graphical output and provides methods to |
22 |
|
|
* render the system. |
23 |
|
|
*/ |
24 |
|
|
class Graphics { |
25 |
|
|
public: |
26 |
|
|
inline static Simulation *simulation; |
27 |
|
|
inline static float framerate; |
28 |
|
|
inline static std::chrono::time_point<std::chrono::system_clock> startCurrentFrame; |
29 |
|
|
inline static std::chrono::time_point<std::chrono::system_clock> startLastFrame; |
30 |
|
|
inline static GLFWwindow *window; |
31 |
|
|
inline static int windowWidth; |
32 |
|
|
inline static int windowHeight; |
33 |
|
|
inline static std::map<std::string, Shader *> shader; |
34 |
|
|
inline static Camera camera; |
35 |
|
|
inline static std::map<std::string, unsigned int> VAO; |
36 |
|
|
inline static unsigned int coordinateBuffer; |
37 |
|
|
inline static unsigned int positionBuffer; |
38 |
|
|
inline static unsigned int sigmaBuffer; |
39 |
|
|
inline static unsigned int speciesBuffer; |
40 |
|
|
inline static unsigned int orientationBuffer; |
41 |
|
|
inline static std::string colorscheme; |
42 |
|
|
inline static float lastX; |
43 |
|
|
inline static float lastY; |
44 |
|
|
inline static bool firstMouse; |
45 |
|
|
|
46 |
|
|
inline static std::vector<float> sphereVertices; |
47 |
|
|
|
48 |
|
|
Graphics(Simulation *simulation, const YAML::Node &config); |
49 |
|
|
~Graphics(); |
50 |
|
|
|
51 |
|
|
static void setUniversalUniforms(); |
52 |
|
|
static void drawSystem(); |
53 |
|
|
static void drawParticles(); |
54 |
|
|
|
55 |
|
|
static void draw(); |
56 |
|
|
static void resetCamera(); |
57 |
|
|
static void printStatusAndWait(); |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
#else |
61 |
|
|
|
62 |
|
|
#include "system.hpp" |
63 |
|
|
|
64 |
|
|
/** |
65 |
|
|
* We still provide a dummy class that does not do anything if we compile |
66 |
|
|
* without graphics support. This way, we do not have to change the main |
67 |
|
|
* simulation loop and still have stubs for draw() and printStatusAndWait(). |
68 |
|
|
*/ |
69 |
|
|
class Graphics { |
70 |
|
|
public: |
71 |
|
✗ |
Graphics(Simulation *simulation, const YAML::Node &config) {} |
72 |
|
|
static void draw() {} |
73 |
|
|
static void resetCamera() {} |
74 |
|
|
static void printStatusAndWait() {} |
75 |
|
|
}; |
76 |
|
|
|
77 |
|
|
#endif |
78 |
|
|
|