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