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

Revision 511, 4.3 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 MyBeam;
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                                                           MyBeam &beam,
162                                                           const int samples,
163                                                           BeamSampleStatistics &stat
164                                                           );
165
166  void
167  SampleViewpointContributions(
168                                                           Intersectable *sourceObject,
169                                                           MyBeam &beam,
170                                                           const int desiredSamples,
171                                                           BeamSampleStatistics &stat
172                                                           );
173
174};
175
176
177
178class GlRendererWidget : public QGLWidget, public GlRenderer
179{
180  Q_OBJECT
181public:
182
183  // point of the last mouse click used for movement in the scene
184  Vector3 mousePoint;
185
186  bool mTopView;
187 
188  GlRendererWidget(SceneGraph *sceneGraph,
189                                   ViewCellsManager *viewcells,
190                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
191                                   ):
192        GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
193  {
194        mTopView = false;
195  }
196
197  virtual void SetupCamera();
198
199  void initializeGL() {
200        InitGL();
201  }
202  void resizeGL(int w, int h);
203  void paintGL();
204  void timerEvent(QTimerEvent *) {
205          update();
206  }
207
208  void mousePressEvent(QMouseEvent *);
209  void mouseReleaseEvent(QMouseEvent *);
210  void mouseMoveEvent(QMouseEvent *);
211
212  void keyPressEvent ( QKeyEvent * e ) ;
213 
214  float
215  RenderErrors();
216
217  virtual int GetWidth() const { return width(); }
218  virtual int GetHeight() const { return height(); }
219
220};
221
222
223extern GlRendererWidget *rendererWidget;
224
225#endif
226
Note: See TracBrowser for help on using the repository browser.