-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathrenderer.cpp
221 lines (183 loc) · 5.12 KB
/
renderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* Copyright (c) 2011-2017, Stefan Eilemann <[email protected]>
* Daniel Nachbaur <[email protected]>
* Petros Kataras <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "renderer.h"
#include "application.h"
#include "detail/objectMap.h"
#include "detail/renderer.h"
#include "detail/window.h"
#include "viewData.h"
namespace seq
{
Renderer::Renderer(Application& application)
: _impl(new detail::Renderer)
, app_(application)
{
}
Renderer::~Renderer()
{
delete _impl;
}
co::Object* Renderer::getFrameData()
{
return _impl->getFrameData();
}
const ObjectManager& Renderer::getObjectManager() const
{
return _impl->getObjectManager();
}
ObjectManager& Renderer::getObjectManager()
{
return _impl->getObjectManager();
}
const GLEWContext* Renderer::glewGetContext() const
{
return _impl->glewGetContext();
}
const ViewData* Renderer::getViewData() const
{
return _impl->getViewData();
}
ViewData* Renderer::createViewData(View& view)
{
return new ViewData(view);
}
void Renderer::destroyViewData(ViewData* viewData)
{
delete viewData;
}
const Frustumf& Renderer::getFrustum() const
{
return _impl->getFrustum();
}
const Matrix4f& Renderer::getViewMatrix() const
{
return _impl->getViewMatrix();
}
const Matrix4f& Renderer::getModelMatrix() const
{
return _impl->getModelMatrix();
}
const PixelViewport& Renderer::getPixelViewport() const
{
return _impl->getPixelViewport();
}
uint32_t Renderer::getWindowID() const
{
const eq::Window* window = _impl->getWindow();
return window ? window->getSerial() : CO_INSTANCE_INVALID;
}
bool Renderer::initContext(co::Object* /*initData*/)
{
return _impl->initContext();
}
bool Renderer::exitContext()
{
return _impl->exitContext();
}
void Renderer::clear(co::Object* /*frameData*/)
{
_impl->clear();
}
void Renderer::requestRedraw()
{
_impl->requestRedraw();
}
void Renderer::updateNearFar(const Vector4f& boundingSphere)
{
const Matrix4f& view = getViewMatrix();
const Matrix4f& viewInv = view.inverse();
const Vector3f& zero = viewInv * Vector3f();
Vector3f front = viewInv * Vector3f(0.0f, 0.0f, -1.0f);
front -= zero;
front.normalize();
front *= boundingSphere.w();
const Vector3f& translation = getModelMatrix().getTranslation();
const Vector3f& center =
translation - boundingSphere.get_sub_vector<3, 0>();
const Vector3f& nearPoint = view * (center - front);
const Vector3f& farPoint = view * (center + front);
if (_impl->useOrtho())
{
LBASSERTINFO(fabs(farPoint.z() - nearPoint.z()) >
std::numeric_limits<float>::epsilon(),
nearPoint << " == " << farPoint);
setNearFar(-nearPoint.z(), -farPoint.z());
}
else
{
// estimate minimal value of near plane based on frustum size
const eq::Frustumf& frustum = _impl->getFrustum();
const float width = fabs(frustum.right() - frustum.left());
const float height = fabs(frustum.top() - frustum.bottom());
const float size = LB_MIN(width, height);
const float minNear = frustum.nearPlane() / size * .001f;
const float zNear = LB_MAX(minNear, -nearPoint.z());
const float zFar = LB_MAX(zNear * 2.f, -farPoint.z());
setNearFar(zNear, zFar);
}
}
void Renderer::updateNearFar(const AABBf& box)
{
updateNearFar({box.getCenter(), box.getSize().length() * 0.5f});
}
void Renderer::setNearFar(const float nearPlane, const float farPlane)
{
_impl->setNearFar(nearPlane, farPlane);
}
void Renderer::applyRenderContext()
{
_impl->applyRenderContext();
}
void Renderer::bindDrawFrameBuffer()
{
_impl->bindDrawFrameBuffer();
}
const RenderContext& Renderer::getRenderContext() const
{
return _impl->getRenderContext();
}
void Renderer::applyModelMatrix()
{
_impl->applyModelMatrix();
}
void Renderer::applyScreenFrustum()
{
_impl->applyScreenFrustum();
}
void Renderer::applyPerspectiveFrustum()
{
_impl->applyPerspectiveFrustum();
}
co::Object* Renderer::createObject(const uint32_t type)
{
return app_.createObject(type);
}
void Renderer::destroyObject(co::Object* object, const uint32_t type)
{
app_.destroyObject(object, type);
}
co::Object* Renderer::mapObject(const uint128_t& identifier,
co::Object* instance)
{
return _impl->mapObject(identifier, instance);
}
bool Renderer::unmap(co::Object* object)
{
return _impl->unmap(object);
}
}