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