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