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