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

Revision 572, 5.1 KB checked in by bittner, 18 years ago (diff)

gl render error estimation changes for backface culling empty viewspace detection

  • 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#include "Beam.h"
13
14class SceneGraph;
15class ViewCellsManager;
16class Mesh;
17class MeshInstance;
18class Intersectable;
19class Material;
20class Beam;
21class KdTree;
22class QWidget;
23class GlRendererBuffer;
24class BeamSampleStatistics;
25
26struct VssRayContainer;
27
28struct PvsRenderStatistics {
29 
30  float maxError;
31  float sumError;
32  int frames;
33  int errorFreeFrames;
34
35  PvsRenderStatistics() { Reset(); }
36 
37  void Reset() {
38        maxError = 0.0f;
39        sumError = 0.0f;
40        frames = 0;
41        errorFreeFrames = 0;
42  }
43
44  float GetMaxError() { return maxError; }
45  float GetAvgError() { return sumError/frames; }
46  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
47 
48};
49
50
51/** Class encapsulating gl rendering for the scene.
52        There is no gl context binding so the binding is performed in the
53        derived classes
54*/
55
56class GlRenderer: public Renderer
57{
58
59public:
60  ObjectContainer mObjects;
61   
62  Vector3 mViewPoint;
63  Vector3 mViewDirection;
64
65  int timerId;
66  bool mUseFalseColors;
67
68  HaltonSequence halton;
69 
70  int mFrame;
71  bool mWireFrame;
72  bool mDetectEmptyViewSpace;
73
74  KdTree *mKdTree;
75
76  QWaitCondition mRenderingFinished;
77 
78 
79  GlRenderer(SceneGraph *sceneGraph,
80                         ViewCellsManager *viewcells,
81                         KdTree *tree);
82 
83  ~GlRenderer();
84
85
86  void SetupFalseColor(const int id);
87  void RenderIntersectable(Intersectable *);
88  void RenderViewCell(ViewCell *vc);
89  void RenderMeshInstance(MeshInstance *mi);
90  void RenderMesh(Mesh *m);
91  void SetupMaterial(Material *m);
92  virtual void SetupCamera();
93 
94  bool
95  RenderScene();
96
97  void
98  SetupProjection(const int w, const int h);
99
100 
101 
102  float
103  GetPixelError();
104
105  void InitGL();
106
107  virtual int GetWidth() const = 0;
108  virtual int GetHeight() const = 0;
109
110  int GetId(int r, int g, int b) const;
111};
112
113
114class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
115{
116public:
117        GlRendererBuffer(const int w,
118                                         const int h,
119                                         SceneGraph *sceneGraph,
120                                         ViewCellsManager *viewcells,
121                                         KdTree *tree);
122
123 
124  void
125  EvalPvsStat();
126
127  void
128  ClearErrorBuffer();
129 
130
131  virtual int GetWidth() const { return width(); }
132  virtual int GetHeight() const { return height(); }
133
134
135  void RandomViewPoint();
136  void SampleBeamContributions(
137                                                           Intersectable *sourceObject,
138                                                           Beam &beam,
139                                                           const int samples,
140                                                           BeamSampleStatistics &stat
141                                                           );
142
143  void
144  SampleViewpointContributions(
145                                                           Intersectable *sourceObject,
146                                                           const Vector3 viewPoint,
147                                                           Beam &beam,
148                                                           const int desiredSamples,
149                                                           BeamSampleStatistics &stat
150                                                           );
151
152  void InitGL();
153
154  /** Computes rays from information gained with hw sampling-
155  */
156  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
157
158  int ComputePvs() const;
159
160
161  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
162
163  PvsRenderStatistics mPvsStat;
164   
165  int mPvsStatFrames;
166  vector<float> mPvsErrorBuffer;
167private:
168       
169        static void GenQueries(const int numQueries);
170       
171        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
172                                                                         const Beam &beam,
173                                                                         Intersectable *sourceObject);
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                                   KdTree *tree,
191                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
192                                   ):
193        GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
194  {
195        mTopView = false;
196  }
197
198  virtual void SetupCamera();
199
200  void initializeGL() {
201        InitGL();
202  }
203  void resizeGL(int w, int h);
204  void paintGL();
205  void timerEvent(QTimerEvent *) {
206          update();
207  }
208
209  void mousePressEvent(QMouseEvent *);
210  void mouseReleaseEvent(QMouseEvent *);
211  void mouseMoveEvent(QMouseEvent *);
212
213  void keyPressEvent ( QKeyEvent * e ) ;
214 
215  float
216  RenderErrors();
217
218  virtual int GetWidth() const { return width(); }
219  virtual int GetHeight() const { return height(); }
220};
221
222
223extern GlRendererWidget *rendererWidget;
224
225class GlDebuggerWidget : public QGLWidget
226{
227        Q_OBJECT
228public:
229    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
230    ~GlDebuggerWidget();
231    void initializeGL();
232    void resizeGL(int w, int h);
233    void paintGL();
234    void timerEvent(QTimerEvent *) { update(); }
235    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
236    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
237
238    void initCommon();
239    void initPbuffer();
240
241         GlRendererBuffer *mRenderBuffer;
242
243         Beam mBeam;
244         int mSamples;
245         Intersectable *mSourceObject;
246private:
247    GLuint dynamicTexture;
248    int timerId;
249};
250
251extern GlDebuggerWidget *debuggerWidget;
252
253#endif
254
Note: See TracBrowser for help on using the repository browser.