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 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 |
|
---|
139 | virtual void
|
---|
140 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
141 |
|
---|
142 |
|
---|
143 | virtual float
|
---|
144 | GetPixelError(int &pvsSize);
|
---|
145 |
|
---|
146 | virtual void
|
---|
147 | EvalPvsStat();
|
---|
148 |
|
---|
149 | void InitGL();
|
---|
150 |
|
---|
151 | virtual int GetWidth() const { return 0; }
|
---|
152 | virtual int GetHeight() const { return 0; }
|
---|
153 |
|
---|
154 | int GetId(int r, int g, int b) const;
|
---|
155 |
|
---|
156 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
157 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
158 |
|
---|
159 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
160 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
161 |
|
---|
162 | virtual void ClearErrorBuffer();
|
---|
163 |
|
---|
164 |
|
---|
165 | public:
|
---|
166 |
|
---|
167 | int mFrame;
|
---|
168 | bool mWireFrame;
|
---|
169 |
|
---|
170 | PvsRenderStatistics mPvsStat;
|
---|
171 |
|
---|
172 | int mPvsStatFrames;
|
---|
173 | struct PvsErrorEntry {
|
---|
174 | PvsErrorEntry() {}
|
---|
175 | float mError;
|
---|
176 | int mPvsSize;
|
---|
177 | Vector3 mPosition;
|
---|
178 | Vector3 mDirection;
|
---|
179 | };
|
---|
180 |
|
---|
181 | protected:
|
---|
182 |
|
---|
183 |
|
---|
184 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
185 |
|
---|
186 | PvsCache mPvsCache;
|
---|
187 |
|
---|
188 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
189 |
|
---|
190 | ObjectContainer mObjects;
|
---|
191 |
|
---|
192 | Vector3 mViewPoint;
|
---|
193 | Vector3 mViewDirection;
|
---|
194 |
|
---|
195 | int timerId;
|
---|
196 | bool mUseFalseColors;
|
---|
197 | bool mUseForcedColors;
|
---|
198 |
|
---|
199 | HaltonSequence halton;
|
---|
200 |
|
---|
201 |
|
---|
202 | bool mDetectEmptyViewSpace;
|
---|
203 | bool mSnapErrorFrames;
|
---|
204 |
|
---|
205 | bool mRenderBoxes;
|
---|
206 |
|
---|
207 | bool mUseGlLists;
|
---|
208 |
|
---|
209 | string mSnapPrefix;
|
---|
210 |
|
---|
211 | GLUquadric *mSphere;
|
---|
212 |
|
---|
213 | KdTree *mKdTree;
|
---|
214 |
|
---|
215 | };
|
---|
216 |
|
---|
217 | /* Class implementing an OpenGl render buffer.
|
---|
218 | */
|
---|
219 | class GlRendererBuffer: public GlRenderer
|
---|
220 | {
|
---|
221 |
|
---|
222 | public:
|
---|
223 |
|
---|
224 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
225 | ViewCellsManager *viewcells,
|
---|
226 | KdTree *tree);
|
---|
227 |
|
---|
228 | virtual ~GlRendererBuffer();
|
---|
229 |
|
---|
230 | /** Evaluates render cost of a point sample.
|
---|
231 | @param sample the render cost sample to be evaluated
|
---|
232 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
233 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
234 | */
|
---|
235 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
236 | const bool useOcclusionQueries,
|
---|
237 | const int threshold);
|
---|
238 |
|
---|
239 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
240 | are distributed uniformly over the defined view space.
|
---|
241 |
|
---|
242 | @param numSamples the number of point samples taken
|
---|
243 | @param samples stores the taken point samples in a container
|
---|
244 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
245 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
246 | */
|
---|
247 | virtual void SampleRenderCost(const int numSamples,
|
---|
248 | vector<RenderCostSample> &samples,
|
---|
249 | const bool useOcclusionQueries,
|
---|
250 | const int threshold = 0);
|
---|
251 |
|
---|
252 |
|
---|
253 | /** Implerment in subclasses.
|
---|
254 | */
|
---|
255 | virtual void EvalPvsStat();
|
---|
256 |
|
---|
257 |
|
---|
258 | virtual int GetWidth() const = 0;
|
---|
259 | virtual int GetHeight() const = 0;
|
---|
260 |
|
---|
261 | virtual void MakeCurrent() = 0;
|
---|
262 | virtual void DoneCurrent() = 0;
|
---|
263 |
|
---|
264 |
|
---|
265 | virtual void SampleBeamContributions(
|
---|
266 | Intersectable *sourceObject,
|
---|
267 | Beam &beam,
|
---|
268 | const int samples,
|
---|
269 | BeamSampleStatistics &stat
|
---|
270 | );
|
---|
271 |
|
---|
272 | virtual void
|
---|
273 | SampleViewpointContributions(
|
---|
274 | Intersectable *sourceObject,
|
---|
275 | const Vector3 viewPoint,
|
---|
276 | Beam &beam,
|
---|
277 | const int desiredSamples,
|
---|
278 | BeamSampleStatistics &stat
|
---|
279 | );
|
---|
280 |
|
---|
281 | virtual void InitGL();
|
---|
282 |
|
---|
283 | /** Computes rays from information gained with hw sampling-
|
---|
284 | */
|
---|
285 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
286 |
|
---|
287 | virtual int ComputePvs() const = 0;
|
---|
288 |
|
---|
289 |
|
---|
290 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
291 |
|
---|
292 |
|
---|
293 |
|
---|
294 |
|
---|
295 | protected:
|
---|
296 | unsigned int *mPixelBuffer;
|
---|
297 |
|
---|
298 | static void GenQueries(const int numQueries);
|
---|
299 |
|
---|
300 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
301 | const Beam &beam,
|
---|
302 |
|
---|
303 | Intersectable *sourceObject);
|
---|
304 |
|
---|
305 | /** Evaluates query for one direction using item buffer.
|
---|
306 | */
|
---|
307 | virtual void EvalQueryWithItemBuffer();
|
---|
308 |
|
---|
309 | /** Evaluates query for one direction using occlusion queries.
|
---|
310 | */
|
---|
311 | virtual void EvalQueryWithOcclusionQueries();
|
---|
312 |
|
---|
313 | public:
|
---|
314 | // matt: remove qt dependencies
|
---|
315 | // signals:
|
---|
316 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
317 | };
|
---|
318 |
|
---|
319 |
|
---|
320 | /** Abstract class for implmenenting a gl render widget.
|
---|
321 | */
|
---|
322 | class GlRendererWidget: public GlRenderer
|
---|
323 | {
|
---|
324 | public:
|
---|
325 |
|
---|
326 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
327 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
328 | {}
|
---|
329 |
|
---|
330 | GlRendererWidget() {}
|
---|
331 |
|
---|
332 | virtual ~GlRendererWidget() {}
|
---|
333 |
|
---|
334 | //virtual void Create() {}
|
---|
335 | virtual void Show() {}
|
---|
336 |
|
---|
337 |
|
---|
338 | protected:
|
---|
339 |
|
---|
340 |
|
---|
341 | // SceneGraph *mSceneGraph;
|
---|
342 | // ViewCellsManager *mViewCellsManager;
|
---|
343 | // KdTree *mKdTree;
|
---|
344 | };
|
---|
345 |
|
---|
346 | //extern GlRendererWidget *rendererWidget;
|
---|
347 |
|
---|
348 | };
|
---|
349 |
|
---|
350 | #endif
|
---|