1 | #ifndef __QTGLRENDERER_H
|
---|
2 | #define __QTGLRENDERER_H
|
---|
3 |
|
---|
4 | #include <QtOpenGL>
|
---|
5 | #include <QWaitCondition>
|
---|
6 | #include <QMutex>
|
---|
7 |
|
---|
8 | #include "Vector3.h"
|
---|
9 | #include "Containers.h"
|
---|
10 | #include "Halton.h"
|
---|
11 | #include "Renderer.h"
|
---|
12 | #include "GlRenderer.h"
|
---|
13 | #include "Beam.h"
|
---|
14 | #include "QtPreprocessorThread.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | class QWidget;
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | namespace GtpVisibilityPreprocessor {
|
---|
22 |
|
---|
23 | class SceneGraph;
|
---|
24 | class ViewCellsManager;
|
---|
25 | class Mesh;
|
---|
26 | class MeshInstance;
|
---|
27 | class Intersectable;
|
---|
28 | class Material;
|
---|
29 | class Beam;
|
---|
30 | class KdTree;
|
---|
31 | class GlRendererBuffer;
|
---|
32 | class BeamSampleStatistics;
|
---|
33 | class OcclusionQuery;
|
---|
34 | class TransformedMeshInstance;
|
---|
35 |
|
---|
36 |
|
---|
37 | struct VssRayContainer;
|
---|
38 | struct PvsRenderStatistics;
|
---|
39 | struct RenderCostSample;
|
---|
40 |
|
---|
41 |
|
---|
42 | class QtGlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRendererBuffer
|
---|
43 | {
|
---|
44 | Q_OBJECT
|
---|
45 | public:
|
---|
46 | QtGlRendererBuffer(const int w,
|
---|
47 | const int h,
|
---|
48 | SceneGraph *sceneGraph,
|
---|
49 | ViewCellsManager *viewcells,
|
---|
50 | KdTree *tree);
|
---|
51 |
|
---|
52 | ~QtGlRendererBuffer() {}
|
---|
53 |
|
---|
54 | virtual void MakeCurrent();
|
---|
55 | virtual void DoneCurrent();
|
---|
56 |
|
---|
57 | virtual int GetWidth() const { return width(); }
|
---|
58 | virtual int GetHeight() const { return height(); }
|
---|
59 |
|
---|
60 | int ComputePvs() const { return 0; }
|
---|
61 |
|
---|
62 | float
|
---|
63 | GetPixelError(int &pvsSize);
|
---|
64 |
|
---|
65 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | public:
|
---|
71 | signals:
|
---|
72 | void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
73 | };
|
---|
74 |
|
---|
75 |
|
---|
76 | class QtRendererControlWidget : public QWidget
|
---|
77 | {
|
---|
78 | Q_OBJECT
|
---|
79 | public:
|
---|
80 |
|
---|
81 | QListWidget *mPvsErrorWidget;
|
---|
82 |
|
---|
83 | QtRendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
84 |
|
---|
85 | public slots:
|
---|
86 |
|
---|
87 | void FocusNextPvsErrorFrame();
|
---|
88 | void UpdatePvsErrorItem(int i,
|
---|
89 | GlRendererBuffer::PvsErrorEntry &);
|
---|
90 |
|
---|
91 | signals:
|
---|
92 |
|
---|
93 | void ComputeVisibility();
|
---|
94 | void StopComputation();
|
---|
95 | void SetRandomViewPoint();
|
---|
96 | void UpdateAllPvs();
|
---|
97 | void SetViewCellGranularity(int);
|
---|
98 | void SetTransferFunction(int);
|
---|
99 | void SetSceneCut(int);
|
---|
100 | void SetTopDistance(int);
|
---|
101 | void SetVisibilityFilterSize(int);
|
---|
102 | void SetSpatialFilterSize(int);
|
---|
103 |
|
---|
104 | void SetShowRays(bool);
|
---|
105 | void SetRenderFilter(bool);
|
---|
106 | void SetRenderVisibilityEstimates(bool);
|
---|
107 | void SetUseFilter(bool);
|
---|
108 | void SetUseSpatialFilter(bool);
|
---|
109 | void SetRenderErrors(bool);
|
---|
110 | void SetRenderBoxes(bool);
|
---|
111 | void SetShowViewCells(bool);
|
---|
112 | void SetShowRenderCost(bool);
|
---|
113 | void SetShowPvsSizes(bool);
|
---|
114 | void SetTopView(bool);
|
---|
115 | void SetCutViewCells(bool);
|
---|
116 | void SetCutScene(bool);
|
---|
117 |
|
---|
118 | };
|
---|
119 |
|
---|
120 |
|
---|
121 | class QtGlRendererWidget : public QGLWidget, public GlRendererWidget
|
---|
122 | {
|
---|
123 | Q_OBJECT
|
---|
124 | public:
|
---|
125 |
|
---|
126 | // point of the last mouse click used for movement in the scene
|
---|
127 | Vector3 mousePoint;
|
---|
128 |
|
---|
129 | bool mTopView;
|
---|
130 | bool mRenderViewCells;
|
---|
131 | bool mCutViewCells;
|
---|
132 | bool mCutScene;
|
---|
133 | bool mRenderErrors;
|
---|
134 | bool mRenderFilter;
|
---|
135 | bool mRenderVisibilityEstimates;
|
---|
136 | bool mUseFilter;
|
---|
137 | bool mUseSpatialFilter;
|
---|
138 | bool mShowRenderCost;
|
---|
139 | bool mShowRays;
|
---|
140 |
|
---|
141 | bool mShowPvsSizes;
|
---|
142 | float mSpatialFilterSize;
|
---|
143 |
|
---|
144 | Plane3 mSceneCutPlane;
|
---|
145 | float mTopDistance;
|
---|
146 |
|
---|
147 | // some statistics
|
---|
148 | int mPvsSize;
|
---|
149 | float mRenderError;
|
---|
150 | float mTransferFunction;
|
---|
151 |
|
---|
152 | unsigned int mIndexBufferSize;
|
---|
153 |
|
---|
154 | QtRendererControlWidget *mControlWidget;
|
---|
155 |
|
---|
156 | QtPreprocessorThread *mPreprocessorThread;
|
---|
157 |
|
---|
158 | QtGlRendererWidget(SceneGraph *sceneGraph,
|
---|
159 | ViewCellsManager *viewcells,
|
---|
160 | KdTree *tree,
|
---|
161 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
162 | );
|
---|
163 |
|
---|
164 | QtGlRendererWidget() {};
|
---|
165 |
|
---|
166 | void SetThread(QtPreprocessorThread *t) {
|
---|
167 | mPreprocessorThread = t;
|
---|
168 | }
|
---|
169 | void
|
---|
170 | RenderRenderCost();
|
---|
171 |
|
---|
172 | virtual void SetupCamera();
|
---|
173 |
|
---|
174 | void initializeGL() {
|
---|
175 | InitGL();
|
---|
176 | }
|
---|
177 |
|
---|
178 | virtual void InitGL();
|
---|
179 |
|
---|
180 | void resizeGL(int w, int h);
|
---|
181 | void paintGL();
|
---|
182 | void timerEvent(QTimerEvent *event);
|
---|
183 | void mousePressEvent(QMouseEvent *);
|
---|
184 | void mouseReleaseEvent(QMouseEvent *);
|
---|
185 | void mouseMoveEvent(QMouseEvent *);
|
---|
186 |
|
---|
187 | void keyPressEvent(QKeyEvent * e);
|
---|
188 |
|
---|
189 | void RenderPvs();
|
---|
190 |
|
---|
191 | float RenderErrors();
|
---|
192 | void RenderInfo();
|
---|
193 |
|
---|
194 | virtual int GetWidth() const { return width(); }
|
---|
195 | virtual int GetHeight() const { return height(); }
|
---|
196 |
|
---|
197 | // virtual void
|
---|
198 | // SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
199 |
|
---|
200 | virtual void
|
---|
201 | SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
|
---|
202 |
|
---|
203 | void
|
---|
204 | RenderViewCells();
|
---|
205 |
|
---|
206 |
|
---|
207 | virtual void Show() {
|
---|
208 | show();
|
---|
209 | }
|
---|
210 |
|
---|
211 | bool PvsChanged(ViewCell *viewcell) const;
|
---|
212 |
|
---|
213 | /////////
|
---|
214 |
|
---|
215 | //QMutex mMutex;
|
---|
216 |
|
---|
217 |
|
---|
218 | public slots:
|
---|
219 |
|
---|
220 | void UpdateAllPvs();
|
---|
221 | void ComputeVisibility();
|
---|
222 | void StopComputation();
|
---|
223 | void SetRandomViewPoint();
|
---|
224 |
|
---|
225 | void SetRenderErrors(bool b) {
|
---|
226 | mRenderErrors = b;
|
---|
227 | updateGL();
|
---|
228 | }
|
---|
229 |
|
---|
230 | void SetRenderBoxes(bool b) {
|
---|
231 | mRenderBoxes = b;
|
---|
232 | updateGL();
|
---|
233 | }
|
---|
234 |
|
---|
235 | void SetRenderFilter(bool b) {
|
---|
236 | mRenderFilter = b;
|
---|
237 | updateGL();
|
---|
238 | }
|
---|
239 |
|
---|
240 | void SetRenderVisibilityEstimates(bool b) {
|
---|
241 | mRenderVisibilityEstimates = b;
|
---|
242 | updateGL();
|
---|
243 | }
|
---|
244 |
|
---|
245 | void SetUseFilter(bool b) {
|
---|
246 | mUseFilter = b;
|
---|
247 | mPvsCache.Reset();
|
---|
248 | updateGL();
|
---|
249 | }
|
---|
250 |
|
---|
251 | void SetUseSpatialFilter(bool b) {
|
---|
252 | mUseSpatialFilter = b;
|
---|
253 | mPvsCache.Reset();
|
---|
254 | updateGL();
|
---|
255 | }
|
---|
256 |
|
---|
257 |
|
---|
258 | void
|
---|
259 | SetViewCellGranularity(int number);
|
---|
260 |
|
---|
261 | void SetTransferFunction(int number)
|
---|
262 | {
|
---|
263 | mTransferFunction = number/1000.0f;
|
---|
264 | updateGL();
|
---|
265 | }
|
---|
266 |
|
---|
267 | void SetVisibilityFilterSize(int number);
|
---|
268 |
|
---|
269 | void
|
---|
270 | SetSpatialFilterSize(int number);
|
---|
271 |
|
---|
272 | void
|
---|
273 | SetSceneCut(int cut);
|
---|
274 |
|
---|
275 | void
|
---|
276 | SetTopDistance(int dist);
|
---|
277 |
|
---|
278 | void SetShowViewCells(bool b) {
|
---|
279 | mRenderViewCells = b;
|
---|
280 | updateGL();
|
---|
281 | }
|
---|
282 |
|
---|
283 | void SetShowRays(bool b) {
|
---|
284 | mShowRays = b;
|
---|
285 | updateGL();
|
---|
286 | }
|
---|
287 |
|
---|
288 | void SetShowRenderCost(bool b) {
|
---|
289 | mShowRenderCost = b;
|
---|
290 | updateGL();
|
---|
291 | }
|
---|
292 |
|
---|
293 | void SetShowPvsSizes(bool b) {
|
---|
294 | mShowPvsSizes = b;
|
---|
295 | updateGL();
|
---|
296 | }
|
---|
297 |
|
---|
298 | void SetTopView(bool b) {
|
---|
299 | mTopView = b;
|
---|
300 | updateGL();
|
---|
301 | }
|
---|
302 |
|
---|
303 | void SetCutViewCells(bool b) {
|
---|
304 | mCutViewCells = b;
|
---|
305 | updateGL();
|
---|
306 | }
|
---|
307 | void SetCutScene(bool b) {
|
---|
308 | mCutScene = b;
|
---|
309 | updateGL();
|
---|
310 | }
|
---|
311 |
|
---|
312 | void _RenderPvs();
|
---|
313 |
|
---|
314 | void _UpdatePvsIndices();
|
---|
315 |
|
---|
316 | void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
|
---|
317 |
|
---|
318 |
|
---|
319 |
|
---|
320 | /////////
|
---|
321 |
|
---|
322 | signals:
|
---|
323 | void PvsUpdated();
|
---|
324 | };
|
---|
325 |
|
---|
326 |
|
---|
327 | class QtGlDebuggerWidget : public QGLWidget
|
---|
328 | {
|
---|
329 | Q_OBJECT
|
---|
330 | public:
|
---|
331 | QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
332 | ~QtGlDebuggerWidget();
|
---|
333 | void initializeGL();
|
---|
334 | void resizeGL(int w, int h);
|
---|
335 | void paintGL();
|
---|
336 | void timerEvent(QTimerEvent *) { update(); }
|
---|
337 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
338 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
339 |
|
---|
340 | void initCommon();
|
---|
341 | void initPbuffer();
|
---|
342 |
|
---|
343 |
|
---|
344 | QtGlRendererBuffer *mRenderBuffer;
|
---|
345 |
|
---|
346 | Beam mBeam;
|
---|
347 | int mSamples;
|
---|
348 | Intersectable *mSourceObject;
|
---|
349 |
|
---|
350 | private:
|
---|
351 |
|
---|
352 | GLuint dynamicTexture;
|
---|
353 | int timerId;
|
---|
354 | };
|
---|
355 |
|
---|
356 |
|
---|
357 | extern QtGlDebuggerWidget *debuggerWidget;
|
---|
358 |
|
---|
359 | };
|
---|
360 |
|
---|
361 | #endif
|
---|
362 |
|
---|