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