source: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h @ 502

Revision 502, 3.4 KB checked in by bittner, 19 years ago (diff)

bsp viewcell location

  • Property svn:executable set to *
Line 
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
13class SceneGraph;
14class ViewCellsManager;
15class Mesh;
16class MeshInstance;
17class Intersectable;
18class Material;
19
20struct 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
48class GlRenderer: public Renderer
49{
50
51public:
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  bool mWireFrame;
64
65  QWaitCondition mRenderingFinished;
66 
67 
68  GlRenderer(SceneGraph *sceneGraph,
69                         ViewCellsManager *viewcells);
70 
71  ~GlRenderer();
72
73
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);
79  virtual void SetupCamera();
80  void RandomViewPoint();
81 
82  bool
83  RenderScene();
84
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
100class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
101{
102
103public:
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();
122        doneCurrent();
123
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
141class GlRendererWidget : public QGLWidget, public GlRenderer
142{
143  Q_OBJECT
144public:
145
146  // point of the last mouse click used for movement in the scene
147  Vector3 mousePoint;
148
149  bool mTopView;
150 
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)
156  {
157        mTopView = false;
158  }
159
160  virtual void SetupCamera();
161
162  void initializeGL() {
163        InitGL();
164  }
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
176  RenderErrors();
177
178  virtual int GetWidth() const { return width(); }
179  virtual int GetHeight() const { return height(); }
180
181};
182
183
184extern GlRendererWidget *rendererWidget;
185
186#endif
187
Note: See TracBrowser for help on using the repository browser.