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