[865] | 1 | #ifndef __GLRENDERER_H
|
---|
| 2 | #define __GLRENDERER_H
|
---|
[492] | 3 |
|
---|
| 4 | #include "Vector3.h"
|
---|
| 5 | #include "Containers.h"
|
---|
| 6 | #include "Halton.h"
|
---|
[497] | 7 | #include "Renderer.h"
|
---|
[540] | 8 | #include "Beam.h"
|
---|
[492] | 9 |
|
---|
[863] | 10 |
|
---|
[860] | 11 | namespace GtpVisibilityPreprocessor {
|
---|
| 12 |
|
---|
[492] | 13 | class SceneGraph;
|
---|
| 14 | class ViewCellsManager;
|
---|
| 15 | class Mesh;
|
---|
| 16 | class MeshInstance;
|
---|
| 17 | class Intersectable;
|
---|
| 18 | class Material;
|
---|
[512] | 19 | class Beam;
|
---|
[532] | 20 | class KdTree;
|
---|
[538] | 21 | class GlRendererBuffer;
|
---|
[531] | 22 | class BeamSampleStatistics;
|
---|
[1001] | 23 | class OcclusionQuery;
|
---|
| 24 | class TransformedMeshInstance;
|
---|
[531] | 25 |
|
---|
[540] | 26 | struct VssRayContainer;
|
---|
| 27 |
|
---|
[492] | 28 | struct PvsRenderStatistics {
|
---|
| 29 |
|
---|
| 30 | float maxError;
|
---|
| 31 | float sumError;
|
---|
[713] | 32 | int sumPvsSize;
|
---|
[492] | 33 | int frames;
|
---|
| 34 | int errorFreeFrames;
|
---|
[502] | 35 |
|
---|
[492] | 36 | PvsRenderStatistics() { Reset(); }
|
---|
| 37 |
|
---|
[498] | 38 | void Reset() {
|
---|
[492] | 39 | maxError = 0.0f;
|
---|
| 40 | sumError = 0.0f;
|
---|
| 41 | frames = 0;
|
---|
| 42 | errorFreeFrames = 0;
|
---|
[713] | 43 | sumPvsSize = 0;
|
---|
[492] | 44 | }
|
---|
| 45 |
|
---|
| 46 | float GetMaxError() { return maxError; }
|
---|
| 47 | float GetAvgError() { return sumError/frames; }
|
---|
| 48 | float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; }
|
---|
[713] | 49 | float GetAvgPvs() { return sumPvsSize/(float)frames; }
|
---|
[492] | 50 |
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[811] | 53 | struct RenderCostSample {
|
---|
[496] | 54 |
|
---|
[811] | 55 | RenderCostSample() {}
|
---|
| 56 |
|
---|
| 57 | void Reset() {
|
---|
| 58 | mVisibleObjects = 0;
|
---|
| 59 | mVisiblePixels = 0;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[991] | 62 | Vector3 mPosition;
|
---|
| 63 |
|
---|
[811] | 64 | // visible object from the given point
|
---|
| 65 | int mVisibleObjects;
|
---|
| 66 |
|
---|
| 67 | // visible pixels
|
---|
| 68 | int mVisiblePixels;
|
---|
| 69 |
|
---|
| 70 | };
|
---|
| 71 |
|
---|
[496] | 72 | /** Class encapsulating gl rendering for the scene.
|
---|
| 73 | There is no gl context binding so the binding is performed in the
|
---|
| 74 | derived classes
|
---|
| 75 | */
|
---|
[497] | 76 | class GlRenderer: public Renderer
|
---|
[492] | 77 | {
|
---|
[496] | 78 |
|
---|
[492] | 79 | public:
|
---|
| 80 |
|
---|
| 81 | GlRenderer(SceneGraph *sceneGraph,
|
---|
[532] | 82 | ViewCellsManager *viewcells,
|
---|
| 83 | KdTree *tree);
|
---|
[496] | 84 |
|
---|
[1151] | 85 | GlRenderer() {}
|
---|
| 86 |
|
---|
[1145] | 87 | virtual ~GlRenderer();
|
---|
[492] | 88 |
|
---|
[496] | 89 |
|
---|
[492] | 90 | void SetupFalseColor(const int id);
|
---|
| 91 | void RenderIntersectable(Intersectable *);
|
---|
[535] | 92 | void RenderViewCell(ViewCell *vc);
|
---|
[492] | 93 | void RenderMeshInstance(MeshInstance *mi);
|
---|
[1001] | 94 | void RenderTransformedMeshInstance(TransformedMeshInstance *mi);
|
---|
[492] | 95 | void RenderMesh(Mesh *m);
|
---|
| 96 | void SetupMaterial(Material *m);
|
---|
[502] | 97 | virtual void SetupCamera();
|
---|
[496] | 98 |
|
---|
[497] | 99 | bool
|
---|
[496] | 100 | RenderScene();
|
---|
[492] | 101 |
|
---|
[811] | 102 | void
|
---|
| 103 | _RenderScene();
|
---|
[589] | 104 |
|
---|
[811] | 105 |
|
---|
[608] | 106 | virtual void
|
---|
[811] | 107 | SetupProjection(const int w, const int h, const float angle = 70.0f);
|
---|
[496] | 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | void InitGL();
|
---|
| 113 |
|
---|
| 114 | virtual int GetWidth() const = 0;
|
---|
| 115 | virtual int GetHeight() const = 0;
|
---|
[540] | 116 |
|
---|
| 117 | int GetId(int r, int g, int b) const;
|
---|
[1151] | 118 |
|
---|
| 119 | inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; }
|
---|
| 120 | inline const string GetSnapPrefix() { return mSnapPrefix; }
|
---|
| 121 |
|
---|
| 122 | inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; }
|
---|
| 123 | inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; }
|
---|
| 124 |
|
---|
| 125 | protected:
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | vector<OcclusionQuery *> mOcclusionQueries;
|
---|
| 129 |
|
---|
| 130 | ObjectContainer mObjects;
|
---|
| 131 |
|
---|
| 132 | Vector3 mViewPoint;
|
---|
| 133 | Vector3 mViewDirection;
|
---|
| 134 |
|
---|
| 135 | int timerId;
|
---|
| 136 | bool mUseFalseColors;
|
---|
| 137 | bool mUseForcedColors;
|
---|
| 138 |
|
---|
| 139 | HaltonSequence halton;
|
---|
| 140 |
|
---|
| 141 | int mFrame;
|
---|
| 142 | bool mWireFrame;
|
---|
| 143 |
|
---|
| 144 | bool mDetectEmptyViewSpace;
|
---|
| 145 | bool mSnapErrorFrames;
|
---|
| 146 |
|
---|
| 147 | bool mUseGlLists;
|
---|
| 148 |
|
---|
| 149 | string mSnapPrefix;
|
---|
| 150 |
|
---|
| 151 | KdTree *mKdTree;
|
---|
| 152 |
|
---|
[496] | 153 | };
|
---|
| 154 |
|
---|
[1146] | 155 | /* Class implementing an OpenGl render buffer.
|
---|
| 156 | */
|
---|
[1145] | 157 | class GlRendererBuffer: public GlRenderer
|
---|
[496] | 158 | {
|
---|
[1145] | 159 |
|
---|
[496] | 160 | public:
|
---|
[1151] | 161 |
|
---|
[1145] | 162 | GlRendererBuffer(SceneGraph *sceneGraph,
|
---|
[811] | 163 | ViewCellsManager *viewcells,
|
---|
| 164 | KdTree *tree);
|
---|
[589] | 165 |
|
---|
[811] | 166 |
|
---|
[1001] | 167 | /** Evaluates render cost of a point sample.
|
---|
| 168 | @param sample the render cost sample to be evaluated
|
---|
| 169 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 170 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 171 | */
|
---|
| 172 | void EvalRenderCostSample(RenderCostSample &sample,
|
---|
| 173 | const bool useOcclusionQueries,
|
---|
| 174 | const int threshold);
|
---|
[811] | 175 |
|
---|
[1001] | 176 | /** Evaluates render cost of a number of point samples. The point samples
|
---|
| 177 | are distributed uniformly over the defined view space.
|
---|
[811] | 178 |
|
---|
[1001] | 179 | @param numSamples the number of point samples taken
|
---|
| 180 | @param samples stores the taken point samples in a container
|
---|
| 181 | @param useOcclusionQueries if occlusion queries should be used or item buffer
|
---|
| 182 | @param threshold number of pixels / samples from where an object is considered visible.
|
---|
| 183 | */
|
---|
| 184 | void SampleRenderCost(const int numSamples,
|
---|
| 185 | vector<RenderCostSample> &samples,
|
---|
| 186 | const bool useOcclusionQueries,
|
---|
[1145] | 187 | const int threshold = 0)
|
---|
| 188 | {}
|
---|
[811] | 189 |
|
---|
[1145] | 190 | /** Implerment in subclasses.
|
---|
| 191 | */
|
---|
| 192 | void EvalPvsStat() {};
|
---|
[1001] | 193 |
|
---|
[1145] | 194 | void ClearErrorBuffer();
|
---|
[496] | 195 |
|
---|
| 196 |
|
---|
[1145] | 197 | virtual int GetWidth() const { return 0; }
|
---|
| 198 | virtual int GetHeight() const { return 0; }
|
---|
[496] | 199 |
|
---|
[507] | 200 |
|
---|
[563] | 201 | void RandomViewPoint();
|
---|
[507] | 202 | void SampleBeamContributions(
|
---|
| 203 | Intersectable *sourceObject,
|
---|
[512] | 204 | Beam &beam,
|
---|
[507] | 205 | const int samples,
|
---|
| 206 | BeamSampleStatistics &stat
|
---|
| 207 | );
|
---|
| 208 |
|
---|
| 209 | void
|
---|
| 210 | SampleViewpointContributions(
|
---|
| 211 | Intersectable *sourceObject,
|
---|
[514] | 212 | const Vector3 viewPoint,
|
---|
[512] | 213 | Beam &beam,
|
---|
[507] | 214 | const int desiredSamples,
|
---|
| 215 | BeamSampleStatistics &stat
|
---|
| 216 | );
|
---|
| 217 |
|
---|
[540] | 218 | void InitGL();
|
---|
| 219 |
|
---|
| 220 | /** Computes rays from information gained with hw sampling-
|
---|
| 221 | */
|
---|
| 222 | void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
|
---|
| 223 |
|
---|
| 224 | int ComputePvs() const;
|
---|
| 225 |
|
---|
[576] | 226 | float
|
---|
[713] | 227 | GetPixelError(int &pvsSize);
|
---|
[540] | 228 |
|
---|
| 229 | int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
|
---|
| 230 |
|
---|
| 231 | PvsRenderStatistics mPvsStat;
|
---|
[532] | 232 |
|
---|
[540] | 233 | int mPvsStatFrames;
|
---|
[713] | 234 | struct PvsErrorEntry {
|
---|
[1145] | 235 | PvsErrorEntry() {}
|
---|
| 236 | float mError;
|
---|
| 237 | int mPvsSize;
|
---|
| 238 | Vector3 mPosition;
|
---|
| 239 | Vector3 mDirection;
|
---|
[713] | 240 | };
|
---|
| 241 |
|
---|
| 242 | vector<PvsErrorEntry> mPvsErrorBuffer;
|
---|
| 243 |
|
---|
[997] | 244 |
|
---|
[1145] | 245 | protected:
|
---|
| 246 | unsigned int *mPixelBuffer;
|
---|
[811] | 247 |
|
---|
[513] | 248 | static void GenQueries(const int numQueries);
|
---|
[589] | 249 |
|
---|
| 250 | void SetupProjectionForViewPoint(const Vector3 &viewPoint,
|
---|
| 251 | const Beam &beam,
|
---|
[746] | 252 |
|
---|
[525] | 253 | Intersectable *sourceObject);
|
---|
[746] | 254 |
|
---|
[1001] | 255 | /** Evaluates query for one direction using item buffer.
|
---|
| 256 | */
|
---|
[997] | 257 | void EvalQueryWithItemBuffer();
|
---|
[1146] | 258 |
|
---|
[1001] | 259 | /** Evaluates query for one direction using occlusion queries.
|
---|
| 260 | */
|
---|
[997] | 261 | void EvalQueryWithOcclusionQueries();
|
---|
| 262 |
|
---|
[746] | 263 | public:
|
---|
[1145] | 264 | // matt: remove qt dependencies
|
---|
| 265 | // signals:
|
---|
| 266 | // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
|
---|
[496] | 267 | };
|
---|
| 268 |
|
---|
[1146] | 269 |
|
---|
| 270 | /** Abstract class for implmenenting a gl render widget.
|
---|
| 271 | */
|
---|
[1151] | 272 | class GlRendererWidget: public GlRenderer
|
---|
[1146] | 273 | {
|
---|
| 274 | public:
|
---|
| 275 |
|
---|
[1151] | 276 | GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
|
---|
| 277 | GlRenderer(sceneGraph, vcm, kdTree)
|
---|
| 278 | {}
|
---|
[1146] | 279 |
|
---|
[1151] | 280 | GlRendererWidget() {}
|
---|
[1146] | 281 |
|
---|
[1151] | 282 | virtual ~GlRendererWidget() {}
|
---|
[1146] | 283 |
|
---|
| 284 | //virtual void Create() {}
|
---|
| 285 | virtual void Show() {}
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | protected:
|
---|
| 289 |
|
---|
| 290 |
|
---|
| 291 | SceneGraph *mSceneGraph;
|
---|
| 292 | ViewCellsManager *mViewCellsManager;
|
---|
| 293 | KdTree *mKdTree;
|
---|
[608] | 294 | };
|
---|
| 295 |
|
---|
[1151] | 296 | //extern GlRendererWidget *rendererWidget;
|
---|
| 297 |
|
---|
[1146] | 298 | };
|
---|
[492] | 299 |
|
---|
[1146] | 300 | #endif |
---|