#ifndef __GLRENDERER_H #define __GLRENDERER_H #include "Vector3.h" #include "Containers.h" #include "Halton.h" #include "Renderer.h" #include "Beam.h" namespace GtpVisibilityPreprocessor { class SceneGraph; class ViewCellsManager; class Mesh; class MeshInstance; class Intersectable; class Material; class Beam; class KdTree; class GlRendererBuffer; class BeamSampleStatistics; class OcclusionQuery; class TransformedMeshInstance; 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; } Vector3 mPosition; // 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: GlRenderer(SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree); GlRenderer() {} virtual ~GlRenderer(); void SetupFalseColor(const int id); void RenderIntersectable(Intersectable *); void RenderViewCell(ViewCell *vc); void RenderMeshInstance(MeshInstance *mi); void RenderTransformedMeshInstance(TransformedMeshInstance *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; inline const bool GetSnapErrorFrames() { return mSnapErrorFrames; } inline const string GetSnapPrefix() { return mSnapPrefix; } inline void SetSnapErrorFrames(bool snapframes) { mSnapErrorFrames = snapframes; } inline void SetSnapPrefix(const string &pref) { mSnapPrefix = pref; } protected: vector mOcclusionQueries; ObjectContainer mObjects; Vector3 mViewPoint; Vector3 mViewDirection; int timerId; bool mUseFalseColors; bool mUseForcedColors; HaltonSequence halton; int mFrame; bool mWireFrame; bool mDetectEmptyViewSpace; bool mSnapErrorFrames; bool mUseGlLists; string mSnapPrefix; KdTree *mKdTree; }; /* Class implementing an OpenGl render buffer. */ class GlRendererBuffer: public GlRenderer { public: GlRendererBuffer(SceneGraph *sceneGraph, ViewCellsManager *viewcells, KdTree *tree); /** Evaluates render cost of a point sample. @param sample the render cost sample to be evaluated @param useOcclusionQueries if occlusion queries should be used or item buffer @param threshold number of pixels / samples from where an object is considered visible. */ void EvalRenderCostSample(RenderCostSample &sample, const bool useOcclusionQueries, const int threshold); /** Evaluates render cost of a number of point samples. The point samples are distributed uniformly over the defined view space. @param numSamples the number of point samples taken @param samples stores the taken point samples in a container @param useOcclusionQueries if occlusion queries should be used or item buffer @param threshold number of pixels / samples from where an object is considered visible. */ void SampleRenderCost(const int numSamples, vector &samples, const bool useOcclusionQueries, const int threshold = 0) {} /** Implerment in subclasses. */ void EvalPvsStat() {}; void ClearErrorBuffer(); virtual int GetWidth() const { return 0; } virtual int GetHeight() const { return 0; } 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; protected: unsigned int *mPixelBuffer; static void GenQueries(const int numQueries); void SetupProjectionForViewPoint(const Vector3 &viewPoint, const Beam &beam, Intersectable *sourceObject); /** Evaluates query for one direction using item buffer. */ void EvalQueryWithItemBuffer(); /** Evaluates query for one direction using occlusion queries. */ void EvalQueryWithOcclusionQueries(); public: // matt: remove qt dependencies // signals: // void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &); }; /** Abstract class for implmenenting a gl render widget. */ class GlRendererWidget: public GlRenderer { public: GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree): GlRenderer(sceneGraph, vcm, kdTree) {} GlRendererWidget() {} virtual ~GlRendererWidget() {} //virtual void Create() {} virtual void Show() {} protected: SceneGraph *mSceneGraph; ViewCellsManager *mViewCellsManager; KdTree *mKdTree; }; //extern GlRendererWidget *rendererWidget; }; #endif