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