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