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