BALL 1.5.0
Loading...
Searching...
No Matches
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
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
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
45#endif
46
47#ifndef BALL_DATATYPE_REGULARDATA3D_H
49#endif
50
51#ifndef APIENTRY
52#define APIENTRY
53#endif
54
55class QFont;
56
57namespace 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
75 : public Renderer
76 {
77 friend class Scene;
78 public:
79
82 {
84 RENDER_MODE_UNDEFINED = 0,
85
88
91
93 RENDER_MODE_ALWAYS_FRONT
94 };
95
96
99 {
101 DIRECT_RENDERING = 0,
102
105
107 REBUILD_DISPLAY_LISTS
108 };
109
110
117 {
118 public:
119
120 WrongModes(const char* file, int line, int mode, int precision);
121 };
122
124 typedef unsigned int Name;
125
128
130 virtual ~GLRenderer();
131
133 virtual void clear();
134
136 void dump(std::ostream& s, Size depth) const;
137
139 inline Name getName(const GeometricObject& object);
140
143
144 using Renderer::init;
145
147 virtual bool init(const Stage& stage, float width, float height);
148
150 virtual void setLights(bool reset_all = false);
151
154 virtual void setSmoothLines(bool smooth_lines);
155 virtual bool getSmoothLines();
156
159 virtual void pickObjects(Position x1, Position y1, Position x2, Position y2,
160 std::list<GeometricObject*>& objects);
161
166
171 void pickObjects2(std::list<GeometricObject*>& objects);
172
175 void setFogIntensity(float intensity);
176
179
182
184 void setSize(float width, float height);
185
187 float getXScale() const;
188
190 float getYScale() const;
191
193 virtual void updateBackgroundColor();
194
195 // Initialise transparent rendering
197
198 // Initialise solid rendering
199 void initSolid();
200
201 // Initialise always front rendering
203
205 void setAntialiasing(bool state);
206
209
212
214 void drawBuffered(const Representation& rep);
215
217 bool hasDisplayListFor(const Representation& rep) const;
218
221
223 void setRenderMode(RenderMode mode) { render_mode_ = mode;}
224
229 virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode);
230
232 virtual bool render(const Representation& representation, bool for_display_list = false);
233
234 virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode);
235
239 bool isExtensionSupported(const String& extension) const;
240
243
246
249
252
255
257 vector<String> getExtensions();
258
261
263 bool enableVertexBuffers(bool state);
264
267
270
273
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
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
302
303 void renderRepresentation_(const Representation& representation, bool for_display_list);
304
307
309 virtual void renderLabel_(const Label& /*label*/);
310
312 virtual void renderLine_(const Line& /*line*/);
313
315 virtual void renderMultiLine_(const MultiLine& line);
316
318 virtual void renderMesh_(const Mesh& /*mesh*/);
319
321 virtual void renderQuadMesh_(const QuadMesh& /*mesh*/);
322
325
328
336 virtual void renderRuler();
337
339 virtual void renderPoint_(const Point& /*point*/);
340
342 virtual void renderSimpleBox_(const SimpleBox& /*box*/);
343
345 virtual void renderBox_(const Box& /*box*/);
346
348 virtual void renderSphere_(const Sphere& /*sphere*/);
349
351 virtual void renderDisc_(const Disc& /*disc*/);
352
354 virtual void renderTube_(const Tube& /*tube*/);
355
357 virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/);
358
360 virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/);
361
363 virtual void renderClippingPlane_(const ClippingPlane& plane);
364
367
368 //_
369 void setColor4ub_(const GeometricObject& object);
370
371 //_
373
374 //_
376
377 //_
379
380 //_
381 void createDottedSphere_(int precision);
382
383 //_
384 void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision);
385
386 //_
388
389 //_
391
392 //_
394
395 //_
397
398 //_
399 void normalVector3_(const Vector3& v);
400
401
402 //_
404
405 //_
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
420
421 //_
422 void setOrthographicZoom(float orthographic_zoom);
423
424 //_
426
427 //_
428 void generateIlluminationTexture_(float ka, float kd, float kr, float shininess);
429
432
433 // Sets the current OpenGL material
437
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
466 GLubyte line_tex_[128][128][4];
467
468 // naming of geometric objects
473
481
483
492 GLUquadricObj* GLU_quadric_obj_;
495
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
#define BALL_VIEW_EXPORT
HashMap class based on the STL map (containing serveral convenience functions)
Definition hashMap.h:74
WrongModes(const char *file, int line, int mode, int precision)
bool enableVertexBuffers(bool state)
float getYScale() const
HashMap< const GeometricObject *, Name > NameHashMap
Definition glRenderer.h:469
Position display_lists_index_
Definition glRenderer.h:488
GeometricObjectHashMap name_to_object_
Definition glRenderer.h:474
virtual void renderSimpleBox_(const SimpleBox &)
Render a simple box (parallel to the axes)
void setAntialiasing(bool state)
Enable or disable antialiasing.
void subdivideTriangle_(Vector3 &v1, Vector3 &v2, Vector3 &v3, int precision)
virtual void renderTube_(const Tube &)
Render a tube.
RenderMode getRenderMode() const
virtual void renderQuadMesh_(const QuadMesh &)
Render a quad mesh.
virtual void renderToBuffer(RenderTarget *renderTarget, BufferMode)
void updateMaterialForRepresentation(Representation const *rep)
Definition glRenderer.h:294
virtual void setLights(bool reset_all=false)
Set the light sources according to the stage.
virtual void renderBox_(const Box &)
Render a box.
GLDisplayList * GL_tubes_list_
Definition glRenderer.h:461
virtual void renderLine_(const Line &)
Render a line.
void generateIlluminationTexture_(float ka, float kd, float kr, float shininess)
GLDisplayList * sphere_list_
Definition glRenderer.h:463
void scale_(float f)
virtual void renderTwoColoredTube_(const TwoColoredTube &)
Render a tube with two colors.
HashMap< Name, const GeometricObject * > GeometricObjectHashMap
Definition glRenderer.h:470
void clearVertexBuffersFor(Representation &rep)
void setMaterial_(const Stage::Material &mat)
void setColor4ub_(const GeometricObject &object)
void translateVector3_(const Vector3 &v)
virtual void bufferingDependentRender_(const Representation &repr, BufferMode mode)
void renderRepresentation_(const Representation &representation, bool for_display_list)
void setColorRGBA_(const ColorRGBA &color)
virtual void clear()
Explicit default initialization.
HashMap< const Representation *, vector< MeshBuffer * > > MeshBufferHashMap
Definition glRenderer.h:472
GLRenderer()
Default Constructor.
void setupGridClipPlanes_(const GridVisualisation &slice)
virtual void renderTwoColoredLine_(const TwoColoredLine &)
Render a line with two colors.
Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height)
GLDisplayList * GL_boxes_list_
Definition glRenderer.h:462
GLUquadricObj * GLU_quadric_obj_
Definition glRenderer.h:492
Name getName(const GeometricObject &object)
DrawingMode getDrawingMode() const
DrawingMode drawing_mode_
Definition glRenderer.h:436
void renderRepresentations_(BufferMode mode)
void texCoordVector3_(const Vector3 &v)
Definition glRenderer.h:406
virtual bool getSmoothLines()
virtual void renderRuler()
Position createTextureFromGrid(const RegularData3D &grid, const ColorMap &map)
void scaleVector3_(const Vector3 &v)
virtual void renderDisc_(const Disc &)
Render a disc.
virtual void renderPoint_(const Point &)
Render a single point.
virtual bool render(const Representation &representation, bool for_display_list=false)
virtual void renderGridVisualisation_(const GridVisualisation &vol)
Render a grid slice.
void bufferRepresentation(const Representation &rep)
Buffer the visualisation for the given Representation into OpenGL VertexBuffer Objects and DisplayLis...
void updateCamera(const Camera *camera=0)
vector< String > getExtensions()
void dump(std::ostream &s, Size depth) const
virtual void renderSphere_(const Sphere &)
Render a sphere.
void setFogIntensity(float intensity)
MeshBufferHashMap rep_to_buffers_
Definition glRenderer.h:477
void setSize(float width, float height)
Set the size of the display.
HashMap< const RegularData3D *, Position > grid_to_texture_
Definition glRenderer.h:493
virtual void pickObjects(Position x1, Position y1, Position x2, Position y2, std::list< GeometricObject * > &objects)
bool isExtensionSupported(const String &extension) const
virtual ~GLRenderer()
Destructor.
void removeRepresentation(const Representation &rep)
Remove all VertexBuffer and DisplayLists for the given Representation.
DisplayListHashMap display_lists_
Definition glRenderer.h:476
void drawBuffered(const Representation &rep)
Draw the visualisation of the given Representation from the VertexBuffers and a DisplayList.
void removeTextureFor_(const RegularData3D &grid)
void setRenderMode(RenderMode mode)
Definition glRenderer.h:223
void pickObjects1(Position x1, Position y1, Position x2, Position y2)
float getXScale() const
GLDisplayList * GL_spheres_list_
Definition glRenderer.h:460
bool hasDisplayListFor(const Representation &rep) const
Test if a Representation has a DisplayList.
void initGLU_(DrawingMode mode)
virtual void renderLabel_(const Label &)
bool vertexBuffersSupported() const
void createDottedSphere_(int precision)
virtual void updateBackgroundColor()
Update the background color from the stage.
NameHashMap object_to_name_
Definition glRenderer.h:475
@ DISPLAY_LISTS_RENDERING
Render the contents of the display lists.
Definition glRenderer.h:104
virtual void renderMultiLine_(const MultiLine &line)
Render an illuminated line.
bool vertexBuffersEnabled() const
virtual void renderClippingPlane_(const ClippingPlane &plane)
virtual void getFrustum(float &near_f, float &far_f, float &left_f, float &right_f, float &top_f, float &bottom_f)
void rotateVector3Angle_(const Vector3 &v, Real angle)
virtual void setSmoothLines(bool smooth_lines)
GeometricObject * getObject(GLRenderer::Name name) const
void vertexVector3_(const Vector3 &v)
void setOrthographicZoom(float orthographic_zoom)
unsigned int Name
Typedef for OPENGL names.
Definition glRenderer.h:124
void pickObjects2(std::list< GeometricObject * > &objects)
GLDisplayList line_list_
Definition glRenderer.h:464
virtual bool init(const Stage &stage, float width, float height)
Initialise the renderer, e.g. the display lists.
void setupStereo(float eye_separation, float focal_length)
float getOrthographicZoom(void)
virtual void renderMesh_(const Mesh &)
Render a surface mesh.
void normalVector3_(const Vector3 &v)
HashMap< const Representation *, GLDisplayList * > DisplayListHashMap
Definition glRenderer.h:471
#define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS
Definition glRenderer.h:61
DrawingMode
Enumeration for Drawing Modes.