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