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.
This commit is contained in:
Don BURNS 2002-03-13 22:44:22 +00:00
parent bc30edb9e6
commit d0ee300405
4 changed files with 32 additions and 4 deletions

View File

@ -10,6 +10,7 @@
#include <osg/State>
#include <osg/Types>
#include <osg/Vec2>
#include <osg/NodeVisitor>
#include <vector>
#include <map>
@ -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> _drawCallback;
ref_ptr<CullCallback> _cullCallback;
// static cache of deleted display lists which can only
// by completely deleted once the appropriate OpenGL context

View File

@ -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()

View File

@ -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())
{

View File

@ -895,11 +895,18 @@ void CullVisitor::apply(Geode& node)
Matrix* matrix = getCurrentMatrix();
for(int i=0;i<node.getNumDrawables();++i)
{
Drawable* drawable = node.getDrawable(i);
const BoundingBox &bb =drawable->getBound();
if( drawable->getCullCallback() )
{
if( drawable->getCullCallback()->cull( this, drawable ) == true )
continue;
}
else
{
if (isCulled(bb,mode)) continue;
}
//SandB change: