source: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h @ 525

Revision 525, 4.5 KB checked in by mattausch, 18 years ago (diff)
  • Property svn:executable set to *
Line 
1#ifndef __RENDERER_H
2#define __RENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
6//#include <QGLPixelBuffer>
7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
11#include "Renderer.h"
12
13class SceneGraph;
14class ViewCellsManager;
15class Mesh;
16class MeshInstance;
17class Intersectable;
18class Material;
19class Beam;
20
21struct PvsRenderStatistics {
22 
23  float maxError;
24  float sumError;
25  int frames;
26  int errorFreeFrames;
27
28  PvsRenderStatistics() { Reset(); }
29 
30  void Reset() {
31        maxError = 0.0f;
32        sumError = 0.0f;
33        frames = 0;
34        errorFreeFrames = 0;
35  }
36
37  float GetMaxError() { return maxError; }
38  float GetAvgError() { return sumError/frames; }
39  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
40 
41};
42
43
44/** Class encapsulating gl rendering for the scene.
45        There is no gl context binding so the binding is performed in the
46        derived classes
47*/
48
49class GlRenderer: public Renderer
50{
51
52public:
53  ObjectContainer mObjects;
54   
55  Vector3 mViewPoint;
56  Vector3 mViewDirection;
57
58  int timerId;
59  bool mUseFalseColors;
60
61  HaltonSequence halton;
62 
63  int mFrame;
64  bool mWireFrame;
65
66  QWaitCondition mRenderingFinished;
67 
68 
69  GlRenderer(SceneGraph *sceneGraph,
70                         ViewCellsManager *viewcells);
71 
72  ~GlRenderer();
73
74
75  void SetupFalseColor(const int id);
76  void RenderIntersectable(Intersectable *);
77  void RenderMeshInstance(MeshInstance *mi);
78  void RenderMesh(Mesh *m);
79  void SetupMaterial(Material *m);
80  virtual void SetupCamera();
81  void RandomViewPoint();
82 
83  bool
84  RenderScene();
85
86  void
87  SetupProjection(const int w, const int h);
88
89 
90 
91  float
92  GetPixelError();
93
94  void InitGL();
95
96  virtual int GetWidth() const = 0;
97  virtual int GetHeight() const = 0;
98};
99
100
101class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
102{
103
104public:
105  int mPvsStatFrames;
106  vector<float> mPvsErrorBuffer;
107 
108  PvsRenderStatistics mPvsStat;
109
110
111  GlRendererBuffer(const int w,
112                                   const int h,
113                                   SceneGraph *sceneGraph,
114                                   ViewCellsManager *viewcells):
115        QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
116
117        mPvsStatFrames = 10000;
118        mPvsErrorBuffer.resize(mPvsStatFrames);
119        ClearErrorBuffer();
120
121        makeCurrent();
122        InitGL();
123        doneCurrent();
124
125  }
126 
127  void
128  EvalPvsStat();
129
130  void
131  ClearErrorBuffer();
132 
133
134  virtual int GetWidth() const { return width(); }
135  virtual int GetHeight() const { return height(); }
136
137
138
139  // the values need for rss tree update computed already inside the glrendererbuffer
140  // not all of them need to be computed
141  struct BeamSampleStatistics {
142
143        enum {COMPUTE_PVS_SIZE, COMPUTE_RAY_CONTRIBUTIONS, COMPUTE_PVS_ENTROPY};
144        int flags;
145
146        BeamSampleStatistics():flags(COMPUTE_RAY_CONTRIBUTIONS) {}
147       
148        float pvsSize;
149        float rays;
150        float rayContributions;
151        float pvsEntropy;
152        float rayLengthEntropy;
153        float importance;
154       
155        float weightedRayContribution;
156  };
157 
158
159  void SampleBeamContributions(
160                                                           Intersectable *sourceObject,
161                                                           Beam &beam,
162                                                           const int samples,
163                                                           BeamSampleStatistics &stat
164                                                           );
165
166  void
167  SampleViewpointContributions(
168                                                           Intersectable *sourceObject,
169                                                           const Vector3 viewPoint,
170                                                           Beam &beam,
171                                                           const int desiredSamples,
172                                                           BeamSampleStatistics &stat
173                                                           );
174
175private:
176        static void GenQueries(const int numQueries);
177        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
178                                                                         const Beam &beam,
179                                                                         Intersectable *sourceObject);
180};
181
182
183
184class GlRendererWidget : public QGLWidget, public GlRenderer
185{
186  Q_OBJECT
187public:
188
189  // point of the last mouse click used for movement in the scene
190  Vector3 mousePoint;
191
192  bool mTopView;
193 
194  GlRendererWidget(SceneGraph *sceneGraph,
195                                   ViewCellsManager *viewcells,
196                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
197                                   ):
198        GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
199  {
200        mTopView = false;
201  }
202
203  virtual void SetupCamera();
204
205  void initializeGL() {
206        InitGL();
207  }
208  void resizeGL(int w, int h);
209  void paintGL();
210  void timerEvent(QTimerEvent *) {
211          update();
212  }
213
214  void mousePressEvent(QMouseEvent *);
215  void mouseReleaseEvent(QMouseEvent *);
216  void mouseMoveEvent(QMouseEvent *);
217
218  void keyPressEvent ( QKeyEvent * e ) ;
219 
220  float
221  RenderErrors();
222
223  virtual int GetWidth() const { return width(); }
224  virtual int GetHeight() const { return height(); }
225
226};
227
228
229extern GlRendererWidget *rendererWidget;
230
231#endif
232
Note: See TracBrowser for help on using the repository browser.