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