[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;
|
---|
[1585] | 27 | class BvhNode;
|
---|
| 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 |
|
---|
[492] | 108 | void SetupFalseColor(const int id);
|
---|
| 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 |
|
---|
[811] | 138 |
|
---|
[608] | 139 | virtual void
|
---|
[811] | 140 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[496] | 141 |
|
---|
| 142 |
|
---|
[1931] | 143 | virtual float
|
---|
| 144 | GetPixelError(int &pvsSize);
|
---|
[496] | 145 |
|
---|
[1931] | 146 | virtual void
|
---|
| 147 | EvalPvsStat();
|
---|
[496] | 148 |
|
---|
| 149 | void InitGL();
|
---|
| 150 |
|
---|
[1940] | 151 | virtual int GetWidth() const { return 0; }
|
---|
| 152 | virtual int GetHeight() const { return 0; }
|
---|
[540] | 153 |
|
---|
| 154 | int GetId(int r, int g, int b) const;
|
---|
[1151] | 155 |
|
---|
| 156 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
| 157 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
| 158 |
|
---|
| 159 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
| 160 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
| 161 |
|
---|
[1931] | 162 | virtual void ClearErrorBuffer();
|
---|
| 163 |
|
---|
| 164 |
|
---|
[1832] | 165 | public:
|
---|
[1940] | 166 |
|
---|
[1832] | 167 | int mFrame;
|
---|
| 168 | bool mWireFrame;
|
---|
[1931] | 169 |
|
---|
| 170 | PvsRenderStatistics mPvsStat;
|
---|
| 171 |
|
---|
| 172 | int mPvsStatFrames;
|
---|
| 173 | struct PvsErrorEntry {
|
---|
| 174 | PvsErrorEntry() {}
|
---|
| 175 | float mError;
|
---|
| 176 | int mPvsSize;
|
---|
| 177 | Vector3 mPosition;
|
---|
| 178 | Vector3 mDirection;
|
---|
| 179 | };
|
---|
| 180 |
|
---|
[1151] | 181 | protected:
|
---|
| 182 |
|
---|
[1931] | 183 |
|
---|
| 184 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
[1151] | 185 |
|
---|
[1931] | 186 | PvsCache mPvsCache;
|
---|
| 187 |
|
---|
[1151] | 188 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
| 189 |
|
---|
| 190 | ObjectContainer mObjects;
|
---|
| 191 |
|
---|
| 192 | Vector3 mViewPoint;
|
---|
| 193 | Vector3 mViewDirection;
|
---|
| 194 |
|
---|
| 195 | int timerId;
|
---|
| 196 | bool mUseFalseColors;
|
---|
| 197 | bool mUseForcedColors;
|
---|
| 198 |
|
---|
| 199 | HaltonSequence halton;
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 | bool mDetectEmptyViewSpace;
|
---|
| 203 | bool mSnapErrorFrames;
|
---|
| 204 |
|
---|
[1594] | 205 | bool mRenderBoxes;
|
---|
| 206 |
|
---|
[1151] | 207 | bool mUseGlLists;
|
---|
| 208 |
|
---|
| 209 | string mSnapPrefix;
|
---|
| 210 |
|
---|
[1608] | 211 | GLUquadric *mSphere;
|
---|
| 212 |
|
---|
[1151] | 213 | KdTree *mKdTree;
|
---|
| 214 |
|
---|
[496] | 215 | };
|
---|
| 216 |
|
---|
[1146] | 217 | /* Class implementing an OpenGl render buffer.
|
---|
| 218 | */
|
---|
[1145] | 219 | class GlRendererBuffer: public GlRenderer
|
---|
[496] | 220 | {
|
---|
[1145] | 221 |
|
---|
[496] | 222 | public:
|
---|
[1151] | 223 |
|
---|
[1145] | 224 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
[811] | 225 | ViewCellsManager *viewcells,
|
---|
| 226 | KdTree *tree);
|
---|
[589] | 227 |
|
---|
[1785] | 228 | virtual ~GlRendererBuffer();
|
---|
[811] | 229 |
|
---|
[1001] | 230 | /** Evaluates render cost of a point sample.
|
---|
| 231 | @param sample the render cost sample to be evaluated
|
---|
| 232 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 233 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 234 | */
|
---|
[1785] | 235 | virtual void EvalRenderCostSample(RenderCostSample &sample,
|
---|
[1001] | 236 | const bool useOcclusionQueries,
|
---|
| 237 | const int threshold);
|
---|
[811] | 238 |
|
---|
[1001] | 239 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
| 240 | are distributed uniformly over the defined view space.
|
---|
[811] | 241 |
|
---|
[1001] | 242 | @param numSamples the number of point samples taken
|
---|
| 243 | @param samples stores the taken point samples in a container
|
---|
| 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.
|
---|
| 246 | */
|
---|
[1785] | 247 | virtual void SampleRenderCost(const int numSamples,
|
---|
| 248 | vector<RenderCostSample> &samples,
|
---|
| 249 | const bool useOcclusionQueries,
|
---|
| 250 | const int threshold = 0);
|
---|
| 251 |
|
---|
[811] | 252 |
|
---|
[1145] | 253 | /** Implerment in subclasses.
|
---|
| 254 | */
|
---|
[1785] | 255 | virtual void EvalPvsStat();
|
---|
[1001] | 256 |
|
---|
[496] | 257 |
|
---|
[1785] | 258 | virtual int GetWidth() const = 0;
|
---|
| 259 | virtual int GetHeight() const = 0;
|
---|
[496] | 260 |
|
---|
[1785] | 261 | virtual void MakeCurrent() = 0;
|
---|
| 262 | virtual void DoneCurrent() = 0;
|
---|
| 263 |
|
---|
[507] | 264 |
|
---|
[1785] | 265 | virtual void SampleBeamContributions(
|
---|
[507] | 266 | Intersectable *sourceObject,
|
---|
[512] | 267 | Beam &beam,
|
---|
[507] | 268 | const int samples,
|
---|
| 269 | BeamSampleStatistics &stat
|
---|
| 270 | );
|
---|
| 271 |
|
---|
[1785] | 272 | virtual void
|
---|
[507] | 273 | SampleViewpointContributions(
|
---|
| 274 | Intersectable *sourceObject,
|
---|
[514] | 275 | const Vector3 viewPoint,
|
---|
[512] | 276 | Beam &beam,
|
---|
[507] | 277 | const int desiredSamples,
|
---|
| 278 | BeamSampleStatistics &stat
|
---|
| 279 | );
|
---|
| 280 |
|
---|
[1785] | 281 | virtual void InitGL();
|
---|
[540] | 282 |
|
---|
| 283 | /** Computes rays from information gained with hw sampling-
|
---|
| 284 | */
|
---|
[1785] | 285 | virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
[540] | 286 |
|
---|
[1785] | 287 | virtual int ComputePvs() const = 0;
|
---|
[540] | 288 |
|
---|
[1785] | 289 |
|
---|
| 290 | virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
|
---|
[713] | 291 |
|
---|
[1931] | 292 |
|
---|
| 293 |
|
---|
[997] | 294 |
|
---|
[1145] | 295 | protected:
|
---|
[1785] | 296 | unsigned int *mPixelBuffer;
|
---|
[811] | 297 |
|
---|
[1785] | 298 | static void GenQueries(const int numQueries);
|
---|
[589] | 299 |
|
---|
[1785] | 300 | virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
[589] | 301 | const Beam &beam,
|
---|
[746] | 302 |
|
---|
[525] | 303 | Intersectable *sourceObject);
|
---|
[746] | 304 |
|
---|
[1001] | 305 | /** Evaluates query for one direction using item buffer.
|
---|
| 306 | */
|
---|
[1785] | 307 | virtual void EvalQueryWithItemBuffer();
|
---|
[1146] | 308 |
|
---|
[1001] | 309 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 310 | */
|
---|
[1785] | 311 | virtual void EvalQueryWithOcclusionQueries();
|
---|
[997] | 312 |
|
---|
[746] | 313 | public:
|
---|
[1145] | 314 | // matt: remove qt dependencies
|
---|
| 315 | // signals:
|
---|
| 316 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
[496] | 317 | };
|
---|
| 318 |
|
---|
[1146] | 319 |
|
---|
| 320 | /** Abstract class for implmenenting a gl render widget.
|
---|
| 321 | */
|
---|
[1151] | 322 | class GlRendererWidget: public GlRenderer
|
---|
[1146] | 323 | {
|
---|
| 324 | public:
|
---|
| 325 |
|
---|
[1151] | 326 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
| 327 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
| 328 | {}
|
---|
[1146] | 329 |
|
---|
[1151] | 330 | GlRendererWidget() {}
|
---|
[1146] | 331 |
|
---|
[1151] | 332 | virtual ~GlRendererWidget() {}
|
---|
[1146] | 333 |
|
---|
| 334 | //virtual void Create() {}
|
---|
| 335 | virtual void Show() {}
|
---|
| 336 |
|
---|
| 337 |
|
---|
| 338 | protected:
|
---|
| 339 |
|
---|
| 340 |
|
---|
[1387] | 341 | // SceneGraph *mSceneGraph;
|
---|
| 342 | // ViewCellsManager *mViewCellsManager;
|
---|
| 343 | // KdTree *mKdTree;
|
---|
[608] | 344 | };
|
---|
| 345 |
|
---|
[1151] | 346 | //extern GlRendererWidget *rendererWidget;
|
---|
| 347 |
|
---|
[1146] | 348 | };
|
---|
[492] | 349 |
|
---|
[1387] | 350 | #endif
|
---|