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