[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;
|
---|
[2600] | 30 | class SceneGraphLeaf;
|
---|
[2702] | 31 | class Preprocessor;
|
---|
[2048] | 32 |
|
---|
[540] | 33 | struct VssRayContainer;
|
---|
[2593] | 34 | struct GLUquadric;
|
---|
[540] | 35 |
|
---|
[2593] | 36 |
|
---|
| 37 | struct PvsRenderStatistics
|
---|
| 38 | {
|
---|
[492] | 39 | float maxError;
|
---|
| 40 | float sumError;
|
---|
[713] | 41 | int sumPvsSize;
|
---|
[492] | 42 | int frames;
|
---|
| 43 | int errorFreeFrames;
|
---|
[2709] | 44 | int pass;
|
---|
[502] | 45 |
|
---|
[2709] | 46 | PvsRenderStatistics(): pass(0) { Reset(); }
|
---|
[492] | 47 |
|
---|
[2593] | 48 | void Reset()
|
---|
| 49 | {
|
---|
[492] | 50 | maxError = 0.0f;
|
---|
| 51 | sumError = 0.0f;
|
---|
| 52 | frames = 0;
|
---|
| 53 | errorFreeFrames = 0;
|
---|
[713] | 54 | sumPvsSize = 0;
|
---|
[492] | 55 | }
|
---|
| 56 |
|
---|
| 57 | float GetMaxError() { return maxError; }
|
---|
| 58 | float GetAvgError() { return sumError/frames; }
|
---|
| 59 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
[713] | 60 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
[492] | 61 |
|
---|
| 62 | };
|
---|
| 63 |
|
---|
[2538] | 64 |
|
---|
[2593] | 65 | struct PvsCache
|
---|
| 66 | {
|
---|
| 67 | PvsCache():mViewCell(NULL), mUnfilteredPvsSize(0) {}
|
---|
[1824] | 68 |
|
---|
[2593] | 69 | void Reset()
|
---|
| 70 | {
|
---|
[2643] | 71 | mViewCell = NULL;
|
---|
[2723] | 72 | mPvs.Clear(false);
|
---|
[2593] | 73 | filteredBoxes.clear();
|
---|
| 74 | mUnfilteredPvsSize = 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | ViewCell *mViewCell;
|
---|
| 78 | ObjectPvs mPvs;
|
---|
| 79 | int mUnfilteredPvsSize;
|
---|
| 80 | vector<AxisAlignedBox3> filteredBoxes;
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 |
|
---|
[811] | 84 | struct RenderCostSample {
|
---|
[496] | 85 |
|
---|
[811] | 86 | RenderCostSample() {}
|
---|
| 87 |
|
---|
| 88 | void Reset() {
|
---|
| 89 | mVisibleObjects = 0;
|
---|
| 90 | mVisiblePixels = 0;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[991] | 93 | Vector3 mPosition;
|
---|
| 94 |
|
---|
[811] | 95 | // visible object from the given point
|
---|
| 96 | int mVisibleObjects;
|
---|
| 97 |
|
---|
| 98 | // visible pixels
|
---|
| 99 | int mVisiblePixels;
|
---|
[1161] | 100 |
|
---|
| 101 | ObjectPvs mPvs;
|
---|
[811] | 102 |
|
---|
| 103 | };
|
---|
| 104 |
|
---|
[496] | 105 | /** Class encapsulating gl rendering for the scene.
|
---|
| 106 | There is no gl context binding so the binding is performed in the
|
---|
| 107 | derived classes
|
---|
| 108 | */
|
---|
[497] | 109 | class GlRenderer: public Renderer
|
---|
[492] | 110 | {
|
---|
[2538] | 111 | friend class GlobalLinesRenderer;
|
---|
| 112 | friend class ViewCellsManager;
|
---|
[496] | 113 |
|
---|
[492] | 114 | public:
|
---|
| 115 |
|
---|
| 116 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[532] | 117 | ViewCellsManager *viewcells,
|
---|
| 118 | KdTree *tree);
|
---|
[496] | 119 |
|
---|
[1151] | 120 | GlRenderer() {}
|
---|
| 121 |
|
---|
[1145] | 122 | virtual ~GlRenderer();
|
---|
[492] | 123 |
|
---|
[496] | 124 |
|
---|
[1931] | 125 | virtual void RandomViewPoint();
|
---|
| 126 |
|
---|
[1960] | 127 | void SetupFalseColor(const unsigned int id);
|
---|
[492] | 128 | void RenderIntersectable(Intersectable *);
|
---|
[535] | 129 | void RenderViewCell(ViewCell *vc);
|
---|
[492] | 130 | void RenderMeshInstance(MeshInstance *mi);
|
---|
[1001] | 131 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
[492] | 132 | void RenderMesh(Mesh *m);
|
---|
| 133 | void SetupMaterial(Material *m);
|
---|
[502] | 134 | virtual void SetupCamera();
|
---|
[1581] | 135 |
|
---|
| 136 | void
|
---|
[2593] | 137 | RenderRays(const VssRayContainer &rays, int colorType = 0, int showDistribution = 15, int maxAge = 9999999);
|
---|
[1581] | 138 |
|
---|
| 139 | void
|
---|
| 140 | RenderTriangle(TriangleIntersectable *object);
|
---|
| 141 |
|
---|
[1585] | 142 | void
|
---|
| 143 | RenderBox(const AxisAlignedBox3 &box);
|
---|
| 144 |
|
---|
| 145 | void
|
---|
| 146 | RenderBvhNode(BvhNode *node);
|
---|
[1594] | 147 |
|
---|
| 148 | void
|
---|
| 149 | RenderKdNode(KdNode *node);
|
---|
| 150 |
|
---|
[497] | 151 | bool
|
---|
[496] | 152 | RenderScene();
|
---|
[492] | 153 |
|
---|
[811] | 154 | void
|
---|
| 155 | _RenderScene();
|
---|
[589] | 156 |
|
---|
[1983] | 157 | void
|
---|
[2002] | 158 | _RenderSceneTriangles();
|
---|
| 159 |
|
---|
[2538] | 160 | void _RenderSceneTrianglesWithDrawArrays();
|
---|
| 161 |
|
---|
[2002] | 162 | void
|
---|
[1983] | 163 | RenderViewPoint();
|
---|
[811] | 164 |
|
---|
[2615] | 165 | void _RenderDynamicObject(SceneGraphLeaf *leaf);
|
---|
| 166 |
|
---|
[608] | 167 | virtual void
|
---|
[811] | 168 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[496] | 169 |
|
---|
[2023] | 170 | virtual bool ValidViewPoint();
|
---|
[496] | 171 |
|
---|
[2709] | 172 | /** Gets the pixel error of the current view point.
|
---|
| 173 | returns the size of the pvs for the current view point. pass returns the
|
---|
| 174 | current pass of the evaluation.
|
---|
| 175 | */
|
---|
| 176 | virtual float GetPixelError(int &pvsSize, int pass);
|
---|
[496] | 177 |
|
---|
[2664] | 178 | virtual void EvalPvsStat();
|
---|
[496] | 179 |
|
---|
[2670] | 180 | /** Prepare the pvs for rendering.
|
---|
| 181 | */
|
---|
| 182 | virtual void PreparePvs(const ObjectPvs &pvs);
|
---|
| 183 | /** Helper function that recursively prepares the indices for VBO renderin.
|
---|
| 184 | */
|
---|
[2620] | 185 | void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
|
---|
| 186 |
|
---|
| 187 |
|
---|
[2048] | 188 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
| 189 |
|
---|
[1997] | 190 | virtual void InitGL();
|
---|
[496] | 191 |
|
---|
[2709] | 192 | virtual int GetWidth() const {return 0;}
|
---|
| 193 | virtual int GetHeight() const {return 0;}
|
---|
[540] | 194 |
|
---|
[1960] | 195 | unsigned int GetId(const unsigned char r,
|
---|
| 196 | const unsigned char g,
|
---|
| 197 | const unsigned char b) const;
|
---|
[1151] | 198 |
|
---|
| 199 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
[2176] | 200 | inline const std::string GetSnapPrefix() { return mSnapPrefix; }
|
---|
[1151] | 201 |
|
---|
| 202 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
[2176] | 203 | inline void SetSnapPrefix(const std::string &pref) { mSnapPrefix = pref; }
|
---|
[1151] | 204 |
|
---|
[1931] | 205 | virtual void ClearErrorBuffer();
|
---|
| 206 |
|
---|
[2002] | 207 | virtual float GetAvgPixelError() {
|
---|
| 208 | return mPvsStat.GetAvgError()*GetWidth()*GetHeight();
|
---|
| 209 | }
|
---|
[2008] | 210 |
|
---|
| 211 | virtual float GetMaxPixelError() {
|
---|
[2543] | 212 | return mPvsStat.GetMaxError()*GetWidth()*GetHeight();
|
---|
[2008] | 213 | }
|
---|
[2543] | 214 |
|
---|
[2598] | 215 | void SetViewPoint(const Vector3 &vp) { mViewPoint = vp; }
|
---|
| 216 | void SetViewDirection(const Vector3 &vd) { mViewDirection = vd; }
|
---|
| 217 |
|
---|
[2625] | 218 | Vector3 GetViewPoint() const { return mViewPoint; }
|
---|
[2670] | 219 |
|
---|
[2686] | 220 | bool GetUseVbos() const { return mUseVbos; }
|
---|
[2670] | 221 |
|
---|
[2686] | 222 |
|
---|
[1832] | 223 | public:
|
---|
[1940] | 224 |
|
---|
[2543] | 225 | int mCurrentFrame;
|
---|
| 226 | int mFrame;
|
---|
| 227 | bool mWireFrame;
|
---|
[1931] | 228 |
|
---|
[2543] | 229 | PvsRenderStatistics mPvsStat;
|
---|
[2017] | 230 |
|
---|
[2620] | 231 | unsigned int mIndexBufferSize;
|
---|
| 232 |
|
---|
[2543] | 233 | int mPvsStatFrames;
|
---|
| 234 | struct PvsErrorEntry {
|
---|
| 235 | PvsErrorEntry() {}
|
---|
| 236 | float mError;
|
---|
| 237 | int mPvsSize;
|
---|
| 238 | Vector3 mPosition;
|
---|
| 239 | Vector3 mDirection;
|
---|
| 240 | };
|
---|
[2050] | 241 |
|
---|
[2702] | 242 | Preprocessor *GetPreprocessor();
|
---|
| 243 |
|
---|
| 244 |
|
---|
[2543] | 245 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
[2671] | 246 |
|
---|
[2643] | 247 | bool mComputeGVS;
|
---|
[2543] | 248 |
|
---|
[1151] | 249 | protected:
|
---|
| 250 |
|
---|
[2600] | 251 | void CreateVertexArrays(SceneGraphLeaf *leaf);
|
---|
[2538] | 252 | void DeleteVbos();
|
---|
| 253 | void EnableDrawArrays();
|
---|
| 254 | void DisableDrawArrays();
|
---|
[1151] | 255 |
|
---|
[2538] | 256 | void RenderKdLeaf(KdLeaf *leaf);
|
---|
[1931] | 257 |
|
---|
[2686] | 258 |
|
---|
[2538] | 259 | //////////////////
|
---|
[1151] | 260 |
|
---|
[2538] | 261 | PvsCache mPvsCache;
|
---|
[1151] | 262 |
|
---|
[2538] | 263 | unsigned int mVboId;
|
---|
| 264 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
[1151] | 265 |
|
---|
[2538] | 266 | ObjectContainer mObjects;
|
---|
[1594] | 267 |
|
---|
[2538] | 268 | Vector3 mViewPoint;
|
---|
| 269 | Vector3 mViewDirection;
|
---|
[1151] | 270 |
|
---|
[2538] | 271 | int timerId;
|
---|
| 272 | bool mUseFalseColors;
|
---|
| 273 | bool mUseForcedColors;
|
---|
[1151] | 274 |
|
---|
[2538] | 275 | HaltonSequence halton;
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | bool mDetectEmptyViewSpace;
|
---|
| 279 | bool mSnapErrorFrames;
|
---|
| 280 |
|
---|
| 281 | bool mRenderBoxes;
|
---|
| 282 |
|
---|
| 283 | bool mUseGlLists;
|
---|
| 284 |
|
---|
| 285 | std::string mSnapPrefix;
|
---|
| 286 |
|
---|
| 287 | GLUquadric *mSphere;
|
---|
| 288 |
|
---|
| 289 | KdTree *mKdTree;
|
---|
| 290 |
|
---|
| 291 | Vector3 *mData;
|
---|
| 292 | unsigned int *mIndices;
|
---|
| 293 |
|
---|
| 294 | bool mUseVbos;
|
---|
[2671] | 295 |
|
---|
| 296 | int mRenderedNodes;
|
---|
[496] | 297 | };
|
---|
| 298 |
|
---|
[2538] | 299 |
|
---|
[1146] | 300 | /* Class implementing an OpenGl render buffer.
|
---|
| 301 | */
|
---|
[1145] | 302 | class GlRendererBuffer: public GlRenderer
|
---|
[496] | 303 | {
|
---|
[1145] | 304 |
|
---|
[496] | 305 | public:
|
---|
[1151] | 306 |
|
---|
[1968] | 307 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
[2702] | 308 | ViewCellsManager *viewcells,
|
---|
| 309 | KdTree *tree);
|
---|
[589] | 310 |
|
---|
[1968] | 311 | virtual ~GlRendererBuffer();
|
---|
[811] | 312 |
|
---|
[1001] | 313 | /** Evaluates render cost of a point sample.
|
---|
[1968] | 314 | @param sample the render cost sample to be evaluated
|
---|
| 315 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 316 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
[1001] | 317 | */
|
---|
[1968] | 318 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 319 | const bool useOcclusionQueries,
|
---|
| 320 | const int threshold);
|
---|
[811] | 321 |
|
---|
[1001] | 322 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
[1968] | 323 | are distributed uniformly over the defined view space.
|
---|
[811] | 324 |
|
---|
[1968] | 325 | @param numSamples the number of point samples taken
|
---|
| 326 | @param samples stores the taken point samples in a container
|
---|
| 327 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 328 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
[1001] | 329 | */
|
---|
[1968] | 330 | virtual void SampleRenderCost(const int numSamples,
|
---|
[2538] | 331 | vector<RenderCostSample> &samples,
|
---|
| 332 | const bool useOcclusionQueries,
|
---|
| 333 | const int threshold = 0);
|
---|
[1145] | 334 | /** Implerment in subclasses.
|
---|
| 335 | */
|
---|
[1968] | 336 | virtual void EvalPvsStat();
|
---|
[1001] | 337 |
|
---|
[2048] | 338 | virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
|
---|
[496] | 339 |
|
---|
[1968] | 340 | virtual int GetWidth() const = 0;
|
---|
| 341 | virtual int GetHeight() const = 0;
|
---|
[496] | 342 |
|
---|
[2677] | 343 | virtual void MakeLive() = 0;
|
---|
| 344 | virtual void DoneLive() = 0;
|
---|
[507] | 345 |
|
---|
[2023] | 346 | virtual bool ValidViewPoint();
|
---|
[507] | 347 |
|
---|
[1968] | 348 | virtual void SampleBeamContributions(
|
---|
[2538] | 349 | Intersectable *sourceObject,
|
---|
| 350 | Beam &beam,
|
---|
| 351 | const int samples,
|
---|
| 352 | BeamSampleStatistics &stat
|
---|
| 353 | );
|
---|
[507] | 354 |
|
---|
[2538] | 355 | virtual void SampleViewpointContributions(
|
---|
| 356 | Intersectable *sourceObject,
|
---|
| 357 | const Vector3 viewPoint,
|
---|
| 358 | Beam &beam,
|
---|
| 359 | const int desiredSamples,
|
---|
| 360 | BeamSampleStatistics &stat
|
---|
| 361 | );
|
---|
[540] | 362 |
|
---|
[1968] | 363 | virtual void InitGL();
|
---|
| 364 | /** Computes rays from information gained with hw sampling-
|
---|
| 365 | */
|
---|
| 366 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
[540] | 367 |
|
---|
[1968] | 368 | virtual int ComputePvs() const = 0;
|
---|
[713] | 369 |
|
---|
[1968] | 370 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
[1931] | 371 |
|
---|
| 372 |
|
---|
[1145] | 373 | protected:
|
---|
[746] | 374 |
|
---|
[1968] | 375 | unsigned int *mPixelBuffer;
|
---|
[746] | 376 |
|
---|
[2663] | 377 | static void GenQueries(int numQueries);
|
---|
[1968] | 378 |
|
---|
| 379 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
[2538] | 380 | const Beam &beam,
|
---|
| 381 | Intersectable *sourceObject);
|
---|
[1001] | 382 | /** Evaluates query for one direction using item buffer.
|
---|
| 383 | */
|
---|
[1968] | 384 | virtual void EvalQueryWithItemBuffer();
|
---|
[1001] | 385 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 386 | */
|
---|
[1968] | 387 | virtual void EvalQueryWithOcclusionQueries();
|
---|
[496] | 388 | };
|
---|
| 389 |
|
---|
[1146] | 390 |
|
---|
| 391 | /** Abstract class for implmenenting a gl render widget.
|
---|
| 392 | */
|
---|
[1151] | 393 | class GlRendererWidget: public GlRenderer
|
---|
[1146] | 394 | {
|
---|
| 395 | public:
|
---|
[1968] | 396 |
|
---|
[1151] | 397 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
| 398 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
[1968] | 399 | {}
|
---|
[1146] | 400 |
|
---|
[1968] | 401 | GlRendererWidget() {}
|
---|
[1146] | 402 |
|
---|
[1968] | 403 | virtual ~GlRendererWidget() {}
|
---|
[2538] | 404 |
|
---|
[1968] | 405 | virtual void Show() {}
|
---|
[608] | 406 | };
|
---|
| 407 |
|
---|
[1151] | 408 |
|
---|
[1146] | 409 | };
|
---|
[492] | 410 |
|
---|
[1387] | 411 | #endif
|
---|