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