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 runningOnVirtualBox();
250 
252  bool enableVertexBuffers(bool state);
253 
255  bool vertexBuffersEnabled() const;
256 
258  DrawingMode getDrawingMode() const;
259 
261  void initPerspective();
262 
264  void setProjection();
265 
266  //_
267  void setColorRGBA_(const ColorRGBA& color);
268 
269  //_
270  void vertexVector3_(const Vector3& v);
271 
272  //
273  void updateCamera(const Camera* camera = 0);
274 
275  //
276  void setupStereo(float eye_separation, float focal_length);
277 
278  Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map);
279  void removeTextureFor_(const RegularData3D& grid);
280 
281  virtual void getFrustum(float& near_f, float& far_f, float& left_f, float& right_f, float& top_f, float& bottom_f);
282 
283  void updateMaterialForRepresentation(Representation const* rep) { bufferRepresentation(*rep); }
284 
285  protected:
286 
290  bool mapViewplaneToScreen_();
291 
292  void renderRepresentation_(const Representation& representation, bool for_display_list);
293 
295  void renderRepresentations_(BufferMode mode);
296 
298  virtual void renderLabel_(const Label& /*label*/);
299 
301  virtual void renderLine_(const Line& /*line*/);
302 
304  virtual void renderMultiLine_(const MultiLine& line);
305 
307  virtual void renderMesh_(const Mesh& /*mesh*/);
308 
310  virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
311 
313  void initDrawingMeshes_();
314 
316  void initDrawingOthers_();
317 
325  virtual void renderRuler();
326 
328  virtual void renderPoint_(const Point& /*point*/);
329 
331  virtual void renderSimpleBox_(const SimpleBox& /*box*/);
332 
334  virtual void renderBox_(const Box& /*box*/);
335 
337  virtual void renderSphere_(const Sphere& /*sphere*/);
338 
340  virtual void renderDisc_(const Disc& /*disc*/);
341 
343  virtual void renderTube_(const Tube& /*tube*/);
344 
346  virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
347 
349  virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
350 
352  virtual void renderClippingPlane_(const ClippingPlane& plane);
353 
355  virtual void renderGridVisualisation_(const GridVisualisation& vol);
356 
357  //_
358  void setColor4ub_(const GeometricObject& object);
359 
360  //_
361  void createSpheres_();
362 
363  //_
364  void createTubes_();
365 
366  //_
367  void createBoxes_();
368 
369  //_
370  void createDottedSphere_(int precision);
371 
372  //_
373  void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
374 
375  //_
376  void createLineBox_();
377 
378  //_
379  void createDotBox_();
380 
381  //_
382  void createSolidBox_();
383 
384  //_
385  void clearNames_();
386 
387  //_
388  void normalVector3_(const Vector3& v);
389 
390 
391  //_
392  void translateVector3_(const Vector3& v);
393 
394  //_
395  void texCoordVector3_(const Vector3& v)
396  { glTexCoord3f(v.x, v.y, v.z); }
397 
398  //_
399  void scaleVector3_(const Vector3& v);
400 
401  //_
402  void rotateVector3Angle_(const Vector3& v, Real angle);
403 
404  //_
405  void scale_(float f);
406 
407 
408  void initGLU_(DrawingMode mode);
409 
410  //_
411  void setOrthographicZoom(float orthographic_zoom);
412 
413  //_
414  float getOrthographicZoom(void);
415 
416  //_
417  void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
418 
419  inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height);
420  void setupGridClipPlanes_(const GridVisualisation& slice);
421 
422  // Sets the current OpenGL material
423  void setMaterial_(const Stage::Material& mat);
426 
429 
430  //_
431  float near_;
432  //_
433  float far_;
434  //_
435  float left_;
436  //_
437  float right_;
438  //_
439  float top_;
440  //_
441  float bottom_;
442 
443  //_
444  float x_scale_;
445 
446  //_
447  float y_scale_;
448 
455  GLubyte line_tex_[128][128][4];
456 
457  // naming of geometric objects
462 
470 
472 
481  GLUquadricObj* GLU_quadric_obj_;
483  GLuint cel_texture_;
484 
486  };
487 
488 # ifndef BALL_NO_INLINE_FUNCTIONS
489 # include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.iC>
490 # endif
491 
492  } // namespace VIEW
493 } // namespace BALL
494 
495 #endif // BALL_VIEW_RENDERING_GLRENDERER_H
GLDisplayList * sphere_list_
Definition: glRenderer.h:452
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:425
HashMap< Name, const GeometricObject * > GeometricObjectHashMap
Definition: glRenderer.h:459
GLUquadricObj * GLU_quadric_obj_
Definition: glRenderer.h:481
HashMap< const GeometricObject *, Name > NameHashMap
Definition: glRenderer.h:458
void updateMaterialForRepresentation(Representation const *rep)
Definition: glRenderer.h:283
#define BALL_VIEW_EXPORT
Definition: COMMON/global.h:52
GLDisplayList line_list_
Definition: glRenderer.h:453
MeshBufferHashMap rep_to_buffers_
Definition: glRenderer.h:466
const char * getName()
Definition: rtti.h:97
HashMap< const RegularData3D *, Position > grid_to_texture_
Definition: glRenderer.h:482
Render the contents of the display lists.
Definition: glRenderer.h:93
RenderMode render_mode_
Definition: glRenderer.h:471
GeometricObjectHashMap name_to_object_
Definition: glRenderer.h:463
virtual bool init(Scene &scene)
GLDisplayList * GL_boxes_list_
Definition: glRenderer.h:451
#define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS
Definition: glRenderer.h:50
GLDisplayList * GL_tubes_list_
Definition: glRenderer.h:450
HashMap< const Representation *, vector< MeshBuffer * > > MeshBufferHashMap
Definition: glRenderer.h:461
void texCoordVector3_(const Vector3 &v)
Definition: glRenderer.h:395
NameHashMap object_to_name_
Definition: glRenderer.h:464
Position display_lists_index_
Definition: glRenderer.h:477
DisplayListHashMap display_lists_
Definition: glRenderer.h:465
GLDisplayList * GL_spheres_list_
Definition: glRenderer.h:449
HashMap< const Representation *, GLDisplayList * > DisplayListHashMap
Definition: glRenderer.h:460