Line data Source code
1 :
2 : /* Copyright (c) 2011-2013, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #ifndef EQSEQUEL_RENDERER_H
19 : #define EQSEQUEL_RENDERER_H
20 :
21 : #include <co/objectFactory.h> // interface
22 : #include <seq/types.h>
23 :
24 : namespace seq
25 : {
26 : /**
27 : * A renderer instance.
28 : *
29 : * All calls to one renderer instance are guaranteed to be executed from a
30 : * single thread.
31 : */
32 : class Renderer : public co::ObjectFactory
33 : {
34 : public:
35 : /** Construct a new renderer. @version 1.0 */
36 : SEQ_API Renderer( Application& application );
37 :
38 : /** Destruct this renderer. @version 1.0 */
39 : SEQ_API virtual ~Renderer();
40 :
41 : /** @name Operations */
42 : //@{
43 : /**
44 : * Initialize the renderer.
45 : *
46 : * Called once per renderer with a rendering context current before the
47 : * first call to initContext().
48 : *
49 : * @param initData a per-renderer instance of the object passed to
50 : * Config::init().
51 : * @return true on success, false otherwise.
52 : * @version 1.0
53 : */
54 2 : SEQ_API virtual bool init( co::Object* initData LB_UNUSED )
55 2 : { return true; }
56 :
57 : /**
58 : * De-initialize the renderer.
59 : *
60 : * Called just before the last context will be destroyed after the last call
61 : * to exitContext().
62 : *
63 : * @return true on success, false otherwise.
64 : * @version 1.0
65 : */
66 2 : SEQ_API virtual bool exit() { return true; }
67 :
68 : /**
69 : * Initialize a rendering context.
70 : *
71 : * Called for each window handled by this renderer, after the context has
72 : * been created and made current.
73 : *
74 : * @param initData a per-renderer instance of the object passed to
75 : * Config::init().
76 : * @return true on success, false otherwise.
77 : * @version 1.0
78 : */
79 : SEQ_API virtual bool initContext( co::Object* initData );
80 :
81 : /**
82 : * De-initialize a rendering context.
83 : *
84 : * Called just before the context will be destroyed.
85 : *
86 : * @return true on success, false otherwise.
87 : * @version 1.0
88 : */
89 : SEQ_API virtual bool exitContext();
90 :
91 : /**
92 : * Clear the frame buffer.
93 : *
94 : * @param frameData the renderer's instance of the object passed to
95 : * Config::run.
96 : * @version 1.0
97 : */
98 : SEQ_API virtual void clear( co::Object* frameData );
99 :
100 : /**
101 : * Render the scene.
102 : *
103 : * @param frameData the renderer's instance of the object passed to
104 : * Config::run.
105 : * @version 1.0
106 : */
107 : virtual void draw( co::Object* frameData ) = 0;
108 :
109 : /**
110 : * Update the near and far planes to tightly enclose the given sphere.
111 : *
112 : * @param boundingSphere the sphere bounding of the scene to be rendered.
113 : * @version 1.7.1
114 : */
115 : SEQ_API void updateNearFar( const Vector4f& boundingSphere );
116 :
117 :
118 : /**
119 : * Set the near and far planes.
120 : *
121 : * The given near and far planes update the current perspective and
122 : * orthographics frustum accordingly.
123 : *
124 : * @param nearPlane the near plane.
125 : * @param farPlane the far plane.
126 : * @version 1.7.1
127 : */
128 : SEQ_API void setNearFar( const float nearPlane, const float farPlane );
129 :
130 : /**
131 : * Apply the current rendering parameters to the rendering context.
132 : *
133 : * This method sets the draw buffer, color mask, viewport as well as the
134 : * projection and view matrix.
135 : *
136 : * This method is only to be called from clear(), draw() and TBD.
137 : * @version 1.0
138 : */
139 : SEQ_API virtual void applyRenderContext();
140 :
141 : /** @return the current rendering parameters. @version 1.4 */
142 : SEQ_API const RenderContext& getRenderContext() const;
143 :
144 : /**
145 : * Apply the current model matrix to the rendering context.
146 : *
147 : * This method is not included in applyRenderContext() since ligthing
148 : * parameters are often applied before positioning the model.
149 : *
150 : * This method is only to be called from clear(), draw() and TBD.
151 : * @version 1.0
152 : */
153 : SEQ_API virtual void applyModelMatrix();
154 : //@}
155 :
156 : /** @name Data Access */
157 : //@{
158 16 : detail::Renderer* getImpl() { return _impl; } //!< @internal
159 : co::Object* getFrameData(); // @warning experimental
160 :
161 : /** @return the application instance for this renderer. @version 1.0 */
162 1 : Application& getApplication() { return app_; }
163 :
164 : /** @return the application instance for this renderer. @version 1.0 */
165 : const Application& getApplication() const { return app_; }
166 :
167 : /**
168 : * Create a new per-view data instance.
169 : *
170 : * Called once for each view used by this renderer. Creates the view
171 : * instance used by the renderer to retrieve parameters from the
172 : * application for rendering.
173 : *
174 : * @return the new view data
175 : * @version 1.0
176 : */
177 : SEQ_API virtual ViewData* createViewData();
178 :
179 : /** Delete the given view data. @version 1.0 */
180 : SEQ_API virtual void destroyViewData( ViewData* viewData );
181 :
182 : /**
183 : * Get the GLEW context for this renderer.
184 : *
185 : * The glew context provides access to OpenGL extensions. This function
186 : * does not follow the Sequel naming conventions, since GLEW uses a
187 : * function of this name to automatically resolve OpenGL function entry
188 : * points. Therefore, any OpenGL function support by the driver can be
189 : * directly called from any method of an initialized renderer.
190 : *
191 : * @return the extended OpenGL function table for the window's OpenGL
192 : * context.
193 : * @version 1.0
194 : */
195 : SEQ_API const GLEWContext* glewGetContext() const;
196 :
197 : /** @return the current view frustum. @version 1.0 */
198 : SEQ_API const Frustumf& getFrustum() const;
199 :
200 : /** @return the current view (frustum) transformation. @version 1.0 */
201 : SEQ_API const Matrix4f& getViewMatrix() const;
202 :
203 : /** @return the current model (scene) transformation. @version 1.0 */
204 : SEQ_API const Matrix4f& getModelMatrix() const;
205 : //@}
206 :
207 : /** @name ObjectFactory interface, forwards to Application instance. */
208 : //@{
209 : SEQ_API virtual co::Object* createObject( const uint32_t type );
210 : SEQ_API virtual void destroyObject( co::Object* object,
211 : const uint32_t type );
212 : //@}
213 :
214 : private:
215 : detail::Renderer* const _impl;
216 : Application& app_;
217 : };
218 : }
219 : #endif // EQSEQUEL_RENDERER_H
|