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