| 1 |
|
| 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 |
| 9 |
# include <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 |
| 17 |
# include <BALL/VIEW/DATATYPE/colorRGBA.h> |
| 18 |
#endif |
| 19 |
|
| 20 |
#ifndef BALL_VIEW_KERNEL_GEOMETRICOBJECT_H |
| 21 |
# include <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_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 |
| 44 |
# include <BALL/VIEW/RENDERING/glDisplayList.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifndef BALL_DATATYPE_REGULARDATA3D_H |
| 48 |
# include <BALL/DATATYPE/regularData3D.h> |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifndef APIENTRY |
| 52 |
#define APIENTRY |
| 53 |
#endif |
| 54 |
|
| 55 |
class QFont; |
| 56 |
|
| 57 |
namespace BALL |
| 58 |
{ |
| 59 |
|
| 60 |
|
| 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 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
class BALL_VIEW_EXPORT GLRenderer |
| 75 |
: public Renderer |
| 76 |
{ |
| 77 |
friend class Scene; |
| 78 |
public: |
| 79 |
|
| 80 |
|
| 81 |
enum RenderMode |
| 82 |
{ |
| 83 |
|
| 84 |
RENDER_MODE_UNDEFINED = 0, |
| 85 |
|
| 86 |
|
| 87 |
RENDER_MODE_SOLID, |
| 88 |
|
| 89 |
|
| 90 |
RENDER_MODE_TRANSPARENT, |
| 91 |
|
| 92 |
|
| 93 |
RENDER_MODE_ALWAYS_FRONT |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
enum BufferMode |
| 99 |
{ |
| 100 |
|
| 101 |
DIRECT_RENDERING = 0, |
| 102 |
|
| 103 |
|
| 104 |
DISPLAY_LISTS_RENDERING, |
| 105 |
|
| 106 |
|
| 107 |
REBUILD_DISPLAY_LISTS |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
class BALL_VIEW_EXPORT WrongModes: public Exception::GeneralException |
| 117 |
{ |
| 118 |
public: |
| 119 |
|
| 120 |
WrongModes(const char* file, int line, int mode, int precision); |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
typedef unsigned int Name; |
| 125 |
|
| 126 |
|
| 127 |
GLRenderer(); |
| 128 |
|
| 129 |
|
| 130 |
virtual ~GLRenderer(); |
| 131 |
|
| 132 |
|
| 133 |
virtual void clear(); |
| 134 |
|
| 135 |
|
| 136 |
void dump(std::ostream& s, Size depth) const; |
| 137 |
|
| 138 |
|
| 139 |
inline Name getName(const GeometricObject& object); |
| 140 |
|
| 141 |
|
| 142 |
GeometricObject* getObject(GLRenderer::Name name) const; |
| 143 |
|
| 144 |
using Renderer::init; |
| 145 |
|
| 146 |
|
| 147 |
virtual bool init(const Stage& stage, float width, float height); |
| 148 |
|
| 149 |
|
| 150 |
virtual void setLights(bool reset_all = false); |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
virtual void setSmoothLines(bool smooth_lines); |
| 155 |
virtual bool getSmoothLines(); |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
virtual void pickObjects(Position x1, Position y1, Position x2, Position y2, |
| 160 |
std::list<GeometricObject*>& objects); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
void pickObjects1(Position x1, Position y1, Position x2, Position y2); |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void pickObjects2(std::list<GeometricObject*>& objects); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
void setFogIntensity(float intensity); |
| 176 |
|
| 177 |
|
| 178 |
void enterPickingMode(); |
| 179 |
|
| 180 |
|
| 181 |
void exitPickingMode(); |
| 182 |
|
| 183 |
|
| 184 |
void setSize(float width, float height); |
| 185 |
|
| 186 |
|
| 187 |
float getXScale() const; |
| 188 |
|
| 189 |
|
| 190 |
float getYScale() const; |
| 191 |
|
| 192 |
|
| 193 |
virtual void updateBackgroundColor(); |
| 194 |
|
| 195 |
|
| 196 |
void initTransparent(); |
| 197 |
|
| 198 |
|
| 199 |
void initSolid(); |
| 200 |
|
| 201 |
|
| 202 |
void initAlwaysFront(); |
| 203 |
|
| 204 |
|
| 205 |
void setAntialiasing(bool state); |
| 206 |
|
| 207 |
|
| 208 |
void removeRepresentation(const Representation& rep); |
| 209 |
|
| 210 |
|
| 211 |
void bufferRepresentation(const Representation& rep); |
| 212 |
|
| 213 |
|
| 214 |
void drawBuffered(const Representation& rep); |
| 215 |
|
| 216 |
|
| 217 |
bool hasDisplayListFor(const Representation& rep) const; |
| 218 |
|
| 219 |
|
| 220 |
RenderMode getRenderMode() const; |
| 221 |
|
| 222 |
|
| 223 |
void setRenderMode(RenderMode mode) { render_mode_ = mode;} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode); |
| 230 |
|
| 231 |
|
| 232 |
virtual bool render(const Representation& representation, bool for_display_list = false); |
| 233 |
|
| 234 |
virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode); |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
bool isExtensionSupported(const String& extension) const; |
| 240 |
|
| 241 |
|
| 242 |
void clearVertexBuffersFor(Representation& rep); |
| 243 |
|
| 244 |
|
| 245 |
bool vertexBuffersSupported() const; |
| 246 |
|
| 247 |
|
| 248 |
String getVendor(); |
| 249 |
|
| 250 |
|
| 251 |
String getRenderer(); |
| 252 |
|
| 253 |
|
| 254 |
String getOpenGLVersion(); |
| 255 |
|
| 256 |
|
| 257 |
vector<String> getExtensions(); |
| 258 |
|
| 259 |
|
| 260 |
bool runningOnVirtualBox(); |
| 261 |
|
| 262 |
|
| 263 |
bool enableVertexBuffers(bool state); |
| 264 |
|
| 265 |
|
| 266 |
bool vertexBuffersEnabled() const; |
| 267 |
|
| 268 |
|
| 269 |
DrawingMode getDrawingMode() const; |
| 270 |
|
| 271 |
|
| 272 |
void initPerspective(); |
| 273 |
|
| 274 |
|
| 275 |
void setProjection(); |
| 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 |
|
| 289 |
Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map); |
| 290 |
void removeTextureFor_(const RegularData3D& grid); |
| 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 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
bool mapViewplaneToScreen_(); |
| 302 |
|
| 303 |
void renderRepresentation_(const Representation& representation, bool for_display_list); |
| 304 |
|
| 305 |
|
| 306 |
void renderRepresentations_(BufferMode mode); |
| 307 |
|
| 308 |
|
| 309 |
virtual void renderLabel_(const Label& ); |
| 310 |
|
| 311 |
|
| 312 |
virtual void renderLine_(const Line& ); |
| 313 |
|
| 314 |
|
| 315 |
virtual void renderMultiLine_(const MultiLine& line); |
| 316 |
|
| 317 |
|
| 318 |
virtual void renderMesh_(const Mesh& ); |
| 319 |
|
| 320 |
|
| 321 |
virtual void renderQuadMesh_(const QuadMesh& ); |
| 322 |
|
| 323 |
|
| 324 |
void initDrawingMeshes_(); |
| 325 |
|
| 326 |
|
| 327 |
void initDrawingOthers_(); |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
virtual void renderRuler(); |
| 337 |
|
| 338 |
|
| 339 |
virtual void renderPoint_(const Point& ); |
| 340 |
|
| 341 |
|
| 342 |
virtual void renderSimpleBox_(const SimpleBox& ); |
| 343 |
|
| 344 |
|
| 345 |
virtual void renderBox_(const Box& ); |
| 346 |
|
| 347 |
|
| 348 |
virtual void renderSphere_(const Sphere& ); |
| 349 |
|
| 350 |
|
| 351 |
virtual void renderDisc_(const Disc& ); |
| 352 |
|
| 353 |
|
| 354 |
virtual void renderTube_(const Tube& ); |
| 355 |
|
| 356 |
|
| 357 |
virtual void renderTwoColoredLine_(const TwoColoredLine& ); |
| 358 |
|
| 359 |
|
| 360 |
virtual void renderTwoColoredTube_(const TwoColoredTube& ); |
| 361 |
|
| 362 |
|
| 363 |
virtual void renderClippingPlane_(const ClippingPlane& plane); |
| 364 |
|
| 365 |
|
| 366 |
virtual void renderGridVisualisation_(const GridVisualisation& vol); |
| 367 |
|
| 368 |
|
| 369 |
void setColor4ub_(const GeometricObject& object); |
| 370 |
|
| 371 |
|
| 372 |
void createSpheres_(); |
| 373 |
|
| 374 |
|
| 375 |
void createTubes_(); |
| 376 |
|
| 377 |
|
| 378 |
void createBoxes_(); |
| 379 |
|
| 380 |
|
| 381 |
void createDottedSphere_(int precision); |
| 382 |
|
| 383 |
|
| 384 |
void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision); |
| 385 |
|
| 386 |
|
| 387 |
void createLineBox_(); |
| 388 |
|
| 389 |
|
| 390 |
void createDotBox_(); |
| 391 |
|
| 392 |
|
| 393 |
void createSolidBox_(); |
| 394 |
|
| 395 |
|
| 396 |
void clearNames_(); |
| 397 |
|
| 398 |
|
| 399 |
void normalVector3_(const Vector3& v); |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
void translateVector3_(const Vector3& v); |
| 404 |
|
| 405 |
|
| 406 |
void texCoordVector3_(const Vector3& v) |
| 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 |
|
| 419 |
void initGLU_(DrawingMode mode); |
| 420 |
|
| 421 |
|
| 422 |
void setOrthographicZoom(float orthographic_zoom); |
| 423 |
|
| 424 |
|
| 425 |
float getOrthographicZoom(void); |
| 426 |
|
| 427 |
|
| 428 |
void generateIlluminationTexture_(float ka, float kd, float kr, float shininess); |
| 429 |
|
| 430 |
inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height); |
| 431 |
void setupGridClipPlanes_(const GridVisualisation& slice); |
| 432 |
|
| 433 |
|
| 434 |
void setMaterial_(const Stage::Material& mat); |
| 435 |
|
| 436 |
DrawingMode drawing_mode_; |
| 437 |
|
| 438 |
|
| 439 |
Index drawing_precision_; |
| 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 |
|
| 460 |
GLDisplayList* GL_spheres_list_; |
| 461 |
GLDisplayList* GL_tubes_list_; |
| 462 |
GLDisplayList* GL_boxes_list_; |
| 463 |
GLDisplayList* sphere_list_; |
| 464 |
GLDisplayList line_list_; |
| 465 |
GLuint line_texture_bind_; |
| 466 |
GLubyte line_tex_[128][128][4]; |
| 467 |
|
| 468 |
|
| 469 |
typedef HashMap<const GeometricObject*, Name> NameHashMap; |
| 470 |
typedef HashMap<Name, const GeometricObject*> GeometricObjectHashMap; |
| 471 |
typedef HashMap<const Representation*, GLDisplayList*> DisplayListHashMap; |
| 472 |
typedef HashMap<const Representation*, vector<MeshBuffer*> > MeshBufferHashMap; |
| 473 |
|
| 474 |
GeometricObjectHashMap name_to_object_; |
| 475 |
NameHashMap object_to_name_; |
| 476 |
DisplayListHashMap display_lists_; |
| 477 |
MeshBufferHashMap rep_to_buffers_; |
| 478 |
Name all_names_; |
| 479 |
GLuint object_buffer_[BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS]; |
| 480 |
Vector3 normal_vector_; |
| 481 |
|
| 482 |
RenderMode render_mode_; |
| 483 |
|
| 484 |
bool use_vertex_buffer_; |
| 485 |
bool smooth_lines_; |
| 486 |
bool picking_mode_; |
| 487 |
ModelType model_type_; |
| 488 |
Position display_lists_index_; |
| 489 |
bool single_pick_; |
| 490 |
bool drawed_other_object_; |
| 491 |
bool drawed_mesh_; |
| 492 |
GLUquadricObj* GLU_quadric_obj_; |
| 493 |
HashMap<const RegularData3D*, Position> grid_to_texture_; |
| 494 |
GLuint cel_texture_; |
| 495 |
|
| 496 |
float orthographic_zoom_; |
| 497 |
}; |
| 498 |
|
| 499 |
# ifndef BALL_NO_INLINE_FUNCTIONS |
| 500 |
# include <BALL/VIEW/RENDERING/RENDERERS/glRenderer.iC> |
| 501 |
# endif |
| 502 |
|
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
#endif |