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