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