xoreos  0.0.5
subscenequad.cpp
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 #include <algorithm>
26 
27 #include "glm/gtc/type_ptr.hpp"
28 
29 #include "src/common/maths.h"
30 
32 
33 #include "src/events/events.h"
34 
35 namespace Graphics {
36 
37 namespace Aurora {
38 
40  GUIElement(GUIElement::kGUIElementFront), _lastSampled(0),
41  _x(0), _y(0), _width(0), _height(0), _clearEnabled(true) {
42  /*
43  * This distance value should ensure, that the subscene stays before panels and background
44  * but behind anything else.
45  */
46  _distance = -100;
47 }
48 
50 }
51 
53  // Save the viewport information for later restoration.
54  glPushAttrib(GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT);
55 
56  glEnable(GL_DEPTH_TEST);
57  glDepthFunc(GL_LEQUAL);
58 
59  // Set the new viewport.
60  glViewport(_x, _y, _width, _height);
61 
62  glMatrixMode(GL_PROJECTION);
63  glPushMatrix();
64  glLoadIdentity();
65  glMultMatrixf(glm::value_ptr(_projection));
66 
67  glMatrixMode(GL_MODELVIEW);
68  glPushMatrix();
69  glLoadIdentity();
70  glMultMatrixf(glm::value_ptr(_transformation));
71 
72  glEnable(GL_SCISSOR_TEST);
73  glScissor(_x, _y, _width, _height);
74 
75  if (_clearEnabled)
76  glClear(GL_COLOR_BUFFER_BIT);
77 
78  float elapsedTime = 0;
79  const uint32 now = EventMan.getTimestamp();
80 
81  if (_lastSampled != 0)
82  elapsedTime = (now - _lastSampled) / 1000.0f;
83 
84  _lastSampled = now;
85 
86  for (size_t i = 0; i < _renderables.size(); ++i) {
87  _renderables[i]->advanceTime(elapsedTime);
88  _renderables[i]->render(pass);
89  }
90 
91  glDisable(GL_SCISSOR_TEST);
92 
93  // Restore the original projection matrix.
94  glMatrixMode(GL_PROJECTION);
95  glPopMatrix();
96  glMatrixMode(GL_MODELVIEW);
97  glPopMatrix();
98 
99  // Restore the original viewport.
100  glPopAttrib();
101 }
102 
103 void SubSceneQuad::setPosition(int x, int y) {
104  _x = x;
105  _y = y;
106 }
107 
108 void SubSceneQuad::setSize(int width, int height) {
109  _width = width;
110  _height = height;
111 }
112 
113 void SubSceneQuad::setDistance(float distance) {
114  _distance = distance;
115 }
116 
117 void SubSceneQuad::setProjectionMatrix(const glm::mat4 &projection) {
118  _projection = projection;
119 }
120 
121 void SubSceneQuad::setGlobalTransformationMatrix(const glm::mat4 &transformation) {
122  _transformation = transformation;
123 }
124 
125 void SubSceneQuad::setClearEnabled(bool clearEnabled) {
126  _clearEnabled = clearEnabled;
127 }
128 
129 void SubSceneQuad::add(Renderable *renderable) {
130  _renderables.push_back(renderable);
131 }
132 
133 void SubSceneQuad::remove(Renderable *renderable) {
134  std::vector<Renderable *>::iterator iter = std::find(_renderables.begin(), _renderables.end(), renderable);
135  if (iter != _renderables.end()) {
136  _renderables.erase(iter);
137  }
138 }
139 
140 } // End of namespace Aurora
141 
142 } // End of namespace Graphics
void setDistance(float distance)
double _distance
The distance of the object from the viewer.
Definition: renderable.h:101
void add(Renderable *renderable)
Add a renderable to the sub scene.
void setProjectionMatrix(const glm::mat4 &projection)
Mathematical helpers.
void render(RenderPass pass)
Render the object.
void remove(Renderable *renderable)
Remove a renderable from the sub scene.
RenderPass
Definition: types.h:97
void setClearEnabled(bool clearEnabled)
The global events manager.
void calculateDistance()
Calculate the object&#39;s distance.
void setSize(int width, int height)
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
An object that can be displayed by the graphics manager.
Definition: renderable.h:42
An element of the GUI.
Definition: guielement.h:33
uint32 _height
Definition: h263.cpp:54
void setGlobalTransformationMatrix(const glm::mat4 &transformation)
uint32_t uint32
Definition: types.h:204
void setPosition(int x, int y)
The quad for displaying a subscene.
#define pass
Definition: fft.cpp:257
uint32 _width
Definition: h263.cpp:53
std::vector< Renderable * > _renderables
Definition: subscenequad.h:58