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