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 : #ifndef EQSEQUEL_RENDERER_H
21 : #define EQSEQUEL_RENDERER_H
22 :
23 : #include <co/objectFactory.h> // interface
24 : #include <seq/types.h>
25 :
26 : namespace seq
27 : {
28 : /**
29 : * A renderer instance.
30 : *
31 : * All calls to one renderer instance are guaranteed to be executed from a
32 : * single thread.
33 : */
34 : class Renderer : public co::ObjectFactory
35 : {
36 : public:
37 : /** Construct a new renderer. @version 1.0 */
38 : SEQ_API explicit Renderer( Application& application );
39 :
40 : /** Destruct this renderer. @version 1.0 */
41 : SEQ_API virtual ~Renderer();
42 :
43 : /** @name Operations */
44 : //@{
45 : /**
46 : * Initialize the renderer.
47 : *
48 : * Called once per renderer with a rendering context current before the
49 : * first call to initContext().
50 : *
51 : * @param initData a per-renderer instance of the object passed to
52 : * Config::init().
53 : * @return true on success, false otherwise.
54 : * @version 1.0
55 : */
56 0 : SEQ_API virtual bool init( co::Object* initData LB_UNUSED )
57 0 : { return true; }
58 :
59 : /**
60 : * De-initialize the renderer.
61 : *
62 : * Called just before the last context will be destroyed after the last call
63 : * to exitContext().
64 : *
65 : * @return true on success, false otherwise.
66 : * @version 1.0
67 : */
68 0 : SEQ_API virtual bool exit() { return true; }
69 :
70 : /**
71 : * Initialize a rendering context.
72 : *
73 : * Called for each window handled by this renderer, after the context has
74 : * been created and made current.
75 : *
76 : * @param initData a per-renderer instance of the object passed to
77 : * Config::init().
78 : * @return true on success, false otherwise.
79 : * @version 1.0
80 : */
81 : SEQ_API virtual bool initContext( co::Object* initData );
82 :
83 : /**
84 : * De-initialize a rendering context.
85 : *
86 : * Called just before the context will be destroyed.
87 : *
88 : * @return true on success, false otherwise.
89 : * @version 1.0
90 : */
91 : SEQ_API virtual bool exitContext();
92 :
93 : /**
94 : * Clear the frame buffer.
95 : *
96 : * @param frameData the renderer's instance of the object passed to
97 : * Config::run.
98 : * @version 1.0
99 : */
100 : SEQ_API virtual void clear( co::Object* frameData );
101 :
102 : /**
103 : * Render the scene.
104 : *
105 : * @param frameData the renderer's instance of the object passed to
106 : * Config::run.
107 : * @version 1.0
108 : */
109 : virtual void draw( co::Object* frameData ) = 0;
110 :
111 : /** Request another call to draw(). @version 1.12 */
112 : SEQ_API void requestRedraw();
113 :
114 : /**
115 : * Update the near and far planes to tightly enclose the given sphere.
116 : *
117 : * @param boundingSphere the sphere bounding of the scene to be rendered.
118 : * @version 1.7.1
119 : */
120 : SEQ_API void updateNearFar( const Vector4f& boundingSphere );
121 :
122 : /**
123 : * Set the near and far planes.
124 : *
125 : * The given near and far planes update the current perspective and
126 : * orthographics frustum accordingly.
127 : *
128 : * @param nearPlane the near plane.
129 : * @param farPlane the far plane.
130 : * @version 1.7.1
131 : */
132 : SEQ_API void setNearFar( const float nearPlane, const float farPlane );
133 :
134 : /**
135 : * Apply the current rendering parameters to the rendering context.
136 : *
137 : * This method sets the draw buffer, color mask, viewport as well as the
138 : * projection and view matrix.
139 : *
140 : * This method is only to be called from clear(), draw() and TBD.
141 : * @version 1.0
142 : */
143 : SEQ_API virtual void applyRenderContext();
144 :
145 : /**
146 : * Bind the window draw buffer, which can be (multisampled) FBO or window
147 : * buffer.
148 : * @version 1.12
149 : */
150 : SEQ_API void bindDrawFrameBuffer();
151 :
152 : /** @return the current rendering parameters. @version 1.4 */
153 : SEQ_API const RenderContext& getRenderContext() const;
154 :
155 : /**
156 : * Apply the current model matrix to the rendering context.
157 : *
158 : * This method is not included in applyRenderContext() since ligthing
159 : * parameters are often applied before positioning the model.
160 : *
161 : * This method is only to be called from clear(), draw() and TBD.
162 : * @version 1.0
163 : */
164 : SEQ_API virtual void applyModelMatrix();
165 :
166 : /**
167 : * Apply an orthographic frustum for pixel-based 2D operations.
168 : *
169 : * One unit of the frustum covers one pixel on screen. The frustum is
170 : * positioned relative to the eq::View.
171 : * @version 1.8
172 : */
173 : SEQ_API virtual void applyScreenFrustum();
174 :
175 : /**
176 : * Apply the perspective frustum matrix for the current rendering task.
177 : * @version 1.8
178 : */
179 : SEQ_API virtual void applyPerspectiveFrustum();
180 :
181 : /**
182 : * @warning experimental
183 : * @return true when the event was handled, false if not.
184 : */
185 0 : SEQ_API virtual bool processEvent( const eq::Event& ) { return false; }
186 : //@}
187 :
188 : /** @name Data Access */
189 : //@{
190 0 : detail::Renderer* getImpl() { return _impl; } //!< @internal
191 :
192 : /**
193 : * @return A frame-synchronous instance of the data passed to
194 : * Application::run().
195 : * @version 1.8
196 : */
197 : SEQ_API co::Object* getFrameData();
198 :
199 : /** @return the application instance for this renderer. @version 1.0 */
200 : Application& getApplication() { return app_; }
201 :
202 : /** @return the application instance for this renderer. @version 1.0 */
203 : const Application& getApplication() const { return app_; }
204 :
205 : /** @return the object manager of this renderer. @version 1.0 */
206 : SEQ_API const ObjectManager& getObjectManager() const;
207 :
208 : /** @return the object manager of this renderer. @version 1.0 */
209 : SEQ_API ObjectManager& getObjectManager();
210 :
211 : /**
212 : * Create a new per-view data instance.
213 : *
214 : * Called once for each view used by this renderer. Creates the view
215 : * instance used by the renderer to retrieve parameters from the
216 : * application for rendering.
217 : *
218 : * @param view the view requesting the view data
219 : * @return the new view data
220 : * @version 1.11
221 : */
222 : SEQ_API virtual ViewData* createViewData( View& view );
223 :
224 : /** Delete the given view data. @version 1.0 */
225 : SEQ_API virtual void destroyViewData( ViewData* viewData );
226 :
227 : /** @return the current view data. @version 1.12 */
228 : SEQ_API const ViewData* getViewData() const;
229 :
230 : /**
231 : * Get the GLEW context for this renderer.
232 : *
233 : * The glew context provides access to OpenGL extensions. This function
234 : * does not follow the Sequel naming conventions, since GLEW uses a
235 : * function of this name to automatically resolve OpenGL function entry
236 : * points. Therefore, any OpenGL function support by the driver can be
237 : * directly called from any method of an initialized renderer.
238 : *
239 : * @return the extended OpenGL function table for the window's OpenGL
240 : * context.
241 : * @version 1.0
242 : */
243 : SEQ_API const GLEWContext* glewGetContext() const;
244 :
245 : /** @return the current view frustum. @version 1.0 */
246 : SEQ_API const Frustumf& getFrustum() const;
247 :
248 : /** @return the current view (frustum) transformation. @version 1.0 */
249 : SEQ_API const Matrix4f& getViewMatrix() const;
250 :
251 : /** @return the current model (scene) transformation. @version 1.0 */
252 : SEQ_API const Matrix4f& getModelMatrix() const;
253 :
254 : /** @return the current rendering area. @version 1.8 */
255 : SEQ_API const PixelViewport& getPixelViewport() const;
256 :
257 : /**
258 : * @return a unique, stable identifier for the current window.
259 : * @version 1.8
260 : */
261 : SEQ_API uint32_t getWindowID() const;
262 : //@}
263 :
264 : /** @name Distributed Object API */
265 : //@{
266 : /** @sa seq::Application::createObject() */
267 : SEQ_API virtual co::Object* createObject( const uint32_t type );
268 :
269 : /** @sa seq::Application::destroyObject() */
270 : SEQ_API virtual void destroyObject( co::Object* object,
271 : const uint32_t type );
272 :
273 : /**
274 : * Map and return an object.
275 : *
276 : * @param identifier unique object identifier used for map operation
277 : * @param instance already created instance to skip factory creation
278 : * @return 0 if not registered, the valid instance otherwise
279 : * @version 1.8
280 : * @sa co::ObjectMap::map()
281 : */
282 : SEQ_API co::Object* mapObject( const uint128_t& identifier,
283 : co::Object* instance );
284 :
285 : /**
286 : * Unmap an object from the object map.
287 : *
288 : * @param object the object to unmap
289 : * @return false on if object was not mapped, true otherwise
290 : * @version 1.0
291 : * @sa co::ObjectMap::unmap()
292 : */
293 : SEQ_API bool unmap( co::Object* object );
294 : //@}
295 :
296 : private:
297 : detail::Renderer* const _impl;
298 : Application& app_;
299 : };
300 : }
301 : #endif // EQSEQUEL_RENDERER_H
|