Added support for DYNAMIC/STATIC osg::Transform types and added new osg::Drawable::getStats
and supportsAttributeUpdate(..) and applyAttributeUpdate(...) methods which will be to enable hooks into Drawable subclasses.
This commit is contained in:
parent
3c5b9c813d
commit
96085619ee
@ -16,6 +16,13 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
class Statistics;
|
||||
class Vec2;
|
||||
class Vec3;
|
||||
class Vec4;
|
||||
|
||||
|
||||
|
||||
/** Pure virtual base class for drawable Geometry. Contains no drawing primitives
|
||||
directly, these are provided by subclasses such as GeoSet. State attributes
|
||||
for a Drawable are maintained in StateSet which the Drawable maintains
|
||||
@ -67,6 +74,8 @@ class SG_EXPORT Drawable : public Object
|
||||
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
|
||||
void dirtyDisplayList();
|
||||
|
||||
|
||||
|
||||
inline void dirtyBound() { _bbox_computed = false; }
|
||||
|
||||
/** get bounding box of geoset.
|
||||
@ -84,10 +93,92 @@ class SG_EXPORT Drawable : public Object
|
||||
* If the drawable has _useDisplayList set to true then use an OpenGL display
|
||||
* list, automatically compiling one if required.
|
||||
* Otherwise call drawImmediateMode().
|
||||
* Note, draw method should not be overridden in subclasses as it
|
||||
* Note, draw method should *not* be overridden in subclasses as it
|
||||
* manages the optional display list.
|
||||
*/
|
||||
inline void draw(State& state)
|
||||
inline void draw(State& state);
|
||||
|
||||
/** Immediately compile this drawable into an OpenGL Display List.
|
||||
Note I, operation is ignored if _useDisplayList to false.
|
||||
Note II, compile is not intended to be overridden in subclasses.*/
|
||||
void compile(State& state);
|
||||
|
||||
/** draw directly ignoring an OpenGL display list which could be attached.
|
||||
* This is the internal draw method which does the drawing itself,
|
||||
* and is the method to override when deriving from Drawable.
|
||||
*/
|
||||
virtual void drawImmediateMode(State& state) = 0;
|
||||
|
||||
/** use deleteDisplayList instead of glDeleteList to allow
|
||||
* OpenGL display list to cached until they can be deleted
|
||||
* by the OpenGL context in which they were created, specified
|
||||
* by contextID.*/
|
||||
static void deleteDisplayList(uint contextID,uint globj);
|
||||
|
||||
/** flush all the cached display list which need to be deleted
|
||||
* in the OpenGL context related to contextID.*/
|
||||
static void flushDeletedDisplayLists(uint contextID);
|
||||
|
||||
|
||||
/** Collect Stistics count from Drawable.*/
|
||||
virtual bool getStats(Statistics&) { return false; }
|
||||
|
||||
|
||||
enum AttributeBitMask
|
||||
{
|
||||
COORDS = 0x1,
|
||||
NORMALS = 0x2,
|
||||
COLORS = 0x4,
|
||||
TEXTURE_COORDS = 0x8,
|
||||
TEXTURE_COORDS_0 = TEXTURE_COORDS,
|
||||
TEXTURE_COORDS_1 = 0x16,
|
||||
TEXTURE_COORDS_2 = 0x32,
|
||||
TEXTURE_COORDS_3 = 0x64
|
||||
};
|
||||
|
||||
struct AttributeUpdateFunctor
|
||||
{
|
||||
virtual bool apply(AttributeBitMask abm,Vec2* begin,Vec2* end) { return false; }
|
||||
virtual bool apply(AttributeBitMask abm,Vec3* begin,Vec3* end) { return false; }
|
||||
virtual bool apply(AttributeBitMask abm,Vec4* begin,Vec4* end) { return false; }
|
||||
};
|
||||
|
||||
virtual bool suppportsAttributeUpdate(AttributeBitMask) { return false; }
|
||||
|
||||
virtual bool applyAttributeUpdate(AttributeBitMask,AttributeUpdateFunctor&) { return false; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Drawable(const Drawable&):Object() {}
|
||||
Drawable& operator = (const Drawable&) { return *this;}
|
||||
|
||||
virtual ~Drawable();
|
||||
|
||||
/** compute the bounding box of the drawable. Method must be
|
||||
implemented by subclasses.*/
|
||||
virtual const bool computeBound() const = 0;
|
||||
|
||||
ref_ptr<StateSet> _dstate;
|
||||
|
||||
bool _supportsDisplayList;
|
||||
bool _useDisplayList;
|
||||
|
||||
typedef std::vector<uint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
mutable BoundingBox _bbox;
|
||||
mutable bool _bbox_computed;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedDisplayListCache;
|
||||
static DeletedDisplayListCache s_deletedDisplayListCache;
|
||||
|
||||
};
|
||||
|
||||
inline void Drawable::draw(State& state)
|
||||
{
|
||||
if (_useDisplayList)
|
||||
{
|
||||
@ -123,57 +214,6 @@ class SG_EXPORT Drawable : public Object
|
||||
}
|
||||
}
|
||||
|
||||
/** Immediately compile this drawable into an OpenGL Display List.
|
||||
Note I, operation is ignored if _useDisplayList to false.
|
||||
Note II, compile is not intended to be overridden in subclasses.*/
|
||||
void compile(State& state);
|
||||
|
||||
/** draw directly ignoring an OpenGL display list which could be attached.
|
||||
* This is the internal draw method which does the drawing itself,
|
||||
* and is the method to override when deriving from Drawable.
|
||||
*/
|
||||
virtual void drawImmediateMode(State& state) = 0;
|
||||
|
||||
/** use deleteDisplayList instead of glDeleteList to allow
|
||||
* OpenGL display list to cached until they can be deleted
|
||||
* by the OpenGL context in which they were created, specified
|
||||
* by contextID.*/
|
||||
static void deleteDisplayList(uint contextID,uint globj);
|
||||
|
||||
/** flush all the cached display list which need to be deleted
|
||||
* in the OpenGL context related to contextID.*/
|
||||
static void flushDeletedDisplayLists(uint contextID);
|
||||
|
||||
protected:
|
||||
|
||||
Drawable(const Drawable&):Object() {}
|
||||
Drawable& operator = (const Drawable&) { return *this;}
|
||||
|
||||
virtual ~Drawable();
|
||||
|
||||
/** compute the bounding box of the drawable. Method must be
|
||||
implemented by subclasses.*/
|
||||
virtual const bool computeBound() const = 0;
|
||||
|
||||
ref_ptr<StateSet> _dstate;
|
||||
|
||||
bool _supportsDisplayList;
|
||||
bool _useDisplayList;
|
||||
|
||||
typedef std::vector<uint> GLObjectList;
|
||||
mutable GLObjectList _globjList;
|
||||
|
||||
mutable BoundingBox _bbox;
|
||||
mutable bool _bbox_computed;
|
||||
|
||||
// static cache of deleted display lists which can only
|
||||
// by completely deleted once the appropriate OpenGL context
|
||||
// is set.
|
||||
typedef std::map<uint,std::set<uint> > DeletedDisplayListCache;
|
||||
static DeletedDisplayListCache s_deletedDisplayListCache;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,19 @@ class Impostor;
|
||||
class EarthSky;
|
||||
|
||||
/** Visitor for type safe operations on osg::Node's.
|
||||
Based on GOF's Visitor pattern.*/
|
||||
Based on GOF's Visitor pattern. The NodeVisitor
|
||||
is useful for developing type safe operations to nodes
|
||||
in the scene graph (as per Visitor pattern), and adds to this
|
||||
support for optional scene graph traversal to allow
|
||||
operations to be applied to whole scenes at once. The Visitor
|
||||
pattern uses a technique of double dispatch as a mechanism to
|
||||
called the appropriate apply(..) method of the NodeVisitor. To
|
||||
use this feature one must use the Node::accept(NodeVisitor) which
|
||||
is extended in each Node subclass, rather than the NodeVisitor
|
||||
apply directly. So use root->accept(myVisitor); instead of
|
||||
myVisitor.apply(*root). The later method will bypass the double
|
||||
dispatch and the appropriate NodeVisitor::apply(..) method will
|
||||
not be called. */
|
||||
class SG_EXPORT NodeVisitor : public Referenced
|
||||
{
|
||||
public:
|
||||
|
@ -23,6 +23,24 @@ class SG_EXPORT Transform : public Group
|
||||
|
||||
META_Node(Transform);
|
||||
|
||||
/** Range of type that the Transform can be.*/
|
||||
enum Type
|
||||
{
|
||||
DYNAMIC,
|
||||
STATIC
|
||||
};
|
||||
|
||||
/** Set the Transform Type, which can be DYNAMIC - the Marix
|
||||
* value is updated duing the main loop, or STATIC - the Matrix
|
||||
* is constant throughut the life of the main loop. STATIC
|
||||
* Transforms can be optimized away is some instances, which
|
||||
* can improve performanc so unless you plan to modify the
|
||||
* Matrix explicity set the Matrix to STATIC. The default
|
||||
* value is DYNAMIC.*/
|
||||
inline void setType(Type type) { _type = type; }
|
||||
/** Get the Transform Type.*/
|
||||
inline const Type getType() const { return _type; }
|
||||
|
||||
void setMatrix(const Matrix& mat );
|
||||
inline Matrix& getMatrix() { return *_matrix; }
|
||||
inline const Matrix& getMatrix() const { return *_matrix; }
|
||||
@ -39,6 +57,7 @@ class SG_EXPORT Transform : public Group
|
||||
|
||||
virtual const bool computeBound() const;
|
||||
|
||||
Type _type;
|
||||
ref_ptr<Matrix> _matrix;
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,7 @@ using namespace osg;
|
||||
|
||||
Transform::Transform()
|
||||
{
|
||||
_type = DYNAMIC;
|
||||
_matrix = new osg::Matrix();
|
||||
_matrix->makeIdent();
|
||||
}
|
||||
@ -11,6 +12,7 @@ Transform::Transform()
|
||||
|
||||
Transform::Transform(const Matrix& mat )
|
||||
{
|
||||
_type = DYNAMIC;
|
||||
(*_matrix) = mat;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user