1 | #ifndef __QTGLRENDERER_H
|
---|
2 | #define __QTGLRENDERER_H
|
---|
3 |
|
---|
4 | #include <QtOpenGL>
|
---|
5 | #include <QWaitCondition>
|
---|
6 |
|
---|
7 | //#include <QGLPixelBuffer>
|
---|
8 |
|
---|
9 | #include "Vector3.h"
|
---|
10 | #include "Containers.h"
|
---|
11 | #include "Halton.h"
|
---|
12 | #include "Renderer.h"
|
---|
13 | #include "GlRenderer.h"
|
---|
14 | #include "Beam.h"
|
---|
15 | #include "QtPreprocessorThread.h"
|
---|
16 | class QWidget;
|
---|
17 | //class QtPreprocessorThread;
|
---|
18 |
|
---|
19 | namespace GtpVisibilityPreprocessor {
|
---|
20 |
|
---|
21 | class SceneGraph;
|
---|
22 | class ViewCellsManager;
|
---|
23 | class Mesh;
|
---|
24 | class MeshInstance;
|
---|
25 | class Intersectable;
|
---|
26 | class Material;
|
---|
27 | class Beam;
|
---|
28 | class KdTree;
|
---|
29 | class GlRendererBuffer;
|
---|
30 | class BeamSampleStatistics;
|
---|
31 | class OcclusionQuery;
|
---|
32 | class TransformedMeshInstance;
|
---|
33 |
|
---|
34 |
|
---|
35 | struct VssRayContainer;
|
---|
36 | struct PvsRenderStatistics;
|
---|
37 | struct RenderCostSample;
|
---|
38 |
|
---|
39 |
|
---|
40 | class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
|
---|
41 | {
|
---|
42 | Q_OBJECT
|
---|
43 | public:
|
---|
44 | QtGlRendererBuffer(const int w,
|
---|
45 | const int h,
|
---|
46 | SceneGraph *sceneGraph,
|
---|
47 | ViewCellsManager *viewcells,
|
---|
48 | KdTree *tree);
|
---|
49 |
|
---|
50 | ~QtGlRendererBuffer();
|
---|
51 |
|
---|
52 | /** Evaluates render cost of a point sample.
|
---|
53 | @param sample the render cost sample to be evaluated
|
---|
54 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
55 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
56 | */
|
---|
57 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
58 | const bool useOcclusionQueries,
|
---|
59 | const int threshold);
|
---|
60 |
|
---|
61 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
62 | are distributed uniformly over the defined view space.
|
---|
63 |
|
---|
64 | @param numSamples the number of point samples taken
|
---|
65 | @param samples stores the taken point samples in a container
|
---|
66 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
67 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
68 | */
|
---|
69 | void SampleRenderCost(const int numSamples,
|
---|
70 | vector<RenderCostSample> &samples,
|
---|
71 | const bool useOcclusionQueries,
|
---|
72 | const int threshold = 0);
|
---|
73 |
|
---|
74 |
|
---|
75 | void
|
---|
76 | EvalPvsStat();
|
---|
77 |
|
---|
78 | void
|
---|
79 | ClearErrorBuffer();
|
---|
80 |
|
---|
81 |
|
---|
82 | virtual int GetWidth() const { return width(); }
|
---|
83 | virtual int GetHeight() const { return height(); }
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 | void SampleBeamContributions(
|
---|
88 | Intersectable *sourceObject,
|
---|
89 | Beam &beam,
|
---|
90 | const int samples,
|
---|
91 | BeamSampleStatistics &stat
|
---|
92 | );
|
---|
93 |
|
---|
94 | void
|
---|
95 | SampleViewpointContributions(
|
---|
96 | Intersectable *sourceObject,
|
---|
97 | const Vector3 viewPoint,
|
---|
98 | Beam &beam,
|
---|
99 | const int desiredSamples,
|
---|
100 | BeamSampleStatistics &stat
|
---|
101 | );
|
---|
102 |
|
---|
103 | void InitGL();
|
---|
104 |
|
---|
105 | /** Computes rays from information gained with hw sampling-
|
---|
106 | */
|
---|
107 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
108 |
|
---|
109 | int ComputePvs() const;
|
---|
110 |
|
---|
111 | float
|
---|
112 | GetPixelError(int &pvsSize);
|
---|
113 |
|
---|
114 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
115 |
|
---|
116 |
|
---|
117 | private:
|
---|
118 |
|
---|
119 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
120 | const Beam &beam,
|
---|
121 | Intersectable *sourceObject);
|
---|
122 |
|
---|
123 |
|
---|
124 | public:
|
---|
125 | signals:
|
---|
126 | void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
127 | };
|
---|
128 |
|
---|
129 |
|
---|
130 | class QtRendererControlWidget : public QWidget
|
---|
131 | {
|
---|
132 | Q_OBJECT
|
---|
133 | public:
|
---|
134 |
|
---|
135 | QListWidget *mPvsErrorWidget;
|
---|
136 |
|
---|
137 | QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
138 |
|
---|
139 | public slots:
|
---|
140 |
|
---|
141 | void FocusNextPvsErrorFrame();
|
---|
142 | void UpdatePvsErrorItem(int i,
|
---|
143 | GlRendererBuffer::PvsErrorEntry &);
|
---|
144 |
|
---|
145 | signals:
|
---|
146 |
|
---|
147 | void ComputeVisibility();
|
---|
148 | void StopComputation();
|
---|
149 | void UpdateAllPvs();
|
---|
150 | void SetViewCellGranularity(int);
|
---|
151 | void SetTransferFunction(int);
|
---|
152 | void SetSceneCut(int);
|
---|
153 | void SetTopDistance(int);
|
---|
154 | void SetVisibilityFilterSize(int);
|
---|
155 | void SetSpatialFilterSize(int);
|
---|
156 |
|
---|
157 | void SetShowRays(bool);
|
---|
158 | void SetRenderFilter(bool);
|
---|
159 | void SetRenderVisibilityEstimates(bool);
|
---|
160 | void SetUseFilter(bool);
|
---|
161 | void SetUseSpatialFilter(bool);
|
---|
162 | void SetRenderErrors(bool);
|
---|
163 | void SetRenderBoxes(bool);
|
---|
164 | void SetShowViewCells(bool);
|
---|
165 | void SetShowRenderCost(bool);
|
---|
166 | void SetShowPvsSizes(bool);
|
---|
167 | void SetTopView(bool);
|
---|
168 | void SetCutViewCells(bool);
|
---|
169 | void SetCutScene(bool);
|
---|
170 |
|
---|
171 | };
|
---|
172 |
|
---|
173 |
|
---|
174 | struct PvsCache {
|
---|
175 | PvsCache():mViewCell(NULL) {}
|
---|
176 | Reset() { mViewCell = NULL; mPvs.Clear(); }
|
---|
177 | ViewCell *mViewCell;
|
---|
178 | ObjectPvs mPvs;
|
---|
179 | };
|
---|
180 |
|
---|
181 | class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
|
---|
182 | {
|
---|
183 | Q_OBJECT
|
---|
184 | public:
|
---|
185 |
|
---|
186 | // point of the last mouse click used for movement in the scene
|
---|
187 | Vector3 mousePoint;
|
---|
188 |
|
---|
189 | bool mTopView;
|
---|
190 | bool mRenderViewCells;
|
---|
191 | bool mCutViewCells;
|
---|
192 | bool mCutScene;
|
---|
193 | bool mRenderErrors;
|
---|
194 | bool mRenderFilter;
|
---|
195 | bool mRenderVisibilityEstimates;
|
---|
196 | bool mUseFilter;
|
---|
197 | bool mUseSpatialFilter;
|
---|
198 | bool mShowRenderCost;
|
---|
199 | bool mShowRays;
|
---|
200 |
|
---|
201 | bool mShowPvsSizes;
|
---|
202 | float mSpatialFilterSize;
|
---|
203 |
|
---|
204 | Plane3 mSceneCutPlane;
|
---|
205 | float mTopDistance;
|
---|
206 |
|
---|
207 | // some statistics
|
---|
208 | int mPvsSize;
|
---|
209 | float mRenderError;
|
---|
210 | float mTransferFunction;
|
---|
211 |
|
---|
212 | float mManipulatorLastQuat[4];
|
---|
213 | float mManipulatorScale;
|
---|
214 | PvsCache mPvsCache;
|
---|
215 |
|
---|
216 | QtRendererControlWidget *mControlWidget;
|
---|
217 |
|
---|
218 | QtPreprocessorThread *mPreprocessorThread;
|
---|
219 |
|
---|
220 | QtGlRendererWidget(SceneGraph *sceneGraph,
|
---|
221 | ViewCellsManager *viewcells,
|
---|
222 | KdTree *tree,
|
---|
223 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
224 | );
|
---|
225 |
|
---|
226 | QtGlRendererWidget() {};
|
---|
227 |
|
---|
228 | void SetThread(QtPreprocessorThread *t) {
|
---|
229 | mPreprocessorThread = t;
|
---|
230 | }
|
---|
231 | void
|
---|
232 | RenderRenderCost();
|
---|
233 |
|
---|
234 | virtual void SetupCamera();
|
---|
235 | // setup a transformation for manipulator
|
---|
236 | void
|
---|
237 | SetupManipulator();
|
---|
238 |
|
---|
239 | void initializeGL() {
|
---|
240 | InitGL();
|
---|
241 | }
|
---|
242 | void resizeGL(int w, int h);
|
---|
243 | void paintGL();
|
---|
244 | void timerEvent(QTimerEvent *) {
|
---|
245 | update();
|
---|
246 | }
|
---|
247 |
|
---|
248 | void mousePressEvent(QMouseEvent *);
|
---|
249 | void mouseReleaseEvent(QMouseEvent *);
|
---|
250 | void mouseMoveEvent(QMouseEvent *);
|
---|
251 |
|
---|
252 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
253 |
|
---|
254 | void
|
---|
255 | RenderPvs();
|
---|
256 |
|
---|
257 | float
|
---|
258 | RenderErrors();
|
---|
259 | void
|
---|
260 | RenderInfo();
|
---|
261 |
|
---|
262 | virtual int GetWidth() const { return width(); }
|
---|
263 | virtual int GetHeight() const { return height(); }
|
---|
264 |
|
---|
265 | // virtual void
|
---|
266 | // SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
267 |
|
---|
268 | virtual void
|
---|
269 | SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
|
---|
270 |
|
---|
271 | virtual void
|
---|
272 | SetupManipulatorProjection(const int w, const int h, const float angle = 70.0f);
|
---|
273 |
|
---|
274 | void
|
---|
275 | RenderViewCells();
|
---|
276 |
|
---|
277 |
|
---|
278 | virtual void Show() {
|
---|
279 | show();
|
---|
280 | }
|
---|
281 |
|
---|
282 | public slots:
|
---|
283 |
|
---|
284 | void UpdateAllPvs();
|
---|
285 | void ComputeVisibility();
|
---|
286 | void StopComputation();
|
---|
287 |
|
---|
288 | void SetRenderErrors(bool b) {
|
---|
289 | mRenderErrors = b;
|
---|
290 | updateGL();
|
---|
291 | }
|
---|
292 |
|
---|
293 | void SetRenderBoxes(bool b) {
|
---|
294 | mRenderBoxes = b;
|
---|
295 | updateGL();
|
---|
296 | }
|
---|
297 |
|
---|
298 | void SetRenderFilter(bool b) {
|
---|
299 | mRenderFilter = b;
|
---|
300 | updateGL();
|
---|
301 | }
|
---|
302 |
|
---|
303 | void SetRenderVisibilityEstimates(bool b) {
|
---|
304 | mRenderVisibilityEstimates = b;
|
---|
305 | updateGL();
|
---|
306 | }
|
---|
307 |
|
---|
308 | void SetUseFilter(bool b) {
|
---|
309 | mUseFilter = b;
|
---|
310 | mPvsCache.Reset();
|
---|
311 | updateGL();
|
---|
312 | }
|
---|
313 |
|
---|
314 | void SetUseSpatialFilter(bool b) {
|
---|
315 | mUseSpatialFilter = b;
|
---|
316 | mPvsCache.Reset();
|
---|
317 | updateGL();
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|
321 | void
|
---|
322 | SetViewCellGranularity(int number);
|
---|
323 |
|
---|
324 | void
|
---|
325 | SetTransferFunction(int number) {
|
---|
326 | mTransferFunction = number/1000.0f;
|
---|
327 | updateGL();
|
---|
328 | }
|
---|
329 |
|
---|
330 | void
|
---|
331 | SetVisibilityFilterSize(int number);
|
---|
332 |
|
---|
333 | void
|
---|
334 | SetSpatialFilterSize(int number);
|
---|
335 |
|
---|
336 | void
|
---|
337 | SetSceneCut(int cut);
|
---|
338 |
|
---|
339 | void
|
---|
340 | SetTopDistance(int dist);
|
---|
341 |
|
---|
342 | void SetShowViewCells(bool b) {
|
---|
343 | mRenderViewCells = b;
|
---|
344 | updateGL();
|
---|
345 | }
|
---|
346 |
|
---|
347 | void SetShowRays(bool b) {
|
---|
348 | mShowRays = b;
|
---|
349 | updateGL();
|
---|
350 | }
|
---|
351 |
|
---|
352 | void SetShowRenderCost(bool b) {
|
---|
353 | mShowRenderCost = b;
|
---|
354 | updateGL();
|
---|
355 | }
|
---|
356 |
|
---|
357 | void SetShowPvsSizes(bool b) {
|
---|
358 | mShowPvsSizes = b;
|
---|
359 | updateGL();
|
---|
360 | }
|
---|
361 |
|
---|
362 | void SetTopView(bool b) {
|
---|
363 | mTopView = b;
|
---|
364 | updateGL();
|
---|
365 | }
|
---|
366 |
|
---|
367 | void SetCutViewCells(bool b) {
|
---|
368 | mCutViewCells = b;
|
---|
369 | updateGL();
|
---|
370 | }
|
---|
371 | void SetCutScene(bool b) {
|
---|
372 | mCutScene = b;
|
---|
373 | updateGL();
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | };
|
---|
378 |
|
---|
379 |
|
---|
380 | class QtGlDebuggerWidget : public QGLWidget
|
---|
381 | {
|
---|
382 | Q_OBJECT
|
---|
383 | public:
|
---|
384 | QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
385 | ~QtGlDebuggerWidget();
|
---|
386 | void initializeGL();
|
---|
387 | void resizeGL(int w, int h);
|
---|
388 | void paintGL();
|
---|
389 | void timerEvent(QTimerEvent *) { update(); }
|
---|
390 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
391 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
392 |
|
---|
393 | void initCommon();
|
---|
394 | void initPbuffer();
|
---|
395 |
|
---|
396 |
|
---|
397 | QtGlRendererBuffer *mRenderBuffer;
|
---|
398 |
|
---|
399 | Beam mBeam;
|
---|
400 | int mSamples;
|
---|
401 | Intersectable *mSourceObject;
|
---|
402 |
|
---|
403 | private:
|
---|
404 | GLuint dynamicTexture;
|
---|
405 | int timerId;
|
---|
406 | };
|
---|
407 |
|
---|
408 | extern QtGlDebuggerWidget *debuggerWidget;
|
---|
409 |
|
---|
410 | };
|
---|
411 |
|
---|
412 | #endif
|
---|
413 |
|
---|