1 | #ifndef __RENDERER_H
|
---|
2 | #define __RENDERER_H
|
---|
3 |
|
---|
4 | #include <QtOpenGL>
|
---|
5 | #include <QWaitCondition>
|
---|
6 | //#include <QGLPixelBuffer>
|
---|
7 |
|
---|
8 | #include "Vector3.h"
|
---|
9 | #include "Containers.h"
|
---|
10 | #include "Halton.h"
|
---|
11 | #include "Renderer.h"
|
---|
12 |
|
---|
13 | class SceneGraph;
|
---|
14 | class ViewCellsManager;
|
---|
15 | class Mesh;
|
---|
16 | class MeshInstance;
|
---|
17 | class Intersectable;
|
---|
18 | class Material;
|
---|
19 | class Beam;
|
---|
20 |
|
---|
21 | struct PvsRenderStatistics {
|
---|
22 |
|
---|
23 | float maxError;
|
---|
24 | float sumError;
|
---|
25 | int frames;
|
---|
26 | int errorFreeFrames;
|
---|
27 |
|
---|
28 | PvsRenderStatistics() { Reset(); }
|
---|
29 |
|
---|
30 | void Reset() {
|
---|
31 | maxError = 0.0f;
|
---|
32 | sumError = 0.0f;
|
---|
33 | frames = 0;
|
---|
34 | errorFreeFrames = 0;
|
---|
35 | }
|
---|
36 |
|
---|
37 | float GetMaxError() { return maxError; }
|
---|
38 | float GetAvgError() { return sumError/frames; }
|
---|
39 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
40 |
|
---|
41 | };
|
---|
42 |
|
---|
43 |
|
---|
44 | /** Class encapsulating gl rendering for the scene.
|
---|
45 | There is no gl context binding so the binding is performed in the
|
---|
46 | derived classes
|
---|
47 | */
|
---|
48 |
|
---|
49 | class GlRenderer: public Renderer
|
---|
50 | {
|
---|
51 |
|
---|
52 | public:
|
---|
53 | ObjectContainer mObjects;
|
---|
54 |
|
---|
55 | Vector3 mViewPoint;
|
---|
56 | Vector3 mViewDirection;
|
---|
57 |
|
---|
58 | int timerId;
|
---|
59 | bool mUseFalseColors;
|
---|
60 |
|
---|
61 | HaltonSequence halton;
|
---|
62 |
|
---|
63 | int mFrame;
|
---|
64 | bool mWireFrame;
|
---|
65 |
|
---|
66 | QWaitCondition mRenderingFinished;
|
---|
67 |
|
---|
68 |
|
---|
69 | GlRenderer(SceneGraph *sceneGraph,
|
---|
70 | ViewCellsManager *viewcells);
|
---|
71 |
|
---|
72 | ~GlRenderer();
|
---|
73 |
|
---|
74 |
|
---|
75 | void SetupFalseColor(const int id);
|
---|
76 | void RenderIntersectable(Intersectable *);
|
---|
77 | void RenderMeshInstance(MeshInstance *mi);
|
---|
78 | void RenderMesh(Mesh *m);
|
---|
79 | void SetupMaterial(Material *m);
|
---|
80 | virtual void SetupCamera();
|
---|
81 | void RandomViewPoint();
|
---|
82 |
|
---|
83 | bool
|
---|
84 | RenderScene();
|
---|
85 |
|
---|
86 | void
|
---|
87 | SetupProjection(const int w, const int h);
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | float
|
---|
92 | GetPixelError();
|
---|
93 |
|
---|
94 | void InitGL();
|
---|
95 |
|
---|
96 | virtual int GetWidth() const = 0;
|
---|
97 | virtual int GetHeight() const = 0;
|
---|
98 | };
|
---|
99 |
|
---|
100 |
|
---|
101 | class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
|
---|
102 | {
|
---|
103 |
|
---|
104 | public:
|
---|
105 | int mPvsStatFrames;
|
---|
106 | vector<float> mPvsErrorBuffer;
|
---|
107 |
|
---|
108 | PvsRenderStatistics mPvsStat;
|
---|
109 |
|
---|
110 |
|
---|
111 | GlRendererBuffer(const int w,
|
---|
112 | const int h,
|
---|
113 | SceneGraph *sceneGraph,
|
---|
114 | ViewCellsManager *viewcells):
|
---|
115 | QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
|
---|
116 |
|
---|
117 | mPvsStatFrames = 10000;
|
---|
118 | mPvsErrorBuffer.resize(mPvsStatFrames);
|
---|
119 | ClearErrorBuffer();
|
---|
120 |
|
---|
121 | makeCurrent();
|
---|
122 | InitGL();
|
---|
123 | doneCurrent();
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | void
|
---|
128 | EvalPvsStat();
|
---|
129 |
|
---|
130 | void
|
---|
131 | ClearErrorBuffer();
|
---|
132 |
|
---|
133 |
|
---|
134 | virtual int GetWidth() const { return width(); }
|
---|
135 | virtual int GetHeight() const { return height(); }
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 | // the values need for rss tree update computed already inside the glrendererbuffer
|
---|
140 | // not all of them need to be computed
|
---|
141 | struct BeamSampleStatistics {
|
---|
142 |
|
---|
143 | enum {COMPUTE_PVS_SIZE, COMPUTE_RAY_CONTRIBUTIONS, COMPUTE_PVS_ENTROPY};
|
---|
144 | int flags;
|
---|
145 |
|
---|
146 | BeamSampleStatistics():flags(COMPUTE_RAY_CONTRIBUTIONS) {}
|
---|
147 |
|
---|
148 | float pvsSize;
|
---|
149 | float rays;
|
---|
150 | float rayContributions;
|
---|
151 | float pvsEntropy;
|
---|
152 | float rayLengthEntropy;
|
---|
153 | float importance;
|
---|
154 |
|
---|
155 | float weightedRayContribution;
|
---|
156 | };
|
---|
157 |
|
---|
158 |
|
---|
159 | void SampleBeamContributions(
|
---|
160 | Intersectable *sourceObject,
|
---|
161 | Beam &beam,
|
---|
162 | const int samples,
|
---|
163 | BeamSampleStatistics &stat
|
---|
164 | );
|
---|
165 |
|
---|
166 | void
|
---|
167 | SampleViewpointContributions(
|
---|
168 | Intersectable *sourceObject,
|
---|
169 | const Vector3 viewPoint,
|
---|
170 | Beam &beam,
|
---|
171 | const int desiredSamples,
|
---|
172 | BeamSampleStatistics &stat
|
---|
173 | );
|
---|
174 |
|
---|
175 | private:
|
---|
176 | static void GenQueries(const int numQueries);
|
---|
177 |
|
---|
178 | };
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
183 | {
|
---|
184 | Q_OBJECT
|
---|
185 | public:
|
---|
186 |
|
---|
187 | // point of the last mouse click used for movement in the scene
|
---|
188 | Vector3 mousePoint;
|
---|
189 |
|
---|
190 | bool mTopView;
|
---|
191 |
|
---|
192 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
193 | ViewCellsManager *viewcells,
|
---|
194 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
195 | ):
|
---|
196 | GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
|
---|
197 | {
|
---|
198 | mTopView = false;
|
---|
199 | }
|
---|
200 |
|
---|
201 | virtual void SetupCamera();
|
---|
202 |
|
---|
203 | void initializeGL() {
|
---|
204 | InitGL();
|
---|
205 | }
|
---|
206 | void resizeGL(int w, int h);
|
---|
207 | void paintGL();
|
---|
208 | void timerEvent(QTimerEvent *) {
|
---|
209 | update();
|
---|
210 | }
|
---|
211 |
|
---|
212 | void mousePressEvent(QMouseEvent *);
|
---|
213 | void mouseReleaseEvent(QMouseEvent *);
|
---|
214 | void mouseMoveEvent(QMouseEvent *);
|
---|
215 |
|
---|
216 | void keyPressEvent ( QKeyEvent * e ) ;
|
---|
217 |
|
---|
218 | float
|
---|
219 | RenderErrors();
|
---|
220 |
|
---|
221 | virtual int GetWidth() const { return width(); }
|
---|
222 | virtual int GetHeight() const { return height(); }
|
---|
223 |
|
---|
224 | };
|
---|
225 |
|
---|
226 |
|
---|
227 | extern GlRendererWidget *rendererWidget;
|
---|
228 |
|
---|
229 | #endif
|
---|
230 |
|
---|