Line data Source code
1 :
2 : /* Copyright (c) 2011-2016, Stefan Eilemann <eile@eyescale.ch>
3 : * Daniel Nachbaur <danielnachbaur@gmail.com>
4 : * Petros Kataras <petroskataras@gmail.com>
5 : *
6 : * This library is free software; you can redistribute it and/or modify it under
7 : * the terms of the GNU Lesser General Public License version 2.1 as published
8 : * by the Free Software Foundation.
9 : *
10 : * This library is distributed in the hope that it will be useful, but WITHOUT
11 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 : * details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with this library; if not, write to the Free Software Foundation, Inc.,
17 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #include "renderer.h"
21 :
22 : #include "channel.h"
23 : #include "pipe.h"
24 : #include "window.h"
25 : #include "objectMap.h"
26 :
27 : #include <seq/renderer.h>
28 : #include <eq/config.h>
29 :
30 : namespace seq
31 : {
32 : namespace detail
33 : {
34 14 : static const RenderContext dummyContext;
35 :
36 0 : Renderer::Renderer()
37 : : _glewContext( 0 )
38 : , _pipe( 0 )
39 : , _window( 0 )
40 0 : , _channel( 0 )
41 0 : {}
42 :
43 0 : Renderer::~Renderer()
44 : {
45 0 : LBASSERT( !_pipe );
46 0 : LBASSERT( !_channel );
47 0 : }
48 :
49 0 : co::Object* Renderer::mapObject( const uint128_t& identifier,
50 : co::Object* instance )
51 : {
52 0 : if( !_pipe )
53 0 : return 0;
54 :
55 0 : seq::detail::ObjectMap* objectMap = _pipe->getObjectMap();
56 0 : return objectMap ? objectMap->map(identifier, instance) : 0;
57 : }
58 :
59 0 : bool Renderer::unmap( co::Object* object )
60 : {
61 0 : if( !_pipe )
62 0 : return false;
63 :
64 0 : seq::detail::ObjectMap* objectMap = _pipe->getObjectMap();
65 0 : return objectMap ? objectMap->unmap(object) : false;
66 : }
67 :
68 0 : co::Object* Renderer::getFrameData()
69 : {
70 0 : return _pipe->getFrameData();
71 : }
72 :
73 0 : const ObjectManager& Renderer::getObjectManager() const
74 : {
75 0 : return _window->getObjectManager();
76 : }
77 :
78 0 : ObjectManager& Renderer::getObjectManager()
79 : {
80 0 : return _window->getObjectManager();
81 : }
82 :
83 0 : const ViewData* Renderer::getViewData() const
84 : {
85 0 : return _channel->getViewData();
86 : }
87 :
88 0 : const Frustumf& Renderer::getFrustum() const
89 : {
90 0 : LBASSERT( _channel );
91 0 : static Frustumf none;
92 0 : return _channel ? _channel->getFrustum() : none;
93 : }
94 :
95 0 : const Matrix4f& Renderer::getViewMatrix() const
96 : {
97 0 : LBASSERT( _channel );
98 0 : static const Matrix4f identity;
99 0 : return _channel ? _channel->getViewMatrix() : identity;
100 : }
101 :
102 0 : const Matrix4f& Renderer::getModelMatrix() const
103 : {
104 0 : LBASSERT( _channel );
105 0 : static const Matrix4f identity;
106 0 : return _channel ? _channel->getModelMatrix() : identity;
107 : }
108 :
109 0 : const PixelViewport& Renderer::getPixelViewport() const
110 : {
111 0 : LBASSERT( _channel );
112 0 : static const PixelViewport nullPVP;
113 0 : return _channel ? _channel->getPixelViewport() : nullPVP;
114 : }
115 :
116 0 : bool Renderer::useOrtho() const
117 : {
118 0 : LBASSERT( _channel );
119 0 : return _channel ? _channel->useOrtho() : false;
120 : }
121 :
122 0 : void Renderer::applyScreenFrustum()
123 : {
124 0 : LBASSERT( _channel );
125 0 : if( _channel )
126 0 : _channel->applyScreenFrustum();
127 0 : }
128 :
129 0 : void Renderer::applyPerspectiveFrustum()
130 : {
131 0 : LBASSERT( _channel );
132 0 : if( _channel )
133 0 : _channel->applyPerspective();
134 0 : }
135 :
136 0 : void Renderer::setNearFar( const float nearPlane, const float farPlane )
137 : {
138 0 : LBASSERT( _channel );
139 0 : if( _channel )
140 0 : _channel->setNearFar( nearPlane, farPlane );
141 0 : }
142 :
143 0 : void Renderer::setWindow( Window* window )
144 : {
145 0 : _window = window;
146 0 : _glewContext = window ? window->glewGetContext() : 0;
147 0 : }
148 :
149 0 : void Renderer::setChannel( Channel* channel )
150 : {
151 0 : _channel = channel;
152 0 : _glewContext = channel ? channel->glewGetContext() : 0;
153 0 : }
154 :
155 0 : bool Renderer::initContext()
156 : {
157 0 : return _window ? _window->initContext() : false;
158 : }
159 :
160 0 : bool Renderer::exitContext()
161 : {
162 0 : return _window ? _window->exitContext() : false;
163 : }
164 :
165 0 : void Renderer::clear()
166 : {
167 0 : LBASSERT( _channel );
168 0 : if( _channel )
169 0 : _channel->clear();
170 0 : }
171 :
172 0 : void Renderer::requestRedraw()
173 : {
174 0 : LBASSERT( _channel );
175 0 : if( _channel )
176 0 : _channel->getConfig()->sendEvent( EVENT_REDRAW );
177 0 : }
178 :
179 0 : void Renderer::applyRenderContext()
180 : {
181 0 : LBASSERT( _channel );
182 0 : if( _channel )
183 0 : _channel->applyRenderContext();
184 0 : }
185 :
186 0 : void Renderer::bindDrawFrameBuffer()
187 : {
188 0 : LBASSERT( _channel );
189 0 : if( _channel )
190 0 : _channel->bindDrawFrameBuffer();
191 0 : }
192 :
193 0 : const RenderContext& Renderer::getRenderContext() const
194 : {
195 0 : LBASSERT( _channel );
196 0 : if( _channel )
197 0 : return _channel->getRenderContext();
198 0 : return dummyContext;
199 : }
200 :
201 0 : void Renderer::applyModelMatrix()
202 : {
203 0 : LBASSERT( _channel );
204 0 : if( _channel )
205 0 : _channel->applyModelMatrix();
206 0 : }
207 :
208 : }
209 42 : }
|