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 | void PreparePvs(const ObjectPvs &pvs);
|
---|
175 | void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
|
---|
176 |
|
---|
177 |
|
---|
178 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
179 |
|
---|
180 | virtual void InitGL();
|
---|
181 |
|
---|
182 | virtual int GetWidth() const { return 0; }
|
---|
183 | virtual int GetHeight() const { return 0; }
|
---|
184 |
|
---|
185 | unsigned int GetId(const unsigned char r,
|
---|
186 | const unsigned char g,
|
---|
187 | const unsigned char b) const;
|
---|
188 |
|
---|
189 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
190 | inline const std::string GetSnapPrefix() { return mSnapPrefix; }
|
---|
191 |
|
---|
192 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
193 | inline void SetSnapPrefix(const std::string &pref) { mSnapPrefix = pref; }
|
---|
194 |
|
---|
195 | virtual void ClearErrorBuffer();
|
---|
196 |
|
---|
197 | virtual float GetAvgPixelError() {
|
---|
198 | return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
|
---|
199 | }
|
---|
200 |
|
---|
201 | virtual float GetMaxPixelError() {
|
---|
202 | return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
|
---|
203 | }
|
---|
204 |
|
---|
205 | void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; }
|
---|
206 | void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; }
|
---|
207 |
|
---|
208 | Vector3 GetViewPoint() const { return mViewPoint; }
|
---|
209 | public:
|
---|
210 |
|
---|
211 | int mCurrentFrame;
|
---|
212 | int mFrame;
|
---|
213 | bool mWireFrame;
|
---|
214 |
|
---|
215 | PvsRenderStatistics mPvsStat;
|
---|
216 |
|
---|
217 | unsigned int mIndexBufferSize;
|
---|
218 |
|
---|
219 | int mPvsStatFrames;
|
---|
220 | struct PvsErrorEntry {
|
---|
221 | PvsErrorEntry() {}
|
---|
222 | float mError;
|
---|
223 | int mPvsSize;
|
---|
224 | Vector3 mPosition;
|
---|
225 | Vector3 mDirection;
|
---|
226 | };
|
---|
227 |
|
---|
228 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
229 | bool mComputeGVS;
|
---|
230 |
|
---|
231 | protected:
|
---|
232 |
|
---|
233 | void CreateVertexArrays(SceneGraphLeaf *leaf);
|
---|
234 | void DeleteVbos();
|
---|
235 | void EnableDrawArrays();
|
---|
236 | void DisableDrawArrays();
|
---|
237 |
|
---|
238 | void RenderKdLeaf(KdLeaf *leaf);
|
---|
239 |
|
---|
240 |
|
---|
241 | //////////////////
|
---|
242 |
|
---|
243 | PvsCache mPvsCache;
|
---|
244 |
|
---|
245 | unsigned int mVboId;
|
---|
246 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
247 |
|
---|
248 | ObjectContainer mObjects;
|
---|
249 |
|
---|
250 | Vector3 mViewPoint;
|
---|
251 | Vector3 mViewDirection;
|
---|
252 |
|
---|
253 | int timerId;
|
---|
254 | bool mUseFalseColors;
|
---|
255 | bool mUseForcedColors;
|
---|
256 |
|
---|
257 | HaltonSequence halton;
|
---|
258 |
|
---|
259 |
|
---|
260 | bool mDetectEmptyViewSpace;
|
---|
261 | bool mSnapErrorFrames;
|
---|
262 |
|
---|
263 | bool mRenderBoxes;
|
---|
264 |
|
---|
265 | bool mUseGlLists;
|
---|
266 |
|
---|
267 | std::string mSnapPrefix;
|
---|
268 |
|
---|
269 | GLUquadric *mSphere;
|
---|
270 |
|
---|
271 | KdTree *mKdTree;
|
---|
272 |
|
---|
273 | Vector3 *mData;
|
---|
274 | unsigned int *mIndices;
|
---|
275 |
|
---|
276 | bool mUseVbos;
|
---|
277 | };
|
---|
278 |
|
---|
279 |
|
---|
280 | /* Class implementing an OpenGl render buffer.
|
---|
281 | */
|
---|
282 | class GlRendererBuffer: public GlRenderer
|
---|
283 | {
|
---|
284 |
|
---|
285 | public:
|
---|
286 |
|
---|
287 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
288 | ViewCellsManager *viewcells,
|
---|
289 | KdTree *tree);
|
---|
290 |
|
---|
291 | virtual ~GlRendererBuffer();
|
---|
292 |
|
---|
293 | /** Evaluates render cost of a point sample.
|
---|
294 | @param sample the render cost sample to be evaluated
|
---|
295 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
296 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
297 | */
|
---|
298 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
299 | const bool useOcclusionQueries,
|
---|
300 | const int threshold);
|
---|
301 |
|
---|
302 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
303 | are distributed uniformly over the defined view space.
|
---|
304 |
|
---|
305 | @param numSamples the number of point samples taken
|
---|
306 | @param samples stores the taken point samples in a container
|
---|
307 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
308 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
309 | */
|
---|
310 | virtual void SampleRenderCost(const int numSamples,
|
---|
311 | vector<RenderCostSample> &samples,
|
---|
312 | const bool useOcclusionQueries,
|
---|
313 | const int threshold = 0);
|
---|
314 | /** Implerment in subclasses.
|
---|
315 | */
|
---|
316 | virtual void EvalPvsStat();
|
---|
317 |
|
---|
318 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
319 |
|
---|
320 | virtual int GetWidth() const = 0;
|
---|
321 | virtual int GetHeight() const = 0;
|
---|
322 |
|
---|
323 | virtual void MakeCurrent() = 0;
|
---|
324 | virtual void DoneCurrent() = 0;
|
---|
325 |
|
---|
326 | virtual bool ValidViewPoint();
|
---|
327 |
|
---|
328 | virtual void SampleBeamContributions(
|
---|
329 | Intersectable *sourceObject,
|
---|
330 | Beam &beam,
|
---|
331 | const int samples,
|
---|
332 | BeamSampleStatistics &stat
|
---|
333 | );
|
---|
334 |
|
---|
335 | virtual void SampleViewpointContributions(
|
---|
336 | Intersectable *sourceObject,
|
---|
337 | const Vector3 viewPoint,
|
---|
338 | Beam &beam,
|
---|
339 | const int desiredSamples,
|
---|
340 | BeamSampleStatistics &stat
|
---|
341 | );
|
---|
342 |
|
---|
343 | virtual void InitGL();
|
---|
344 | /** Computes rays from information gained with hw sampling-
|
---|
345 | */
|
---|
346 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
347 |
|
---|
348 | virtual int ComputePvs() const = 0;
|
---|
349 |
|
---|
350 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
351 |
|
---|
352 |
|
---|
353 | protected:
|
---|
354 |
|
---|
355 | unsigned int *mPixelBuffer;
|
---|
356 |
|
---|
357 | static void GenQueries(int numQueries);
|
---|
358 |
|
---|
359 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
360 | const Beam &beam,
|
---|
361 | Intersectable *sourceObject);
|
---|
362 | /** Evaluates query for one direction using item buffer.
|
---|
363 | */
|
---|
364 | virtual void EvalQueryWithItemBuffer();
|
---|
365 | /** Evaluates query for one direction using occlusion queries.
|
---|
366 | */
|
---|
367 | virtual void EvalQueryWithOcclusionQueries();
|
---|
368 | };
|
---|
369 |
|
---|
370 |
|
---|
371 | /** Abstract class for implmenenting a gl render widget.
|
---|
372 | */
|
---|
373 | class GlRendererWidget: public GlRenderer
|
---|
374 | {
|
---|
375 | public:
|
---|
376 |
|
---|
377 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
378 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
379 | {}
|
---|
380 |
|
---|
381 | GlRendererWidget() {}
|
---|
382 |
|
---|
383 | virtual ~GlRendererWidget() {}
|
---|
384 |
|
---|
385 | virtual void Show() {}
|
---|
386 | };
|
---|
387 |
|
---|
388 |
|
---|
389 | };
|
---|
390 |
|
---|
391 | #endif
|
---|