[865] | 1 | #ifndef __GLRENDERER_H
|
---|
| 2 | #define __GLRENDERER_H
|
---|
[492] | 3 |
|
---|
[1001] | 4 | //#include "glInterface.h"
|
---|
[492] | 5 | #include <QtOpenGL>
|
---|
| 6 | #include <QWaitCondition>
|
---|
[1001] | 7 |
|
---|
[500] | 8 | //#include <QGLPixelBuffer>
|
---|
[492] | 9 |
|
---|
| 10 | #include "Vector3.h"
|
---|
| 11 | #include "Containers.h"
|
---|
| 12 | #include "Halton.h"
|
---|
[497] | 13 | #include "Renderer.h"
|
---|
[540] | 14 | #include "Beam.h"
|
---|
[492] | 15 |
|
---|
[863] | 16 | class QWidget;
|
---|
| 17 |
|
---|
[860] | 18 | namespace GtpVisibilityPreprocessor {
|
---|
| 19 |
|
---|
[492] | 20 | class SceneGraph;
|
---|
| 21 | class ViewCellsManager;
|
---|
| 22 | class Mesh;
|
---|
| 23 | class MeshInstance;
|
---|
| 24 | class Intersectable;
|
---|
| 25 | class Material;
|
---|
[512] | 26 | class Beam;
|
---|
[532] | 27 | class KdTree;
|
---|
[538] | 28 | class GlRendererBuffer;
|
---|
[531] | 29 | class BeamSampleStatistics;
|
---|
[1001] | 30 | class OcclusionQuery;
|
---|
| 31 | class TransformedMeshInstance;
|
---|
[531] | 32 |
|
---|
[540] | 33 | struct VssRayContainer;
|
---|
| 34 |
|
---|
[492] | 35 | struct PvsRenderStatistics {
|
---|
| 36 |
|
---|
| 37 | float maxError;
|
---|
| 38 | float sumError;
|
---|
[713] | 39 | int sumPvsSize;
|
---|
[492] | 40 | int frames;
|
---|
| 41 | int errorFreeFrames;
|
---|
[502] | 42 |
|
---|
[492] | 43 | PvsRenderStatistics() { Reset(); }
|
---|
| 44 |
|
---|
[498] | 45 | void Reset() {
|
---|
[492] | 46 | maxError = 0.0f;
|
---|
| 47 | sumError = 0.0f;
|
---|
| 48 | frames = 0;
|
---|
| 49 | errorFreeFrames = 0;
|
---|
[713] | 50 | sumPvsSize = 0;
|
---|
[492] | 51 | }
|
---|
| 52 |
|
---|
| 53 | float GetMaxError() { return maxError; }
|
---|
| 54 | float GetAvgError() { return sumError/frames; }
|
---|
| 55 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
[713] | 56 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
[492] | 57 |
|
---|
| 58 | };
|
---|
| 59 |
|
---|
[811] | 60 | struct RenderCostSample {
|
---|
[496] | 61 |
|
---|
[811] | 62 | RenderCostSample() {}
|
---|
| 63 |
|
---|
| 64 | void Reset() {
|
---|
| 65 | mVisibleObjects = 0;
|
---|
| 66 | mVisiblePixels = 0;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[991] | 69 | Vector3 mPosition;
|
---|
| 70 |
|
---|
[811] | 71 | // visible object from the given point
|
---|
| 72 | int mVisibleObjects;
|
---|
| 73 |
|
---|
| 74 | // visible pixels
|
---|
| 75 | int mVisiblePixels;
|
---|
| 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 | */
|
---|
| 83 |
|
---|
[497] | 84 | class GlRenderer: public Renderer
|
---|
[492] | 85 | {
|
---|
[496] | 86 |
|
---|
[492] | 87 | public:
|
---|
| 88 | ObjectContainer mObjects;
|
---|
[498] | 89 |
|
---|
[492] | 90 | Vector3 mViewPoint;
|
---|
| 91 | Vector3 mViewDirection;
|
---|
| 92 |
|
---|
| 93 | int timerId;
|
---|
| 94 | bool mUseFalseColors;
|
---|
[746] | 95 | bool mUseForcedColors;
|
---|
[492] | 96 |
|
---|
| 97 | HaltonSequence halton;
|
---|
| 98 |
|
---|
| 99 | int mFrame;
|
---|
[502] | 100 | bool mWireFrame;
|
---|
[589] | 101 |
|
---|
[811] | 102 | bool mDetectEmptyViewSpace;
|
---|
[589] | 103 | bool mSnapErrorFrames;
|
---|
[811] | 104 |
|
---|
| 105 | bool mUseGlLists;
|
---|
| 106 |
|
---|
[589] | 107 | QString mSnapPrefix;
|
---|
[502] | 108 |
|
---|
[532] | 109 | KdTree *mKdTree;
|
---|
| 110 |
|
---|
[492] | 111 | QWaitCondition mRenderingFinished;
|
---|
| 112 |
|
---|
[1001] | 113 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
[492] | 114 |
|
---|
| 115 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[532] | 116 | ViewCellsManager *viewcells,
|
---|
| 117 | KdTree *tree);
|
---|
[496] | 118 |
|
---|
[492] | 119 | ~GlRenderer();
|
---|
| 120 |
|
---|
[496] | 121 |
|
---|
[492] | 122 | void SetupFalseColor(const int id);
|
---|
| 123 | void RenderIntersectable(Intersectable *);
|
---|
[535] | 124 | void RenderViewCell(ViewCell *vc);
|
---|
[492] | 125 | void RenderMeshInstance(MeshInstance *mi);
|
---|
[1001] | 126 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
[492] | 127 | void RenderMesh(Mesh *m);
|
---|
| 128 | void SetupMaterial(Material *m);
|
---|
[502] | 129 | virtual void SetupCamera();
|
---|
[496] | 130 |
|
---|
[497] | 131 | bool
|
---|
[496] | 132 | RenderScene();
|
---|
[492] | 133 |
|
---|
[811] | 134 | void
|
---|
| 135 | _RenderScene();
|
---|
[589] | 136 |
|
---|
[811] | 137 |
|
---|
[608] | 138 | virtual void
|
---|
[811] | 139 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[496] | 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | void InitGL();
|
---|
| 145 |
|
---|
| 146 | virtual int GetWidth() const = 0;
|
---|
| 147 | virtual int GetHeight() const = 0;
|
---|
[540] | 148 |
|
---|
| 149 | int GetId(int r, int g, int b) const;
|
---|
[496] | 150 | };
|
---|
| 151 |
|
---|
| 152 |
|
---|
[865] | 153 | class GlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRenderer
|
---|
[496] | 154 | {
|
---|
[746] | 155 | Q_OBJECT
|
---|
[496] | 156 | public:
|
---|
[811] | 157 | GlRendererBuffer(const int w,
|
---|
| 158 | const int h,
|
---|
| 159 | SceneGraph *sceneGraph,
|
---|
| 160 | ViewCellsManager *viewcells,
|
---|
| 161 | KdTree *tree);
|
---|
[589] | 162 |
|
---|
[811] | 163 |
|
---|
[1001] | 164 | /** Evaluates render cost of a point sample.
|
---|
| 165 | @param sample the render cost sample to be evaluated
|
---|
| 166 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 167 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 168 | */
|
---|
| 169 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 170 | const bool useOcclusionQueries,
|
---|
| 171 | const int threshold);
|
---|
[811] | 172 |
|
---|
[1001] | 173 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
| 174 | are distributed uniformly over the defined view space.
|
---|
[811] | 175 |
|
---|
[1001] | 176 | @param numSamples the number of point samples taken
|
---|
| 177 | @param samples stores the taken point samples in a container
|
---|
| 178 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 179 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 180 | */
|
---|
| 181 | void SampleRenderCost(const int numSamples,
|
---|
| 182 | vector<RenderCostSample> &samples,
|
---|
| 183 | const bool useOcclusionQueries,
|
---|
| 184 | const int threshold = 0);
|
---|
[811] | 185 |
|
---|
[1001] | 186 |
|
---|
[811] | 187 | void
|
---|
[496] | 188 | EvalPvsStat();
|
---|
| 189 |
|
---|
| 190 | void
|
---|
| 191 | ClearErrorBuffer();
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | virtual int GetWidth() const { return width(); }
|
---|
| 195 | virtual int GetHeight() const { return height(); }
|
---|
| 196 |
|
---|
[507] | 197 |
|
---|
[563] | 198 | void RandomViewPoint();
|
---|
[507] | 199 | void SampleBeamContributions(
|
---|
| 200 | Intersectable *sourceObject,
|
---|
[512] | 201 | Beam &beam,
|
---|
[507] | 202 | const int samples,
|
---|
| 203 | BeamSampleStatistics &stat
|
---|
| 204 | );
|
---|
| 205 |
|
---|
| 206 | void
|
---|
| 207 | SampleViewpointContributions(
|
---|
| 208 | Intersectable *sourceObject,
|
---|
[514] | 209 | const Vector3 viewPoint,
|
---|
[512] | 210 | Beam &beam,
|
---|
[507] | 211 | const int desiredSamples,
|
---|
| 212 | BeamSampleStatistics &stat
|
---|
| 213 | );
|
---|
| 214 |
|
---|
[540] | 215 | void InitGL();
|
---|
| 216 |
|
---|
| 217 | /** Computes rays from information gained with hw sampling-
|
---|
| 218 | */
|
---|
| 219 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
| 220 |
|
---|
| 221 | int ComputePvs() const;
|
---|
| 222 |
|
---|
[576] | 223 | float
|
---|
[713] | 224 | GetPixelError(int &pvsSize);
|
---|
[540] | 225 |
|
---|
| 226 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
| 227 |
|
---|
| 228 | PvsRenderStatistics mPvsStat;
|
---|
[532] | 229 |
|
---|
[540] | 230 | int mPvsStatFrames;
|
---|
[713] | 231 | struct PvsErrorEntry {
|
---|
| 232 | PvsErrorEntry() {}
|
---|
| 233 | float mError;
|
---|
| 234 | int mPvsSize;
|
---|
[746] | 235 | Vector3 mPosition;
|
---|
| 236 | Vector3 mDirection;
|
---|
[713] | 237 | };
|
---|
| 238 |
|
---|
| 239 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
| 240 |
|
---|
[997] | 241 |
|
---|
[513] | 242 | private:
|
---|
[811] | 243 | unsigned int *mPixelBuffer;
|
---|
| 244 |
|
---|
[513] | 245 | static void GenQueries(const int numQueries);
|
---|
[589] | 246 |
|
---|
| 247 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 248 | const Beam &beam,
|
---|
[746] | 249 |
|
---|
[525] | 250 | Intersectable *sourceObject);
|
---|
[746] | 251 |
|
---|
[1001] | 252 | /** Evaluates query for one direction using item buffer.
|
---|
| 253 | */
|
---|
[997] | 254 | void EvalQueryWithItemBuffer();
|
---|
[1001] | 255 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 256 | */
|
---|
[997] | 257 | void EvalQueryWithOcclusionQueries();
|
---|
| 258 |
|
---|
[746] | 259 | public:
|
---|
| 260 | signals:
|
---|
[1008] | 261 | void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
[496] | 262 | };
|
---|
| 263 |
|
---|
| 264 |
|
---|
[608] | 265 | class RendererControlWidget : public QWidget
|
---|
| 266 | {
|
---|
| 267 | Q_OBJECT
|
---|
| 268 | public:
|
---|
[746] | 269 |
|
---|
| 270 | QListWidget *mPvsErrorWidget;
|
---|
| 271 |
|
---|
[608] | 272 | RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
|
---|
[496] | 273 |
|
---|
[746] | 274 | public slots:
|
---|
| 275 |
|
---|
| 276 | void FocusNextPvsErrorFrame();
|
---|
| 277 | void UpdatePvsErrorItem(int i,
|
---|
| 278 | GlRendererBuffer::PvsErrorEntry &);
|
---|
| 279 |
|
---|
[608] | 280 | signals:
|
---|
| 281 |
|
---|
[1006] | 282 | void SetViewCellGranularity(int);
|
---|
| 283 | void SetSceneCut(int);
|
---|
| 284 | void SetTopDistance(int);
|
---|
| 285 | void SetVisibilityFilterSize(int);
|
---|
| 286 | void SetSpatialFilterSize(int);
|
---|
[608] | 287 |
|
---|
[1006] | 288 | void SetRenderFilter(bool);
|
---|
| 289 | void SetUseFilter(bool);
|
---|
| 290 | void SetUseSpatialFilter(bool);
|
---|
| 291 | void SetRenderErrors(bool);
|
---|
| 292 | void SetShowViewCells(bool);
|
---|
| 293 | void SetShowRenderCost(bool);
|
---|
| 294 | void SetShowPvsSizes(bool);
|
---|
| 295 | void SetTopView(bool);
|
---|
| 296 | void SetCutViewCells(bool);
|
---|
| 297 | void SetCutScene(bool);
|
---|
[608] | 298 |
|
---|
[746] | 299 |
|
---|
[608] | 300 | };
|
---|
| 301 |
|
---|
[496] | 302 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
| 303 | {
|
---|
| 304 | Q_OBJECT
|
---|
| 305 | public:
|
---|
| 306 |
|
---|
[502] | 307 | // point of the last mouse click used for movement in the scene
|
---|
| 308 | Vector3 mousePoint;
|
---|
| 309 |
|
---|
| 310 | bool mTopView;
|
---|
[599] | 311 | bool mRenderViewCells;
|
---|
[608] | 312 | bool mCutViewCells;
|
---|
| 313 | bool mCutScene;
|
---|
[746] | 314 | bool mRenderErrors;
|
---|
| 315 | bool mRenderFilter;
|
---|
[884] | 316 | bool mUseFilter;
|
---|
| 317 | bool mUseSpatialFilter;
|
---|
[746] | 318 | bool mShowRenderCost;
|
---|
[884] | 319 |
|
---|
[746] | 320 | bool mShowPvsSizes;
|
---|
[884] | 321 | float mSpatialFilterSize;
|
---|
| 322 |
|
---|
[608] | 323 | Plane3 mSceneCutPlane;
|
---|
| 324 | float mTopDistance;
|
---|
[746] | 325 |
|
---|
| 326 | // some statistics
|
---|
| 327 | int mPvsSize;
|
---|
| 328 | float mRenderError;
|
---|
| 329 |
|
---|
| 330 | RendererControlWidget *mControlWidget;
|
---|
[608] | 331 |
|
---|
[496] | 332 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
| 333 | ViewCellsManager *viewcells,
|
---|
[532] | 334 | KdTree *tree,
|
---|
[496] | 335 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
[599] | 336 | );
|
---|
[496] | 337 |
|
---|
[599] | 338 |
|
---|
[502] | 339 | virtual void SetupCamera();
|
---|
| 340 |
|
---|
[496] | 341 | void initializeGL() {
|
---|
| 342 | InitGL();
|
---|
| 343 | }
|
---|
[492] | 344 | void resizeGL(int w, int h);
|
---|
| 345 | void paintGL();
|
---|
| 346 | void timerEvent(QTimerEvent *) {
|
---|
| 347 | update();
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | void mousePressEvent(QMouseEvent *);
|
---|
| 351 | void mouseReleaseEvent(QMouseEvent *);
|
---|
| 352 | void mouseMoveEvent(QMouseEvent *);
|
---|
| 353 |
|
---|
[504] | 354 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
[746] | 355 |
|
---|
| 356 | void
|
---|
| 357 | RenderPvs();
|
---|
| 358 |
|
---|
[492] | 359 | float
|
---|
[589] | 360 | RenderErrors();
|
---|
| 361 | void
|
---|
| 362 | RenderInfo();
|
---|
[492] | 363 |
|
---|
[496] | 364 | virtual int GetWidth() const { return width(); }
|
---|
| 365 | virtual int GetHeight() const { return height(); }
|
---|
[599] | 366 |
|
---|
[1004] | 367 | virtual void
|
---|
| 368 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[599] | 369 |
|
---|
| 370 | void
|
---|
| 371 | RenderViewCells();
|
---|
| 372 |
|
---|
| 373 | public slots:
|
---|
| 374 |
|
---|
[746] | 375 | void SetRenderErrors(bool b) {
|
---|
| 376 | mRenderErrors = b;
|
---|
| 377 | updateGL();
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | void SetRenderFilter(bool b) {
|
---|
| 381 | mRenderFilter = b;
|
---|
| 382 | updateGL();
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[884] | 385 | void SetUseFilter(bool b) {
|
---|
| 386 | mUseFilter = b;
|
---|
| 387 | updateGL();
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | void SetUseSpatialFilter(bool b) {
|
---|
| 391 | mUseSpatialFilter = b;
|
---|
| 392 | updateGL();
|
---|
| 393 | }
|
---|
| 394 |
|
---|
[746] | 395 |
|
---|
[713] | 396 | void
|
---|
[746] | 397 | SetViewCellGranularity(int number);
|
---|
| 398 |
|
---|
| 399 | void
|
---|
[713] | 400 | SetVisibilityFilterSize(int number);
|
---|
[884] | 401 |
|
---|
| 402 | void
|
---|
| 403 | SetSpatialFilterSize(int number);
|
---|
[746] | 404 |
|
---|
[713] | 405 | void
|
---|
| 406 | SetSceneCut(int cut);
|
---|
| 407 |
|
---|
| 408 | void
|
---|
| 409 | SetTopDistance(int dist);
|
---|
| 410 |
|
---|
[608] | 411 | void SetShowViewCells(bool b) {
|
---|
| 412 | mRenderViewCells = b;
|
---|
| 413 | updateGL();
|
---|
| 414 | }
|
---|
[746] | 415 |
|
---|
| 416 | void SetShowRenderCost(bool b) {
|
---|
| 417 | mShowRenderCost = b;
|
---|
| 418 | updateGL();
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | void SetShowPvsSizes(bool b) {
|
---|
| 422 | mShowPvsSizes = b;
|
---|
| 423 | updateGL();
|
---|
| 424 | }
|
---|
| 425 |
|
---|
[608] | 426 | void SetTopView(bool b) {
|
---|
| 427 | mTopView = b;
|
---|
| 428 | updateGL();
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | void SetCutViewCells(bool b) {
|
---|
| 432 | mCutViewCells = b;
|
---|
| 433 | updateGL();
|
---|
| 434 | }
|
---|
| 435 | void SetCutScene(bool b) {
|
---|
| 436 | mCutScene = b;
|
---|
| 437 | updateGL();
|
---|
| 438 | }
|
---|
| 439 |
|
---|
[746] | 440 |
|
---|
[492] | 441 | };
|
---|
| 442 |
|
---|
| 443 |
|
---|
[496] | 444 | extern GlRendererWidget *rendererWidget;
|
---|
[492] | 445 |
|
---|
[538] | 446 | class GlDebuggerWidget : public QGLWidget
|
---|
| 447 | {
|
---|
[540] | 448 | Q_OBJECT
|
---|
[538] | 449 | public:
|
---|
[540] | 450 | GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL);
|
---|
[538] | 451 | ~GlDebuggerWidget();
|
---|
| 452 | void initializeGL();
|
---|
| 453 | void resizeGL(int w, int h);
|
---|
| 454 | void paintGL();
|
---|
| 455 | void timerEvent(QTimerEvent *) { update(); }
|
---|
| 456 | void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
|
---|
| 457 | void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }
|
---|
| 458 |
|
---|
| 459 | void initCommon();
|
---|
| 460 | void initPbuffer();
|
---|
| 461 |
|
---|
[608] | 462 |
|
---|
[538] | 463 | GlRendererBuffer *mRenderBuffer;
|
---|
| 464 |
|
---|
[540] | 465 | Beam mBeam;
|
---|
| 466 | int mSamples;
|
---|
| 467 | Intersectable *mSourceObject;
|
---|
[608] | 468 |
|
---|
[538] | 469 | private:
|
---|
| 470 | GLuint dynamicTexture;
|
---|
| 471 | int timerId;
|
---|
| 472 | };
|
---|
| 473 |
|
---|
| 474 | extern GlDebuggerWidget *debuggerWidget;
|
---|
| 475 |
|
---|
[863] | 476 | };
|
---|
[860] | 477 |
|
---|
[492] | 478 | #endif
|
---|
| 479 |
|
---|