Debian Codegraph @

include/BALL/VIEW/RENDERING/RENDERERS/glRenderer.h

raw symbols SCIP
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4
5 #ifndef BALL_VIEW_RENDERING_RENDERERS_GLRENDERER_H
6 #define BALL_VIEW_RENDERING_RENDERERS_GLRENDERER_H
7
8 #ifndef BALL_VIEW_RENDERING_RENDERERS_RENDERER_H
9 # include <BALL/VIEW/RENDERING/RENDERERS/renderer.h>
10 #endif
11
12 #ifndef BALL_MATHS_QUATERNION_H
13 # include <BALL/MATHS/quaternion.h>
14 #endif
15
16 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H
17 # include <BALL/VIEW/DATATYPE/colorRGBA.h>
18 #endif
19
20 #ifndef BALL_VIEW_KERNEL_GEOMETRICOBJECT_H
21 # include <BALL/VIEW/KERNEL/geometricObject.h>
22 #endif
23
24 #ifndef BALL_VIEW_KERNEL_STAGE_H
25 # include <BALL/VIEW/KERNEL/stage.h>
26 #endif
27
28 #ifdef BALL_COMPILER_MSVC
29 # define WINDOWS_LEAN_AND_MEAN
30 # include <windows.h>
31 #endif
32
33 #ifdef BALL_HAS_GLEW
34 # include <GL/glew.h>
35 #elif defined(BALL_OS_DARWIN)
36 # include <OpenGL/gl.h>
37 # include <OpenGL/glu.h>
38 #else
39 # include <GL/gl.h>
40 # include <GL/glu.h>
41 #endif
42
43 #ifndef BALL_VIEW_RENDERING_GLDISPLAYLIST_H
44 # include <BALL/VIEW/RENDERING/glDisplayList.h>
45 #endif
46
47 #ifndef BALL_DATATYPE_REGULARDATA3D_H
48 # include <BALL/DATATYPE/regularData3D.h>
49 #endif
50
51 #ifndef APIENTRY
52 #define APIENTRY
53 #endif
54
55 class QFont;
56
57 namespace BALL
58 {
59 // defines the maximal number of GL-objects, which can be selected in picking mode
60 // a number as big as 100.000 is needed for large molecules, just to be sure we use a million
61 #define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS 1000000
62 namespace VIEW
63 {
64 class Scene;
65 class GLDisplayList;
66 class MeshBuffer;
67 class ColorMap;
68 class RenderTarget;
69
70 /** GLRenderer
71 Renderer which provides hardware accelerated OPENGL rendering.
72 \ingroup ViewRendering
73 */
74 class BALL_VIEW_EXPORT GLRenderer
75 : public Renderer
76 {
77 friend class Scene;
78 public:
79
80 ///
81 enum RenderMode
82 {
83 ///
84 RENDER_MODE_UNDEFINED = 0,
85
86 ///
87 RENDER_MODE_SOLID,
88
89 ///
90 RENDER_MODE_TRANSPARENT,
91
92 ///
93 RENDER_MODE_ALWAYS_FRONT
94 };
95
96
97 ////
98 enum BufferMode
99 {
100 /// Render without display lists, directly to the Scene
101 DIRECT_RENDERING = 0,
102
103 /// Render the contents of the display lists
104 DISPLAY_LISTS_RENDERING,
105
106 /// Rebuild the contents of the display lists and redraw them
107 REBUILD_DISPLAY_LISTS
108 };
109
110
111 /** WrongModes Exception class.
112 This exeption will be thrown if the <b> drawing_precision_</b> or
113 <b> drawing_mode_</b> are not allowed.
114 \see GeneralException
115 */
116 class BALL_VIEW_EXPORT WrongModes: public Exception::GeneralException
117 {
118 public:
119
120 WrongModes(const char* file, int line, int mode, int precision);
121 };
122
123 /// Typedef for OPENGL names
124 typedef unsigned int Name;
125
126 /// Default Constructor.
127 GLRenderer();
128
129 /// Destructor
130 virtual ~GLRenderer();
131
132 /// Explicit default initialization.
133 virtual void clear();
134
135 ///
136 void dump(std::ostream& s, Size depth) const;
137
138 ///
139 inline Name getName(const GeometricObject& object);
140
141 ///
142 GeometricObject* getObject(GLRenderer::Name name) const;
143
144 using Renderer::init;
145
146 /// Initialise the renderer, e.g. the display lists.
147 virtual bool init(const Stage& stage, float width, float height);
148
149 /// Set the light sources according to the stage
150 virtual void setLights(bool reset_all = false);
151
152 ///Should the lines in the line representation and the wireframe models
153 ///be smoothed?
154 virtual void setSmoothLines(bool smooth_lines);
155 virtual bool getSmoothLines();
156
157 /** Pick all objects in the given screen rectangle.
158 */
159 virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
160 std::list<GeometricObject*>& objects);
161
162 /** Pick geometric objects
163 \param x1, y1, x2, y2 the rectangle of the selection
164 */
165 void pickObjects1(Position x1, Position y1, Position x2, Position y2);
166
167 /** Pick geometric objects method2.
168 Call this method after pickObjects1 and rendering the representations.
169 \param objects returns the picked objects
170 */
171 void pickObjects2(std::list<GeometricObject*>& objects);
172
173 /** Set the GL_FOG intensity
174 */
175 void setFogIntensity(float intensity);
176
177 ///
178 void enterPickingMode();
179
180 ///
181 void exitPickingMode();
182
183 ///
184 void setSize(float width, float height);
185
186 ///
187 float getXScale() const;
188
189 ///
190 float getYScale() const;
191
192 /// Update the background color from the stage
193 virtual void updateBackgroundColor();
194
195 // Initialise transparent rendering
196 void initTransparent();
197
198 // Initialise solid rendering
199 void initSolid();
200
201 // Initialise always front rendering
202 void initAlwaysFront();
203
204 /// Enable or disable antialiasing
205 void setAntialiasing(bool state);
206
207 /// Remove all VertexBuffer and DisplayLists for the given Representation
208 void removeRepresentation(const Representation& rep);
209
210 /// Buffer the visualisation for the given Representation into OpenGL VertexBuffer Objects and DisplayLists.
211 void bufferRepresentation(const Representation& rep);
212
213 /// Draw the visualisation of the given Representation from the VertexBuffers and a DisplayList.
214 void drawBuffered(const Representation& rep);
215
216 /// Test if a Representation has a DisplayList.
217 bool hasDisplayListFor(const Representation& rep) const;
218
219 ///
220 RenderMode getRenderMode() const;
221
222 ///
223 void setRenderMode(RenderMode mode) { render_mode_ = mode;}
224
225 /** This function renders into the buffer of the RenderTarget which has to be
226 * made current before this function is called. Buffers are not automatically
227 * swapped afterwards!
228 */
229 virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode);
230
231 ///
232 virtual bool render(const Representation& representation, bool for_display_list = false);
233
234 virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode);
235
236 /** Test if a given opengl extension is supported by the current driver.
237 Call this only after Scene::initializeGL();
238 */
239 bool isExtensionSupported(const String& extension) const;
240
241 ///
242 void clearVertexBuffersFor(Representation& rep);
243
244 ///
245 bool vertexBuffersSupported() const;
246
247 ///
248 String getVendor();
249
250 ///
251 String getRenderer();
252
253 ///
254 String getOpenGLVersion();
255
256 ///
257 vector<String> getExtensions();
258
259 ///
260 bool runningOnVirtualBox();
261
262 ///
263 bool enableVertexBuffers(bool state);
264
265 ///
266 bool vertexBuffersEnabled() const;
267
268 ///
269 DrawingMode getDrawingMode() const;
270
271 ///
272 void initPerspective();
273
274 ///
275 void setProjection();
276
277 //_
278 void setColorRGBA_(const ColorRGBA& color);
279
280 //_
281 void vertexVector3_(const Vector3& v);
282
283 //
284 void updateCamera(const Camera* camera = 0);
285
286 //
287 void setupStereo(float eye_separation, float focal_length);
288
289 Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map);
290 void removeTextureFor_(const RegularData3D& grid);
291
292 virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f, float& top_f, float& bottom_f);
293
294 void updateMaterialForRepresentation(Representation const* rep) { bufferRepresentation(*rep); }
295
296 protected:
297
298 /** Maps the current viewplane to screen coordinates.
299 * Returns false if the projection matrix is not correctly initialized.
300 */
301 bool mapViewplaneToScreen_();
302
303 void renderRepresentation_(const Representation& representation, bool for_display_list);
304
305 ///
306 void renderRepresentations_(BufferMode mode);
307
308 ///
309 virtual void renderLabel_(const Label& /*label*/);
310
311 ///
312 virtual void renderLine_(const Line& /*line*/);
313
314 /// Render an illuminated line
315 virtual void renderMultiLine_(const MultiLine& line);
316
317 ///
318 virtual void renderMesh_(const Mesh& /*mesh*/);
319
320 ///
321 virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
322
323 ///
324 void initDrawingMeshes_();
325
326 ///
327 void initDrawingOthers_();
328
329 /** Render a ruler.
330 *
331 * If supported by the renderer implementation, this function will produce
332 * a simple ruler that is rendered together with the other representations.
333 * The main use of this function is in the edit mode, where it can help to
334 * straighten-up structures and to correctly estimate angles and distances.
335 */
336 virtual void renderRuler();
337
338 ///
339 virtual void renderPoint_(const Point& /*point*/);
340
341 ///
342 virtual void renderSimpleBox_(const SimpleBox& /*box*/);
343
344 ///
345 virtual void renderBox_(const Box& /*box*/);
346
347 ///
348 virtual void renderSphere_(const Sphere& /*sphere*/);
349
350 ///
351 virtual void renderDisc_(const Disc& /*disc*/);
352
353 ///
354 virtual void renderTube_(const Tube& /*tube*/);
355
356 ///
357 virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
358
359 ///
360 virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
361
362 ///
363 virtual void renderClippingPlane_(const ClippingPlane& plane);
364
365 /// Render a grid slice
366 virtual void renderGridVisualisation_(const GridVisualisation& vol);
367
368 //_
369 void setColor4ub_(const GeometricObject& object);
370
371 //_
372 void createSpheres_();
373
374 //_
375 void createTubes_();
376
377 //_
378 void createBoxes_();
379
380 //_
381 void createDottedSphere_(int precision);
382
383 //_
384 void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
385
386 //_
387 void createLineBox_();
388
389 //_
390 void createDotBox_();
391
392 //_
393 void createSolidBox_();
394
395 //_
396 void clearNames_();
397
398 //_
399 void normalVector3_(const Vector3& v);
400
401
402 //_
403 void translateVector3_(const Vector3& v);
404
405 //_
406 void texCoordVector3_(const Vector3& v)
407 { glTexCoord3f(v.x, v.y, v.z); }
408
409 //_
410 void scaleVector3_(const Vector3& v);
411
412 //_
413 void rotateVector3Angle_(const Vector3& v, Real angle);
414
415 //_
416 void scale_(float f);
417
418
419 void initGLU_(DrawingMode mode);
420
421 //_
422 void setOrthographicZoom(float orthographic_zoom);
423
424 //_
425 float getOrthographicZoom(void);
426
427 //_
428 void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
429
430 inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height);
431 void setupGridClipPlanes_(const GridVisualisation& slice);
432
433 // Sets the current OpenGL material
434 void setMaterial_(const Stage::Material& mat);
435 ///
436 DrawingMode drawing_mode_;
437
438 ///
439 Index drawing_precision_;
440
441 //_
442 float near_;
443 //_
444 float far_;
445 //_
446 float left_;
447 //_
448 float right_;
449 //_
450 float top_;
451 //_
452 float bottom_;
453
454 //_
455 float x_scale_;
456
457 //_
458 float y_scale_;
459
460 GLDisplayList* GL_spheres_list_;
461 GLDisplayList* GL_tubes_list_;
462 GLDisplayList* GL_boxes_list_;
463 GLDisplayList* sphere_list_;
464 GLDisplayList line_list_;
465 GLuint line_texture_bind_;
466 GLubyte line_tex_[128][128][4];
467
468 // naming of geometric objects
469 typedef HashMap<const GeometricObject*, Name> NameHashMap;
470 typedef HashMap<Name, const GeometricObject*> GeometricObjectHashMap;
471 typedef HashMap<const Representation*, GLDisplayList*> DisplayListHashMap;
472 typedef HashMap<const Representation*, vector<MeshBuffer*> > MeshBufferHashMap;
473
474 GeometricObjectHashMap name_to_object_;
475 NameHashMap object_to_name_;
476 DisplayListHashMap display_lists_;
477 MeshBufferHashMap rep_to_buffers_;
478 Name all_names_;
479 GLuint object_buffer_[BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS];
480 Vector3 normal_vector_;
481
482 RenderMode render_mode_;
483
484 bool use_vertex_buffer_;
485 bool smooth_lines_;
486 bool picking_mode_;
487 ModelType model_type_;
488 Position display_lists_index_;
489 bool single_pick_;
490 bool drawed_other_object_;
491 bool drawed_mesh_;
492 GLUquadricObj* GLU_quadric_obj_;
493 HashMap<const RegularData3D*, Position> grid_to_texture_;
494 GLuint cel_texture_;
495
496 float orthographic_zoom_;
497 };
498
499 # ifndef BALL_NO_INLINE_FUNCTIONS
500 # include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.iC>
501 # endif
502
503 } // namespace VIEW
504 } // namespace BALL
505
506 #endif // BALL_VIEW_RENDERING_GLRENDERER_H