BALL
1.4.1
|
00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: glRenderer.h,v 1.36.16.1 2007/03/25 21:26:15 oliver Exp $ 00005 // 00006 00007 #ifndef BALL_VIEW_RENDERING_GLRENDERER_H 00008 #define BALL_VIEW_RENDERING_GLRENDERER_H 00009 00010 #ifndef BALL_VIEW_RENDERING_RENDERER_H 00011 # include <BALL/VIEW/RENDERING/renderer.h> 00012 #endif 00013 00014 #ifndef BALL_MATHS_QUATERNION_H 00015 # include <BALL/MATHS/quaternion.h> 00016 #endif 00017 00018 #ifndef BALL_VIEW_DATATYPE_COLORRGBA_H 00019 # include <BALL/VIEW/DATATYPE/colorRGBA.h> 00020 #endif 00021 00022 #ifndef BALL_VIEW_KERNEL_GEOMETRICOBJECT_H 00023 # include <BALL/VIEW/KERNEL/geometricObject.h> 00024 #endif 00025 00026 #ifndef BALL_VIEW_KERNEL_STAGE_H 00027 # include <BALL/VIEW/KERNEL/stage.h> 00028 #endif 00029 00030 #ifdef BALL_HAS_GLEW 00031 # include <GL/glew.h> 00032 #endif 00033 00034 #ifndef BALL_VIEW_RENDERING_GLDISPLAYLIST_H 00035 # include <BALL/VIEW/RENDERING/glDisplayList.h> 00036 #endif 00037 00038 #ifndef BALL_DATATYPE_REGULARDATA3D_H 00039 # include <BALL/DATATYPE/regularData3D.h> 00040 #endif 00041 00042 #ifndef APIENTRY 00043 #define APIENTRY 00044 #endif 00045 00046 class QFont; 00047 00048 namespace BALL 00049 { 00050 // defines the maximal number of GL-objects, which can be selected in picking mode 00051 // a number as big as 100.000 is needed for large molecules, just to be sure we use a million 00052 #define BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS 1000000 00053 namespace VIEW 00054 { 00055 class Scene; 00056 class GLDisplayList; 00057 class MeshBuffer; 00058 class ColorMap; 00059 class RenderTarget; 00060 00065 class BALL_VIEW_EXPORT GLRenderer 00066 : public Renderer 00067 { 00068 friend class Scene; 00069 public: 00070 00072 enum StereoMode 00073 { 00074 NO_STEREO = 0, 00075 00077 ACTIVE_STEREO, 00078 00080 DUAL_VIEW_STEREO, 00081 00083 DUAL_VIEW_DIFFERENT_DISPLAY_STEREO 00084 }; 00085 00087 enum RenderMode 00088 { 00090 RENDER_MODE_UNDEFINED = 0, 00091 00093 RENDER_MODE_SOLID, 00094 00096 RENDER_MODE_TRANSPARENT, 00097 00099 RENDER_MODE_ALWAYS_FRONT 00100 }; 00101 00102 00104 enum BufferMode 00105 { 00107 DIRECT_RENDERING = 0, 00108 00110 DISPLAY_LISTS_RENDERING, 00111 00113 REBUILD_DISPLAY_LISTS 00114 }; 00115 00116 00122 class BALL_VIEW_EXPORT WrongModes: public Exception::GeneralException 00123 { 00124 public: 00125 00126 WrongModes(const char* file, int line, int mode, int precision); 00127 }; 00128 00130 typedef unsigned int Name; 00131 00133 GLRenderer(); 00134 00136 virtual ~GLRenderer(); 00137 00139 virtual void clear(); 00140 00142 void dump(std::ostream& s, Size depth) const; 00143 00145 inline Name getName(const GeometricObject& object); 00146 00148 GeometricObject* getObject(GLRenderer::Name name) const; 00149 00150 virtual bool init(Scene& scene); 00151 00153 virtual bool init(const Stage& stage, float width, float height); 00154 00156 virtual void setLights(bool reset_all = false); 00157 00160 virtual void setSmoothLines(bool smooth_lines); 00161 virtual bool getSmoothLines(); 00162 00166 Vector3 mapViewportTo3D(Position x, Position y); 00167 00171 Vector2 map3DToViewport(const Vector3& vec); 00172 00176 void pickObjects1(Position x1, Position y1, Position x2, Position y2); 00177 00182 void pickObjects2(std::list<GeometricObject*>& objects); 00183 00185 void enterPickingMode(); 00186 00188 void exitPickingMode(); 00189 00191 void setSize(float width, float height); 00192 00194 float getXScale() const; 00195 00197 float getYScale() const; 00198 00200 virtual void updateBackgroundColor(); 00201 00202 // Initialise transparent rendering 00203 void initTransparent(); 00204 00205 // Initialise solid rendering 00206 void initSolid(); 00207 00208 // Initialise always front rendering 00209 void initAlwaysFront(); 00210 00212 void setAntialiasing(bool state); 00213 00215 void removeRepresentation(const Representation& rep); 00216 00218 void bufferRepresentation(const Representation& rep); 00219 00221 void drawBuffered(const Representation& rep); 00222 00224 bool hasDisplayListFor(const Representation& rep) const; 00225 00227 void setStereoMode(StereoMode state); 00228 00230 StereoMode getStereoMode() const; 00231 00233 RenderMode getRenderMode() const; 00234 00236 void setRenderMode(RenderMode mode) { render_mode_ = mode;} 00237 00242 virtual void renderToBuffer(RenderTarget* renderTarget, BufferMode); 00243 00245 virtual bool render(const Representation& representation, bool for_display_list = false); 00246 00247 virtual void bufferingDependentRender_(const Representation& repr, BufferMode mode); 00248 00252 bool isExtensionSupported(const String& extension) const; 00253 00255 void clearVertexBuffersFor(Representation& rep); 00256 00258 bool vertexBuffersSupported() const; 00259 00261 String getVendor(); 00262 00264 String getRenderer(); 00265 00267 String getOpenGLVersion(); 00268 00270 vector<String> getExtensions(); 00271 00273 bool enableVertexBuffers(bool state); 00274 00276 bool vertexBuffersEnabled() const; 00277 00279 DrawingMode getDrawingMode() const; 00280 00282 void initPerspective(); 00283 00285 void setProjection(); 00286 00287 //_ 00288 void setColorRGBA_(const ColorRGBA& color); 00289 00290 //_ 00291 void vertexVector3_(const Vector3& v); 00292 00293 // 00294 void updateCamera(const Camera* camera = 0); 00295 00296 // 00297 void setupStereo(float eye_separation, float focal_length); 00298 00299 Position createTextureFromGrid(const RegularData3D& grid, const ColorMap& map); 00300 void removeTextureFor_(const RegularData3D& grid); 00301 00302 void getFrustum(float& near, float& far, float& left, float& right, float& top, float& bottom); 00303 00304 protected: 00305 00309 bool mapViewplaneToScreen_(); 00310 00311 void renderRepresentation_(const Representation& representation, bool for_display_list); 00312 00314 void renderRepresentations_(BufferMode mode); 00315 00317 virtual void renderLabel_(const Label& /*label*/); 00318 00320 virtual void renderLine_(const Line& /*line*/); 00321 00323 virtual void renderMultiLine_(const MultiLine& line); 00324 00326 virtual void renderMesh_(const Mesh& /*mesh*/); 00327 00329 virtual void renderQuadMesh_(const QuadMesh& /*mesh*/); 00330 00332 void initDrawingMeshes_(); 00333 00335 void initDrawingOthers_(); 00336 00344 virtual void renderRuler(); 00345 00347 virtual void renderPoint_(const Point& /*point*/); 00348 00350 virtual void renderSimpleBox_(const SimpleBox& /*box*/); 00351 00353 virtual void renderBox_(const Box& /*box*/); 00354 00356 virtual void renderSphere_(const Sphere& /*sphere*/); 00357 00359 virtual void renderDisc_(const Disc& /*disc*/); 00360 00362 virtual void renderTube_(const Tube& /*tube*/); 00363 00365 virtual void renderTwoColoredLine_(const TwoColoredLine& /*two_colored_line*/); 00366 00368 virtual void renderTwoColoredTube_(const TwoColoredTube& /*two_colored_tube*/); 00369 00371 virtual void renderClippingPlane_(const ClippingPlane& plane); 00372 00374 virtual void renderGridVisualisation_(const GridVisualisation& vol); 00375 00376 //_ 00377 void setColor4ub_(const GeometricObject& object); 00378 00379 //_ 00380 void createSpheres_(); 00381 00382 //_ 00383 void createTubes_(); 00384 00385 //_ 00386 void createBoxes_(); 00387 00388 //_ 00389 void createDottedSphere_(int precision); 00390 00391 //_ 00392 void subdivideTriangle_(Vector3& v1, Vector3& v2, Vector3& v3, int precision); 00393 00394 //_ 00395 void createLineBox_(); 00396 00397 //_ 00398 void createDotBox_(); 00399 00400 //_ 00401 void createSolidBox_(); 00402 00403 //_ 00404 void clearNames_(); 00405 00406 //_ 00407 void normalVector3_(const Vector3& v); 00408 00409 00410 //_ 00411 void translateVector3_(const Vector3& v); 00412 00413 //_ 00414 void texCoordVector3_(const Vector3& v) 00415 { glTexCoord3f(v.x, v.y, v.z); } 00416 00417 //_ 00418 void scaleVector3_(const Vector3& v); 00419 00420 //_ 00421 void rotateVector3Angle_(const Vector3& v, Real angle); 00422 00423 //_ 00424 void scale_(float f); 00425 00426 00427 void initGLU_(DrawingMode mode); 00428 00429 //_ 00430 void setOrthographicZoom(float orthographic_zoom); 00431 00432 //_ 00433 float getOrthographicZoom(void); 00434 00435 //_ 00436 void generateIlluminationTexture_(float ka, float kd, float kr, float shininess); 00437 00438 inline Position getTextureIndex_(Position x, Position y, Position z, Size width, Size height); 00439 void setupGridClipPlanes_(const GridVisualisation& slice); 00440 00442 DrawingMode drawing_mode_; 00443 00445 Index drawing_precision_; 00446 00447 //_ 00448 float near_; 00449 //_ 00450 float far_; 00451 //_ 00452 float left_; 00453 //_ 00454 float right_; 00455 //_ 00456 float top_; 00457 //_ 00458 float bottom_; 00459 00460 //_ 00461 float x_scale_; 00462 00463 //_ 00464 float y_scale_; 00465 00466 GLDisplayList* GL_spheres_list_; 00467 GLDisplayList* GL_tubes_list_; 00468 GLDisplayList* GL_boxes_list_; 00469 GLDisplayList* sphere_list_; 00470 GLDisplayList line_list_; 00471 GLuint line_texture_bind_; 00472 GLubyte line_tex_[128][128][4]; 00473 00474 // naming of geometric objects 00475 typedef HashMap<const GeometricObject*, Name> NameHashMap; 00476 typedef HashMap<Name, const GeometricObject*> GeometricObjectHashMap; 00477 typedef HashMap<const Representation*, GLDisplayList*> DisplayListHashMap; 00478 typedef HashMap<const Representation*, vector<MeshBuffer*> > MeshBufferHashMap; 00479 00480 GeometricObjectHashMap name_to_object_; 00481 NameHashMap object_to_name_; 00482 DisplayListHashMap display_lists_; 00483 MeshBufferHashMap rep_to_buffers_; 00484 Name all_names_; 00485 GLuint object_buffer_[BALL_GLRENDERER_PICKING_NUMBER_OF_MAX_OBJECTS]; 00486 Vector3 normal_vector_; 00487 00488 StereoMode stereo_; 00489 RenderMode render_mode_; 00490 00491 bool use_vertex_buffer_; 00492 bool smooth_lines_; 00493 bool picking_mode_; 00494 ModelType model_type_; 00495 Position display_lists_index_; 00496 bool single_pick_; 00497 bool drawed_other_object_; 00498 bool drawed_mesh_; 00499 GLUquadricObj* GLU_quadric_obj_; 00500 HashMap<const RegularData3D*, Position> grid_to_texture_; 00501 GLuint cel_texture_; 00502 00503 float orthographic_zoom_; 00504 }; 00505 00506 # ifndef BALL_NO_INLINE_FUNCTIONS 00507 # include <BALL/VIEW/RENDERING/glRenderer.iC> 00508 # endif 00509 00510 } // namespace VIEW 00511 } // namespace BALL 00512 00513 #endif // BALL_VIEW_RENDERING_GLRENDERER_H