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