#ifndef __RENDERER_H #define __RENDERER_H #include #include //#include #include "Vector3.h" #include "Containers.h" #include "Halton.h" #include "Renderer.h" class SceneGraph; class ViewCellsManager; class Mesh; class MeshInstance; class Intersectable; class Material; class Beam; struct PvsRenderStatistics { float maxError; float sumError; int frames; int errorFreeFrames; PvsRenderStatistics() { Reset(); } void Reset() { maxError = 0.0f; sumError = 0.0f; frames = 0; errorFreeFrames = 0; } float GetMaxError() { return maxError; } float GetAvgError() { return sumError/frames; } float GetErrorFreeFrames() { return errorFreeFrames/(float)frames; } }; /** 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; HaltonSequence halton; int mFrame; bool mWireFrame; QWaitCondition mRenderingFinished; GlRenderer(SceneGraph *sceneGraph, ViewCellsManager *viewcells); ~GlRenderer(); void SetupFalseColor(const int id); void RenderIntersectable(Intersectable *); void RenderMeshInstance(MeshInstance *mi); void RenderMesh(Mesh *m); void SetupMaterial(Material *m); virtual void SetupCamera(); void RandomViewPoint(); bool RenderScene(); void SetupProjection(const int w, const int h); float GetPixelError(); void InitGL(); virtual int GetWidth() const = 0; virtual int GetHeight() const = 0; }; class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer { public: int mPvsStatFrames; vector mPvsErrorBuffer; PvsRenderStatistics mPvsStat; GlRendererBuffer(const int w, const int h, SceneGraph *sceneGraph, ViewCellsManager *viewcells): QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells) { mPvsStatFrames = 10000; mPvsErrorBuffer.resize(mPvsStatFrames); ClearErrorBuffer(); makeCurrent(); InitGL(); doneCurrent(); } void EvalPvsStat(); void ClearErrorBuffer(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } // the values need for rss tree update computed already inside the glrendererbuffer // not all of them need to be computed struct BeamSampleStatistics { enum {COMPUTE_PVS_SIZE, COMPUTE_RAY_CONTRIBUTIONS, COMPUTE_PVS_ENTROPY}; int flags; BeamSampleStatistics():flags(COMPUTE_RAY_CONTRIBUTIONS) {} float pvsSize; float rays; float rayContributions; float pvsEntropy; float rayLengthEntropy; float importance; float weightedRayContribution; }; 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 ); private: static void GenQueries(const int numQueries); void SetupProjectionForViewPoint(const Vector3 &viewPoint, const Beam &beam, Intersectable *sourceObject); }; 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; GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *viewcells, QWidget * parent = 0, const QGLWidget * shareWidget = 0, Qt::WFlags f = 0 ): GlRenderer(sceneGraph, viewcells), QGLWidget(parent, shareWidget, f) { mTopView = false; } 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 ) ; float RenderErrors(); virtual int GetWidth() const { return width(); } virtual int GetHeight() const { return height(); } }; extern GlRendererWidget *rendererWidget; #endif