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 RenderCostSample {
|
---|
59 |
|
---|
60 | RenderCostSample() {}
|
---|
61 |
|
---|
62 | void Reset() {
|
---|
63 | mVisibleObjects = 0;
|
---|
64 | mVisiblePixels = 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | Vector3 mPosition;
|
---|
68 |
|
---|
69 | // visible object from the given point
|
---|
70 | int mVisibleObjects;
|
---|
71 |
|
---|
72 | // visible pixels
|
---|
73 | int mVisiblePixels;
|
---|
74 |
|
---|
75 | ObjectPvs mPvs;
|
---|
76 |
|
---|
77 | };
|
---|
78 |
|
---|
79 | /** Class encapsulating gl rendering for the scene.
|
---|
80 | There is no gl context binding so the binding is performed in the
|
---|
81 | derived classes
|
---|
82 | */
|
---|
83 | class GlRenderer: public Renderer
|
---|
84 | {
|
---|
85 |
|
---|
86 | public:
|
---|
87 |
|
---|
88 | GlRenderer(SceneGraph *sceneGraph,
|
---|
89 | ViewCellsManager *viewcells,
|
---|
90 | KdTree *tree);
|
---|
91 |
|
---|
92 | GlRenderer() {}
|
---|
93 |
|
---|
94 | virtual ~GlRenderer();
|
---|
95 |
|
---|
96 |
|
---|
97 | void SetupFalseColor(const int id);
|
---|
98 | void RenderIntersectable(Intersectable *);
|
---|
99 | void RenderViewCell(ViewCell *vc);
|
---|
100 | void RenderMeshInstance(MeshInstance *mi);
|
---|
101 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
102 | void RenderMesh(Mesh *m);
|
---|
103 | void SetupMaterial(Material *m);
|
---|
104 | virtual void SetupCamera();
|
---|
105 |
|
---|
106 | void
|
---|
107 | RenderRays(const VssRayContainer &rays);
|
---|
108 |
|
---|
109 | void
|
---|
110 | RenderTriangle(TriangleIntersectable *object);
|
---|
111 |
|
---|
112 | void
|
---|
113 | RenderBox(const AxisAlignedBox3 &box);
|
---|
114 |
|
---|
115 | void
|
---|
116 | RenderBvhNode(BvhNode *node);
|
---|
117 |
|
---|
118 | void
|
---|
119 | RenderKdNode(KdNode *node);
|
---|
120 |
|
---|
121 | bool
|
---|
122 | RenderScene();
|
---|
123 |
|
---|
124 | void
|
---|
125 | _RenderScene();
|
---|
126 |
|
---|
127 |
|
---|
128 | virtual void
|
---|
129 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | void InitGL();
|
---|
135 |
|
---|
136 | virtual int GetWidth() const = 0;
|
---|
137 | virtual int GetHeight() const = 0;
|
---|
138 |
|
---|
139 | int GetId(int r, int g, int b) const;
|
---|
140 |
|
---|
141 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
142 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
143 |
|
---|
144 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
145 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
146 |
|
---|
147 | protected:
|
---|
148 |
|
---|
149 |
|
---|
150 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
151 |
|
---|
152 | ObjectContainer mObjects;
|
---|
153 |
|
---|
154 | Vector3 mViewPoint;
|
---|
155 | Vector3 mViewDirection;
|
---|
156 |
|
---|
157 | int timerId;
|
---|
158 | bool mUseFalseColors;
|
---|
159 | bool mUseForcedColors;
|
---|
160 |
|
---|
161 | HaltonSequence halton;
|
---|
162 |
|
---|
163 | int mFrame;
|
---|
164 | bool mWireFrame;
|
---|
165 |
|
---|
166 | bool mDetectEmptyViewSpace;
|
---|
167 | bool mSnapErrorFrames;
|
---|
168 |
|
---|
169 | bool mRenderBoxes;
|
---|
170 |
|
---|
171 | bool mUseGlLists;
|
---|
172 |
|
---|
173 | string mSnapPrefix;
|
---|
174 |
|
---|
175 | GLUquadric *mSphere;
|
---|
176 |
|
---|
177 | KdTree *mKdTree;
|
---|
178 |
|
---|
179 | };
|
---|
180 |
|
---|
181 | /* Class implementing an OpenGl render buffer.
|
---|
182 | */
|
---|
183 | class GlRendererBuffer: public GlRenderer
|
---|
184 | {
|
---|
185 |
|
---|
186 | public:
|
---|
187 |
|
---|
188 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
189 | ViewCellsManager *viewcells,
|
---|
190 | KdTree *tree);
|
---|
191 |
|
---|
192 |
|
---|
193 | /** Evaluates render cost of a point sample.
|
---|
194 | @param sample the render cost sample to be evaluated
|
---|
195 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
196 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
197 | */
|
---|
198 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
199 | const bool useOcclusionQueries,
|
---|
200 | const int threshold);
|
---|
201 |
|
---|
202 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
203 | are distributed uniformly over the defined view space.
|
---|
204 |
|
---|
205 | @param numSamples the number of point samples taken
|
---|
206 | @param samples stores the taken point samples in a container
|
---|
207 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
208 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
209 | */
|
---|
210 | void SampleRenderCost(const int numSamples,
|
---|
211 | vector<RenderCostSample> &samples,
|
---|
212 | const bool useOcclusionQueries,
|
---|
213 | const int threshold = 0)
|
---|
214 | {}
|
---|
215 |
|
---|
216 | /** Implerment in subclasses.
|
---|
217 | */
|
---|
218 | void EvalPvsStat() {};
|
---|
219 |
|
---|
220 | void ClearErrorBuffer();
|
---|
221 |
|
---|
222 |
|
---|
223 | virtual int GetWidth() const { return 0; }
|
---|
224 | virtual int GetHeight() const { return 0; }
|
---|
225 |
|
---|
226 |
|
---|
227 | void RandomViewPoint();
|
---|
228 | void SampleBeamContributions(
|
---|
229 | Intersectable *sourceObject,
|
---|
230 | Beam &beam,
|
---|
231 | const int samples,
|
---|
232 | BeamSampleStatistics &stat
|
---|
233 | );
|
---|
234 |
|
---|
235 | void
|
---|
236 | SampleViewpointContributions(
|
---|
237 | Intersectable *sourceObject,
|
---|
238 | const Vector3 viewPoint,
|
---|
239 | Beam &beam,
|
---|
240 | const int desiredSamples,
|
---|
241 | BeamSampleStatistics &stat
|
---|
242 | );
|
---|
243 |
|
---|
244 | void InitGL();
|
---|
245 |
|
---|
246 | /** Computes rays from information gained with hw sampling-
|
---|
247 | */
|
---|
248 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
249 |
|
---|
250 | int ComputePvs() const;
|
---|
251 |
|
---|
252 | float
|
---|
253 | GetPixelError(int &pvsSize);
|
---|
254 |
|
---|
255 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
256 |
|
---|
257 | PvsRenderStatistics mPvsStat;
|
---|
258 |
|
---|
259 | int mPvsStatFrames;
|
---|
260 | struct PvsErrorEntry {
|
---|
261 | PvsErrorEntry() {}
|
---|
262 | float mError;
|
---|
263 | int mPvsSize;
|
---|
264 | Vector3 mPosition;
|
---|
265 | Vector3 mDirection;
|
---|
266 | };
|
---|
267 |
|
---|
268 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
269 |
|
---|
270 |
|
---|
271 | protected:
|
---|
272 | unsigned int *mPixelBuffer;
|
---|
273 |
|
---|
274 | static void GenQueries(const int numQueries);
|
---|
275 |
|
---|
276 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
277 | const Beam &beam,
|
---|
278 |
|
---|
279 | Intersectable *sourceObject);
|
---|
280 |
|
---|
281 | /** Evaluates query for one direction using item buffer.
|
---|
282 | */
|
---|
283 | void EvalQueryWithItemBuffer();
|
---|
284 |
|
---|
285 | /** Evaluates query for one direction using occlusion queries.
|
---|
286 | */
|
---|
287 | void EvalQueryWithOcclusionQueries();
|
---|
288 |
|
---|
289 | public:
|
---|
290 | // matt: remove qt dependencies
|
---|
291 | // signals:
|
---|
292 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
293 | };
|
---|
294 |
|
---|
295 |
|
---|
296 | /** Abstract class for implmenenting a gl render widget.
|
---|
297 | */
|
---|
298 | class GlRendererWidget: public GlRenderer
|
---|
299 | {
|
---|
300 | public:
|
---|
301 |
|
---|
302 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
303 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
304 | {}
|
---|
305 |
|
---|
306 | GlRendererWidget() {}
|
---|
307 |
|
---|
308 | virtual ~GlRendererWidget() {}
|
---|
309 |
|
---|
310 | //virtual void Create() {}
|
---|
311 | virtual void Show() {}
|
---|
312 |
|
---|
313 |
|
---|
314 | protected:
|
---|
315 |
|
---|
316 |
|
---|
317 | // SceneGraph *mSceneGraph;
|
---|
318 | // ViewCellsManager *mViewCellsManager;
|
---|
319 | // KdTree *mKdTree;
|
---|
320 | };
|
---|
321 |
|
---|
322 | //extern GlRendererWidget *rendererWidget;
|
---|
323 |
|
---|
324 | };
|
---|
325 |
|
---|
326 | #endif
|
---|