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