#ifndef __GLRENDERER_H #define __GLRENDERER_H #include #include //#include #include "Vector3.h" #include "Containers.h" #include "Halton.h" #include "Renderer.h" #include "Beam.h" class QWidget; namespace GtpVisibilityPreprocessor { class SceneGraph; class ViewCellsManager; class Mesh; class MeshInstance; class Intersectable; class Material; class Beam; class KdTree; class GlRendererBuffer; class BeamSampleStatistics; struct VssRayContainer; struct PvsRenderStatistics { float maxError; float sumError; int sumPvsSize; int frames; int errorFreeFrames; PvsRenderStatistics() { Reset(); } void Reset() { maxError = 0.0f; sumError = 0.0f; frames = 0; errorFreeFrames = 0; sumPvsSize = 0; } float GetMaxError() { return maxError; } float GetAvgError() { return sumError/frames; } float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; } float GetAvgPvs() { return sumPvsSize/(float)frames; } }; struct RenderCostSample { RenderCostSample() {} void Reset() { mVisibleObjects = 0; mVisiblePixels = 0; } // visible object from the given point int mVisibleObjects; // visible pixels int mVisiblePixels; }; /** Class encapsulating gl rendering for the scene. There is no gl context binding so the binding is performed in the derived classes */ class GlRenderer: public Renderer { public: ObjectContainer mObjects; Vector3 mViewPoint; Vector3 mViewDirection; int timerId; bool mUseFalseColors; bool mUseForcedColors; HaltonSequence halton; int mFrame; bool mWireFrame; bool mDetectEmptyViewSpace; bool mSnapErrorFrames; bool mUseGlLists; QString mSnapPrefix; KdTree *mKdTree; QWaitCondition mRenderingFinished; vector mOcclusionQueries; GlRenderer(SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree); ~GlRenderer(); void SetupFalseColor(const int id); void RenderIntersectable(Intersectable *); void RenderViewCell(ViewCell *vc); void RenderMeshInstance(MeshInstance *mi); void RenderMesh(Mesh *m); void SetupMaterial(Material *m); virtual void SetupCamera(); bool RenderScene(); void _RenderScene(); virtual void SetupProjection(const int w, const int h, const float angle = 70.0f); void InitGL(); virtual int GetWidth() const = 0; virtual int GetHeight() const = 0; int GetId(int r, int g, int b) const; }; class GlRendererBuffer : public QObject, public QGLPixelBuffer, public GlRenderer { Q_OBJECT public: GlRendererBuffer(const int w, const int h, SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree); void EvalRenderCostSample( RenderCostSample &sample ); void SampleRenderCost( const int n, vector &samples ); void EvalPvsStat(); void ClearErrorBuffer(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } void RandomViewPoint(); void SampleBeamContributions( Intersectable *sourceObject, Beam &beam, const int samples, BeamSampleStatistics &stat ); void SampleViewpointContributions( Intersectable *sourceObject, const Vector3 viewPoint, Beam &beam, const int desiredSamples, BeamSampleStatistics &stat ); void InitGL(); /** Computes rays from information gained with hw sampling- */ void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays); int ComputePvs() const; float GetPixelError(int &pvsSize); int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const; PvsRenderStatistics mPvsStat; int mPvsStatFrames; struct PvsErrorEntry { PvsErrorEntry() {} float mError; int mPvsSize; Vector3 mPosition; Vector3 mDirection; }; vector mPvsErrorBuffer; private: unsigned int *mPixelBuffer; static void GenQueries(const int numQueries); void SetupProjectionForViewPoint(const Vector3 &viewPoint, const Beam &beam, Intersectable *sourceObject); public: signals: UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); }; class RendererControlWidget : public QWidget { Q_OBJECT public: QListWidget *mPvsErrorWidget; RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0); public slots: void FocusNextPvsErrorFrame(); void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); signals: SetViewCellGranularity(int); SetSceneCut(int); SetTopDistance(int); SetVisibilityFilterSize(int); SetSpatialFilterSize(int); SetRenderFilter(bool); SetUseFilter(bool); SetUseSpatialFilter(bool); SetRenderErrors(bool); SetShowViewCells(bool); SetShowRenderCost(bool); SetShowPvsSizes(bool); SetTopView(bool); SetCutViewCells(bool); SetCutScene(bool); }; class GlRendererWidget : public QGLWidget, public GlRenderer { Q_OBJECT public: // point of the last mouse click used for movement in the scene Vector3 mousePoint; bool mTopView; bool mRenderViewCells; bool mCutViewCells; bool mCutScene; bool mRenderErrors; bool mRenderFilter; bool mUseFilter; bool mUseSpatialFilter; bool mShowRenderCost; bool mShowPvsSizes; float mSpatialFilterSize; Plane3 mSceneCutPlane; float mTopDistance; // some statistics int mPvsSize; float mRenderError; RendererControlWidget *mControlWidget; GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree, QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 ); virtual void SetupCamera(); void initializeGL() { InitGL(); } void resizeGL(int w, int h); void paintGL(); void timerEvent(QTimerEvent *) { update(); } void mousePressEvent(QMouseEvent *); void mouseReleaseEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *); void keyPressEvent ( QKeyEvent * e ) ; void RenderPvs(); float RenderErrors(); void RenderInfo(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } virtual void SetupProjection(const int w, const int h); void RenderViewCells(); public slots: void SetRenderErrors(bool b) { mRenderErrors = b; updateGL(); } void SetRenderFilter(bool b) { mRenderFilter = b; updateGL(); } void SetUseFilter(bool b) { mUseFilter = b; updateGL(); } void SetUseSpatialFilter(bool b) { mUseSpatialFilter = b; updateGL(); } void SetViewCellGranularity(int number); void SetVisibilityFilterSize(int number); void SetSpatialFilterSize(int number); void SetSceneCut(int cut); void SetTopDistance(int dist); void SetShowViewCells(bool b) { mRenderViewCells = b; updateGL(); } void SetShowRenderCost(bool b) { mShowRenderCost = b; updateGL(); } void SetShowPvsSizes(bool b) { mShowPvsSizes = b; updateGL(); } void SetTopView(bool b) { mTopView = b; updateGL(); } void SetCutViewCells(bool b) { mCutViewCells = b; updateGL(); } void SetCutScene(bool b) { mCutScene = b; updateGL(); } }; extern GlRendererWidget *rendererWidget; class GlDebuggerWidget : public QGLWidget { Q_OBJECT public: GlDebuggerWidget(GlRendererBuffer *buf, QWidget *parent = NULL); ~GlDebuggerWidget(); void initializeGL(); void resizeGL(int w, int h); void paintGL(); void timerEvent(QTimerEvent *) { update(); } void mousePressEvent(QMouseEvent *) { killTimer(timerId); } void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); } void initCommon(); void initPbuffer(); GlRendererBuffer *mRenderBuffer; Beam mBeam; int mSamples; Intersectable *mSourceObject; private: GLuint dynamicTexture; int timerId; }; extern GlDebuggerWidget *debuggerWidget; }; #endif