[865] | 1 | #ifndef __GLRENDERER_H
|
---|
| 2 | #define __GLRENDERER_H
|
---|
[492] | 3 |
|
---|
| 4 | #include "Vector3.h"
|
---|
| 5 | #include "Containers.h"
|
---|
| 6 | #include "Halton.h"
|
---|
[497] | 7 | #include "Renderer.h"
|
---|
[540] | 8 | #include "Beam.h"
|
---|
[2116] | 9 | #include "ObjectPvs.h"
|
---|
[492] | 10 |
|
---|
[863] | 11 |
|
---|
[860] | 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
[492] | 14 | class SceneGraph;
|
---|
| 15 | class ViewCellsManager;
|
---|
| 16 | class Mesh;
|
---|
| 17 | class MeshInstance;
|
---|
| 18 | class Intersectable;
|
---|
| 19 | class Material;
|
---|
[512] | 20 | class Beam;
|
---|
[532] | 21 | class KdTree;
|
---|
[538] | 22 | class GlRendererBuffer;
|
---|
[531] | 23 | class BeamSampleStatistics;
|
---|
[1001] | 24 | class OcclusionQuery;
|
---|
| 25 | class TransformedMeshInstance;
|
---|
[1581] | 26 | class TriangleIntersectable;
|
---|
[1949] | 27 | class BvhNode;
|
---|
[2048] | 28 | class SimpleRayContainer;
|
---|
| 29 |
|
---|
[540] | 30 | struct VssRayContainer;
|
---|
| 31 |
|
---|
[1608] | 32 | struct GLUquadric;
|
---|
| 33 |
|
---|
[492] | 34 | struct PvsRenderStatistics {
|
---|
| 35 |
|
---|
| 36 | float maxError;
|
---|
| 37 | float sumError;
|
---|
[713] | 38 | int sumPvsSize;
|
---|
[492] | 39 | int frames;
|
---|
| 40 | int errorFreeFrames;
|
---|
[502] | 41 |
|
---|
[492] | 42 | PvsRenderStatistics() { Reset(); }
|
---|
| 43 |
|
---|
[498] | 44 | void Reset() {
|
---|
[492] | 45 | maxError = 0.0f;
|
---|
| 46 | sumError = 0.0f;
|
---|
| 47 | frames = 0;
|
---|
| 48 | errorFreeFrames = 0;
|
---|
[713] | 49 | sumPvsSize = 0;
|
---|
[492] | 50 | }
|
---|
| 51 |
|
---|
| 52 | float GetMaxError() { return maxError; }
|
---|
| 53 | float GetAvgError() { return sumError/frames; }
|
---|
| 54 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
[713] | 55 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
[492] | 56 |
|
---|
| 57 | };
|
---|
| 58 |
|
---|
[1824] | 59 | struct PvsCache {
|
---|
| 60 | PvsCache():mViewCell(NULL) {}
|
---|
| 61 | void Reset() { mViewCell = NULL; mPvs.Clear(); filteredBoxes.clear(); }
|
---|
| 62 | ViewCell *mViewCell;
|
---|
| 63 | ObjectPvs mPvs;
|
---|
| 64 | vector<AxisAlignedBox3> filteredBoxes;
|
---|
| 65 | };
|
---|
| 66 |
|
---|
| 67 |
|
---|
[811] | 68 | struct RenderCostSample {
|
---|
[496] | 69 |
|
---|
[811] | 70 | RenderCostSample() {}
|
---|
| 71 |
|
---|
| 72 | void Reset() {
|
---|
| 73 | mVisibleObjects = 0;
|
---|
| 74 | mVisiblePixels = 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[991] | 77 | Vector3 mPosition;
|
---|
| 78 |
|
---|
[811] | 79 | // visible object from the given point
|
---|
| 80 | int mVisibleObjects;
|
---|
| 81 |
|
---|
| 82 | // visible pixels
|
---|
| 83 | int mVisiblePixels;
|
---|
[1161] | 84 |
|
---|
| 85 | ObjectPvs mPvs;
|
---|
[811] | 86 |
|
---|
| 87 | };
|
---|
| 88 |
|
---|
[496] | 89 | /** Class encapsulating gl rendering for the scene.
|
---|
| 90 | There is no gl context binding so the binding is performed in the
|
---|
| 91 | derived classes
|
---|
| 92 | */
|
---|
[497] | 93 | class GlRenderer: public Renderer
|
---|
[492] | 94 | {
|
---|
[496] | 95 |
|
---|
[492] | 96 | public:
|
---|
| 97 |
|
---|
| 98 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[532] | 99 | ViewCellsManager *viewcells,
|
---|
| 100 | KdTree *tree);
|
---|
[496] | 101 |
|
---|
[1151] | 102 | GlRenderer() {}
|
---|
| 103 |
|
---|
[1145] | 104 | virtual ~GlRenderer();
|
---|
[492] | 105 |
|
---|
[496] | 106 |
|
---|
[1931] | 107 | virtual void RandomViewPoint();
|
---|
| 108 |
|
---|
[1960] | 109 | void SetupFalseColor(const unsigned int id);
|
---|
[492] | 110 | void RenderIntersectable(Intersectable *);
|
---|
[535] | 111 | void RenderViewCell(ViewCell *vc);
|
---|
[492] | 112 | void RenderMeshInstance(MeshInstance *mi);
|
---|
[1001] | 113 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
[492] | 114 | void RenderMesh(Mesh *m);
|
---|
| 115 | void SetupMaterial(Material *m);
|
---|
[502] | 116 | virtual void SetupCamera();
|
---|
[1581] | 117 |
|
---|
| 118 | void
|
---|
| 119 | RenderRays(const VssRayContainer &rays);
|
---|
| 120 |
|
---|
| 121 | void
|
---|
| 122 | RenderTriangle(TriangleIntersectable *object);
|
---|
| 123 |
|
---|
[1585] | 124 | void
|
---|
| 125 | RenderBox(const AxisAlignedBox3 &box);
|
---|
| 126 |
|
---|
| 127 | void
|
---|
| 128 | RenderBvhNode(BvhNode *node);
|
---|
[1594] | 129 |
|
---|
| 130 | void
|
---|
| 131 | RenderKdNode(KdNode *node);
|
---|
| 132 |
|
---|
[497] | 133 | bool
|
---|
[496] | 134 | RenderScene();
|
---|
[492] | 135 |
|
---|
[811] | 136 | void
|
---|
| 137 | _RenderScene();
|
---|
[589] | 138 |
|
---|
[1983] | 139 | void
|
---|
[2002] | 140 | _RenderSceneTriangles();
|
---|
| 141 |
|
---|
| 142 | void
|
---|
[1983] | 143 | RenderViewPoint();
|
---|
[811] | 144 |
|
---|
[608] | 145 | virtual void
|
---|
[811] | 146 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[496] | 147 |
|
---|
[2023] | 148 | virtual bool ValidViewPoint();
|
---|
[496] | 149 |
|
---|
[1931] | 150 | virtual float
|
---|
| 151 | GetPixelError(int &pvsSize);
|
---|
[496] | 152 |
|
---|
[1931] | 153 | virtual void
|
---|
| 154 | EvalPvsStat();
|
---|
[496] | 155 |
|
---|
[2048] | 156 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
| 157 |
|
---|
[1997] | 158 | virtual void InitGL();
|
---|
[496] | 159 |
|
---|
[1940] | 160 | virtual int GetWidth() const { return 0; }
|
---|
| 161 | virtual int GetHeight() const { return 0; }
|
---|
[540] | 162 |
|
---|
[1960] | 163 | unsigned int GetId(const unsigned char r,
|
---|
| 164 | const unsigned char g,
|
---|
| 165 | const unsigned char b) const;
|
---|
[1151] | 166 |
|
---|
| 167 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
| 168 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
| 169 |
|
---|
| 170 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
| 171 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
| 172 |
|
---|
[1931] | 173 | virtual void ClearErrorBuffer();
|
---|
| 174 |
|
---|
[2002] | 175 | virtual float GetAvgPixelError() {
|
---|
| 176 | return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
|
---|
| 177 | }
|
---|
[2008] | 178 |
|
---|
| 179 | virtual float GetMaxPixelError() {
|
---|
| 180 | return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
|
---|
| 181 | }
|
---|
[2002] | 182 |
|
---|
[1832] | 183 | public:
|
---|
[1940] | 184 |
|
---|
[1832] | 185 | int mFrame;
|
---|
| 186 | bool mWireFrame;
|
---|
[1931] | 187 |
|
---|
| 188 | PvsRenderStatistics mPvsStat;
|
---|
| 189 |
|
---|
| 190 | int mPvsStatFrames;
|
---|
| 191 | struct PvsErrorEntry {
|
---|
| 192 | PvsErrorEntry() {}
|
---|
| 193 | float mError;
|
---|
| 194 | int mPvsSize;
|
---|
| 195 | Vector3 mPosition;
|
---|
| 196 | Vector3 mDirection;
|
---|
| 197 | };
|
---|
[1944] | 198 | friend class GlobalLinesRenderer;
|
---|
[2017] | 199 | friend class ViewCellsManager;
|
---|
| 200 |
|
---|
[2050] | 201 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
| 202 |
|
---|
[1151] | 203 | protected:
|
---|
| 204 |
|
---|
[1931] | 205 |
|
---|
[1151] | 206 |
|
---|
[1931] | 207 | PvsCache mPvsCache;
|
---|
| 208 |
|
---|
[1151] | 209 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
| 210 |
|
---|
| 211 | ObjectContainer mObjects;
|
---|
| 212 |
|
---|
| 213 | Vector3 mViewPoint;
|
---|
| 214 | Vector3 mViewDirection;
|
---|
| 215 |
|
---|
| 216 | int timerId;
|
---|
| 217 | bool mUseFalseColors;
|
---|
| 218 | bool mUseForcedColors;
|
---|
| 219 |
|
---|
| 220 | HaltonSequence halton;
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | bool mDetectEmptyViewSpace;
|
---|
| 224 | bool mSnapErrorFrames;
|
---|
| 225 |
|
---|
[1594] | 226 | bool mRenderBoxes;
|
---|
| 227 |
|
---|
[1151] | 228 | bool mUseGlLists;
|
---|
| 229 |
|
---|
| 230 | string mSnapPrefix;
|
---|
| 231 |
|
---|
[1608] | 232 | GLUquadric *mSphere;
|
---|
| 233 |
|
---|
[1151] | 234 | KdTree *mKdTree;
|
---|
| 235 |
|
---|
[496] | 236 | };
|
---|
| 237 |
|
---|
[1146] | 238 | /* Class implementing an OpenGl render buffer.
|
---|
| 239 | */
|
---|
[1145] | 240 | class GlRendererBuffer: public GlRenderer
|
---|
[496] | 241 | {
|
---|
[1145] | 242 |
|
---|
[496] | 243 | public:
|
---|
[1151] | 244 |
|
---|
[1968] | 245 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
| 246 | ViewCellsManager *viewcells,
|
---|
| 247 | KdTree *tree);
|
---|
[589] | 248 |
|
---|
[1968] | 249 | virtual ~GlRendererBuffer();
|
---|
[811] | 250 |
|
---|
[1001] | 251 | /** Evaluates render cost of a point sample.
|
---|
[1968] | 252 | @param sample the render cost sample to be evaluated
|
---|
| 253 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 254 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
[1001] | 255 | */
|
---|
[1968] | 256 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 257 | const bool useOcclusionQueries,
|
---|
| 258 | const int threshold);
|
---|
[811] | 259 |
|
---|
[1001] | 260 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
[1968] | 261 | are distributed uniformly over the defined view space.
|
---|
[811] | 262 |
|
---|
[1968] | 263 | @param numSamples the number of point samples taken
|
---|
| 264 | @param samples stores the taken point samples in a container
|
---|
| 265 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 266 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
[1001] | 267 | */
|
---|
[1968] | 268 | virtual void SampleRenderCost(const int numSamples,
|
---|
| 269 | vector<RenderCostSample> &samples,
|
---|
| 270 | const bool useOcclusionQueries,
|
---|
| 271 | const int threshold = 0);
|
---|
[811] | 272 |
|
---|
[1968] | 273 |
|
---|
[1145] | 274 | /** Implerment in subclasses.
|
---|
| 275 | */
|
---|
[1968] | 276 | virtual void EvalPvsStat();
|
---|
[1001] | 277 |
|
---|
[2048] | 278 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
[496] | 279 |
|
---|
[1968] | 280 | virtual int GetWidth() const = 0;
|
---|
| 281 | virtual int GetHeight() const = 0;
|
---|
[496] | 282 |
|
---|
[1968] | 283 | virtual void MakeCurrent() = 0;
|
---|
| 284 | virtual void DoneCurrent() = 0;
|
---|
[507] | 285 |
|
---|
[2023] | 286 | virtual bool ValidViewPoint();
|
---|
[507] | 287 |
|
---|
[1968] | 288 | virtual void SampleBeamContributions(
|
---|
| 289 | Intersectable *sourceObject,
|
---|
| 290 | Beam &beam,
|
---|
| 291 | const int samples,
|
---|
| 292 | BeamSampleStatistics &stat
|
---|
| 293 | );
|
---|
[507] | 294 |
|
---|
[1968] | 295 | virtual void
|
---|
| 296 | SampleViewpointContributions(
|
---|
| 297 | Intersectable *sourceObject,
|
---|
| 298 | const Vector3 viewPoint,
|
---|
| 299 | Beam &beam,
|
---|
| 300 | const int desiredSamples,
|
---|
| 301 | BeamSampleStatistics &stat
|
---|
| 302 | );
|
---|
[540] | 303 |
|
---|
[1968] | 304 | virtual void InitGL();
|
---|
[540] | 305 |
|
---|
[1968] | 306 | /** Computes rays from information gained with hw sampling-
|
---|
| 307 | */
|
---|
| 308 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
[540] | 309 |
|
---|
[1968] | 310 | virtual int ComputePvs() const = 0;
|
---|
[713] | 311 |
|
---|
[1968] | 312 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
[1931] | 313 |
|
---|
| 314 |
|
---|
[1145] | 315 | protected:
|
---|
[746] | 316 |
|
---|
[1968] | 317 | unsigned int *mPixelBuffer;
|
---|
[746] | 318 |
|
---|
[1968] | 319 | static void GenQueries(const int numQueries);
|
---|
| 320 |
|
---|
| 321 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 322 | const Beam &beam,
|
---|
| 323 |
|
---|
| 324 | Intersectable *sourceObject);
|
---|
| 325 |
|
---|
[1001] | 326 | /** Evaluates query for one direction using item buffer.
|
---|
| 327 | */
|
---|
[1968] | 328 | virtual void EvalQueryWithItemBuffer();
|
---|
[1146] | 329 |
|
---|
[1001] | 330 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 331 | */
|
---|
[1968] | 332 | virtual void EvalQueryWithOcclusionQueries();
|
---|
[997] | 333 |
|
---|
[746] | 334 | public:
|
---|
[1145] | 335 | // matt: remove qt dependencies
|
---|
[1968] | 336 | // signals:
|
---|
| 337 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
[496] | 338 | };
|
---|
| 339 |
|
---|
[1146] | 340 |
|
---|
| 341 | /** Abstract class for implmenenting a gl render widget.
|
---|
| 342 | */
|
---|
[1151] | 343 | class GlRendererWidget: public GlRenderer
|
---|
[1146] | 344 | {
|
---|
| 345 | public:
|
---|
[1968] | 346 |
|
---|
[1151] | 347 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
| 348 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
[1968] | 349 | {}
|
---|
[1146] | 350 |
|
---|
[1968] | 351 | GlRendererWidget() {}
|
---|
[1146] | 352 |
|
---|
[1968] | 353 | virtual ~GlRendererWidget() {}
|
---|
[1146] | 354 |
|
---|
[1968] | 355 | //virtual void Create() {}
|
---|
| 356 | virtual void Show() {}
|
---|
[1146] | 357 |
|
---|
[1968] | 358 |
|
---|
[1146] | 359 | protected:
|
---|
| 360 |
|
---|
| 361 |
|
---|
[1968] | 362 | // SceneGraph *mSceneGraph;
|
---|
| 363 | // ViewCellsManager *mViewCellsManager;
|
---|
| 364 | // KdTree *mKdTree;
|
---|
[608] | 365 | };
|
---|
| 366 |
|
---|
[1151] | 367 | //extern GlRendererWidget *rendererWidget;
|
---|
| 368 |
|
---|
[1146] | 369 | };
|
---|
[492] | 370 |
|
---|
[1387] | 371 | #endif
|
---|