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