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

Revision 540, 5.3 KB checked in by mattausch, 19 years ago (diff)
  • Property svn:executable set to *
RevLine 
[492]1#ifndef __RENDERER_H
2#define __RENDERER_H
3
4#include <QtOpenGL>
5#include <QWaitCondition>
[500]6//#include <QGLPixelBuffer>
[492]7
8#include "Vector3.h"
9#include "Containers.h"
10#include "Halton.h"
[497]11#include "Renderer.h"
[540]12#include "Beam.h"
[492]13
14class SceneGraph;
15class ViewCellsManager;
16class Mesh;
17class MeshInstance;
18class Intersectable;
19class Material;
[512]20class Beam;
[532]21class KdTree;
[538]22class QWidget;
23class GlRendererBuffer;
[531]24class BeamSampleStatistics;
25
[540]26struct VssRayContainer;
27
[492]28struct PvsRenderStatistics {
29 
30  float maxError;
31  float sumError;
32  int frames;
33  int errorFreeFrames;
[502]34
[492]35  PvsRenderStatistics() { Reset(); }
36 
[498]37  void Reset() {
[492]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
[496]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
[497]56class GlRenderer: public Renderer
[492]57{
[496]58
[492]59public:
60  ObjectContainer mObjects;
[498]61   
[492]62  Vector3 mViewPoint;
63  Vector3 mViewDirection;
64
65  int timerId;
66  bool mUseFalseColors;
67
68  HaltonSequence halton;
69 
70  int mFrame;
[502]71  bool mWireFrame;
72
[532]73  KdTree *mKdTree;
74
[492]75  QWaitCondition mRenderingFinished;
76 
77 
78  GlRenderer(SceneGraph *sceneGraph,
[532]79                         ViewCellsManager *viewcells,
80                         KdTree *tree);
[496]81 
[492]82  ~GlRenderer();
83
[496]84
[492]85  void SetupFalseColor(const int id);
86  void RenderIntersectable(Intersectable *);
[535]87  void RenderViewCell(ViewCell *vc);
[492]88  void RenderMeshInstance(MeshInstance *mi);
89  void RenderMesh(Mesh *m);
90  void SetupMaterial(Material *m);
[502]91  virtual void SetupCamera();
[492]92  void RandomViewPoint();
[496]93 
[497]94  bool
[496]95  RenderScene();
[492]96
[496]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;
[540]109
110  int GetId(int r, int g, int b) const;
[496]111};
112
113
114class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
115{
116public:
[532]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) {
[496]123
124        mPvsStatFrames = 10000;
125        mPvsErrorBuffer.resize(mPvsStatFrames);
126        ClearErrorBuffer();
127
128        makeCurrent();
129        InitGL();
[502]130        doneCurrent();
131
[532]132        }
[496]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
[507]144
145  void SampleBeamContributions(
146                                                           Intersectable *sourceObject,
[512]147                                                           Beam &beam,
[507]148                                                           const int samples,
149                                                           BeamSampleStatistics &stat
150                                                           );
151
152  void
153  SampleViewpointContributions(
154                                                           Intersectable *sourceObject,
[514]155                                                           const Vector3 viewPoint,
[512]156                                                           Beam &beam,
[507]157                                                           const int desiredSamples,
158                                                           BeamSampleStatistics &stat
159                                                           );
160
[540]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;
[532]173   
[540]174  int mPvsStatFrames;
175  vector<float> mPvsErrorBuffer;
[532]176
[513]177private:
[540]178       
[513]179        static void GenQueries(const int numQueries);
[540]180       
[525]181        void SetupProjectionForViewPoint(const Vector3 &viewPoint,
182                                                                         const Beam &beam,
183                                                                         Intersectable *sourceObject);
[496]184};
185
186
187
188class GlRendererWidget : public QGLWidget, public GlRenderer
189{
190  Q_OBJECT
191public:
192
[502]193  // point of the last mouse click used for movement in the scene
194  Vector3 mousePoint;
195
196  bool mTopView;
197 
[496]198  GlRendererWidget(SceneGraph *sceneGraph,
199                                   ViewCellsManager *viewcells,
[532]200                                   KdTree *tree,
[496]201                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
202                                   ):
[532]203        GlRenderer(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
[502]204  {
205        mTopView = false;
206  }
[496]207
[502]208  virtual void SetupCamera();
209
[496]210  void initializeGL() {
211        InitGL();
212  }
[492]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
[504]223  void keyPressEvent ( QKeyEvent * e ) ;
224 
[492]225  float
[496]226  RenderErrors();
[492]227
[496]228  virtual int GetWidth() const { return width(); }
229  virtual int GetHeight() const { return height(); }
[492]230};
231
232
[496]233extern GlRendererWidget *rendererWidget;
[492]234
[538]235class GlDebuggerWidget : public QGLWidget
236{
[540]237        Q_OBJECT
[538]238public:
[540]239    GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
[538]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
[540]253         Beam mBeam;
254         int mSamples;
255         Intersectable *mSourceObject;
[538]256private:
257    GLuint dynamicTexture;
258    int timerId;
259};
260
261extern GlDebuggerWidget *debuggerWidget;
262
[492]263#endif
264
Note: See TracBrowser for help on using the repository browser.