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