xoreos  0.0.5
graphics.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_GRAPHICS_H
26 #define GRAPHICS_GRAPHICS_H
27 
28 #include "src/common/atomic.h"
29 
30 #include <vector>
31 #include <list>
32 
33 #include "glm/mat4x4.hpp"
34 
35 #include "src/common/types.h"
36 #include "src/common/scopedptr.h"
37 #include "src/common/singleton.h"
38 #include "src/common/mutex.h"
39 #include "src/common/ustring.h"
40 
41 #include "src/graphics/types.h"
42 #include "src/graphics/windowman.h"
43 
45 
46 #include "src/events/notifyable.h"
47 
48 namespace Graphics {
49 
50 namespace Aurora {
51  class Model;
52 }
53 
54 class FPSCounter;
55 class Cursor;
56 class Renderable;
57 
59 class GraphicsManager : public Common::Singleton<GraphicsManager>, public Events::Notifyable {
60 public:
61  enum ScalingType {
64  };
65 
68 
70  void init();
72  void deinit();
73 
75  bool ready() const;
76 
78  bool needManualDeS3TC() const;
80  bool supportMultipleTextures() const;
82  size_t getMultipleTextureCount() const;
83 
85  bool isGL3() const;
86 
88 
90  bool setFSAA(int level);
91 
93  int getCurrentFSAA() const;
94 
96  uint32 getFPS() const;
97 
99  void setCullFace(bool enabled, GLenum mode = GL_BACK);
100 
102  void setGUIScale(ScalingType scaling);
104  void setGUISize(int guiWidth, int guiHeight);
105 
107  void setPerspective(float viewAngle, float clipNear, float clipFar);
109  void setOrthogonal(float clipNear, float clipFar);
110 
112  void setCursor(Cursor *cursor = 0);
113 
115  void takeScreenshot();
116 
118  bool project(float x, float y, float z, float &sX, float &sY, float &sZ);
119 
121  bool unproject(float x, float y,
122  float &x1, float &y1, float &z1,
123  float &x2, float &y2, float &z2) const;
124 
126  Renderable *getObjectAt(float x, float y);
127 
130 
141  void lockFrame();
149  void unlockFrame();
150 
153 
155  void abandon(TextureID *ids, uint32 count);
157  void abandon(ListID ids, uint32 count);
158 
159 
161  void renderScene();
162 
163  // Block of functions below may or may not be modified in the future.
165  const glm::mat4 &getProjectionMatrix() const;
166  glm::mat4 &getProjectionMatrix();
168  const glm::mat4 &getProjectionInverseMatrix() const;
169 
171  const glm::mat4 &getModelviewMatrix() const;
172  glm::mat4 &getModelviewMatrix();
174  const glm::mat4 &getModelviewInverseMatrix() const;
175 
177  void pauseAnimations();
179  void resumeAnimations();
180 
185 
186 private:
187  enum ProjectType {
190  };
191 
192  bool _ready;
193 
194  bool _debugGL;
195 
197 
198  // Extensions
202 
204 
205  int _fsaa;
206 
209 
211 
212  float _viewAngle;
213  float _clipNear;
214  float _clipFar;
215 
219 
221 
223 
224  glm::mat4 _perspective;
225  glm::mat4 _perspectiveInv;
226  glm::mat4 _ortho;
227  glm::mat4 _orthoInv;
228  glm::mat4 _projection;
229  glm::mat4 _projectionInv;
230  glm::mat4 _modelview;
231  glm::mat4 _modelviewInv;
232 
233  boost::atomic<uint32> _frameLock;
234  boost::atomic<bool> _frameEndSignal;
235 
237 
239 
242 
244 
245  std::vector<TextureID> _abandonTextures;
246  std::list<ListID> _abandonLists;
247 
249 
251 
252  void setupScene();
253 
254  bool setupSDLGL();
255  void checkGLExtensions();
256 
258  void perspective(float fovy, float aspect, float zNear, float zFar);
260  void ortho(float left, float right, float bottom, float top, float zNear, float zFar);
261 
262  void rebuildGLContainers();
263  void destroyGLContainers();
264 
265  void destroyContext();
266  void rebuildContext();
267 
268  void cleanupAbandoned();
269 
270  Renderable *getGUIObjectAt(float x, float y) const;
271  Renderable *getWorldObjectAt(float x, float y) const;
272 
273  void buildNewTextures();
274 
275  void beginScene();
276  bool playVideo();
277  bool renderWorld();
278  bool renderGUIFront();
279  bool renderGUIBack();
280  bool renderGUIConsole();
281  bool renderGUI(ScalingType scalingType, QueueType guiQueue, bool disableDepthMask);
282  bool renderCursor();
283 
284  bool renderWorldShader();
285  bool renderGUIFrontShader();
286  bool renderGUIBackShader();
287  bool renderGUIConsoleShader();
288  bool renderGUIShader(ScalingType scalingType, QueueType guiQueue, bool disableDepthMask);
289  bool renderCursorShader();
290 
291  void endScene();
292 
293  void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight);
294 };
295 
296 } // End of namespace Graphics
297 
299 #define GfxMan Graphics::GraphicsManager::instance()
300 
301 #endif // GRAPHICS_GRAPHICS_H
void lockFrame()
Increase the frame lock counter, disabling all frame rendering.
Definition: graphics.cpp:702
bool isGL3() const
Are we currently running an OpenGL 3.x context?
Definition: graphics.cpp:1290
bool _supportMultipleTextures
Do we have support for multiple textures?
Definition: graphics.h:200
Common::Mutex _abandonMutex
A mutex protecting abandoned structures.
Definition: graphics.h:248
Cursor * _cursor
The current cursor.
Definition: graphics.h:236
Class and macro for implementing singletons.
size_t getMultipleTextureCount() const
Return the number of texture units for multiple textures.
Definition: graphics.cpp:195
uint32 getFPS() const
How many frames per second to we render at the moments?
Definition: graphics.cpp:203
ProjectType _projectType
Definition: graphics.h:210
Common::ScopedPtr< FPSCounter > _fpsCounter
Counts the current frames per seconds value.
Definition: graphics.h:220
The graphics manager.
Definition: graphics.h:59
void init()
Initialize the graphics subsystem.
Definition: graphics.cpp:122
uint32 _lastSampled
Timestamp used to advance animations.
Definition: graphics.h:222
Renderable * getObjectAt(float x, float y)
Get the object at this screen position.
Definition: graphics.cpp:879
bool _ready
Was the graphics subsystem successfully initialized?
Definition: graphics.h:192
bool supportMultipleTextures() const
Do we have support for multiple textures?
Definition: graphics.cpp:191
const glm::mat4 & getModelviewInverseMatrix() const
Return the inverse modelview matrix (camera view).
Definition: graphics.cpp:1270
The global window manager.
bool setupSDLGL()
Setup SDL + OpenGL renderer.
Definition: graphics.cpp:242
Common::Mutex _renderableIDMutex
The mutex to govern renderable ID creation.
Definition: graphics.h:241
bool renderGUIShader(ScalingType scalingType, QueueType guiQueue, bool disableDepthMask)
Definition: graphics.cpp:1142
Basic graphics types.
GLuint TextureID
Definition: types.h:45
glm::mat4 _projectionInv
The inverse of our projection matrix.
Definition: graphics.h:229
void resumeAnimations()
Resume animation thread.
Definition: graphics.cpp:1278
A simple scoped smart pointer template.
glm::mat4 _perspective
3D perspective projection matrix.
Definition: graphics.h:224
uint32 _renderableID
The last ID given to a renderable.
Definition: graphics.h:240
An abstract cursor.
Definition: cursor.h:31
glm::mat4 _orthoInv
The inverse of our othographical matrix.
Definition: graphics.h:227
WindowManager::RenderType _renderType
Definition: graphics.h:203
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: graphics.cpp:1354
glm::mat4 _perspectiveInv
The inverse of our perspective matrix.
Definition: graphics.h:225
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:61
A mutex.
Definition: mutex.h:40
GLuint ListID
Definition: types.h:46
QueueType
Definition: types.h:71
ScalingType _scalingType
Definition: graphics.h:216
void registerAnimatedModel(Aurora::Model *model)
Register a model with the animation thread.
Definition: graphics.cpp:1282
bool unproject(float x, float y, float &x1, float &y1, float &z1, float &x2, float &y2, float &z2) const
Map the given screen coordinates onto a line in world space.
Definition: graphics.cpp:607
void setGUISize(int guiWidth, int guiHeight)
Configure the original size of the GUI.
Definition: graphics.cpp:445
bool needManualDeS3TC() const
Do we need to do manual S3TC DXTn decompression?
Definition: graphics.cpp:187
bool _takeScreenshot
Should screenshot be taken?
Definition: graphics.h:238
Low-level type definitions to handle fixed width types portably.
std::list< ListID > _abandonLists
Abandoned lists.
Definition: graphics.h:246
A class that can be notified by the NotificationManager.
void recalculateObjectDistances()
Recalculate all object distances to the camera and resort the objects.
Definition: graphics.cpp:729
bool project(float x, float y, float z, float &sX, float &sY, float &sZ)
Map the given world coordinates onto screen coordinates.
Definition: graphics.cpp:551
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
void perspective(float fovy, float aspect, float zNear, float zFar)
Set up a projection matrix.
Definition: graphics.cpp:467
void unregisterAnimatedModel(Aurora::Model *model)
Unregister a model from the animation thread.
Definition: graphics.cpp:1286
void takeScreenshot()
Take a screenshot.
Definition: graphics.cpp:800
int _fsaa
Current FSAA settings.
Definition: graphics.h:205
glm::mat4 _projection
Our projection matrix.
Definition: graphics.h:228
bool renderGUI(ScalingType scalingType, QueueType guiQueue, bool disableDepthMask)
Definition: graphics.cpp:1027
Helper header to include boost::atomic.
uint32 createRenderableID()
Create a new unique renderable ID.
Definition: graphics.cpp:761
void ortho(float left, float right, float bottom, float top, float zNear, float zFar)
Set up an orthogonal projection matrix.
Definition: graphics.cpp:521
glm::mat4 _modelview
Our base modelview matrix (i.e camera view).
Definition: graphics.h:230
bool isRendererExperimental() const
Definition: graphics.h:87
Unicode string handling.
Thread mutex classes.
An object that can be displayed by the graphics manager.
Definition: renderable.h:42
bool setFSAA(int level)
Set the FSAA settings.
Definition: graphics.cpp:207
void unlockFrame()
Decrease the frame lock counter, potentially re-enabling frame rendering.
Definition: graphics.cpp:723
void setCursor(Cursor *cursor=0)
Set the current cursor.
Definition: graphics.cpp:792
boost::atomic< bool > _frameEndSignal
Definition: graphics.h:234
Renderable * getWorldObjectAt(float x, float y) const
Definition: graphics.cpp:845
const glm::mat4 & getProjectionInverseMatrix() const
Return the inverse screen projection view matrix.
Definition: graphics.cpp:1258
uint32_t uint32
Definition: types.h:204
bool _rendererExperimental
Should we use the experimental shader based renderer?
Definition: graphics.h:196
const glm::mat4 & getModelviewMatrix() const
Return the current modelview matrix (camera view).
Definition: graphics.cpp:1262
Renderable * getGUIObjectAt(float x, float y) const
Definition: graphics.cpp:808
bool ready() const
Was the graphics subsystem successfully initialized?
Definition: graphics.cpp:183
void deinit()
Deinitialize the graphics subsystem.
Definition: graphics.cpp:161
void abandon(TextureID *ids, uint32 count)
Abandon these textures.
Definition: graphics.cpp:767
void setPerspective(float viewAngle, float clipNear, float clipFar)
Change the perspective projection matrix.
Definition: graphics.cpp:450
glm::mat4 _ortho
Orthographical projection matrix.
Definition: graphics.h:226
int getCurrentFSAA() const
Return the current FSAA level.
Definition: graphics.cpp:199
const glm::mat4 & getProjectionMatrix() const
Return the current screen projection view matrix.
Definition: graphics.cpp:1250
void pauseAnimations()
Pause animation thread.
Definition: graphics.cpp:1274
void setGUIScale(ScalingType scaling)
Configure scaling type for the GUI.
Definition: graphics.cpp:441
boost::atomic< uint32 > _frameLock
Definition: graphics.h:233
bool _needManualDeS3TC
Do we need to do manual S3TC DXTn decompression?
Definition: graphics.h:199
bool _debugGL
Should we create an OpenGL debug context?
Definition: graphics.h:194
void renderScene()
Render one complete frame of the scene.
Definition: graphics.cpp:1213
void setOrthogonal(float clipNear, float clipFar)
Change the projection matrix to be orthogonal.
Definition: graphics.cpp:505
bool _hasAbandoned
Do we have abandoned textures/lists?
Definition: graphics.h:243
size_t _multipleTextureCount
The number of texture units for multiple textures.
Definition: graphics.h:201
void setCullFace(bool enabled, GLenum mode=GL_BACK)
Enable/Disable face culling.
Definition: graphics.cpp:422
glm::mat4 _modelviewInv
The inverse of our modelview matrix.
Definition: graphics.h:231
Dedicated animation thread.
std::vector< TextureID > _abandonTextures
Abandoned textures.
Definition: graphics.h:245
Aurora::AnimationThread _animationThread
Definition: graphics.h:250