Preliminary steps to adding update and event callbacks to StateSet, StateAttribute
and Uniform.
This commit is contained in:
parent
c7fb7e8b5f
commit
819d2c6c56
@ -21,10 +21,10 @@ namespace osg {
|
|||||||
class Referenced;
|
class Referenced;
|
||||||
class Object;
|
class Object;
|
||||||
class Image;
|
class Image;
|
||||||
//class Texture;
|
|
||||||
class Texture;
|
class Texture;
|
||||||
class StateSet;
|
class StateSet;
|
||||||
class StateAttribute;
|
class StateAttribute;
|
||||||
|
class Uniform;
|
||||||
class Node;
|
class Node;
|
||||||
class Drawable;
|
class Drawable;
|
||||||
class Array;
|
class Array;
|
||||||
@ -51,6 +51,7 @@ class OSG_EXPORT CopyOp
|
|||||||
DEEP_COPY_ARRAYS = 128,
|
DEEP_COPY_ARRAYS = 128,
|
||||||
DEEP_COPY_PRIMITIVES = 256,
|
DEEP_COPY_PRIMITIVES = 256,
|
||||||
DEEP_COPY_SHAPES = 512,
|
DEEP_COPY_SHAPES = 512,
|
||||||
|
DEEP_COPY_UNIFORMS = 1024,
|
||||||
DEEP_COPY_ALL = 0xffffffff
|
DEEP_COPY_ALL = 0xffffffff
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ class OSG_EXPORT CopyOp
|
|||||||
virtual Array* operator() (const Array* array) const;
|
virtual Array* operator() (const Array* array) const;
|
||||||
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
|
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
|
||||||
virtual Shape* operator() (const Shape* shape) const;
|
virtual Shape* operator() (const Shape* shape) const;
|
||||||
|
virtual Uniform* operator() (const Uniform* shape) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ class OSG_EXPORT Node : public Object
|
|||||||
/** Get const update node callback, called during update traversal. */
|
/** Get const update node callback, called during update traversal. */
|
||||||
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
|
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||||
|
|
||||||
/** Get the number of Children of this node which require App traversal,
|
/** Get the number of Children of this node which require Update traversal,
|
||||||
* since they have an AppCallback attached to them or their children.*/
|
* since they have an Update Callback attached to them or their children.*/
|
||||||
inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
|
inline unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
|
||||||
|
|
||||||
|
|
||||||
@ -149,8 +149,8 @@ class OSG_EXPORT Node : public Object
|
|||||||
/** Get const update node callback, called during update traversal. */
|
/** Get const update node callback, called during update traversal. */
|
||||||
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
|
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
|
||||||
|
|
||||||
/** Get the number of Children of this node which require App traversal,
|
/** Get the number of Children of this node which require Event traversal,
|
||||||
* since they have an AppCallback attached to them or their children.*/
|
* since they have an Event Callback attached to them or their children.*/
|
||||||
inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
|
inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
|
|
||||||
// forward declare State & StateSet
|
// forward declare NodeVisitor, State & StateSet
|
||||||
|
class NodeVisitor;
|
||||||
class State;
|
class State;
|
||||||
class StateSet;
|
class StateSet;
|
||||||
|
|
||||||
@ -244,6 +245,39 @@ class OSG_EXPORT StateAttribute : public Object
|
|||||||
// default to no GLMode's associated with use of the StateAttribute.
|
// default to no GLMode's associated with use of the StateAttribute.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Callback : public virtual osg::Object
|
||||||
|
{
|
||||||
|
Callback() {}
|
||||||
|
|
||||||
|
Callback(const Callback&,const CopyOp&) {}
|
||||||
|
|
||||||
|
META_Object(osg,Callback);
|
||||||
|
|
||||||
|
/** do customized update code.*/
|
||||||
|
virtual void operator () (NodeVisitor*, StateAttribute*) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal.*/
|
||||||
|
void setUpdateCallback(Callback* uc) { _updateCallback = uc; }
|
||||||
|
|
||||||
|
/** Get the non const UpdateCallback.*/
|
||||||
|
Callback* getUpdateCallback() { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const UpdateCallback.*/
|
||||||
|
const Callback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
|
||||||
|
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
|
||||||
|
void setEventCallback(Callback* ec) { _eventCallback = ec; }
|
||||||
|
|
||||||
|
/** Get the non const EventCallback.*/
|
||||||
|
Callback* getEventCallback() { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const EventCallback.*/
|
||||||
|
const Callback* getEventCallback() const { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
|
||||||
/** apply the OpenGL state attributes.
|
/** apply the OpenGL state attributes.
|
||||||
* The global state for the current OpenGL context is passed
|
* The global state for the current OpenGL context is passed
|
||||||
@ -265,6 +299,8 @@ class OSG_EXPORT StateAttribute : public Object
|
|||||||
|
|
||||||
virtual ~StateAttribute() {}
|
virtual ~StateAttribute() {}
|
||||||
|
|
||||||
|
ref_ptr<Callback> _updateCallback;
|
||||||
|
ref_ptr<Callback> _eventCallback;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@
|
|||||||
|
|
||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
|
// forward declare for the purposes of the UpdateCallback.
|
||||||
|
class NodeVisitor;
|
||||||
|
|
||||||
/** Stores a set of modes and attributes which respresent a set of OpenGL state.
|
/** Stores a set of modes and attributes which respresent a set of OpenGL state.
|
||||||
* Notice that a \c StateSet contains just a subset of the whole OpenGL state.
|
* Notice that a \c StateSet contains just a subset of the whole OpenGL state.
|
||||||
* <p>In OSG, each \c Drawable and each \c Node has a reference to a
|
* <p>In OSG, each \c Drawable and each \c Node has a reference to a
|
||||||
@ -354,6 +357,46 @@ class OSG_EXPORT StateSet : public Object
|
|||||||
inline const std::string& getBinName() const { return _binName; }
|
inline const std::string& getBinName() const { return _binName; }
|
||||||
|
|
||||||
|
|
||||||
|
struct Callback : public virtual osg::Object
|
||||||
|
{
|
||||||
|
Callback() {}
|
||||||
|
|
||||||
|
Callback(const Callback&,const CopyOp&) {}
|
||||||
|
|
||||||
|
META_Object(osg,Callback);
|
||||||
|
|
||||||
|
/** do customized callback code.*/
|
||||||
|
virtual void operator() (NodeVisitor*, StateSet*) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Set the Update Callback which allows users to attach customize the updating of an object during the update traversal.*/
|
||||||
|
void setUpdateCallback(Callback* ac);
|
||||||
|
|
||||||
|
/** Get the non const Update Callback.*/
|
||||||
|
Callback* getUpdateCallback() { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const Update Callback.*/
|
||||||
|
const Callback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the number of Objects of this StateSet which require Update traversal,
|
||||||
|
* since they have an Update Callback attached to them or their children.*/
|
||||||
|
inline unsigned int getNumObjectsRequiringUpdateTraversal() const { return _numObjectsRequiringUpdateTraversal; }
|
||||||
|
|
||||||
|
|
||||||
|
/** Set the Event Callback which allows users to attach customize the updating of an object during the event traversal.*/
|
||||||
|
void setEventCallback(Callback* ac);
|
||||||
|
|
||||||
|
/** Get the non const Event Callback.*/
|
||||||
|
Callback* getEventCallback() { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const Event Callback.*/
|
||||||
|
const Callback* getEventCallback() const { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the number of Objects of this StateSet which require Event traversal,
|
||||||
|
* since they have an Eevnt Callback attached to them or their children.*/
|
||||||
|
inline unsigned int getNumObjectsRequiringEventTraversal() const { return _numObjectsRequiringEventTraversal; }
|
||||||
|
|
||||||
|
|
||||||
/** call compile on all StateAttributes contained within this StateSet.*/
|
/** call compile on all StateAttributes contained within this StateSet.*/
|
||||||
void compileGLObjects(State& state) const;
|
void compileGLObjects(State& state) const;
|
||||||
|
|
||||||
@ -406,6 +449,12 @@ class OSG_EXPORT StateSet : public Object
|
|||||||
RenderBinMode _binMode;
|
RenderBinMode _binMode;
|
||||||
int _binNum;
|
int _binNum;
|
||||||
std::string _binName;
|
std::string _binName;
|
||||||
|
|
||||||
|
ref_ptr<Callback> _updateCallback;
|
||||||
|
unsigned int _numObjectsRequiringUpdateTraversal;
|
||||||
|
|
||||||
|
ref_ptr<Callback> _eventCallback;
|
||||||
|
unsigned int _numObjectsRequiringEventTraversal;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,11 +117,11 @@ typedef char GLchar;
|
|||||||
|
|
||||||
namespace osg {
|
namespace osg {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
// forward declare
|
||||||
/** Uniform encapsulates glUniform values */
|
|
||||||
|
|
||||||
class GL2Extensions;
|
class GL2Extensions;
|
||||||
|
class NodeVisitor;
|
||||||
|
|
||||||
|
/** Uniform encapsulates glUniform values */
|
||||||
class OSG_EXPORT Uniform : public Object
|
class OSG_EXPORT Uniform : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -236,11 +236,47 @@ class OSG_EXPORT Uniform : public Object
|
|||||||
bool get( bool& b0, bool& b1, bool& b2 ) const;
|
bool get( bool& b0, bool& b1, bool& b2 ) const;
|
||||||
bool get( bool& b0, bool& b1, bool& b2, bool& b3 ) const;
|
bool get( bool& b0, bool& b1, bool& b2, bool& b3 ) const;
|
||||||
|
|
||||||
|
|
||||||
|
struct Callback : public virtual osg::Object
|
||||||
|
{
|
||||||
|
Callback() {}
|
||||||
|
|
||||||
|
Callback(const Callback&,const CopyOp&) {}
|
||||||
|
|
||||||
|
META_Object(osg,Callback);
|
||||||
|
|
||||||
|
/** do customized update code.*/
|
||||||
|
virtual void operator () (NodeVisitor*, Uniform*) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal.*/
|
||||||
|
void setUpdateCallback(Callback* uc) { _updateCallback = uc; }
|
||||||
|
|
||||||
|
/** Get the non const UpdateCallback.*/
|
||||||
|
Callback* getUpdateCallback() { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const UpdateCallback.*/
|
||||||
|
const Callback* getUpdateCallback() const { return _updateCallback.get(); }
|
||||||
|
|
||||||
|
|
||||||
|
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
|
||||||
|
void setEventCallback(Callback* ec) { _eventCallback = ec; }
|
||||||
|
|
||||||
|
/** Get the non const EventCallback.*/
|
||||||
|
Callback* getEventCallback() { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
/** Get the const EventCallback.*/
|
||||||
|
const Callback* getEventCallback() const { return _eventCallback.get(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void apply(const GL2Extensions* ext, GLint location) const;
|
void apply(const GL2Extensions* ext, GLint location) const;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual ~Uniform() {}
|
virtual ~Uniform() {}
|
||||||
|
Uniform& operator=(const Uniform&); // disallowed
|
||||||
|
|
||||||
bool isCompatibleType( Type t ) const;
|
bool isCompatibleType( Type t ) const;
|
||||||
|
|
||||||
@ -259,8 +295,9 @@ class OSG_EXPORT Uniform : public Object
|
|||||||
GLint i4[4]; // ivec4, bvec4
|
GLint i4[4]; // ivec4, bvec4
|
||||||
} _data;
|
} _data;
|
||||||
|
|
||||||
private:
|
ref_ptr<Callback> _updateCallback;
|
||||||
Uniform& operator=(const Uniform&); // disallowed
|
ref_ptr<Callback> _eventCallback;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ COPY_OP( Image, DEEP_COPY_IMAGES );
|
|||||||
COPY_OP( Array, DEEP_COPY_DRAWABLES );
|
COPY_OP( Array, DEEP_COPY_DRAWABLES );
|
||||||
COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES );
|
COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES );
|
||||||
COPY_OP( Shape, DEEP_COPY_SHAPES );
|
COPY_OP( Shape, DEEP_COPY_SHAPES );
|
||||||
|
COPY_OP( Uniform, DEEP_COPY_UNIFORMS );
|
||||||
|
|
||||||
Referenced* CopyOp::operator() (const Referenced* ref) const
|
Referenced* CopyOp::operator() (const Referenced* ref) const
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,6 @@ StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 //[ TODO
|
|
||||||
// copy uniform values
|
// copy uniform values
|
||||||
for(UniformList::const_iterator rhs_uitr = rhs._uniformList.begin();
|
for(UniformList::const_iterator rhs_uitr = rhs._uniformList.begin();
|
||||||
rhs_uitr != rhs._uniformList.end();
|
rhs_uitr != rhs._uniformList.end();
|
||||||
@ -122,9 +121,8 @@ StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop)
|
|||||||
const std::string& name = rhs_uitr->first;
|
const std::string& name = rhs_uitr->first;
|
||||||
const RefUniformPair& rup = rhs_uitr->second;
|
const RefUniformPair& rup = rhs_uitr->second;
|
||||||
Uniform* uni = copyop(rup.first.get());
|
Uniform* uni = copyop(rup.first.get());
|
||||||
if( uni ) _uniformList[name] = RefUniformPair(uni, rup.second);
|
if (uni) _uniformList[name] = RefUniformPair(uni, rup.second);
|
||||||
}
|
}
|
||||||
#endif //]
|
|
||||||
|
|
||||||
_renderingHint = rhs._renderingHint;
|
_renderingHint = rhs._renderingHint;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user