Renderer.h
Go to the documentation of this file.
1 #ifndef B_RENDERER_H
2 #define B_RENDERER_H
3 
4 /* bRenderer includes */
5 #include "OSdetect.h"
6 #include "Renderer_GL.h"
7 #include "Logger.h"
8 #include "View.h"
9 #include "Input.h"
10 #include "ObjectManager.h"
11 #include "ModelRenderer.h"
12 
13 #ifdef __OBJC__
14 @class RendererCaller;
15 #endif
16 
17 class IRenderProject;
18 
22 class Renderer
23 {
24 public:
25 
26 #ifndef __OBJC__
27  typedef int RendererCaller;
28 #endif
29 
30  /* Functions */
31 
34  Renderer();
35 
38  virtual ~Renderer(){}
39 
46  ViewPtr getView();
47 
51 
55 
59 
62  bool isInitialized();
63 
66  bool isRunning();
67 
75 
82  void setInitFunction(void(*f)());
83 
91  void setLoopFunction(void(*f)(const double deltaTime, const double elapsedTime));
92 
100  void setTerminateFunction(void(*f)());
101 
105  bool initRenderer(std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
106 
111  bool initRenderer(bool fullscreen, std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
112 
119  bool initRenderer(GLint width, GLint height, bool fullscreen = false, std::string windowTitle = bRenderer::DEFAULT_WINDOW_TITLE());
120 
123  void runRenderer();
124 
127  void stopRenderer();
128 
131  void terminateRenderer();
132 
133 private:
134  /* Functions */
135 
138  void update();
139 
142  void reset();
143 
144  /* Variables */
145 
146  bool _initialized = false;
147  bool _running = false;
148 
149  double _elapsedTime = 0.0, _stopTime = 0.0, _startTime = 0.0;
150 
151  ViewPtr _view = nullptr;
152  InputPtr _input = nullptr;
153  ObjectManagerPtr _objectManager = nullptr;
154  ModelRendererPtr _modelRenderer = nullptr;
155 
156  IRenderProject *_renderProject = nullptr;
157 
158  RendererCaller *_rendererCaller = nullptr;
159 
160  void(*_initFunction)() = nullptr;
161  void(*_loopFunction)(const double deltaTime, const double elapsedTime) = nullptr;
162  void(*_terminateFunction)() = nullptr;
163 
164 };
165 
166 typedef std::shared_ptr< Renderer > RendererPtr;
167 
168 #endif /* defined(B_RENDERER_H) */
ModelRendererPtr getModelRenderer()
Returns a pointer to the model renderer.
Definition: Renderer.cpp:27
void runRenderer()
Start the render loop.
void setTerminateFunction(void(*f)())
Sets a static function that gets called when terminating the renderer.
Definition: Renderer.cpp:57
void terminateRenderer()
Terminate the renderer.
The main class that is able to initialize and maintain the render loop as well as a view...
Definition: Renderer.h:22
std::shared_ptr< Input > InputPtr
Definition: Input.h:270
void setLoopFunction(void(*f)(const double deltaTime, const double elapsedTime))
Sets a static function that gets called repeatedly when looping.
Definition: Renderer.cpp:52
std::shared_ptr< ModelRenderer > ModelRendererPtr
Definition: ModelRenderer.h:146
void stopRenderer()
Stop the render loop.
virtual ~Renderer()
Virtual destructor.
Definition: Renderer.h:38
bool isInitialized()
Returns true if the renderer has already been initialized.
Definition: Renderer.cpp:32
This interface needs to be implemented if the renderer should be used in an object oriented manner...
Definition: IRenderProject.h:10
std::shared_ptr< View > ViewPtr
Definition: View.h:225
std::shared_ptr< Renderer > RendererPtr
Definition: Renderer.h:166
bool isRunning()
Returns true if the renderer is running.
Definition: Renderer.cpp:37
InputPtr getInput()
Returns a pointer to the input handler of the renderer.
Definition: Renderer.cpp:17
int RendererCaller
Definition: Renderer.h:27
bool initRenderer(std::string windowTitle=bRenderer::DEFAULT_WINDOW_TITLE())
Do all necessary initializations for the renderer to be ready to run (returns true in the case of suc...
Definition: Renderer.cpp:62
void setInitFunction(void(*f)())
Sets a static function that gets called when initializing the renderer.
Definition: Renderer.cpp:47
std::string DEFAULT_WINDOW_TITLE()
Definition: Configuration.cpp:37
ObjectManagerPtr getObjects()
Returns a pointer to the object management of the renderer.
Definition: Renderer.cpp:22
std::shared_ptr< ObjectManager > ObjectManagerPtr
Definition: ObjectManager.h:690
ViewPtr getView()
Returns a pointer to the view of the renderer.
Definition: Renderer.cpp:12
Renderer()
Constructor.
Definition: Renderer.cpp:7
void setRenderProject(IRenderProject *p)
Sets the project instance to be used for function calls.
Definition: Renderer.cpp:42