Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
graphics_system.h
Go to the documentation of this file.
1 #ifndef GRAPHICS_SYSTEM_H
2 #define GRAPHICS_SYSTEM_H
3 
4 #include <thread>
5 #include <atomic>
6 #include <map>
7 #include <set>
8 #include <string>
9 #ifdef __APPLE__
10 #include <OpenGL/gl3.h>
11 #else
12 #include <GL/glew.h>
13 #endif
14 #define GLFW_INCLUDE_GLCOREARB
15 #include <GLFW/glfw3.h>
16 #include <glm/glm.hpp>
17 #include "graphics/renderable.h"
19 #include "graphics/camera.h"
20 //= SCRIPTABLE
21 
22 namespace Graphics {
27  private:
28  struct RankedLight {
29  std::shared_ptr<Light> light;
30  float influence;
31  friend bool operator<(const RankedLight& left, const RankedLight& right) {
32  return left.influence < right.influence;
33  }
34  };
35 
36  GLFWwindow* window;
37  bool initialized;
38  float delta;
39  float delta_accum;
40 
41  std::string window_title;
42 
43  std::map<int, std::shared_ptr<Graphics::Renderable>> renderables_map;
44 
45  std::list<std::shared_ptr<Light>> lights;
46  unsigned int max_influence_lights;
47 
48  //The next id for renderables
49  int next_id;
50 
51  static void errorCallback(int error, const char* description);
52  static void windowSizeCallback(GLFWwindow* window, int width, int height);
53 
54  WindowExitFunctor window_exit;
55 
56  public:
71  void initialize(const int width, const int height, std::string name, const bool fullscreen, const WindowExitFunctor& window_exit);
77  bool isInitialized() const noexcept;
78 
84  bool isRunning() noexcept;
85 
89  void startRender();
93  void stopRender();
97  void startFrame();
101  void stopFrame();
102 
108  GLFWwindow* getWindow() const noexcept;
109  //= BEGIN SCRIPTABLE
115  int windowHeight();
121  int windowWidth();
122 
128  std::string windowName() const noexcept;
129 
135  void setWindowName(const std::string& name);
136 
145  int addRenderable(std::shared_ptr<Graphics::Renderable> renderable);
154  bool removeRenderable(const int id);
155 
162  int renderablesCount();
163 
169  void setMaxInfluenceLights(const unsigned int number) noexcept;
175  unsigned int getMaxInfluenceLights() const noexcept;
181  void addLight(std::shared_ptr<Light> light) noexcept;
187  void removeLight(std::shared_ptr<Light> light);
188  //= END SCRIPTABLE
189  GLFWwindow* getCurrentWindow() noexcept;
190 
191 
197  void destroy();
198 
199  };
200 }
201 
202 #endif
Definition: window_exit_functor.h:7
int renderablesCount()
Returns the number of renderables currently in the system.
Definition: graphics_system.cpp:139
int addRenderable(std::shared_ptr< Graphics::Renderable > renderable)
Adds a renderable to the renderable pool.
Definition: graphics_system.cpp:120
unsigned int getMaxInfluenceLights() const noexcept
Gets the maximum number of influencing lights.
Definition: graphics_system.cpp:220
void startRender()
Starts a render.
Definition: graphics_system.cpp:150
void setWindowName(const std::string &name)
Sets the window name.
Definition: graphics_system.cpp:116
void setMaxInfluenceLights(const unsigned int number) noexcept
Sets the maximum number influencing lights.
Definition: graphics_system.cpp:216
void removeLight(std::shared_ptr< Light > light)
Removes a light.
Definition: graphics_system.cpp:228
void stopRender()
Stops a render.
bool isRunning() noexcept
Determines if running.
Definition: graphics_system.cpp:86
void initialize(const int width, const int height, std::string name, const bool fullscreen, const WindowExitFunctor &window_exit)
Initializes the graphics system.
Definition: graphics_system.cpp:30
int windowWidth()
Getter for the window height.
Definition: graphics_system.cpp:90
bool isInitialized() const noexcept
Getter to see if system is initialized.
Definition: graphics_system.cpp:82
void stopFrame()
Stops a frame.
Definition: graphics_system.cpp:193
std::string windowName() const noexcept
Getter for the window name.
Definition: graphics_system.cpp:110
Class for graphics system.
Definition: graphics_system.h:26
void startFrame()
Starts a frame.
Definition: graphics_system.cpp:161
~GraphicsSystem()
Definition: graphics_system.cpp:24
void addLight(std::shared_ptr< Light > light) noexcept
Adds a light.
Definition: graphics_system.cpp:224
int windowHeight()
Getter for the window width.
Definition: graphics_system.cpp:100
GLFWwindow * getWindow() const noexcept
Gets the window.
Definition: graphics_system.cpp:197
bool removeRenderable(const int id)
Removes a renderable from the renderable pool.
Definition: graphics_system.cpp:127
void destroy()
Closes window, and destroys GLFW context.
Definition: graphics_system.cpp:232
GLFWwindow * getCurrentWindow() noexcept
Definition: graphics_system.cpp:146
GraphicsSystem()
Definition: graphics_system.cpp:21