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