BALL  1.5.0
glRenderer.h
Go to the documentation of this file.
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
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
18 #endif
19 
20 #ifndef 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_HAS_GLEW
29 # include <GL/glew.h>
30 #elif defined(BALL_OS_DARWIN)
31 # include <OpenGL/gl.h>
32 # include <OpenGL/glu.h>
33 #else
34 # include <GL/gl.h>
35 # include <GL/glu.h>
36 #endif
37 
38 #ifndef BALL_VIEW_RENDERING_GLDISPLAYLIST_H
40 #endif
41 
42 #ifndef BALL_DATATYPE_REGULARDATA3D_H
44 #endif
45 
46 #ifndef APIENTRY
47 #define APIENTRY
48 #endif
49 
50 class QFont;
51 
52 namespace BALL
53 {
54 // defines the maximal number of GL-objects, which can be selected in picking mode
55 // a number as big as 100.000 is needed for large molecules, just to be sure we use a million
56 #define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS 1000000
57  namespace VIEW
58  {
59  class Scene;
60  class GLDisplayList;
61  class MeshBuffer;
62  class ColorMap;
63  class RenderTarget;
64 
70  : public Renderer
71  {
72  friend class Scene;
73  public:
74 
77  {
79  RENDER_MODE_UNDEFINED = 0,
80 
83 
86 
88  RENDER_MODE_ALWAYS_FRONT
89  };
90 
91 
94  {
96  DIRECT_RENDERING = 0,
97 
100 
102  REBUILD_DISPLAY_LISTS
103  };
104 
105 
112  {
113  public:
114 
115  WrongModes(const char* file, int line, int mode, int precision);
116  };
117 
119  typedef unsigned int Name;
120 
122  GLRenderer();
123 
125  virtual ~GLRenderer();
126 
128  virtual void clear();
129 
131  void dump(std::ostream& s, Size depth) const;
132 
134  inline Name getName(const GeometricObject& object);
135 
137  GeometricObject* getObject(GLRenderer::Name name) const;
138 
139  using Renderer::init;
140 
142  virtual bool init(const Stage& stage, float width, float height);
143 
145  virtual void setLights(bool reset_all = false);
146 
149  virtual void setSmoothLines(bool smooth_lines);
150  virtual bool getSmoothLines();
151 
154  virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
155  std::list<GeometricObject*>& objects);
156 
160  void pickObjects1(Position x1, Position y1, Position x2, Position y2);
161 
166  void pickObjects2(std::list<GeometricObject*>& objects);
167 
170  void setFogIntensity(float intensity);
171 
173  void enterPickingMode();
174 
176  void exitPickingMode();
177 
179  void setSize(float width, float height);
180 
182  float getXScale() const;
183 
185  float getYScale() const;
186 
188  virtual void updateBackgroundColor();
189 
190  // Initialise transparent rendering
191  void initTransparent();
192 
193  // Initialise solid rendering
194  void initSolid();
195 
196  // Initialise always front rendering
197  void initAlwaysFront();
198 
200  void setAntialiasing(bool state);
201 
203  void removeRepresentation(const Representation& rep);
204 
206  void bufferRepresentation(const Representation& rep);
207 
209  void drawBuffered(const Representation& rep);
210 
212  bool hasDisplayListFor(const Representation& rep) const;
213 
215  RenderMode getRenderMode() const;
216 
218  void setRenderMode(RenderMode mode) { render_mode_ = mode;}
219 
224  virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode);
225 
227  virtual bool render(const Representation& representation, bool for_display_list = false);
228 
229  virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode);
230 
234  bool isExtensionSupported(const String& extension) const;
235 
237  void clearVertexBuffersFor(Representation& rep);
238 
240  bool vertexBuffersSupported() const;
241 
243  String getVendor();
244 
246  String getRenderer();
247 
249  String getOpenGLVersion();
250 
252  vector<String> getExtensions();
253 
255  bool runningOnVirtualBox();
256 
258  bool enableVertexBuffers(bool state);
259 
261  bool vertexBuffersEnabled() const;
262 
264  DrawingMode getDrawingMode() const;
265 
267  void initPerspective();
268 
270  void setProjection();
271 
272  //_
273  void setColorRGBA_(const ColorRGBA& color);
274 
275  //_
276  void vertexVector3_(const Vector3& v);
277 
278  //
279  void updateCamera(const Camera* camera = 0);
280 
281  //
282  void setupStereo(float eye_separation, float focal_length);
283 
284  Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map);
285  void removeTextureFor_(const RegularData3D& grid);
286 
287  virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f, float& top_f, float& bottom_f);
288 
289  void updateMaterialForRepresentation(Representation const* rep) { bufferRepresentation(*rep); }
290 
291  protected:
292 
296  bool mapViewplaneToScreen_();
297 
298  void renderRepresentation_(const Representation& representation, bool for_display_list);
299 
301  void renderRepresentations_(BufferMode mode);
302 
304  virtual void renderLabel_(const Label& /*label*/);
305 
307  virtual void renderLine_(const Line& /*line*/);
308 
310  virtual void renderMultiLine_(const MultiLine& line);
311 
313  virtual void renderMesh_(const Mesh& /*mesh*/);
314 
316  virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
317 
319  void initDrawingMeshes_();
320 
322  void initDrawingOthers_();
323 
331  virtual void renderRuler();
332 
334  virtual void renderPoint_(const Point& /*point*/);
335 
337  virtual void renderSimpleBox_(const SimpleBox& /*box*/);
338 
340  virtual void renderBox_(const Box& /*box*/);
341 
343  virtual void renderSphere_(const Sphere& /*sphere*/);
344 
346  virtual void renderDisc_(const Disc& /*disc*/);
347 
349  virtual void renderTube_(const Tube& /*tube*/);
350 
352  virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
353 
355  virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
356 
358  virtual void renderClippingPlane_(const ClippingPlane& plane);
359 
361  virtual void renderGridVisualisation_(const GridVisualisation& vol);
362 
363  //_
364  void setColor4ub_(const GeometricObject& object);
365 
366  //_
367  void createSpheres_();
368 
369  //_
370  void createTubes_();
371 
372  //_
373  void createBoxes_();
374 
375  //_
376  void createDottedSphere_(int precision);
377 
378  //_
379  void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
380 
381  //_
382  void createLineBox_();
383 
384  //_
385  void createDotBox_();
386 
387  //_
388  void createSolidBox_();
389 
390  //_
391  void clearNames_();
392 
393  //_
394  void normalVector3_(const Vector3& v);
395 
396 
397  //_
398  void translateVector3_(const Vector3& v);
399 
400  //_
401  void texCoordVector3_(const Vector3& v)
402  { glTexCoord3f(v.x, v.y, v.z); }
403 
404  //_
405  void scaleVector3_(const Vector3& v);
406 
407  //_
408  void rotateVector3Angle_(const Vector3& v, Real angle);
409 
410  //_
411  void scale_(float f);
412 
413 
414  void initGLU_(DrawingMode mode);
415 
416  //_
417  void setOrthographicZoom(float orthographic_zoom);
418 
419  //_
420  float getOrthographicZoom(void);
421 
422  //_
423  void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
424 
425  inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height);
426  void setupGridClipPlanes_(const GridVisualisation& slice);
427 
428  // Sets the current OpenGL material
429  void setMaterial_(const Stage::Material& mat);
432 
435 
436  //_
437  float near_;
438  //_
439  float far_;
440  //_
441  float left_;
442  //_
443  float right_;
444  //_
445  float top_;
446  //_
447  float bottom_;
448 
449  //_
450  float x_scale_;
451 
452  //_
453  float y_scale_;
454 
461  GLubyte line_tex_[128][128][4];
462 
463  // naming of geometric objects
468 
469  GeometricObjectHashMap name_to_object_;
470  NameHashMap object_to_name_;
471  DisplayListHashMap display_lists_;
472  MeshBufferHashMap rep_to_buffers_;
476 
478 
487  GLUquadricObj* GLU_quadric_obj_;
489  GLuint cel_texture_;
490 
492  };
493 
494 # ifndef BALL_NO_INLINE_FUNCTIONS
495 # include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.iC>
496 # endif
497 
498  } // namespace VIEW
499 } // namespace BALL
500 
501 #endif // BALL_VIEW_RENDERING_GLRENDERER_H
HashMap< const RegularData3D *, Position > grid_to_texture_
Definition: glRenderer.h:488
DisplayListHashMap display_lists_
Definition: glRenderer.h:471
Position display_lists_index_
Definition: glRenderer.h:483
DrawingMode
Enumeration for Drawing Modes.
GLDisplayList line_list_
Definition: glRenderer.h:459
Render the contents of the display lists.
Definition: glRenderer.h:99
NameHashMap object_to_name_
Definition: glRenderer.h:470
void texCoordVector3_(const Vector3 &v)
Definition: glRenderer.h:401
HashMap< Name, const GeometricObject * > GeometricObjectHashMap
Definition: glRenderer.h:465
const char * getName()
Definition: rtti.h:97
MeshBufferHashMap rep_to_buffers_
Definition: glRenderer.h:472
GeometricObjectHashMap name_to_object_
Definition: glRenderer.h:469
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
GLDisplayList * sphere_list_
Definition: glRenderer.h:458
unsigned int Name
Typedef for OPENGL names.
Definition: glRenderer.h:119
RenderMode render_mode_
Definition: glRenderer.h:477
GLDisplayList * GL_spheres_list_
Definition: glRenderer.h:455
void updateMaterialForRepresentation(Representation const *rep)
Definition: glRenderer.h:289
virtual bool init(Scene &scene)
GLUquadricObj * GLU_quadric_obj_
Definition: glRenderer.h:487
Definition: constants.h:12
GLDisplayList * GL_boxes_list_
Definition: glRenderer.h:457
HashMap< const GeometricObject *, Name > NameHashMap
Definition: glRenderer.h:464
double precision
Definition: classTest.h:30
HashMap< const Representation *, vector< MeshBuffer * > > MeshBufferHashMap
Definition: glRenderer.h:467
GLDisplayList * GL_tubes_list_
Definition: glRenderer.h:456
HashMap< const Representation *, GLDisplayList * > DisplayListHashMap
Definition: glRenderer.h:466
DrawingMode drawing_mode_
Definition: glRenderer.h:431
void setRenderMode(RenderMode mode)
Definition: glRenderer.h:218
#define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS
Definition: glRenderer.h:56