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