BALL  1.4.2
 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 // $Id: glRenderer.h,v 1.36.16.1 2007/03/25 21:26:15 oliver Exp $
5 //
6 
7 #ifndef BALL_VIEW_RENDERING_GLRENDERER_H
8 #define BALL_VIEW_RENDERING_GLRENDERER_H
9 
10 #ifndef BALL_VIEW_RENDERING_RENDERER_H
12 #endif
13 
14 #ifndef BALL_MATHS_QUATERNION_H
15 # include <BALL/MATHS/quaternion.h>
16 #endif
17 
18 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H
20 #endif
21 
22 #ifndef BALL_VIEW_KERNEL_GEOMETRICOBJECT_H
24 #endif
25 
26 #ifndef BALL_VIEW_KERNEL_STAGE_H
27 # include <BALL/VIEW/KERNEL/stage.h>
28 #endif
29 
30 #ifdef BALL_HAS_GLEW
31 # include <GL/glew.h>
32 #endif
33 
34 #ifndef BALL_VIEW_RENDERING_GLDISPLAYLIST_H
36 #endif
37 
38 #ifndef BALL_DATATYPE_REGULARDATA3D_H
40 #endif
41 
42 #ifndef APIENTRY
43 #define APIENTRY
44 #endif
45 
46 class QFont;
47 
48 namespace BALL
49 {
50 // defines the maximal number of GL-objects, which can be selected in picking mode
51 // a number as big as 100.000 is needed for large molecules, just to be sure we use a million
52 #define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS 1000000
53  namespace VIEW
54  {
55  class Scene;
56  class GLDisplayList;
57  class MeshBuffer;
58  class ColorMap;
59  class RenderTarget;
60 
66  : public Renderer
67  {
68  friend class Scene;
69  public:
70 
73  {
74  NO_STEREO = 0,
75 
78 
81 
83  DUAL_VIEW_DIFFERENT_DISPLAY_STEREO
84  };
85 
88  {
90  RENDER_MODE_UNDEFINED = 0,
91 
94 
97 
99  RENDER_MODE_ALWAYS_FRONT
100  };
101 
102 
105  {
107  DIRECT_RENDERING = 0,
108 
111 
113  REBUILD_DISPLAY_LISTS
114  };
115 
116 
123  {
124  public:
125 
126  WrongModes(const char* file, int line, int mode, int precision);
127  };
128 
130  typedef unsigned int Name;
131 
133  GLRenderer();
134 
136  virtual ~GLRenderer();
137 
139  virtual void clear();
140 
142  void dump(std::ostream& s, Size depth) const;
143 
145  inline Name getName(const GeometricObject& object);
146 
148  GeometricObject* getObject(GLRenderer::Name name) const;
149 
150  virtual bool init(Scene& scene);
151 
153  virtual bool init(const Stage& stage, float width, float height);
154 
156  virtual void setLights(bool reset_all = false);
157 
160  virtual void setSmoothLines(bool smooth_lines);
161  virtual bool getSmoothLines();
162 
166  Vector3 mapViewportTo3D(Position x, Position y);
167 
171  Vector2 map3DToViewport(const Vector3& vec);
172 
176  void pickObjects1(Position x1, Position y1, Position x2, Position y2);
177 
182  void pickObjects2(std::list<GeometricObject*>& objects);
183 
185  void enterPickingMode();
186 
188  void exitPickingMode();
189 
191  void setSize(float width, float height);
192 
194  float getXScale() const;
195 
197  float getYScale() const;
198 
200  virtual void updateBackgroundColor();
201 
202  // Initialise transparent rendering
203  void initTransparent();
204 
205  // Initialise solid rendering
206  void initSolid();
207 
208  // Initialise always front rendering
209  void initAlwaysFront();
210 
212  void setAntialiasing(bool state);
213 
215  void removeRepresentation(const Representation& rep);
216 
218  void bufferRepresentation(const Representation& rep);
219 
221  void drawBuffered(const Representation& rep);
222 
224  bool hasDisplayListFor(const Representation& rep) const;
225 
227  void setStereoMode(StereoMode state);
228 
230  StereoMode getStereoMode() const;
231 
233  RenderMode getRenderMode() const;
234 
236  void setRenderMode(RenderMode mode) { render_mode_ = mode;}
237 
242  virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode);
243 
245  virtual bool render(const Representation& representation, bool for_display_list = false);
246 
247  virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode);
248 
252  bool isExtensionSupported(const String& extension) const;
253 
255  void clearVertexBuffersFor(Representation& rep);
256 
258  bool vertexBuffersSupported() const;
259 
261  String getVendor();
262 
264  String getRenderer();
265 
267  String getOpenGLVersion();
268 
270  vector<String> getExtensions();
271 
273  bool enableVertexBuffers(bool state);
274 
276  bool vertexBuffersEnabled() const;
277 
279  DrawingMode getDrawingMode() const;
280 
282  void initPerspective();
283 
285  void setProjection();
286 
287  //_
288  void setColorRGBA_(const ColorRGBA& color);
289 
290  //_
291  void vertexVector3_(const Vector3& v);
292 
293  //
294  void updateCamera(const Camera* camera = 0);
295 
296  //
297  void setupStereo(float eye_separation, float focal_length);
298 
299  Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map);
300  void removeTextureFor_(const RegularData3D& grid);
301 
302  void getFrustum(float& near, float& far, float& left, float& right, float& top, float& bottom);
303 
304  protected:
305 
309  bool mapViewplaneToScreen_();
310 
311  void renderRepresentation_(const Representation& representation, bool for_display_list);
312 
314  void renderRepresentations_(BufferMode mode);
315 
317  virtual void renderLabel_(const Label& /*label*/);
318 
320  virtual void renderLine_(const Line& /*line*/);
321 
323  virtual void renderMultiLine_(const MultiLine& line);
324 
326  virtual void renderMesh_(const Mesh& /*mesh*/);
327 
329  virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
330 
332  void initDrawingMeshes_();
333 
335  void initDrawingOthers_();
336 
344  virtual void renderRuler();
345 
347  virtual void renderPoint_(const Point& /*point*/);
348 
350  virtual void renderSimpleBox_(const SimpleBox& /*box*/);
351 
353  virtual void renderBox_(const Box& /*box*/);
354 
356  virtual void renderSphere_(const Sphere& /*sphere*/);
357 
359  virtual void renderDisc_(const Disc& /*disc*/);
360 
362  virtual void renderTube_(const Tube& /*tube*/);
363 
365  virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
366 
368  virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
369 
371  virtual void renderClippingPlane_(const ClippingPlane& plane);
372 
374  virtual void renderGridVisualisation_(const GridVisualisation& vol);
375 
376  //_
377  void setColor4ub_(const GeometricObject& object);
378 
379  //_
380  void createSpheres_();
381 
382  //_
383  void createTubes_();
384 
385  //_
386  void createBoxes_();
387 
388  //_
389  void createDottedSphere_(int precision);
390 
391  //_
392  void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
393 
394  //_
395  void createLineBox_();
396 
397  //_
398  void createDotBox_();
399 
400  //_
401  void createSolidBox_();
402 
403  //_
404  void clearNames_();
405 
406  //_
407  void normalVector3_(const Vector3& v);
408 
409 
410  //_
411  void translateVector3_(const Vector3& v);
412 
413  //_
414  void texCoordVector3_(const Vector3& v)
415  { glTexCoord3f(v.x, v.y, v.z); }
416 
417  //_
418  void scaleVector3_(const Vector3& v);
419 
420  //_
421  void rotateVector3Angle_(const Vector3& v, Real angle);
422 
423  //_
424  void scale_(float f);
425 
426 
427  void initGLU_(DrawingMode mode);
428 
429  //_
430  void setOrthographicZoom(float orthographic_zoom);
431 
432  //_
433  float getOrthographicZoom(void);
434 
435  //_
436  void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
437 
438  inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height);
439  void setupGridClipPlanes_(const GridVisualisation& slice);
440 
443 
446 
447  //_
448  float near_;
449  //_
450  float far_;
451  //_
452  float left_;
453  //_
454  float right_;
455  //_
456  float top_;
457  //_
458  float bottom_;
459 
460  //_
461  float x_scale_;
462 
463  //_
464  float y_scale_;
465 
472  GLubyte line_tex_[128][128][4];
473 
474  // naming of geometric objects
479 
487 
490 
499  GLUquadricObj* GLU_quadric_obj_;
501  GLuint cel_texture_;
502 
504  };
505 
506 # ifndef BALL_NO_INLINE_FUNCTIONS
507 # include <BALL/VIEW/RENDERING/glRenderer.iC>
508 # endif
509 
510  } // namespace VIEW
511 } // namespace BALL
512 
513 #endif // BALL_VIEW_RENDERING_GLRENDERER_H