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