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