diff --git a/include/osg/Drawable b/include/osg/Drawable index 82bd235fd..cf1205f5a 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -247,23 +247,38 @@ class SG_EXPORT Drawable : public Object virtual void compile(State& state) const; - struct UpdateCallback : public virtual osg::Referenced + struct UpdateCallback : public virtual osg::Object { - /** do customized app code.*/ - virtual void update(osg::NodeVisitor *visitor, osg::Drawable* drawable) = 0; + UpdateCallback() {} + + UpdateCallback(const UpdateCallback&,const CopyOp&) {} + + META_Object(osg,UpdateCallback) + + /** do customized update code.*/ + virtual void update(osg::NodeVisitor*, osg::Drawable*) {} }; - /** Set the UpdateCallback which allows users to attach customize the undating of an object during the app traversal.*/ + /** Set the UpdateCallback which allows users to attach customize the undating of an object during the update traversal.*/ void setUpdateCallback(UpdateCallback* ac); /** Get the non const UpdateCallback.*/ UpdateCallback* getUpdateCallback() { return _updateCallback.get(); } + /** Get the const UpdateCallback.*/ + const UpdateCallback* getUpdateCallback() const { return _updateCallback.get(); } + - struct CullCallback : public virtual osg::Referenced + struct CullCallback : public virtual osg::Object { - /** do customized cull code.*/ - virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable, osg::State *state=NULL) const = 0; + CullCallback() {} + + CullCallback(const CullCallback&,const CopyOp&) {} + + META_Object(osg,CullCallback) + + /** do customized cull code, return true if drawable should be culled.*/ + virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const { return false; } }; /** Set the CullCallback which allows users to attach customize the culling of Drawable during the cull traversal.*/ @@ -274,6 +289,8 @@ class SG_EXPORT Drawable : public Object /** Get the const CullCallback.*/ const CullCallback* getCullCallback() const { return _cullCallback.get(); } + + /** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object. @@ -281,10 +298,16 @@ class SG_EXPORT Drawable : public Object * the user intends to decorate the exist draw code then simple call the drawable->drawImplementation() from * with the callbacks drawImplementation() method. This allows the users to do both pre and post callbacks * without fuss and can even diable the inner draw in required.*/ - struct DrawCallback : public virtual osg::Referenced + struct DrawCallback : public virtual osg::Object { + DrawCallback() {} + + DrawCallback(const DrawCallback&,const CopyOp&) {} + + META_Object(osg,DrawCallback) + /** do customized draw code.*/ - virtual void drawImplementation(State& state,const osg::Drawable* drawable) const = 0; + virtual void drawImplementation(State&,const osg::Drawable*) const {} }; /** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/ @@ -684,6 +707,44 @@ inline void Drawable::draw(State& state) const drawImplementation(state); }; +/** Drawable CullCallback for adding cluster culling to cull back facing + * drawables.*/ +class SG_EXPORT ClusterCullingCallback : public Drawable::CullCallback +{ + public: + + ClusterCullingCallback(); + ClusterCullingCallback(const ClusterCullingCallback& ccc,const CopyOp& copyop); + ClusterCullingCallback(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation); + ClusterCullingCallback(const osg::Drawable* drawable); + + META_Object(osg,ClusterCullingCallback) + + /** compute the control point, normal and deviation from the contents of the drawable.*/ + void computeFrom(const osg::Drawable* drawable); + + void set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation); + + void setControlPoint(const osg::Vec3& controlPoint) { _controlPoint = controlPoint; } + const osg::Vec3& getControlPoint() const { return _controlPoint; } + + void setNormal(const osg::Vec3& normal) { _normal = normal; } + const osg::Vec3& getNormal() const { return _normal; } + + void setDeviation(float deviation) { _deviation = deviation; } + float getDeviation() const { return _deviation; } + + virtual bool cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const; + + protected: + + virtual ~ClusterCullingCallback() {} + + osg::Vec3 _controlPoint; + osg::Vec3 _normal; + float _deviation; +}; + } diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index b9f04d8d8..dfe671cc0 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -891,3 +892,83 @@ void Drawable::Extensions::glGetOcclusionQueryuiv( GLuint id, GLenum pname, GLui osg::notify(osg::WARN)<<"Error: glGetOcclusionQueryuiv not supported by OpenGL driver"< NormalList; + NormalList _normals; + double _x,_y,_z; +}; + + + +void ClusterCullingCallback::computeFrom(const osg::Drawable* drawable) +{ + TriangleFunctor stf; + drawable->accept(stf); +} + +void ClusterCullingCallback::set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation) +{ + _controlPoint = controlPoint; + _normal = normal; + _deviation = deviation; +} + + +bool ClusterCullingCallback::cull(osg::NodeVisitor*, osg::Drawable*, osg::State*) const +{ + return false; +} diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 1413faf3f..2f4eb7c94 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -15,7 +15,7 @@ using namespace osgDB; DatabasePager::DatabasePager() { - //std::cout<<"Constructing DatabasePager()"<getUseDisplayList() || drawable->getUseVertexBufferObjects()) { - //std::cout<<"Found compilable drawable"<setTimeStamp(plod->getNumChildren(),timeStamp); } group->addChild(databaseRequest->_loadedModel.get()); - std::cout<<"merged subgraph"<_fileName<<" after "<_numOfRequests<<" requests."<_fileName<<" after "<_numOfRequests<<" requests."<referenceCount()==1) { - //std::cout<<" PagedLOD "<referenceCount()<referenceCount()<compile(state); elapsedTime = timer.delta_s(start_tick,timer.tick()); } @@ -521,14 +521,14 @@ void DatabasePager::compileRenderingObjects(osg::State& state, double& available if (!dtc.second.empty() && elapsedTimecompile(state); elapsedTime = timer.delta_s(start_tick,timer.tick()); } @@ -536,7 +536,7 @@ void DatabasePager::compileRenderingObjects(osg::State& state, double& available dwlist.erase(dwlist.begin(),itr); } - //std::cout<<"Checking if compiled"<