BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #endif
31 
32 #ifndef BALL_VIEW_RENDERING_GLDISPLAYLIST_H
34 #endif
35 
36 #ifndef BALL_DATATYPE_REGULARDATA3D_H
38 #endif
39 
40 #ifndef APIENTRY
41 #define APIENTRY
42 #endif
43 
44 class QFont;
45 
46 namespace BALL
47 {
48 // defines the maximal number of GL-objects, which can be selected in picking mode
49 // a number as big as 100.000 is needed for large molecules, just to be sure we use a million
50 #define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS 1000000
51  namespace VIEW
52  {
53  class Scene;
54  class GLDisplayList;
55  class MeshBuffer;
56  class ColorMap;
57  class RenderTarget;
58 
64  : public Renderer
65  {
66  friend class Scene;
67  public:
68 
71  {
73  RENDER_MODE_UNDEFINED = 0,
74 
77 
80 
82  RENDER_MODE_ALWAYS_FRONT
83  };
84 
85 
88  {
90  DIRECT_RENDERING = 0,
91 
94 
96  REBUILD_DISPLAY_LISTS
97  };
98 
99 
106  {
107  public:
108 
109  WrongModes(const char* file, int line, int mode, int precision);
110  };
111 
113  typedef unsigned int Name;
114 
116  GLRenderer();
117 
119  virtual ~GLRenderer();
120 
122  virtual void clear();
123 
125  void dump(std::ostream& s, Size depth) const;
126 
128  inline Name getName(const GeometricObject& object);
129 
131  GeometricObject* getObject(GLRenderer::Name name) const;
132 
133  using Renderer::init;
134 
136  virtual bool init(const Stage& stage, float width, float height);
137 
139  virtual void setLights(bool reset_all = false);
140 
143  virtual void setSmoothLines(bool smooth_lines);
144  virtual bool getSmoothLines();
145 
148  virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
149  std::list<GeometricObject*>& objects);
150 
154  void pickObjects1(Position x1, Position y1, Position x2, Position y2);
155 
160  void pickObjects2(std::list<GeometricObject*>& objects);
161 
164  void setFogIntensity(float intensity);
165 
167  void enterPickingMode();
168 
170  void exitPickingMode();
171 
173  void setSize(float width, float height);
174 
176  float getXScale() const;
177 
179  float getYScale() const;
180 
182  virtual void updateBackgroundColor();
183 
184  // Initialise transparent rendering
185  void initTransparent();
186 
187  // Initialise solid rendering
188  void initSolid();
189 
190  // Initialise always front rendering
191  void initAlwaysFront();
192 
194  void setAntialiasing(bool state);
195 
197  void removeRepresentation(const Representation& rep);
198 
200  void bufferRepresentation(const Representation& rep);
201 
203  void drawBuffered(const Representation& rep);
204 
206  bool hasDisplayListFor(const Representation& rep) const;
207 
209  RenderMode getRenderMode() const;
210 
212  void setRenderMode(RenderMode mode) { render_mode_ = mode;}
213 
218  virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode);
219 
221  virtual bool render(const Representation& representation, bool for_display_list = false);
222 
223  virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode);
224 
228  bool isExtensionSupported(const String& extension) const;
229 
231  void clearVertexBuffersFor(Representation& rep);
232 
234  bool vertexBuffersSupported() const;
235 
237  String getVendor();
238 
240  String getRenderer();
241 
243  String getOpenGLVersion();
244 
246  vector<String> getExtensions();
247 
249  bool enableVertexBuffers(bool state);
250 
252  bool vertexBuffersEnabled() const;
253 
255  DrawingMode getDrawingMode() const;
256 
258  void initPerspective();
259 
261  void setProjection();
262 
263  //_
264  void setColorRGBA_(const ColorRGBA& color);
265 
266  //_
267  void vertexVector3_(const Vector3& v);
268 
269  //
270  void updateCamera(const Camera* camera = 0);
271 
272  //
273  void setupStereo(float eye_separation, float focal_length);
274 
275  Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map);
276  void removeTextureFor_(const RegularData3D& grid);
277 
278  virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f, float& top_f, float& bottom_f);
279 
280  protected:
281 
285  bool mapViewplaneToScreen_();
286 
287  void renderRepresentation_(const Representation& representation, bool for_display_list);
288 
290  void renderRepresentations_(BufferMode mode);
291 
293  virtual void renderLabel_(const Label& /*label*/);
294 
296  virtual void renderLine_(const Line& /*line*/);
297 
299  virtual void renderMultiLine_(const MultiLine& line);
300 
302  virtual void renderMesh_(const Mesh& /*mesh*/);
303 
305  virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
306 
308  void initDrawingMeshes_();
309 
311  void initDrawingOthers_();
312 
320  virtual void renderRuler();
321 
323  virtual void renderPoint_(const Point& /*point*/);
324 
326  virtual void renderSimpleBox_(const SimpleBox& /*box*/);
327 
329  virtual void renderBox_(const Box& /*box*/);
330 
332  virtual void renderSphere_(const Sphere& /*sphere*/);
333 
335  virtual void renderDisc_(const Disc& /*disc*/);
336 
338  virtual void renderTube_(const Tube& /*tube*/);
339 
341  virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
342 
344  virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
345 
347  virtual void renderClippingPlane_(const ClippingPlane& plane);
348 
350  virtual void renderGridVisualisation_(const GridVisualisation& vol);
351 
352  //_
353  void setColor4ub_(const GeometricObject& object);
354 
355  //_
356  void createSpheres_();
357 
358  //_
359  void createTubes_();
360 
361  //_
362  void createBoxes_();
363 
364  //_
365  void createDottedSphere_(int precision);
366 
367  //_
368  void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
369 
370  //_
371  void createLineBox_();
372 
373  //_
374  void createDotBox_();
375 
376  //_
377  void createSolidBox_();
378 
379  //_
380  void clearNames_();
381 
382  //_
383  void normalVector3_(const Vector3& v);
384 
385 
386  //_
387  void translateVector3_(const Vector3& v);
388 
389  //_
390  void texCoordVector3_(const Vector3& v)
391  { glTexCoord3f(v.x, v.y, v.z); }
392 
393  //_
394  void scaleVector3_(const Vector3& v);
395 
396  //_
397  void rotateVector3Angle_(const Vector3& v, Real angle);
398 
399  //_
400  void scale_(float f);
401 
402 
403  void initGLU_(DrawingMode mode);
404 
405  //_
406  void setOrthographicZoom(float orthographic_zoom);
407 
408  //_
409  float getOrthographicZoom(void);
410 
411  //_
412  void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
413 
414  inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height);
415  void setupGridClipPlanes_(const GridVisualisation& slice);
416 
419 
422 
423  //_
424  float near_;
425  //_
426  float far_;
427  //_
428  float left_;
429  //_
430  float right_;
431  //_
432  float top_;
433  //_
434  float bottom_;
435 
436  //_
437  float x_scale_;
438 
439  //_
440  float y_scale_;
441 
448  GLubyte line_tex_[128][128][4];
449 
450  // naming of geometric objects
455 
463 
465 
474  GLUquadricObj* GLU_quadric_obj_;
476  GLuint cel_texture_;
477 
479  };
480 
481 # ifndef BALL_NO_INLINE_FUNCTIONS
482 # include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.iC>
483 # endif
484 
485  } // namespace VIEW
486 } // namespace BALL
487 
488 #endif // BALL_VIEW_RENDERING_GLRENDERER_H
GLDisplayList * sphere_list_
Definition: glRenderer.h:445
unsigned int Name
Typedef for OPENGL names.
Definition: glRenderer.h:113
DrawingMode
Enumeration for Drawing Modes.
void setRenderMode(RenderMode mode)
Definition: glRenderer.h:212
DrawingMode drawing_mode_
Definition: glRenderer.h:418
HashMap< Name, const GeometricObject * > GeometricObjectHashMap
Definition: glRenderer.h:452
GLUquadricObj * GLU_quadric_obj_
Definition: glRenderer.h:474
HashMap< const GeometricObject *, Name > NameHashMap
Definition: glRenderer.h:451
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
GLDisplayList line_list_
Definition: glRenderer.h:446
MeshBufferHashMap rep_to_buffers_
Definition: glRenderer.h:459
const char * getName()
Definition: rtti.h:97
HashMap< const RegularData3D *, Position > grid_to_texture_
Definition: glRenderer.h:475
Render the contents of the display lists.
Definition: glRenderer.h:93
RenderMode render_mode_
Definition: glRenderer.h:464
GeometricObjectHashMap name_to_object_
Definition: glRenderer.h:456
virtual bool init(Scene &scene)
GLDisplayList * GL_boxes_list_
Definition: glRenderer.h:444
#define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS
Definition: glRenderer.h:50
GLDisplayList * GL_tubes_list_
Definition: glRenderer.h:443
HashMap< const Representation *, vector< MeshBuffer * > > MeshBufferHashMap
Definition: glRenderer.h:454
void texCoordVector3_(const Vector3 &v)
Definition: glRenderer.h:390
NameHashMap object_to_name_
Definition: glRenderer.h:457
Position display_lists_index_
Definition: glRenderer.h:470
DisplayListHashMap display_lists_
Definition: glRenderer.h:458
GLDisplayList * GL_spheres_list_
Definition: glRenderer.h:442
HashMap< const Representation *, GLDisplayList * > DisplayListHashMap
Definition: glRenderer.h:453