[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"
|
---|
[492] | 12 |
|
---|
| 13 | class SceneGraph;
|
---|
| 14 | class ViewCellsManager;
|
---|
| 15 | class Mesh;
|
---|
| 16 | class MeshInstance;
|
---|
| 17 | class Intersectable;
|
---|
| 18 | class Material;
|
---|
| 19 |
|
---|
| 20 | struct PvsRenderStatistics {
|
---|
| 21 |
|
---|
| 22 | float maxError;
|
---|
| 23 | float sumError;
|
---|
| 24 | int frames;
|
---|
| 25 | int errorFreeFrames;
|
---|
[502] | 26 |
|
---|
[492] | 27 | PvsRenderStatistics() { Reset(); }
|
---|
| 28 |
|
---|
[498] | 29 | void Reset() {
|
---|
[492] | 30 | maxError = 0.0f;
|
---|
| 31 | sumError = 0.0f;
|
---|
| 32 | frames = 0;
|
---|
| 33 | errorFreeFrames = 0;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | float GetMaxError() { return maxError; }
|
---|
| 37 | float GetAvgError() { return sumError/frames; }
|
---|
| 38 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
| 39 |
|
---|
| 40 | };
|
---|
| 41 |
|
---|
[496] | 42 |
|
---|
| 43 | /** Class encapsulating gl rendering for the scene.
|
---|
| 44 | There is no gl context binding so the binding is performed in the
|
---|
| 45 | derived classes
|
---|
| 46 | */
|
---|
| 47 |
|
---|
[497] | 48 | class GlRenderer: public Renderer
|
---|
[492] | 49 | {
|
---|
[496] | 50 |
|
---|
[492] | 51 | public:
|
---|
| 52 | ObjectContainer mObjects;
|
---|
[498] | 53 |
|
---|
[492] | 54 | Vector3 mViewPoint;
|
---|
| 55 | Vector3 mViewDirection;
|
---|
| 56 |
|
---|
| 57 | int timerId;
|
---|
| 58 | bool mUseFalseColors;
|
---|
| 59 |
|
---|
| 60 | HaltonSequence halton;
|
---|
| 61 |
|
---|
| 62 | int mFrame;
|
---|
[502] | 63 | bool mWireFrame;
|
---|
| 64 |
|
---|
[492] | 65 | QWaitCondition mRenderingFinished;
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[496] | 69 | ViewCellsManager *viewcells);
|
---|
| 70 |
|
---|
[492] | 71 | ~GlRenderer();
|
---|
| 72 |
|
---|
[496] | 73 |
|
---|
[492] | 74 | void SetupFalseColor(const int id);
|
---|
| 75 | void RenderIntersectable(Intersectable *);
|
---|
| 76 | void RenderMeshInstance(MeshInstance *mi);
|
---|
| 77 | void RenderMesh(Mesh *m);
|
---|
| 78 | void SetupMaterial(Material *m);
|
---|
[502] | 79 | virtual void SetupCamera();
|
---|
[492] | 80 | void RandomViewPoint();
|
---|
[496] | 81 |
|
---|
[497] | 82 | bool
|
---|
[496] | 83 | RenderScene();
|
---|
[492] | 84 |
|
---|
[496] | 85 | void
|
---|
| 86 | SetupProjection(const int w, const int h);
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | float
|
---|
| 91 | GetPixelError();
|
---|
| 92 |
|
---|
| 93 | void InitGL();
|
---|
| 94 |
|
---|
| 95 | virtual int GetWidth() const = 0;
|
---|
| 96 | virtual int GetHeight() const = 0;
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
|
---|
| 101 | {
|
---|
| 102 |
|
---|
| 103 | public:
|
---|
| 104 | int mPvsStatFrames;
|
---|
| 105 | vector<float> mPvsErrorBuffer;
|
---|
| 106 |
|
---|
| 107 | PvsRenderStatistics mPvsStat;
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | GlRendererBuffer(const int w,
|
---|
| 111 | const int h,
|
---|
| 112 | SceneGraph *sceneGraph,
|
---|
| 113 | ViewCellsManager *viewcells):
|
---|
| 114 | QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
|
---|
| 115 |
|
---|
| 116 | mPvsStatFrames = 10000;
|
---|
| 117 | mPvsErrorBuffer.resize(mPvsStatFrames);
|
---|
| 118 | ClearErrorBuffer();
|
---|
| 119 |
|
---|
| 120 | makeCurrent();
|
---|
| 121 | InitGL();
|
---|
[502] | 122 | doneCurrent();
|
---|
| 123 |
|
---|
[496] | 124 | }
|
---|
| 125 |
|
---|
| 126 | void
|
---|
| 127 | EvalPvsStat();
|
---|
| 128 |
|
---|
| 129 | void
|
---|
| 130 | ClearErrorBuffer();
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | virtual int GetWidth() const { return width(); }
|
---|
| 135 | virtual int GetHeight() const { return height(); }
|
---|
| 136 |
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
| 142 | {
|
---|
| 143 | Q_OBJECT
|
---|
| 144 | public:
|
---|
| 145 |
|
---|
[502] | 146 | // point of the last mouse click used for movement in the scene
|
---|
| 147 | Vector3 mousePoint;
|
---|
| 148 |
|
---|
| 149 | bool mTopView;
|
---|
| 150 |
|
---|
[496] | 151 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
| 152 | ViewCellsManager *viewcells,
|
---|
| 153 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
| 154 | ):
|
---|
| 155 | GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
|
---|
[502] | 156 | {
|
---|
| 157 | mTopView = false;
|
---|
| 158 | }
|
---|
[496] | 159 |
|
---|
[502] | 160 | virtual void SetupCamera();
|
---|
| 161 |
|
---|
[496] | 162 | void initializeGL() {
|
---|
| 163 | InitGL();
|
---|
| 164 | }
|
---|
[492] | 165 | void resizeGL(int w, int h);
|
---|
| 166 | void paintGL();
|
---|
| 167 | void timerEvent(QTimerEvent *) {
|
---|
| 168 | update();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | void mousePressEvent(QMouseEvent *);
|
---|
| 172 | void mouseReleaseEvent(QMouseEvent *);
|
---|
| 173 | void mouseMoveEvent(QMouseEvent *);
|
---|
| 174 |
|
---|
| 175 | float
|
---|
[496] | 176 | RenderErrors();
|
---|
[492] | 177 |
|
---|
[496] | 178 | virtual int GetWidth() const { return width(); }
|
---|
| 179 | virtual int GetHeight() const { return height(); }
|
---|
[492] | 180 |
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 |
|
---|
[496] | 184 | extern GlRendererWidget *rendererWidget;
|
---|
[492] | 185 |
|
---|
| 186 | #endif
|
---|
| 187 |
|
---|