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 |
|
---|
14 | class SceneGraph;
|
---|
15 | class ViewCellsManager;
|
---|
16 | class Mesh;
|
---|
17 | class MeshInstance;
|
---|
18 | class Intersectable;
|
---|
19 | class Material;
|
---|
20 | class Beam;
|
---|
21 | class KdTree;
|
---|
22 | class QWidget;
|
---|
23 | class GlRendererBuffer;
|
---|
24 | class BeamSampleStatistics;
|
---|
25 |
|
---|
26 | struct VssRayContainer;
|
---|
27 |
|
---|
28 | struct PvsRenderStatistics {
|
---|
29 |
|
---|
30 | float maxError;
|
---|
31 | float sumError;
|
---|
32 | int sumPvsSize;
|
---|
33 | int frames;
|
---|
34 | int errorFreeFrames;
|
---|
35 |
|
---|
36 | PvsRenderStatistics() { Reset(); }
|
---|
37 |
|
---|
38 | void Reset() {
|
---|
39 | maxError = 0.0f;
|
---|
40 | sumError = 0.0f;
|
---|
41 | frames = 0;
|
---|
42 | errorFreeFrames = 0;
|
---|
43 | sumPvsSize = 0;
|
---|
44 | }
|
---|
45 |
|
---|
46 | float GetMaxError() { return maxError; }
|
---|
47 | float GetAvgError() { return sumError/frames; }
|
---|
48 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
49 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
50 |
|
---|
51 | };
|
---|
52 |
|
---|
53 | struct RenderCostSample {
|
---|
54 |
|
---|
55 | RenderCostSample() {}
|
---|
56 |
|
---|
57 | void Reset() {
|
---|
58 | mVisibleObjects = 0;
|
---|
59 | mVisiblePixels = 0;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // visible object from the given point
|
---|
63 | int mVisibleObjects;
|
---|
64 |
|
---|
65 | // visible pixels
|
---|
66 | int mVisiblePixels;
|
---|
67 |
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** Class encapsulating gl rendering for the scene.
|
---|
71 | There is no gl context binding so the binding is performed in the
|
---|
72 | derived classes
|
---|
73 | */
|
---|
74 |
|
---|
75 | class GlRenderer: public Renderer
|
---|
76 | {
|
---|
77 |
|
---|
78 | public:
|
---|
79 | ObjectContainer mObjects;
|
---|
80 |
|
---|
81 | Vector3 mViewPoint;
|
---|
82 | Vector3 mViewDirection;
|
---|
83 |
|
---|
84 | int timerId;
|
---|
85 | bool mUseFalseColors;
|
---|
86 | bool mUseForcedColors;
|
---|
87 |
|
---|
88 | HaltonSequence halton;
|
---|
89 |
|
---|
90 | int mFrame;
|
---|
91 | bool mWireFrame;
|
---|
92 |
|
---|
93 | bool mDetectEmptyViewSpace;
|
---|
94 | bool mSnapErrorFrames;
|
---|
95 |
|
---|
96 | bool mUseGlLists;
|
---|
97 |
|
---|
98 | QString mSnapPrefix;
|
---|
99 |
|
---|
100 | KdTree *mKdTree;
|
---|
101 |
|
---|
102 | QWaitCondition mRenderingFinished;
|
---|
103 |
|
---|
104 | vector<unsigned int> mOcclusionQueries;
|
---|
105 |
|
---|
106 | GlRenderer(SceneGraph *sceneGraph,
|
---|
107 | ViewCellsManager *viewcells,
|
---|
108 | KdTree *tree);
|
---|
109 |
|
---|
110 | ~GlRenderer();
|
---|
111 |
|
---|
112 |
|
---|
113 | void SetupFalseColor(const int id);
|
---|
114 | void RenderIntersectable(Intersectable *);
|
---|
115 | void RenderViewCell(ViewCell *vc);
|
---|
116 | void RenderMeshInstance(MeshInstance *mi);
|
---|
117 | void RenderMesh(Mesh *m);
|
---|
118 | void SetupMaterial(Material *m);
|
---|
119 | virtual void SetupCamera();
|
---|
120 |
|
---|
121 | bool
|
---|
122 | RenderScene();
|
---|
123 |
|
---|
124 | void
|
---|
125 | _RenderScene();
|
---|
126 |
|
---|
127 |
|
---|
128 | virtual void
|
---|
129 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | void InitGL();
|
---|
135 |
|
---|
136 | virtual int GetWidth() const = 0;
|
---|
137 | virtual int GetHeight() const = 0;
|
---|
138 |
|
---|
139 | int GetId(int r, int g, int b) const;
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 | class GlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRenderer
|
---|
144 | {
|
---|
145 | Q_OBJECT
|
---|
146 | public:
|
---|
147 | GlRendererBuffer(const int w,
|
---|
148 | const int h,
|
---|
149 | SceneGraph *sceneGraph,
|
---|
150 | ViewCellsManager *viewcells,
|
---|
151 | KdTree *tree);
|
---|
152 |
|
---|
153 |
|
---|
154 | void
|
---|
155 | EvalRenderCostSample(
|
---|
156 | RenderCostSample &sample
|
---|
157 | );
|
---|
158 |
|
---|
159 | void
|
---|
160 | SampleRenderCost(
|
---|
161 | const int n,
|
---|
162 | vector<RenderCostSample> &samples
|
---|
163 | );
|
---|
164 |
|
---|
165 |
|
---|
166 | void
|
---|
167 | EvalPvsStat();
|
---|
168 |
|
---|
169 | void
|
---|
170 | ClearErrorBuffer();
|
---|
171 |
|
---|
172 |
|
---|
173 | virtual int GetWidth() const { return width(); }
|
---|
174 | virtual int GetHeight() const { return height(); }
|
---|
175 |
|
---|
176 |
|
---|
177 | void RandomViewPoint();
|
---|
178 | void SampleBeamContributions(
|
---|
179 | Intersectable *sourceObject,
|
---|
180 | Beam &beam,
|
---|
181 | const int samples,
|
---|
182 | BeamSampleStatistics &stat
|
---|
183 | );
|
---|
184 |
|
---|
185 | void
|
---|
186 | SampleViewpointContributions(
|
---|
187 | Intersectable *sourceObject,
|
---|
188 | const Vector3 viewPoint,
|
---|
189 | Beam &beam,
|
---|
190 | const int desiredSamples,
|
---|
191 | BeamSampleStatistics &stat
|
---|
192 | );
|
---|
193 |
|
---|
194 | void InitGL();
|
---|
195 |
|
---|
196 | /** Computes rays from information gained with hw sampling-
|
---|
197 | */
|
---|
198 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
199 |
|
---|
200 | int ComputePvs() const;
|
---|
201 |
|
---|
202 | float
|
---|
203 | GetPixelError(int &pvsSize);
|
---|
204 |
|
---|
205 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
206 |
|
---|
207 | PvsRenderStatistics mPvsStat;
|
---|
208 |
|
---|
209 | int mPvsStatFrames;
|
---|
210 | struct PvsErrorEntry {
|
---|
211 | PvsErrorEntry() {}
|
---|
212 | float mError;
|
---|
213 | int mPvsSize;
|
---|
214 | Vector3 mPosition;
|
---|
215 | Vector3 mDirection;
|
---|
216 | };
|
---|
217 |
|
---|
218 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
219 |
|
---|
220 | private:
|
---|
221 | unsigned int *mPixelBuffer;
|
---|
222 |
|
---|
223 | static void GenQueries(const int numQueries);
|
---|
224 |
|
---|
225 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
226 | const Beam &beam,
|
---|
227 |
|
---|
228 | Intersectable *sourceObject);
|
---|
229 |
|
---|
230 | public:
|
---|
231 | signals:
|
---|
232 | UpdatePvsErrorItem(int i,
|
---|
233 | GlRendererBuffer::PvsErrorEntry &);
|
---|
234 | };
|
---|
235 |
|
---|
236 |
|
---|
237 | class RendererControlWidget : public QWidget
|
---|
238 | {
|
---|
239 | Q_OBJECT
|
---|
240 | public:
|
---|
241 |
|
---|
242 | QListWidget *mPvsErrorWidget;
|
---|
243 |
|
---|
244 | RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
245 |
|
---|
246 | public slots:
|
---|
247 |
|
---|
248 | void FocusNextPvsErrorFrame();
|
---|
249 | void UpdatePvsErrorItem(int i,
|
---|
250 | GlRendererBuffer::PvsErrorEntry &);
|
---|
251 |
|
---|
252 | signals:
|
---|
253 |
|
---|
254 | SetViewCellGranularity(int);
|
---|
255 | SetSceneCut(int);
|
---|
256 | SetTopDistance(int);
|
---|
257 | SetVisibilityFilterSize(int);
|
---|
258 |
|
---|
259 | SetRenderFilter(bool);
|
---|
260 | SetRenderErrors(bool);
|
---|
261 | SetShowViewCells(bool);
|
---|
262 | SetShowRenderCost(bool);
|
---|
263 | SetShowPvsSizes(bool);
|
---|
264 | SetTopView(bool);
|
---|
265 | SetCutViewCells(bool);
|
---|
266 | SetCutScene(bool);
|
---|
267 |
|
---|
268 |
|
---|
269 | };
|
---|
270 |
|
---|
271 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
272 | {
|
---|
273 | Q_OBJECT
|
---|
274 | public:
|
---|
275 |
|
---|
276 | // point of the last mouse click used for movement in the scene
|
---|
277 | Vector3 mousePoint;
|
---|
278 |
|
---|
279 | bool mTopView;
|
---|
280 | bool mRenderViewCells;
|
---|
281 | bool mCutViewCells;
|
---|
282 | bool mCutScene;
|
---|
283 | bool mRenderErrors;
|
---|
284 | bool mRenderFilter;
|
---|
285 | bool mShowRenderCost;
|
---|
286 | bool mShowPvsSizes;
|
---|
287 |
|
---|
288 | Plane3 mSceneCutPlane;
|
---|
289 | float mTopDistance;
|
---|
290 |
|
---|
291 | // some statistics
|
---|
292 | int mPvsSize;
|
---|
293 | float mRenderError;
|
---|
294 |
|
---|
295 | RendererControlWidget *mControlWidget;
|
---|
296 |
|
---|
297 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
298 | ViewCellsManager *viewcells,
|
---|
299 | KdTree *tree,
|
---|
300 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
301 | );
|
---|
302 |
|
---|
303 |
|
---|
304 | virtual void SetupCamera();
|
---|
305 |
|
---|
306 | void initializeGL() {
|
---|
307 | InitGL();
|
---|
308 | }
|
---|
309 | void resizeGL(int w, int h);
|
---|
310 | void paintGL();
|
---|
311 | void timerEvent(QTimerEvent *) {
|
---|
312 | update();
|
---|
313 | }
|
---|
314 |
|
---|
315 | void mousePressEvent(QMouseEvent *);
|
---|
316 | void mouseReleaseEvent(QMouseEvent *);
|
---|
317 | void mouseMoveEvent(QMouseEvent *);
|
---|
318 |
|
---|
319 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
320 |
|
---|
321 | void
|
---|
322 | RenderPvs();
|
---|
323 |
|
---|
324 | float
|
---|
325 | RenderErrors();
|
---|
326 | void
|
---|
327 | RenderInfo();
|
---|
328 |
|
---|
329 | virtual int GetWidth() const { return width(); }
|
---|
330 | virtual int GetHeight() const { return height(); }
|
---|
331 |
|
---|
332 | virtual void
|
---|
333 | SetupProjection(const int w, const int h);
|
---|
334 |
|
---|
335 | void
|
---|
336 | RenderViewCells();
|
---|
337 |
|
---|
338 | public slots:
|
---|
339 |
|
---|
340 | void SetRenderErrors(bool b) {
|
---|
341 | mRenderErrors = b;
|
---|
342 | updateGL();
|
---|
343 | }
|
---|
344 |
|
---|
345 | void SetRenderFilter(bool b) {
|
---|
346 | mRenderFilter = b;
|
---|
347 | updateGL();
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | void
|
---|
352 | SetViewCellGranularity(int number);
|
---|
353 |
|
---|
354 | void
|
---|
355 | SetVisibilityFilterSize(int number);
|
---|
356 |
|
---|
357 | void
|
---|
358 | SetSceneCut(int cut);
|
---|
359 |
|
---|
360 | void
|
---|
361 | SetTopDistance(int dist);
|
---|
362 |
|
---|
363 | void SetShowViewCells(bool b) {
|
---|
364 | mRenderViewCells = b;
|
---|
365 | updateGL();
|
---|
366 | }
|
---|
367 |
|
---|
368 | void SetShowRenderCost(bool b) {
|
---|
369 | mShowRenderCost = b;
|
---|
370 | updateGL();
|
---|
371 | }
|
---|
372 |
|
---|
373 | void SetShowPvsSizes(bool b) {
|
---|
374 | mShowPvsSizes = b;
|
---|
375 | updateGL();
|
---|
376 | }
|
---|
377 |
|
---|
378 | void SetTopView(bool b) {
|
---|
379 | mTopView = b;
|
---|
380 | updateGL();
|
---|
381 | }
|
---|
382 |
|
---|
383 | void SetCutViewCells(bool b) {
|
---|
384 | mCutViewCells = b;
|
---|
385 | updateGL();
|
---|
386 | }
|
---|
387 | void SetCutScene(bool b) {
|
---|
388 | mCutScene = b;
|
---|
389 | updateGL();
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | };
|
---|
394 |
|
---|
395 |
|
---|
396 | extern GlRendererWidget *rendererWidget;
|
---|
397 |
|
---|
398 | class GlDebuggerWidget : public QGLWidget
|
---|
399 | {
|
---|
400 | Q_OBJECT
|
---|
401 | public:
|
---|
402 | GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
403 | ~GlDebuggerWidget();
|
---|
404 | void initializeGL();
|
---|
405 | void resizeGL(int w, int h);
|
---|
406 | void paintGL();
|
---|
407 | void timerEvent(QTimerEvent *) { update(); }
|
---|
408 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
409 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
410 |
|
---|
411 | void initCommon();
|
---|
412 | void initPbuffer();
|
---|
413 |
|
---|
414 |
|
---|
415 | GlRendererBuffer *mRenderBuffer;
|
---|
416 |
|
---|
417 | Beam mBeam;
|
---|
418 | int mSamples;
|
---|
419 | Intersectable *mSourceObject;
|
---|
420 |
|
---|
421 | private:
|
---|
422 | GLuint dynamicTexture;
|
---|
423 | int timerId;
|
---|
424 | };
|
---|
425 |
|
---|
426 | extern GlDebuggerWidget *debuggerWidget;
|
---|
427 |
|
---|
428 | #endif
|
---|
429 |
|
---|