[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 |
|
---|
[811] | 192 |
|
---|
[1001] | 193 | /** Evaluates render cost of a point sample.
|
---|
| 194 | @param sample the render cost sample to be evaluated
|
---|
| 195 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 196 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 197 | */
|
---|
| 198 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 199 | const bool useOcclusionQueries,
|
---|
| 200 | const int threshold);
|
---|
[811] | 201 |
|
---|
[1001] | 202 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
| 203 | are distributed uniformly over the defined view space.
|
---|
[811] | 204 |
|
---|
[1001] | 205 | @param numSamples the number of point samples taken
|
---|
| 206 | @param samples stores the taken point samples in a container
|
---|
| 207 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 208 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 209 | */
|
---|
| 210 | void SampleRenderCost(const int numSamples,
|
---|
| 211 | vector<RenderCostSample> &samples,
|
---|
| 212 | const bool useOcclusionQueries,
|
---|
[1145] | 213 | const int threshold = 0)
|
---|
| 214 | {}
|
---|
[811] | 215 |
|
---|
[1145] | 216 | /** Implerment in subclasses.
|
---|
| 217 | */
|
---|
| 218 | void EvalPvsStat() {};
|
---|
[1001] | 219 |
|
---|
[1145] | 220 | void ClearErrorBuffer();
|
---|
[496] | 221 |
|
---|
| 222 |
|
---|
[1145] | 223 | virtual int GetWidth() const { return 0; }
|
---|
| 224 | virtual int GetHeight() const { return 0; }
|
---|
[496] | 225 |
|
---|
[507] | 226 |
|
---|
[563] | 227 | void RandomViewPoint();
|
---|
[507] | 228 | void SampleBeamContributions(
|
---|
| 229 | Intersectable *sourceObject,
|
---|
[512] | 230 | Beam &beam,
|
---|
[507] | 231 | const int samples,
|
---|
| 232 | BeamSampleStatistics &stat
|
---|
| 233 | );
|
---|
| 234 |
|
---|
| 235 | void
|
---|
| 236 | SampleViewpointContributions(
|
---|
| 237 | Intersectable *sourceObject,
|
---|
[514] | 238 | const Vector3 viewPoint,
|
---|
[512] | 239 | Beam &beam,
|
---|
[507] | 240 | const int desiredSamples,
|
---|
| 241 | BeamSampleStatistics &stat
|
---|
| 242 | );
|
---|
| 243 |
|
---|
[540] | 244 | void InitGL();
|
---|
| 245 |
|
---|
| 246 | /** Computes rays from information gained with hw sampling-
|
---|
| 247 | */
|
---|
| 248 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
| 249 |
|
---|
| 250 | int ComputePvs() const;
|
---|
| 251 |
|
---|
[576] | 252 | float
|
---|
[713] | 253 | GetPixelError(int &pvsSize);
|
---|
[540] | 254 |
|
---|
| 255 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
| 256 |
|
---|
| 257 | PvsRenderStatistics mPvsStat;
|
---|
[532] | 258 |
|
---|
[540] | 259 | int mPvsStatFrames;
|
---|
[713] | 260 | struct PvsErrorEntry {
|
---|
[1145] | 261 | PvsErrorEntry() {}
|
---|
| 262 | float mError;
|
---|
| 263 | int mPvsSize;
|
---|
| 264 | Vector3 mPosition;
|
---|
| 265 | Vector3 mDirection;
|
---|
[713] | 266 | };
|
---|
| 267 |
|
---|
| 268 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
| 269 |
|
---|
[997] | 270 |
|
---|
[1145] | 271 | protected:
|
---|
| 272 | unsigned int *mPixelBuffer;
|
---|
[811] | 273 |
|
---|
[513] | 274 | static void GenQueries(const int numQueries);
|
---|
[589] | 275 |
|
---|
| 276 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 277 | const Beam &beam,
|
---|
[746] | 278 |
|
---|
[525] | 279 | Intersectable *sourceObject);
|
---|
[746] | 280 |
|
---|
[1001] | 281 | /** Evaluates query for one direction using item buffer.
|
---|
| 282 | */
|
---|
[997] | 283 | void EvalQueryWithItemBuffer();
|
---|
[1146] | 284 |
|
---|
[1001] | 285 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 286 | */
|
---|
[997] | 287 | void EvalQueryWithOcclusionQueries();
|
---|
| 288 |
|
---|
[746] | 289 | public:
|
---|
[1145] | 290 | // matt: remove qt dependencies
|
---|
| 291 | // signals:
|
---|
| 292 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
[496] | 293 | };
|
---|
| 294 |
|
---|
[1146] | 295 |
|
---|
| 296 | /** Abstract class for implmenenting a gl render widget.
|
---|
| 297 | */
|
---|
[1151] | 298 | class GlRendererWidget: public GlRenderer
|
---|
[1146] | 299 | {
|
---|
| 300 | public:
|
---|
| 301 |
|
---|
[1151] | 302 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
| 303 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
| 304 | {}
|
---|
[1146] | 305 |
|
---|
[1151] | 306 | GlRendererWidget() {}
|
---|
[1146] | 307 |
|
---|
[1151] | 308 | virtual ~GlRendererWidget() {}
|
---|
[1146] | 309 |
|
---|
| 310 | //virtual void Create() {}
|
---|
| 311 | virtual void Show() {}
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 | protected:
|
---|
| 315 |
|
---|
| 316 |
|
---|
[1387] | 317 | // SceneGraph *mSceneGraph;
|
---|
| 318 | // ViewCellsManager *mViewCellsManager;
|
---|
| 319 | // KdTree *mKdTree;
|
---|
[608] | 320 | };
|
---|
| 321 |
|
---|
[1151] | 322 | //extern GlRendererWidget *rendererWidget;
|
---|
| 323 |
|
---|
[1146] | 324 | };
|
---|
[492] | 325 |
|
---|
[1387] | 326 | #endif
|
---|