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

Revision 576, 5.2 KB checked in by bittner, 18 years ago (diff)

rss preprocessor debugging + merge

  • 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  bool mSnapErrorFrames;
74  QString mSnapPrefix;
75
76  KdTree *mKdTree;
77
78  QWaitCondition mRenderingFinished;
79 
80 
81  GlRenderer(SceneGraph *sceneGraph,
82                         ViewCellsManager *viewcells,
83                         KdTree *tree);
84 
85  ~GlRenderer();
86
87
88  void SetupFalseColor(const int id);
89  void RenderIntersectable(Intersectable *);
90  void RenderViewCell(ViewCell *vc);
91  void RenderMeshInstance(MeshInstance *mi);
92  void RenderMesh(Mesh *m);
93  void SetupMaterial(Material *m);
94  virtual void SetupCamera();
95 
96  bool
97  RenderScene();
98
99
100  void
101  SetupProjection(const int w, const int h);
102
103 
104 
105
106  void InitGL();
107
108  virtual int GetWidth() const = 0;
109  virtual int GetHeight() const = 0;
110
111  int GetId(int r, int g, int b) const;
112};
113
114
115class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
116{
117public:
118        GlRendererBuffer(const int w,
119                                         const int h,
120                                         SceneGraph *sceneGraph,
121                                         ViewCellsManager *viewcells,
122                                         KdTree *tree);
123
124 
125  void
126  EvalPvsStat();
127
128  void
129  ClearErrorBuffer();
130 
131
132  virtual int GetWidth() const { return width(); }
133  virtual int GetHeight() const { return height(); }
134
135
136  void RandomViewPoint();
137  void SampleBeamContributions(
138                                                           Intersectable *sourceObject,
139                                                           Beam &beam,
140                                                           const int samples,
141                                                           BeamSampleStatistics &stat
142                                                           );
143
144  void
145  SampleViewpointContributions(
146                                                           Intersectable *sourceObject,
147                                                           const Vector3 viewPoint,
148                                                           Beam &beam,
149                                                           const int desiredSamples,
150                                                           BeamSampleStatistics &stat
151                                                           );
152
153  void InitGL();
154
155  /** Computes rays from information gained with hw sampling-
156  */
157  void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
158
159  int ComputePvs() const;
160
161  float
162  GetPixelError();
163
164  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
165
166  PvsRenderStatistics mPvsStat;
167   
168  int mPvsStatFrames;
169  vector<float> mPvsErrorBuffer;
170private:
171       
172        static void GenQueries(const int numQueries);
173       
174        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
175                                                                         const Beam &beam,
176                                                                         Intersectable *sourceObject);
177};
178
179
180
181class GlRendererWidget : public QGLWidget, public GlRenderer
182{
183  Q_OBJECT
184public:
185
186  // point of the last mouse click used for movement in the scene
187  Vector3 mousePoint;
188
189  bool mTopView;
190 
191  GlRendererWidget(SceneGraph *sceneGraph,
192                                   ViewCellsManager *viewcells,
193                                   KdTree *tree,
194                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
195                                   ):
196        GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
197  {
198        mTopView = false;
199  }
200
201  virtual void SetupCamera();
202
203  void initializeGL() {
204        InitGL();
205  }
206  void resizeGL(int w, int h);
207  void paintGL();
208  void timerEvent(QTimerEvent *) {
209          update();
210  }
211
212  void mousePressEvent(QMouseEvent *);
213  void mouseReleaseEvent(QMouseEvent *);
214  void mouseMoveEvent(QMouseEvent *);
215
216  void keyPressEvent ( QKeyEvent * e ) ;
217 
218  float
219  RenderErrors();
220  void
221  RenderInfo();
222
223  virtual int GetWidth() const { return width(); }
224  virtual int GetHeight() const { return height(); }
225};
226
227
228extern GlRendererWidget *rendererWidget;
229
230class GlDebuggerWidget : public QGLWidget
231{
232        Q_OBJECT
233public:
234    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
235    ~GlDebuggerWidget();
236    void initializeGL();
237    void resizeGL(int w, int h);
238    void paintGL();
239    void timerEvent(QTimerEvent *) { update(); }
240    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
241    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
242
243    void initCommon();
244    void initPbuffer();
245
246         GlRendererBuffer *mRenderBuffer;
247
248         Beam mBeam;
249         int mSamples;
250         Intersectable *mSourceObject;
251private:
252    GLuint dynamicTexture;
253    int timerId;
254};
255
256extern GlDebuggerWidget *debuggerWidget;
257
258#endif
259
Note: See TracBrowser for help on using the repository browser.