From d0ee300405672e850513f43ea7e21978eda17cdb Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Wed, 13 Mar 2002 22:44:22 +0000 Subject: [PATCH] Fixed DrawCallback in Drawable and added CullCallback to Drawable Cull Visitor now checks for a Drawable's CullCallback and calls it if it exists. It then prunes based on the return value (bool) of the cull callback. --- include/osg/Drawable | 21 ++++++++++++++++++++- src/osg/Drawable.cpp | 3 ++- src/osg/Texture.cpp | 1 + src/osgUtil/CullVisitor.cpp | 11 +++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/osg/Drawable b/include/osg/Drawable index 7cf9576ac..f09bab9e1 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -168,7 +169,7 @@ class SG_EXPORT Drawable : public Object struct DrawCallback : public osg::Referenced { /** do customized draw code.*/ - virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const; + virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const = 0; }; friend struct osg::Drawable::DrawCallback; @@ -182,6 +183,23 @@ class SG_EXPORT Drawable : public Object /** Get the const ComputerTransfromCallback.*/ const DrawCallback* getDrawCallback() const { return _drawCallback.get(); } + struct CullCallback : public osg::Referenced + { + /** do customized cull code.*/ + virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable) = 0; + }; + + friend struct osg::Drawable::CullCallback; + + /** Set the CullCallback which allows users to attach customize the drawing of existing Drawable object.*/ + void setCullCallback(CullCallback* cc) { _cullCallback=cc; } + + /** Get the non const ComputerTransfromCallback.*/ + CullCallback* getCullCallback() { return _cullCallback.get(); } + + /** Get the const ComputerTransfromCallback.*/ + const CullCallback* getCullCallback() const { return _cullCallback.get(); } + /** draw directly ignoring an OpenGL display list which could be attached. * This is the internal draw method which does the drawing itself, @@ -277,6 +295,7 @@ class SG_EXPORT Drawable : public Object mutable bool _bbox_computed; ref_ptr _drawCallback; + ref_ptr _cullCallback; // static cache of deleted display lists which can only // by completely deleted once the appropriate OpenGL context diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index bae04228b..10252145d 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -38,7 +38,8 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): _globjList(drawable._globjList), _bbox(drawable._bbox), _bbox_computed(drawable._bbox_computed), - _drawCallback(drawable._drawCallback) + _drawCallback(drawable._drawCallback), + _cullCallback(drawable._cullCallback) {} Drawable::~Drawable() diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 41af275f1..f2b3a5f0d 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -191,6 +191,7 @@ void Texture::apply(State& state) const if (_subloadMode == OFF) { glBindTexture( GL_TEXTURE_2D, handle ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _min_filter); } else if (_image.valid() && _image->data()) { diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 0f5dd4a47..f2d25c55f 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -895,11 +895,18 @@ void CullVisitor::apply(Geode& node) Matrix* matrix = getCurrentMatrix(); for(int i=0;igetBound(); - if (isCulled(bb,mode)) continue; + if( drawable->getCullCallback() ) + { + if( drawable->getCullCallback()->cull( this, drawable ) == true ) + continue; + } + else + { + if (isCulled(bb,mode)) continue; + } //SandB change: