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