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 |
|
---|
20 | struct PvsRenderStatistics {
|
---|
21 |
|
---|
22 | float maxError;
|
---|
23 | float sumError;
|
---|
24 | int frames;
|
---|
25 | int errorFreeFrames;
|
---|
26 |
|
---|
27 | PvsRenderStatistics() { Reset(); }
|
---|
28 |
|
---|
29 | void Reset() {
|
---|
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 |
|
---|
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 |
|
---|
48 | class GlRenderer: public Renderer
|
---|
49 | {
|
---|
50 |
|
---|
51 | public:
|
---|
52 | ObjectContainer mObjects;
|
---|
53 |
|
---|
54 | Vector3 mViewPoint;
|
---|
55 | Vector3 mViewDirection;
|
---|
56 |
|
---|
57 | int timerId;
|
---|
58 | bool mUseFalseColors;
|
---|
59 |
|
---|
60 | HaltonSequence halton;
|
---|
61 |
|
---|
62 | int mFrame;
|
---|
63 |
|
---|
64 | QWaitCondition mRenderingFinished;
|
---|
65 |
|
---|
66 |
|
---|
67 | GlRenderer(SceneGraph *sceneGraph,
|
---|
68 | ViewCellsManager *viewcells);
|
---|
69 |
|
---|
70 | ~GlRenderer();
|
---|
71 |
|
---|
72 |
|
---|
73 | void SetupFalseColor(const int id);
|
---|
74 | void RenderIntersectable(Intersectable *);
|
---|
75 | void RenderMeshInstance(MeshInstance *mi);
|
---|
76 | void RenderMesh(Mesh *m);
|
---|
77 | void SetupMaterial(Material *m);
|
---|
78 | void SetupCamera();
|
---|
79 | void RandomViewPoint();
|
---|
80 |
|
---|
81 | bool
|
---|
82 | RenderScene();
|
---|
83 |
|
---|
84 | void
|
---|
85 | SetupProjection(const int w, const int h);
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | float
|
---|
90 | GetPixelError();
|
---|
91 |
|
---|
92 | void InitGL();
|
---|
93 |
|
---|
94 | virtual int GetWidth() const = 0;
|
---|
95 | virtual int GetHeight() const = 0;
|
---|
96 | };
|
---|
97 |
|
---|
98 |
|
---|
99 | class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
|
---|
100 | {
|
---|
101 |
|
---|
102 | public:
|
---|
103 | int mPvsStatFrames;
|
---|
104 | vector<float> mPvsErrorBuffer;
|
---|
105 |
|
---|
106 | PvsRenderStatistics mPvsStat;
|
---|
107 |
|
---|
108 |
|
---|
109 | GlRendererBuffer(const int w,
|
---|
110 | const int h,
|
---|
111 | SceneGraph *sceneGraph,
|
---|
112 | ViewCellsManager *viewcells):
|
---|
113 | QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) {
|
---|
114 |
|
---|
115 | mPvsStatFrames = 10000;
|
---|
116 | mPvsErrorBuffer.resize(mPvsStatFrames);
|
---|
117 | ClearErrorBuffer();
|
---|
118 |
|
---|
119 | makeCurrent();
|
---|
120 | InitGL();
|
---|
121 |
|
---|
122 | }
|
---|
123 |
|
---|
124 | void
|
---|
125 | EvalPvsStat();
|
---|
126 |
|
---|
127 | void
|
---|
128 | ClearErrorBuffer();
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 | virtual int GetWidth() const { return width(); }
|
---|
133 | virtual int GetHeight() const { return height(); }
|
---|
134 |
|
---|
135 | };
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 | class GlRendererWidget : public QGLWidget, public GlRenderer
|
---|
140 | {
|
---|
141 | Q_OBJECT
|
---|
142 | public:
|
---|
143 |
|
---|
144 | GlRendererWidget(SceneGraph *sceneGraph,
|
---|
145 | ViewCellsManager *viewcells,
|
---|
146 | QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0
|
---|
147 | ):
|
---|
148 | GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f)
|
---|
149 | {}
|
---|
150 |
|
---|
151 | Vector3 mousePoint;
|
---|
152 |
|
---|
153 | void initializeGL() {
|
---|
154 | InitGL();
|
---|
155 | }
|
---|
156 | void resizeGL(int w, int h);
|
---|
157 | void paintGL();
|
---|
158 | void timerEvent(QTimerEvent *) {
|
---|
159 | update();
|
---|
160 | }
|
---|
161 |
|
---|
162 | void mousePressEvent(QMouseEvent *);
|
---|
163 | void mouseReleaseEvent(QMouseEvent *);
|
---|
164 | void mouseMoveEvent(QMouseEvent *);
|
---|
165 |
|
---|
166 | float
|
---|
167 | RenderErrors();
|
---|
168 |
|
---|
169 | virtual int GetWidth() const { return width(); }
|
---|
170 | virtual int GetHeight() const { return height(); }
|
---|
171 |
|
---|
172 | };
|
---|
173 |
|
---|
174 |
|
---|
175 | extern GlRendererWidget *rendererWidget;
|
---|
176 |
|
---|
177 | #endif
|
---|
178 |
|
---|