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

Revision 556, 5.3 KB checked in by bittner, 18 years ago (diff)

debug version looking for glrenderer bug...

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