1 | #ifndef __GLRENDERER_H
|
---|
2 | #define __GLRENDERER_H
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 | #include "Containers.h"
|
---|
6 | #include "Halton.h"
|
---|
7 | #include "Renderer.h"
|
---|
8 | #include "Beam.h"
|
---|
9 | #include "ObjectPvs.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace GtpVisibilityPreprocessor {
|
---|
13 |
|
---|
14 | class SceneGraph;
|
---|
15 | class ViewCellsManager;
|
---|
16 | class Mesh;
|
---|
17 | class MeshInstance;
|
---|
18 | class Intersectable;
|
---|
19 | class Material;
|
---|
20 | class Beam;
|
---|
21 | class KdTree;
|
---|
22 | class GlRendererBuffer;
|
---|
23 | class BeamSampleStatistics;
|
---|
24 | class OcclusionQuery;
|
---|
25 | class TransformedMeshInstance;
|
---|
26 | class TriangleIntersectable;
|
---|
27 | class BvhNode;
|
---|
28 | class SimpleRayContainer;
|
---|
29 |
|
---|
30 | struct VssRayContainer;
|
---|
31 |
|
---|
32 | struct GLUquadric;
|
---|
33 |
|
---|
34 | struct PvsRenderStatistics {
|
---|
35 |
|
---|
36 | float maxError;
|
---|
37 | float sumError;
|
---|
38 | int sumPvsSize;
|
---|
39 | int frames;
|
---|
40 | int errorFreeFrames;
|
---|
41 |
|
---|
42 | PvsRenderStatistics() { Reset(); }
|
---|
43 |
|
---|
44 | void Reset() {
|
---|
45 | maxError = 0.0f;
|
---|
46 | sumError = 0.0f;
|
---|
47 | frames = 0;
|
---|
48 | errorFreeFrames = 0;
|
---|
49 | sumPvsSize = 0;
|
---|
50 | }
|
---|
51 |
|
---|
52 | float GetMaxError() { return maxError; }
|
---|
53 | float GetAvgError() { return sumError/frames; }
|
---|
54 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
55 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
56 |
|
---|
57 | };
|
---|
58 |
|
---|
59 | struct PvsCache {
|
---|
60 | PvsCache():mViewCell(NULL) {}
|
---|
61 | void Reset() { mViewCell = NULL; mPvs.Clear(); filteredBoxes.clear(); }
|
---|
62 | ViewCell *mViewCell;
|
---|
63 | ObjectPvs mPvs;
|
---|
64 | vector<AxisAlignedBox3> filteredBoxes;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | struct RenderCostSample {
|
---|
69 |
|
---|
70 | RenderCostSample() {}
|
---|
71 |
|
---|
72 | void Reset() {
|
---|
73 | mVisibleObjects = 0;
|
---|
74 | mVisiblePixels = 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Vector3 mPosition;
|
---|
78 |
|
---|
79 | // visible object from the given point
|
---|
80 | int mVisibleObjects;
|
---|
81 |
|
---|
82 | // visible pixels
|
---|
83 | int mVisiblePixels;
|
---|
84 |
|
---|
85 | ObjectPvs mPvs;
|
---|
86 |
|
---|
87 | };
|
---|
88 |
|
---|
89 | /** Class encapsulating gl rendering for the scene.
|
---|
90 | There is no gl context binding so the binding is performed in the
|
---|
91 | derived classes
|
---|
92 | */
|
---|
93 | class GlRenderer: public Renderer
|
---|
94 | {
|
---|
95 |
|
---|
96 | public:
|
---|
97 |
|
---|
98 | GlRenderer(SceneGraph *sceneGraph,
|
---|
99 | ViewCellsManager *viewcells,
|
---|
100 | KdTree *tree);
|
---|
101 |
|
---|
102 | GlRenderer() {}
|
---|
103 |
|
---|
104 | virtual ~GlRenderer();
|
---|
105 |
|
---|
106 |
|
---|
107 | virtual void RandomViewPoint();
|
---|
108 |
|
---|
109 | void SetupFalseColor(const unsigned int id);
|
---|
110 | void RenderIntersectable(Intersectable *);
|
---|
111 | void RenderViewCell(ViewCell *vc);
|
---|
112 | void RenderMeshInstance(MeshInstance *mi);
|
---|
113 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
114 | void RenderMesh(Mesh *m);
|
---|
115 | void SetupMaterial(Material *m);
|
---|
116 | virtual void SetupCamera();
|
---|
117 |
|
---|
118 | void
|
---|
119 | RenderRays(const VssRayContainer &rays);
|
---|
120 |
|
---|
121 | void
|
---|
122 | RenderTriangle(TriangleIntersectable *object);
|
---|
123 |
|
---|
124 | void
|
---|
125 | RenderBox(const AxisAlignedBox3 &box);
|
---|
126 |
|
---|
127 | void
|
---|
128 | RenderBvhNode(BvhNode *node);
|
---|
129 |
|
---|
130 | void
|
---|
131 | RenderKdNode(KdNode *node);
|
---|
132 |
|
---|
133 | bool
|
---|
134 | RenderScene();
|
---|
135 |
|
---|
136 | void
|
---|
137 | _RenderScene();
|
---|
138 |
|
---|
139 | void
|
---|
140 | _RenderSceneTriangles();
|
---|
141 |
|
---|
142 | void
|
---|
143 | RenderViewPoint();
|
---|
144 |
|
---|
145 | virtual void
|
---|
146 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
147 |
|
---|
148 | virtual bool ValidViewPoint();
|
---|
149 |
|
---|
150 | virtual float
|
---|
151 | GetPixelError(int &pvsSize);
|
---|
152 |
|
---|
153 | virtual void
|
---|
154 | EvalPvsStat();
|
---|
155 |
|
---|
156 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
157 |
|
---|
158 | virtual void InitGL();
|
---|
159 |
|
---|
160 | virtual int GetWidth() const { return 0; }
|
---|
161 | virtual int GetHeight() const { return 0; }
|
---|
162 |
|
---|
163 | unsigned int GetId(const unsigned char r,
|
---|
164 | const unsigned char g,
|
---|
165 | const unsigned char b) const;
|
---|
166 |
|
---|
167 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
168 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
169 |
|
---|
170 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
171 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
172 |
|
---|
173 | virtual void ClearErrorBuffer();
|
---|
174 |
|
---|
175 | virtual float GetAvgPixelError() {
|
---|
176 | return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
|
---|
177 | }
|
---|
178 |
|
---|
179 | virtual float GetMaxPixelError() {
|
---|
180 | return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
|
---|
181 | }
|
---|
182 |
|
---|
183 | public:
|
---|
184 |
|
---|
185 | int mFrame;
|
---|
186 | bool mWireFrame;
|
---|
187 |
|
---|
188 | PvsRenderStatistics mPvsStat;
|
---|
189 |
|
---|
190 | int mPvsStatFrames;
|
---|
191 | struct PvsErrorEntry {
|
---|
192 | PvsErrorEntry() {}
|
---|
193 | float mError;
|
---|
194 | int mPvsSize;
|
---|
195 | Vector3 mPosition;
|
---|
196 | Vector3 mDirection;
|
---|
197 | };
|
---|
198 | friend class GlobalLinesRenderer;
|
---|
199 | friend class ViewCellsManager;
|
---|
200 |
|
---|
201 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
202 |
|
---|
203 | protected:
|
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 | PvsCache mPvsCache;
|
---|
208 |
|
---|
209 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
210 |
|
---|
211 | ObjectContainer mObjects;
|
---|
212 |
|
---|
213 | Vector3 mViewPoint;
|
---|
214 | Vector3 mViewDirection;
|
---|
215 |
|
---|
216 | int timerId;
|
---|
217 | bool mUseFalseColors;
|
---|
218 | bool mUseForcedColors;
|
---|
219 |
|
---|
220 | HaltonSequence halton;
|
---|
221 |
|
---|
222 |
|
---|
223 | bool mDetectEmptyViewSpace;
|
---|
224 | bool mSnapErrorFrames;
|
---|
225 |
|
---|
226 | bool mRenderBoxes;
|
---|
227 |
|
---|
228 | bool mUseGlLists;
|
---|
229 |
|
---|
230 | string mSnapPrefix;
|
---|
231 |
|
---|
232 | GLUquadric *mSphere;
|
---|
233 |
|
---|
234 | KdTree *mKdTree;
|
---|
235 |
|
---|
236 | };
|
---|
237 |
|
---|
238 | /* Class implementing an OpenGl render buffer.
|
---|
239 | */
|
---|
240 | class GlRendererBuffer: public GlRenderer
|
---|
241 | {
|
---|
242 |
|
---|
243 | public:
|
---|
244 |
|
---|
245 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
246 | ViewCellsManager *viewcells,
|
---|
247 | KdTree *tree);
|
---|
248 |
|
---|
249 | virtual ~GlRendererBuffer();
|
---|
250 |
|
---|
251 | /** Evaluates render cost of a point sample.
|
---|
252 | @param sample the render cost sample to be evaluated
|
---|
253 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
254 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
255 | */
|
---|
256 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
257 | const bool useOcclusionQueries,
|
---|
258 | const int threshold);
|
---|
259 |
|
---|
260 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
261 | are distributed uniformly over the defined view space.
|
---|
262 |
|
---|
263 | @param numSamples the number of point samples taken
|
---|
264 | @param samples stores the taken point samples in a container
|
---|
265 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
266 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
267 | */
|
---|
268 | virtual void SampleRenderCost(const int numSamples,
|
---|
269 | vector<RenderCostSample> &samples,
|
---|
270 | const bool useOcclusionQueries,
|
---|
271 | const int threshold = 0);
|
---|
272 |
|
---|
273 |
|
---|
274 | /** Implerment in subclasses.
|
---|
275 | */
|
---|
276 | virtual void EvalPvsStat();
|
---|
277 |
|
---|
278 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
279 |
|
---|
280 | virtual int GetWidth() const = 0;
|
---|
281 | virtual int GetHeight() const = 0;
|
---|
282 |
|
---|
283 | virtual void MakeCurrent() = 0;
|
---|
284 | virtual void DoneCurrent() = 0;
|
---|
285 |
|
---|
286 | virtual bool ValidViewPoint();
|
---|
287 |
|
---|
288 | virtual void SampleBeamContributions(
|
---|
289 | Intersectable *sourceObject,
|
---|
290 | Beam &beam,
|
---|
291 | const int samples,
|
---|
292 | BeamSampleStatistics &stat
|
---|
293 | );
|
---|
294 |
|
---|
295 | virtual void
|
---|
296 | SampleViewpointContributions(
|
---|
297 | Intersectable *sourceObject,
|
---|
298 | const Vector3 viewPoint,
|
---|
299 | Beam &beam,
|
---|
300 | const int desiredSamples,
|
---|
301 | BeamSampleStatistics &stat
|
---|
302 | );
|
---|
303 |
|
---|
304 | virtual void InitGL();
|
---|
305 |
|
---|
306 | /** Computes rays from information gained with hw sampling-
|
---|
307 | */
|
---|
308 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
309 |
|
---|
310 | virtual int ComputePvs() const = 0;
|
---|
311 |
|
---|
312 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
313 |
|
---|
314 |
|
---|
315 | protected:
|
---|
316 |
|
---|
317 | unsigned int *mPixelBuffer;
|
---|
318 |
|
---|
319 | static void GenQueries(const int numQueries);
|
---|
320 |
|
---|
321 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
322 | const Beam &beam,
|
---|
323 |
|
---|
324 | Intersectable *sourceObject);
|
---|
325 |
|
---|
326 | /** Evaluates query for one direction using item buffer.
|
---|
327 | */
|
---|
328 | virtual void EvalQueryWithItemBuffer();
|
---|
329 |
|
---|
330 | /** Evaluates query for one direction using occlusion queries.
|
---|
331 | */
|
---|
332 | virtual void EvalQueryWithOcclusionQueries();
|
---|
333 |
|
---|
334 | public:
|
---|
335 | // matt: remove qt dependencies
|
---|
336 | // signals:
|
---|
337 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
338 | };
|
---|
339 |
|
---|
340 |
|
---|
341 | /** Abstract class for implmenenting a gl render widget.
|
---|
342 | */
|
---|
343 | class GlRendererWidget: public GlRenderer
|
---|
344 | {
|
---|
345 | public:
|
---|
346 |
|
---|
347 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
348 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
349 | {}
|
---|
350 |
|
---|
351 | GlRendererWidget() {}
|
---|
352 |
|
---|
353 | virtual ~GlRendererWidget() {}
|
---|
354 |
|
---|
355 | //virtual void Create() {}
|
---|
356 | virtual void Show() {}
|
---|
357 |
|
---|
358 |
|
---|
359 | protected:
|
---|
360 |
|
---|
361 |
|
---|
362 | // SceneGraph *mSceneGraph;
|
---|
363 | // ViewCellsManager *mViewCellsManager;
|
---|
364 | // KdTree *mKdTree;
|
---|
365 | };
|
---|
366 |
|
---|
367 | //extern GlRendererWidget *rendererWidget;
|
---|
368 |
|
---|
369 | };
|
---|
370 |
|
---|
371 | #endif
|
---|