1 /**************************************************************************/ 2 /* Copyright 2009 Tim Day */ 3 /* */ 4 /* This file is part of Fracplanet */ 5 /* */ 6 /* Fracplanet is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Fracplanet is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Fracplanet. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Interface for class TriangleMeshViewerDisplay. 22 */ 23 24 #ifndef _triangle_mesh_viewer_display_h_ 25 #define _triangle_mesh_viewer_display_h_ 26 27 #include <deque> 28 29 #include "common.h" 30 #include "parameters_render.h" 31 #include "qtcommon.h" 32 #include "random.h" 33 #include "triangle_mesh.h" 34 35 class TriangleMeshViewer; 36 37 //! Contains the actual rendering functionality of a TriangleMeshViewer. 38 class TriangleMeshViewerDisplay : public QGLWidget 39 { 40 private: 41 42 Q_OBJECT; 43 44 public: 45 46 //! Constructor. 47 TriangleMeshViewerDisplay(TriangleMeshViewer* parent,const QGLFormat& format,const ParametersRender* param,const std::vector<const TriangleMesh*>& m,bool verbose 48 ); 49 50 //! Destructor 51 ~TriangleMeshViewerDisplay(); 52 53 //! Specify a minimum size 54 QSize minimumSizeHint() const; 55 56 //! Guideline size 57 QSize sizeHint() const; 58 59 //! Set the mesh being rendered. 60 void set_mesh(const std::vector<const TriangleMesh*>& m); 61 62 protected: 63 64 //! Called to repaint GL area. 65 void paintGL(); 66 67 //! Set up OpenGL. 68 void initializeGL(); 69 70 //! Deal with resize. 71 void resizeGL(int w,int h); 72 73 public slots: 74 75 //! Called to redisplay scene 76 void draw_frame(const XYZ& p,const XYZ& l,const XYZ& u,float r,float t); 77 78 private: 79 80 //! Need to know this to update framerate text 81 TriangleMeshViewer& _notify; 82 83 //! Control logging 84 const bool _verbose; 85 86 //! The meshes being displayed. 87 /*! NB NOT owned here 88 */ 89 std::vector<const TriangleMesh*> mesh; 90 91 //! Pointer to the rendering parameters. 92 const ParametersRender* parameters; 93 94 //! GL display list index 95 /*! Zero is not a valid value according to red book, so use zero to designate unset */ 96 uint gl_display_list_index; 97 98 99 100 //! Frame count. 101 uint frame_number; 102 103 //! Display area width. 104 uint width; 105 106 //! Display area height. 107 uint height; 108 109 //! Time frames for FPS measurement. 110 QTime frame_time; 111 112 //! Time since FPS last reported. 113 QTime frame_time_reported; 114 115 //! Queue of frame times to average. 116 std::deque<uint> frame_times; 117 118 //@{ 119 //! Parameter of camera position. 120 XYZ camera_position; 121 XYZ camera_lookat; 122 XYZ camera_up; 123 //@} 124 125 //@{ 126 //! Parameters of object 127 float object_tilt; 128 float object_rotation; 129 //@} 130 131 void check_for_gl_errors(const char*) const; 132 133 //! Compute background colour from render parameters and camera height 134 const FloatRGBA background_colour() const; 135 }; 136 137 #endif 138