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

Revision 498, 3.2 KB checked in by mattausch, 19 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
7#include "Vector3.h"
8#include "Containers.h"
9#include "Halton.h"
10#include "Renderer.h"
11
12class SceneGraph;
13class ViewCellsManager;
14class Mesh;
15class MeshInstance;
16class Intersectable;
17class Material;
18
19struct PvsRenderStatistics {
20 
21  float maxError;
22  float sumError;
23  int frames;
24  int errorFreeFrames;
25 
26  PvsRenderStatistics() { Reset(); }
27 
28  void Reset() {
29        maxError = 0.0f;
30        sumError = 0.0f;
31        frames = 0;
32        errorFreeFrames = 0;
33  }
34
35  float GetMaxError() { return maxError; }
36  float GetAvgError() { return sumError/frames; }
37  float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
38 
39};
40
41
42/** Class encapsulating gl rendering for the scene.
43        There is no gl context binding so the binding is performed in the
44        derived classes
45*/
46
47class GlRenderer: public Renderer
48{
49
50public:
51  ObjectContainer mObjects;
52   
53  Vector3 mViewPoint;
54  Vector3 mViewDirection;
55
56  int timerId;
57  bool mUseFalseColors;
58
59  HaltonSequence halton;
60 
61  int mFrame;
62 
63  QWaitCondition mRenderingFinished;
64 
65 
66  GlRenderer(SceneGraph *sceneGraph,
67                         ViewCellsManager *viewcells);
68 
69  ~GlRenderer();
70
71
72  void SetupFalseColor(const int id);
73  void RenderIntersectable(Intersectable *);
74  void RenderMeshInstance(MeshInstance *mi);
75  void RenderMesh(Mesh *m);
76  void SetupMaterial(Material *m);
77  void SetupCamera();
78  void RandomViewPoint();
79 
80  bool
81  RenderScene();
82
83  void
84  SetupProjection(const int w, const int h);
85
86 
87 
88  float
89  GetPixelError();
90
91  void InitGL();
92
93  virtual int GetWidth() const = 0;
94  virtual int GetHeight() const = 0;
95};
96
97
98class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
99{
100
101public:
102  int mPvsStatFrames;
103  vector<float> mPvsErrorBuffer;
104 
105  PvsRenderStatistics mPvsStat;
106
107
108  GlRendererBuffer(const int w,
109                                   const int h,
110                                   SceneGraph *sceneGraph,
111                                   ViewCellsManager *viewcells):
112        QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
113
114        mPvsStatFrames = 10000;
115        mPvsErrorBuffer.resize(mPvsStatFrames);
116        ClearErrorBuffer();
117
118        makeCurrent();
119        InitGL();
120       
121  }
122 
123  void
124  EvalPvsStat();
125
126  void
127  ClearErrorBuffer();
128
129 
130
131  virtual int GetWidth() const { return width(); }
132  virtual int GetHeight() const { return height(); }
133
134};
135
136
137
138class GlRendererWidget : public QGLWidget, public GlRenderer
139{
140  Q_OBJECT
141public:
142
143  GlRendererWidget(SceneGraph *sceneGraph,
144                                   ViewCellsManager *viewcells,
145                                   QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
146                                   ):
147        GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
148  {}
149
150  Vector3 mousePoint;
151 
152  void initializeGL() {
153        InitGL();
154  }
155  void resizeGL(int w, int h);
156  void paintGL();
157  void timerEvent(QTimerEvent *) {
158          update();
159  }
160
161  void mousePressEvent(QMouseEvent *);
162  void mouseReleaseEvent(QMouseEvent *);
163  void mouseMoveEvent(QMouseEvent *);
164
165  float
166  RenderErrors();
167
168  virtual int GetWidth() const { return width(); }
169  virtual int GetHeight() const { return height(); }
170
171};
172
173
174extern GlRendererWidget *rendererWidget;
175
176#endif
177
Note: See TracBrowser for help on using the repository browser.