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