| 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 | |||
| 18 | /** | ||
| 19 | * Having only static members, this class is a singleton, i.e. it can only be | ||
| 20 | * instanciated once. It manages the graphical output and provides methods to | ||
| 21 | * render the system. | ||
| 22 | */ | ||
| 23 | class Graphics { | ||
| 24 | public: | ||
| 25 | inline static Simulation *simulation; | ||
| 26 | inline static float framerate; | ||
| 27 | inline static std::chrono::time_point<std::chrono::system_clock> startCurrentFrame; | ||
| 28 | inline static std::chrono::time_point<std::chrono::system_clock> startLastFrame; | ||
| 29 | inline static GLFWwindow *window; | ||
| 30 | inline static int windowWidth; | ||
| 31 | inline static int windowHeight; | ||
| 32 | inline static std::map<std::string, Shader *> shader; | ||
| 33 | inline static Camera camera; | ||
| 34 | inline static std::map<std::string, unsigned int> VAO; | ||
| 35 | inline static unsigned int coordinateBuffer; | ||
| 36 | inline static unsigned int positionBuffer; | ||
| 37 | inline static unsigned int sigmaBuffer; | ||
| 38 | inline static unsigned int speciesBuffer; | ||
| 39 | inline static unsigned int orientationBuffer; | ||
| 40 | inline static std::string colorscheme; | ||
| 41 | inline static int numColorsFix; | ||
| 42 | inline static float lastX; | ||
| 43 | inline static float lastY; | ||
| 44 | inline static bool firstMouse; | ||
| 45 | inline static glm::vec3 cameraPositionReset; | ||
| 46 | inline static float cameraYawReset; | ||
| 47 | inline static float cameraPitchReset; | ||
| 48 | inline static std::vector<float> positions; | ||
| 49 | inline static std::vector<float> orientations; | ||
| 50 | inline static std::vector<float> sigma; | ||
| 51 | inline static std::vector<int> colors; | ||
| 52 | |||
| 53 | inline static std::vector<float> sphereVertices; | ||
| 54 | |||
| 55 | Graphics(Simulation *simulation, const YAML::Node &config); | ||
| 56 | ~Graphics(); | ||
| 57 | |||
| 58 | static void setUniversalUniforms(); | ||
| 59 | static void drawSystem(); | ||
| 60 | static void drawParticles(); | ||
| 61 | |||
| 62 | static void draw(); | ||
| 63 | static void resetCamera(); | ||
| 64 | static void printStatusAndWait(); | ||
| 65 | }; | ||
| 66 | |||
| 67 | #else | ||
| 68 | |||
| 69 | #include "simulation.hpp" | ||
| 70 | |||
| 71 | /** | ||
| 72 | * We still provide a dummy class that does not do anything if we compile | ||
| 73 | * without graphics support. This way, we do not have to change the main | ||
| 74 | * simulation loop and still have stubs for draw() and printStatusAndWait(). | ||
| 75 | */ | ||
| 76 | class Graphics { | ||
| 77 | public: | ||
| 78 | ✗ | Graphics(Simulation *simulation, const YAML::Node &config) {} | |
| 79 | static void draw() {} | ||
| 80 | static void resetCamera() {} | ||
| 81 | static void printStatusAndWait() {} | ||
| 82 | }; | ||
| 83 | |||
| 84 | #endif | ||
| 85 |