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