From 819d2c6c56d7aeacbd2e483119df283fb3af444e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Apr 2005 22:45:39 +0000 Subject: [PATCH] Preliminary steps to adding update and event callbacks to StateSet, StateAttribute and Uniform. --- include/osg/CopyOp | 4 +++- include/osg/Node | 8 +++---- include/osg/StateAttribute | 38 ++++++++++++++++++++++++++++- include/osg/StateSet | 49 ++++++++++++++++++++++++++++++++++++++ include/osg/Uniform | 47 ++++++++++++++++++++++++++++++++---- src/osg/CopyOp.cpp | 1 + src/osg/StateSet.cpp | 4 +--- 7 files changed, 137 insertions(+), 14 deletions(-) diff --git a/include/osg/CopyOp b/include/osg/CopyOp index f1010406e..cb2920c34 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -21,10 +21,10 @@ namespace osg { class Referenced; class Object; class Image; -//class Texture; class Texture; class StateSet; class StateAttribute; +class Uniform; class Node; class Drawable; class Array; @@ -51,6 +51,7 @@ class OSG_EXPORT CopyOp DEEP_COPY_ARRAYS = 128, DEEP_COPY_PRIMITIVES = 256, DEEP_COPY_SHAPES = 512, + DEEP_COPY_UNIFORMS = 1024, DEEP_COPY_ALL = 0xffffffff }; @@ -70,6 +71,7 @@ class OSG_EXPORT CopyOp virtual Array* operator() (const Array* array) const; virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const; virtual Shape* operator() (const Shape* shape) const; + virtual Uniform* operator() (const Uniform* shape) const; protected: diff --git a/include/osg/Node b/include/osg/Node index 92cee72da..c065e0bf6 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -135,8 +135,8 @@ class OSG_EXPORT Node : public Object /** Get const update node callback, called during update traversal. */ inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); } - /** Get the number of Children of this node which require App traversal, - * since they have an AppCallback attached to them or their children.*/ + /** Get the number of Children of this node which require Update traversal, + * since they have an Update Callback attached to them or their children.*/ 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. */ inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); } - /** Get the number of Children of this node which require App traversal, - * since they have an AppCallback attached to them or their children.*/ + /** Get the number of Children of this node which require Event traversal, + * since they have an Event Callback attached to them or their children.*/ inline unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; } diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index 287a3259a..7fc7bad62 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -30,7 +30,8 @@ namespace osg { -// forward declare State & StateSet +// forward declare NodeVisitor, State & StateSet +class NodeVisitor; class State; class StateSet; @@ -244,6 +245,39 @@ class OSG_EXPORT StateAttribute : public Object // default to no GLMode's associated with use of the StateAttribute. 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. * The global state for the current OpenGL context is passed @@ -265,6 +299,8 @@ class OSG_EXPORT StateAttribute : public Object virtual ~StateAttribute() {} + ref_ptr _updateCallback; + ref_ptr _eventCallback; }; } diff --git a/include/osg/StateSet b/include/osg/StateSet index f9d62d7cf..b2f7e7b7f 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -33,6 +33,9 @@ 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. * Notice that a \c StateSet contains just a subset of the whole OpenGL state. *

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; } + 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.*/ void compileGLObjects(State& state) const; @@ -406,6 +449,12 @@ class OSG_EXPORT StateSet : public Object RenderBinMode _binMode; int _binNum; std::string _binName; + + ref_ptr _updateCallback; + unsigned int _numObjectsRequiringUpdateTraversal; + + ref_ptr _eventCallback; + unsigned int _numObjectsRequiringEventTraversal; }; diff --git a/include/osg/Uniform b/include/osg/Uniform index bd1574590..7c74f3482 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -117,11 +117,11 @@ typedef char GLchar; namespace osg { -/////////////////////////////////////////////////////////////////////////// -/** Uniform encapsulates glUniform values */ - +// forward declare class GL2Extensions; +class NodeVisitor; +/** Uniform encapsulates glUniform values */ class OSG_EXPORT Uniform : public Object { 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, 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; protected: + virtual ~Uniform() {} + Uniform& operator=(const Uniform&); // disallowed bool isCompatibleType( Type t ) const; @@ -259,8 +295,9 @@ class OSG_EXPORT Uniform : public Object GLint i4[4]; // ivec4, bvec4 } _data; - private: - Uniform& operator=(const Uniform&); // disallowed + ref_ptr _updateCallback; + ref_ptr _eventCallback; + }; } diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index 9256ccb1d..9762bfbe4 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -39,6 +39,7 @@ COPY_OP( Image, DEEP_COPY_IMAGES ); COPY_OP( Array, DEEP_COPY_DRAWABLES ); COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES ); COPY_OP( Shape, DEEP_COPY_SHAPES ); +COPY_OP( Uniform, DEEP_COPY_UNIFORMS ); Referenced* CopyOp::operator() (const Referenced* ref) const { diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 66a96af63..ba03c29bb 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -113,7 +113,6 @@ StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop) } } -#if 0 //[ TODO // copy uniform values for(UniformList::const_iterator rhs_uitr = rhs._uniformList.begin(); 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 RefUniformPair& rup = rhs_uitr->second; 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;