Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods,

forcing users to use osgDB::readRef*File() methods.  The later is preferable as it closes a potential threading bug when using paging databases in conjunction
with the osgDB::Registry Object Cache.  This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only
a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another
thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero.  Using osgDB::readREf*File() makes sure the a ref_ptr<> is
passed back and the referenceCount never goes to zero.

To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File()
usage.  The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of
templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group:

    bool addChild(Node* child); // old method which can only be used with a Node*

    tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method

These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache
and multi-threaded loaded more robust.



git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-10-22 13:42:19 +00:00
parent 79fb9abbbf
commit dd996a3289
295 changed files with 2503 additions and 2172 deletions

View File

@@ -187,6 +187,8 @@ class OSG_EXPORT Drawable : public Node
*/
inline void setShape(Shape* shape) { _shape = shape; }
template<class T> void setShape(const ref_ptr<T>& shape) { setShape(shape.get()); }
/** Get the Shape of the Drawable.*/
inline Shape* getShape() { return _shape.get(); }

View File

@@ -49,6 +49,8 @@ class OSG_EXPORT Geode : public Group
*/
virtual bool addDrawable( Drawable *drawable );
template<class T> bool addDrawable( const ref_ptr<T>& drawable ) { return addDrawable(drawable.get()); }
/** Remove a \c Drawable from the \c Geode.
* Equivalent to <tt>removeDrawable(getDrawableIndex(drawable)</tt>.
* @param drawable The drawable to be removed.
@@ -57,6 +59,8 @@ class OSG_EXPORT Geode : public Group
*/
virtual bool removeDrawable( Drawable *drawable );
template<class T> bool removeDrawable( const ref_ptr<T>& drawable ) { return removeDrawable( drawable.get() ); }
/** Remove <tt>Drawable</tt>(s) from the specified position in
* <tt>Geode</tt>'s drawable list.
* @param i The index of the first \c Drawable to remove.
@@ -73,6 +77,8 @@ class OSG_EXPORT Geode : public Group
*/
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
template<class T, class R> bool replaceDrawable( const ref_ptr<T>& origDraw, const ref_ptr<R>& newDraw ) { return replaceDrawable(origDraw.get(), newDraw.get()); }
/** Set \c Drawable at position \c i.
* Decrement the reference count origGSet and increments the
* reference count of newGset, and dirty the bounding sphere
@@ -85,6 +91,8 @@ class OSG_EXPORT Geode : public Group
*/
virtual bool setDrawable( unsigned int i, Drawable* drawable );
template<class T> bool setDrawable( unsigned int i, const ref_ptr<T>& drawable ) { return setDrawable(i, drawable.get()); }
/** Return the number of <tt>Drawable</tt>s currently attached to the
* \c Geode.
*/
@@ -108,6 +116,8 @@ class OSG_EXPORT Geode : public Group
return false;
}
template<class T> bool containsDrawable(const ref_ptr<T>& drawable) const { return containsDrawable(drawable.get()); }
/** Get the index number of \c drawable.
* @return A value between 0 and <tt>getNumDrawables()-1</tt> if
* \c drawable is found; if not found, then
@@ -118,6 +128,8 @@ class OSG_EXPORT Geode : public Group
return getChildIndex(drawable);
}
template<class T> unsigned int getDrawableIndex( const ref_ptr<T>& drawable ) const { return getDrawableIndex(drawable.get()); }
/** Compile OpenGL Display List for each drawable.*/
void compileDrawables(RenderInfo& renderInfo);

View File

@@ -50,6 +50,8 @@ class OSG_EXPORT Group : public Node
*/
virtual bool addChild( Node *child );
template<class T> bool addChild( const ref_ptr<T>& child ) { return addChild(child.get()); }
/** Insert Node to Group at specific location.
* The new child node is inserted into the child list
* before the node at the specified index. No nodes
@@ -57,6 +59,8 @@ class OSG_EXPORT Group : public Node
*/
virtual bool insertChild( unsigned int index, Node *child );
template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child ) { return insertChild(index, child.get()); }
/** Remove Node from Group.
* If Node is contained in Group then remove it from the child
* list, decrement its reference count, and dirty the
@@ -67,6 +71,8 @@ class OSG_EXPORT Group : public Node
*/
virtual bool removeChild( Node *child );
template<class T> bool removeChild( const ref_ptr<T>& child ) { return removeChild(child.get()); }
/** Remove Node from Group.
* If Node is contained in Group then remove it from the child
* list, decrement its reference count, and dirty the
@@ -91,6 +97,8 @@ class OSG_EXPORT Group : public Node
*/
virtual bool replaceChild( Node *origChild, Node* newChild );
template<class T, class R> bool replaceChild( const ref_ptr<T>& origChild, const ref_ptr<R>& newChild ) { return replaceChild( origChild.get(), newChild.get()); }
/** Return the number of children nodes. */
virtual unsigned int getNumChildren() const;
@@ -124,6 +132,8 @@ class OSG_EXPORT Group : public Node
return false;
}
template<class T> bool conatainsNode(const ref_ptr<T>& node) const { return containsNode(node.get()); }
/** Get the index number of child, return a value between
* 0 and _children.size()-1 if found, if not found then
* return _children.size().

View File

@@ -542,11 +542,17 @@ class Geode;
* Use the image's s and t values to scale the dimensions of the image.
*/
extern OSG_EXPORT Geode* createGeodeForImage(Image* image);
template<class T> Geode* createGeodeForImage(const ref_ptr<T>& image) { return createGeodeForImage(image.get()); }
/** Convenience function to be used by image loaders to generate a valid geode
* to return for readNode().
* Use the specified s and t values to scale the dimensions of the image.
*/
extern OSG_EXPORT Geode* createGeodeForImage(Image* image,float s,float t);
extern OSG_EXPORT Geode* createGeodeForImage(Image* image, float s, float t);
template<class T> Geode* createGeodeForImage(const ref_ptr<T>& image, float s, float t) { return createGeodeForImage(image.get(), s, t); }
}

View File

@@ -92,6 +92,8 @@ class OSG_EXPORT ImageSequence : public ImageStream
void addImage(osg::Image* image);
template<class T> void addImage(const osg::ref_ptr<T>& image) { addImage(image.get()); }
void setImage(int s,int t,int r,
GLint internalTextureformat,
GLenum pixelFormat,GLenum type,
@@ -100,6 +102,9 @@ class OSG_EXPORT ImageSequence : public ImageStream
int packing=1) { Image::setImage(s,t,r,internalTextureformat, pixelFormat, type, data, mode, packing); }
void setImage(unsigned int pos, osg::Image* image);
template<class T> void setImage(unsigned int pos, const osg::ref_ptr<T>& image) { setImage(pos, image.get()); }
Image* getImage(unsigned int pos);
const Image* getImage(unsigned int pos) const;
@@ -108,7 +113,7 @@ class OSG_EXPORT ImageSequence : public ImageStream
ImageDataList& getImageDataList() { return _imageDataList; }
const ImageDataList& getImageDataList() const { return _imageDataList; }
/** ImageSequence requires a call to update(NodeVisitor*) during the update traversal so return true.*/
virtual bool requiresUpdateCall() const { return true; }

View File

@@ -48,9 +48,13 @@ class OSG_EXPORT LOD : public Group
virtual void traverse(NodeVisitor& nv);
using osg::Group::addChild;
virtual bool addChild(Node *child);
virtual bool addChild(Node *child, float min, float max);
virtual bool addChild(Node *child, float rmin, float rmax);
template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); }
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);

View File

@@ -212,6 +212,8 @@ class OSG_EXPORT Node : public Object
/** Set update node callback, called during update traversal. */
void setUpdateCallback(Callback* nc);
template<class T> void setUpdateCallback(const ref_ptr<T>& nc) { setUpdateCallback(nc.get()); }
/** Get update node callback, called during update traversal. */
inline Callback* getUpdateCallback() { return _updateCallback.get(); }
@@ -226,6 +228,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addUpdateCallback(const ref_ptr<T>& nc) { addUpdateCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeUpdateCallback(Callback* nc) {
if (nc != NULL && _updateCallback.valid()) {
@@ -239,6 +243,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void removeUpdateCallback(const ref_ptr<T>& nc) { removeUpdateCallback(nc.get()); }
/** 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; }
@@ -247,6 +253,8 @@ class OSG_EXPORT Node : public Object
/** Set event node callback, called during event traversal. */
void setEventCallback(Callback* nc);
template<class T> void setEventCallback(const ref_ptr<T>& nc) { setEventCallback(nc.get()); }
/** Get event node callback, called during event traversal. */
inline Callback* getEventCallback() { return _eventCallback.get(); }
@@ -261,6 +269,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addEventCallback(const ref_ptr<T>& nc) { addEventCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeEventCallback(Callback* nc) {
if (nc != NULL && _eventCallback.valid()) {
@@ -274,7 +284,9 @@ class OSG_EXPORT Node : public Object
}
}
/** Get the number of Children of this node which require Event traversal,
template<class T> void removeEventCallback(const ref_ptr<T>& nc) { removeEventCallback(nc.get()); }
/** 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; }
@@ -282,6 +294,8 @@ class OSG_EXPORT Node : public Object
/** Set cull node callback, called during cull traversal. */
void setCullCallback(Callback* nc) { _cullCallback = nc; }
template<class T> void setCullCallback(const ref_ptr<T>& nc) { setCullCallback(nc.get()); }
/** Get cull node callback, called during cull traversal. */
inline Callback* getCullCallback() { return _cullCallback.get(); }
@@ -296,6 +310,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void addCullCallback(const ref_ptr<T>& nc) { addCullCallback(nc.get()); }
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeCullCallback(Callback* nc) {
if (nc != NULL && _cullCallback.valid()) {
@@ -309,6 +325,8 @@ class OSG_EXPORT Node : public Object
}
}
template<class T> void removeCullCallback(const ref_ptr<T>& nc) { removeCullCallback(nc.get()); }
/** Set the view frustum/small feature culling of this node to be active or inactive.
* The default value is true for _cullingActive. Used as a guide
* to the cull traversal.*/
@@ -360,6 +378,8 @@ class OSG_EXPORT Node : public Object
/** Set the node's StateSet.*/
void setStateSet(osg::StateSet* stateset);
template<class T> void setStateSet(const osg::ref_ptr<T>& stateset) { setStateSet(stateset.get()); }
/** return the node's StateSet, if one does not already exist create it
* set the node and return the newly created StateSet. This ensures
* that a valid StateSet is always returned and can be used directly.*/
@@ -444,6 +464,8 @@ class OSG_EXPORT Node : public Object
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundingSphereCallback(ComputeBoundingSphereCallback* callback) { _computeBoundCallback = callback; }
template<class T> void setComputeBoundingSphereCallback(const ref_ptr<T>& callback) { setComputeBoundingSphereCallback(callback.get()); }
/** Get the compute bound callback.*/
ComputeBoundingSphereCallback* getComputeBoundingSphereCallback() { return _computeBoundCallback.get(); }

View File

@@ -104,7 +104,7 @@ class OSG_EXPORT NodeVisitor : public virtual Object
* Equivalent to dynamic_cast<const NodeVisitor*>(this).*/
virtual const NodeVisitor* asNodeVisitor() const { return this; }
/** Method to call to reset visitor. Useful if your visitor accumulates
state during a traversal, and you plan to reuse the visitor.
To flush that state for the next traversal: call reset() prior
@@ -303,7 +303,7 @@ class OSG_EXPORT NodeVisitor : public virtual Object
virtual double getPreLoadTime() const = 0;
virtual osg::Image* readImageFile(const std::string& fileName, const osg::Referenced* options=0) = 0;
virtual osg::ref_ptr<osg::Image> readRefImageFile(const std::string& fileName, const osg::Referenced* options=0) = 0;
virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options=0) = 0;

View File

@@ -92,8 +92,8 @@ class OSG_EXPORT Object : public Referenced
/** return the compound class name that combines the library name and class name.*/
std::string getCompoundClassName() const { return std::string(libraryName()) + std::string("::") + std::string(className()); }
/** Convert 'this' into a Node pointer if Object is a Node, otherwise return 0.
* Equivalent to dynamic_cast<Node*>(this).*/
virtual Node* asNode() { return 0; }
@@ -168,6 +168,8 @@ class OSG_EXPORT Object : public Referenced
/** set the UserDataContainer object.*/
void setUserDataContainer(osg::UserDataContainer* udc);
template<class T> void setUserDataContainer(const ref_ptr<T>& udc) { setUserDataContainer(udc.get()); }
/** get the UserDataContainer attached to this object.*/
osg::UserDataContainer* getUserDataContainer() { return _userDataContainer; }
@@ -187,6 +189,8 @@ class OSG_EXPORT Object : public Referenced
*/
virtual void setUserData(Referenced* obj);
template<class T> void setUserData(const ref_ptr<T>& ud) { setUserData(ud.get()); }
/** Get user data.*/
virtual Referenced* getUserData();

View File

@@ -31,15 +31,19 @@ class OSG_EXPORT PagedLOD : public LOD
META_Node(osg, PagedLOD);
virtual void traverse(NodeVisitor& nv);
using osg::Group::addChild;
virtual bool addChild(Node *child);
virtual bool addChild(Node *child, float min, float max);
virtual bool addChild(Node *child, float rmin, float rmax);
virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); }
virtual bool addChild(Node *child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f) { return addChild(child.get(), rmin, rmax, filename, priorityOffset, priorityScale); }
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);

View File

@@ -86,6 +86,8 @@ class OSG_EXPORT Program : public osg::StateAttribute
* Mark Program as needing relink. Return true for success */
bool addShader( Shader* shader );
template<class T> bool addShader( const ref_ptr<T>& shader ) { return addShader(shader.get()); }
unsigned int getNumShaders() const { return static_cast<unsigned int>(_shaderList.size()); }
Shader* getShader( unsigned int i ) { return _shaderList[i].get(); }
@@ -95,6 +97,8 @@ class OSG_EXPORT Program : public osg::StateAttribute
* Mark Program as needing relink. Return true for success */
bool removeShader( Shader* shader );
template<class T> bool removeShader( const ref_ptr<T>& shader ) { return removeShader(shader.get()); }
/** Set/get GL program parameters */
void setParameter( GLenum pname, GLint value );
GLint getParameter( GLenum pname ) const;

View File

@@ -36,9 +36,14 @@ class OSG_EXPORT ProxyNode : public Group
virtual void traverse(NodeVisitor& nv);
using osg::Group::addChild;
virtual bool addChild(Node *child);
virtual bool addChild(Node *child, const std::string& filename);
template<class T> bool addChild( const ref_ptr<T>& child, const std::string& filename) { return addChild(child.get(), filename); }
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);

View File

@@ -41,14 +41,22 @@ class OSG_EXPORT Sequence : public Group
// maintained. New code should set defaultTime and use addChild, and
// not mess with the setTime method
using osg::Group::addChild;
using osg::Group::insertChild;
using osg::Group::removeChild;
virtual bool addChild( Node *child);
virtual bool addChild( Node *child, double t);
template<class T> bool addChild( const ref_ptr<T>& child, double t) { return addChild(child.get(), t); }
virtual bool insertChild( unsigned int index, Node *child);
virtual bool insertChild( unsigned int index, Node *child, double t);
template<class T> bool insertChild( unsigned int index, const ref_ptr<T>& child, double t) { return insertChild(index, child.get(), t); }
virtual bool removeChild( Node *child );
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);

View File

@@ -622,6 +622,8 @@ class OSG_EXPORT CompositeShape : public Shape
/** Add a child to the list.*/
void addChild(Shape* shape) { _children.push_back(shape); }
template<class T> void addChild( const ref_ptr<T>& child ) { addChild(child.get()); }
/** remove a child from the list.*/
void removeChild(unsigned int i) { _children.erase(_children.begin()+i); }

View File

@@ -132,6 +132,12 @@ class OSG_EXPORT ShapeDrawable : public Drawable
ShapeDrawable(Shape* shape, TessellationHints* hints=0);
template<class T> ShapeDrawable(const ref_ptr<T>& shape, TessellationHints* hints=0):
_color(1.0f,1.0f,1.0f,1.0f),
_tessellationHints(hints) { setShape(shape.get()); }
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);

View File

@@ -160,15 +160,21 @@ class OSG_EXPORT StateSet : public Object
/** Set this StateSet to contain specified attribute and override flag.*/
void setAttribute(StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
template<class T> void setAttribute(const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setAttribute(attribute.get(), value); }
/** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
void setAttributeAndModes(StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
template<class T> void setAttributeAndModes(const ref_ptr<T>& attribute, StateAttribute::GLModeValue value=StateAttribute::ON) { setAttribute(attribute.get(), value); }
/** remove attribute of specified type from StateSet.*/
void removeAttribute(StateAttribute::Type type, unsigned int member=0);
/** remove attribute from StateSet.*/
void removeAttribute(StateAttribute *attribute);
template<class T> void removeAttribute(const ref_ptr<T>& attribute) { removeAttribute(attribute.get()); }
/** Get specified StateAttribute for specified type.
* Returns NULL if no type is contained within StateSet.*/
StateAttribute* getAttribute(StateAttribute::Type type, unsigned int member = 0);
@@ -226,15 +232,22 @@ class OSG_EXPORT StateSet : public Object
/** Set this StateSet to contain specified attribute and override flag.*/
void setTextureAttribute(unsigned int unit,StateAttribute *attribute, StateAttribute::OverrideValue value=StateAttribute::OFF);
template<class T> void setTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttribute( unit, attribute.get(), value); }
/** Set this StateSet to contain specified attribute and set the associated GLMode's to specified value.*/
void setTextureAttributeAndModes(unsigned int unit,StateAttribute *attribute, StateAttribute::GLModeValue value=StateAttribute::ON);
template<class T> void setTextureAttributeAndModes(unsigned int unit, const ref_ptr<T>& attribute, StateAttribute::OverrideValue value=StateAttribute::OFF) { setTextureAttributeAndModes( unit, attribute.get(), value); }
/** remove texture attribute of specified type from StateSet.*/
void removeTextureAttribute(unsigned int unit, StateAttribute::Type type);
/** remove texture attribute from StateSet.*/
void removeTextureAttribute(unsigned int unit, StateAttribute *attribute);
template<class T> void removeTextureAttribute(unsigned int unit, const ref_ptr<T>& attribute) { removeTextureAttribute(unit, attribute.get()); }
/** Get specified Texture related StateAttribute for specified type.
* Returns NULL if no type is contained within StateSet.*/
StateAttribute* getTextureAttribute(unsigned int unit,StateAttribute::Type type);
@@ -278,12 +291,16 @@ class OSG_EXPORT StateSet : public Object
/** Set this StateSet to contain specified uniform and override flag.*/
void addUniform(Uniform* uniform, StateAttribute::OverrideValue value=StateAttribute::ON);
template<class T> void addUniform(const ref_ptr<T>& uniform, StateAttribute::OverrideValue value=StateAttribute::ON) { addUniform( uniform.get(), value); }
/** remove uniform of specified name from StateSet.*/
void removeUniform(const std::string& name);
/** remove Uniform from StateSet.*/
void removeUniform(Uniform* uniform);
template<class T> void removeUniform(const ref_ptr<T>& uniform) { removeUniform(uniform.get()); }
/** Get Uniform for specified name.
* Returns NULL if no matching Uniform is contained within StateSet.*/
Uniform* getUniform(const std::string& name);
@@ -427,6 +444,8 @@ class OSG_EXPORT StateSet : public Object
/** Set the Update Callback which allows users to attach customize the updating of an object during the update traversal.*/
void setUpdateCallback(Callback* ac);
template<class T> void setUpdateCallback(const ref_ptr<T>& ac) { setUpdateCallback(ac.get()); }
/** Get the non const Update Callback.*/
Callback* getUpdateCallback() { return _updateCallback.get(); }
@@ -447,6 +466,8 @@ class OSG_EXPORT StateSet : public Object
/** Set the Event Callback which allows users to attach customize the updating of an object during the event traversal.*/
void setEventCallback(Callback* ac);
template<class T> void setEventCallback(const ref_ptr<T>& ec) { setEventCallback(ec.get()); }
/** Get the non const Event Callback.*/
Callback* getEventCallback() { return _eventCallback.get(); }

View File

@@ -45,6 +45,9 @@ class OSG_EXPORT Switch : public Group
bool getNewChildDefaultValue() const { return _newChildDefaultValue; }
using osg::Group::addChild;
using osg::Group::insertChild;
virtual bool addChild( Node *child );
virtual bool addChild( Node *child, bool value );

View File

@@ -747,6 +747,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
/** Sets the texture image for the specified face. */
virtual void setImage(unsigned int face, Image* image) = 0;
template<class T> void setImage(unsigned int face, const ref_ptr<T>& image) { setImage(face, image.get()); }
/** Gets the texture image for the specified face. */
virtual Image* getImage(unsigned int face) = 0;
@@ -760,6 +762,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute
/** Set the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/
void setReadPBuffer(GraphicsContext* context) { _readPBuffer = context; }
template<class T> void setReadPBuffer(const ref_ptr<T>& context) { setReadPBuffer(context.get()); }
/** Get the PBuffer graphics context to read from when using PBuffers for RenderToTexture.*/
GraphicsContext* getReadPBuffer() { return _readPBuffer.get(); }

View File

@@ -36,6 +36,13 @@ class OSG_EXPORT Texture1D : public Texture
Texture1D(Image* image);
template<class T> Texture1D(const osg::ref_ptr<T>& image):
_textureWidth(0),
_numMipmapLevels(0)
{
setImage(image.get());
}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Texture1D(const Texture1D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
@@ -49,6 +56,8 @@ class OSG_EXPORT Texture1D : public Texture
/** Sets the texture image. */
void setImage(Image* image);
template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
/** Gets the texture image. */
Image* getImage() { return _image.get(); }

View File

@@ -30,6 +30,15 @@ class OSG_EXPORT Texture2D : public Texture
Texture2D(Image* image);
template<class T> Texture2D(const osg::ref_ptr<T>& image):
_textureWidth(0),
_textureHeight(0),
_numMipmapLevels(0)
{
setUseHardwareMipMapGeneration(true);
setImage(image.get());
}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Texture2D(const Texture2D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
@@ -43,6 +52,8 @@ class OSG_EXPORT Texture2D : public Texture
/** Sets the texture image. */
void setImage(Image* image);
template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
/** Gets the texture image. */
Image* getImage() { return _image.get(); }
@@ -59,6 +70,8 @@ class OSG_EXPORT Texture2D : public Texture
/** Sets the texture image, ignoring face. */
virtual void setImage(unsigned int, Image* image) { setImage(image); }
template<class T> void setImage(unsigned int, const ref_ptr<T>& image) { setImage(image.get()); }
/** Gets the texture image, ignoring face. */
virtual Image* getImage(unsigned int) { return _image.get(); }

View File

@@ -48,6 +48,8 @@ class OSG_EXPORT Texture2DArray : public Texture
/** Set the texture image for specified layer. */
virtual void setImage(unsigned int layer, Image* image);
template<class T> void setImage(unsigned int layer, const ref_ptr<T>& image) { setImage(layer, image.get()); }
/** Get the texture image for specified layer. */
virtual Image* getImage(unsigned int layer);

View File

@@ -63,6 +63,7 @@ class OSG_EXPORT Texture2DMultisample : public Texture
// unnecessary for Texture2DMultisample
virtual void setImage(unsigned int /*face*/, Image* /*image*/) {}
virtual Image* getImage(unsigned int /*face*/) { return NULL; }
virtual const Image* getImage(unsigned int /*face*/) const { return NULL; }
virtual unsigned int getNumImages() const {return 0; }

View File

@@ -30,6 +30,16 @@ class OSG_EXPORT Texture3D : public Texture
Texture3D(Image* image);
template<class T> Texture3D(const osg::ref_ptr<T>& image):
_textureWidth(0),
_textureHeight(0),
_textureDepth(0),
_numMipmapLevels(0)
{
setImage(image.get());
}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
@@ -43,6 +53,8 @@ class OSG_EXPORT Texture3D : public Texture
/** Sets the texture image. */
void setImage(Image* image);
template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
/** Gets the texture image. */
Image* getImage() { return _image.get(); }

View File

@@ -49,6 +49,8 @@ class OSG_EXPORT TextureCubeMap : public Texture
/** Set the texture image for specified face. */
virtual void setImage(unsigned int face, Image* image);
template<class T> void setImage(unsigned int face, const ref_ptr<T>& image) { setImage(face, image.get()); }
/** Get the texture image for specified face. */
virtual Image* getImage(unsigned int face);

View File

@@ -36,6 +36,19 @@ class OSG_EXPORT TextureRectangle : public Texture
TextureRectangle(Image* image);
template<class T> TextureRectangle(const osg::ref_ptr<T>& image):
_textureWidth(0),
_textureHeight(0)
{
setWrap(WRAP_S, CLAMP);
setWrap(WRAP_T, CLAMP);
setFilter(MIN_FILTER, LINEAR);
setFilter(MAG_FILTER, LINEAR);
setImage(image.get());
}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
TextureRectangle(const TextureRectangle& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
@@ -49,6 +62,8 @@ class OSG_EXPORT TextureRectangle : public Texture
/** Set the texture image. */
void setImage(Image* image);
template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
/** Get the texture image. */
Image* getImage() { return _image.get(); }

View File

@@ -47,6 +47,8 @@ class OSG_EXPORT UserDataContainer : public osg::Object
*/
virtual void setUserData(Referenced* obj) = 0;
using osg::Object::setUserData;
/** Get user data.*/
virtual Referenced* getUserData() = 0;
@@ -56,6 +58,8 @@ class OSG_EXPORT UserDataContainer : public osg::Object
/** Add user data object. Returns the index position of object added. */
virtual unsigned int addUserObject(Object* obj) = 0;
template<class T> unsigned int addUserObject(const osg::ref_ptr<T>& obj) { return addUserObject(obj.get()); }
/** Add element to list of user data objects.*/
virtual void setUserObject(unsigned int i, Object* obj) = 0;
@@ -127,6 +131,9 @@ class OSG_EXPORT DefaultUserDataContainer : public osg::UserDataContainer
*/
virtual void setUserData(Referenced* obj);
using osg::Object::setUserData;
using osg::UserDataContainer::addUserObject;
/** Get user data.*/
virtual Referenced* getUserData();

View File

@@ -78,7 +78,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
void setPreLoadTime(double preLoadTime) { _preLoadTime=preLoadTime; }
virtual double getPreLoadTime() const { return _preLoadTime; }
virtual osg::Image* readImageFile(const std::string& fileName, const osg::Referenced* options=0);
virtual osg::ref_ptr<osg::Image> readRefImageFile(const std::string& fileName, const osg::Referenced* options=0);
virtual void requestImageFile(const std::string& fileName, osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const osg::FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& imageRequest, const osg::Referenced* options);

View File

@@ -288,10 +288,10 @@ class OSGDB_EXPORT Input : public FieldReaderIterator
virtual osg::Node* readNode();
virtual osg::Shader* readShader();
virtual osg::Object* readObject(const std::string& fileName);
virtual osg::Image* readImage(const std::string& fileName);
virtual osg::Node* readNode(const std::string& fileName);
virtual osg::Shader* readShader(const std::string& fileName);
virtual osg::ref_ptr<osg::Object> readObject(const std::string& fileName);
virtual osg::ref_ptr<osg::Image> readImage(const std::string& fileName);
virtual osg::ref_ptr<osg::Node> readNode(const std::string& fileName);
virtual osg::ref_ptr<osg::Shader> readShader(const std::string& fileName);
virtual osg::Object* getObjectForUniqueID(const std::string& uniqueID);
virtual void registerUniqueIDForObject(const std::string& uniqueID,osg::Object* obj);

View File

@@ -137,17 +137,12 @@ public:
InputStream& operator>>( osg::BoundingSpheref& bs );
InputStream& operator>>( osg::BoundingSphered& bs );
InputStream& operator>>( osg::Image*& img ) { img = readImage(); return *this; }
InputStream& operator>>( osg::Array*& a ) { if (_fileVersion>=112) a = readObjectOfType<osg::Array>(); else a = readArray(); return *this; }
InputStream& operator>>( osg::PrimitiveSet*& p ) { if (_fileVersion>=112) p = readObjectOfType<osg::PrimitiveSet>(); else p = readPrimitiveSet(); return *this; }
InputStream& operator>>( osg::Object*& obj ) { obj = readObject(); return *this; }
InputStream& operator>>( osg::ref_ptr<osg::Image>& ptr ) { ptr = readImage(); return *this; }
InputStream& operator>>( osg::ref_ptr<osg::Array>& ptr ) { if (_fileVersion>=112) ptr = readObjectOfType<osg::Array>(); else ptr = readArray(); return *this; }
InputStream& operator>>( osg::ref_ptr<osg::PrimitiveSet>& ptr ) { if (_fileVersion>=112) ptr = readObjectOfType<osg::PrimitiveSet>(); else ptr = readPrimitiveSet(); return *this; }
template<typename T> InputStream& operator>>( osg::ref_ptr<T>& ptr )
{ ptr = static_cast<T*>(readObject()); return *this; }
{ ptr = readObjectOfType<T>(); return *this; }
// Convenient methods for reading
bool matchString( const std::string& str ) { return _in->matchString(str); }
@@ -160,23 +155,31 @@ public:
unsigned int readSize() { unsigned int size; *this>>size; return size; }
// Global reading functions
osg::Array* readArray();
osg::PrimitiveSet* readPrimitiveSet();
osg::Image* readImage(bool readFromExternal=true);
osg::ref_ptr<osg::Array> readArray();
osg::ref_ptr<osg::PrimitiveSet> readPrimitiveSet();
osg::ref_ptr<osg::Image> readImage(bool readFromExternal=true);
template<typename T>
T* readObjectOfType()
osg::ref_ptr<T> readObjectOfType()
{
osg::ref_ptr<osg::Object> obj = readObject();
T* ptr = dynamic_cast<T*>(obj.get());
if (ptr) { obj.release(); return ptr; }
if (ptr) { return ptr; }
else return 0;
}
osg::Object* readObject( osg::Object* existingObj=0 );
osg::ref_ptr<osg::Object> readObject( osg::Object* existingObj=0 );
osg::ref_ptr<osg::Object> readObjectFields( const std::string& className, unsigned int id, osg::Object* existingObj=0);
osg::Object* readObjectFields( const std::string& className, unsigned int id, osg::Object* existingObj=0);
template<typename T>
osg::ref_ptr<T> readObjectFieldsOfType( const std::string& className, unsigned int id, osg::Object* existingObj=0)
{
osg::ref_ptr<osg::Object> obj = readObjectFields(className, id, existingObj);
T* ptr = dynamic_cast<T*>(obj.get());
if (ptr) { return ptr; }
else return 0;
}
/// set an input iterator, used directly when not using InputStream with a traditional file releated stream.
void setInputIterator( InputIterator* ii ) { _in = ii; }

View File

@@ -26,6 +26,215 @@
namespace osgDB {
/** Read an osg::Object from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const Options* options);
/** Read an osg::Object from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
{
return readRefObjectFile(filename, Registry::instance()->getOptions());
}
template<class T>
inline osg::ref_ptr<T> readRefFile(const std::string& filename, const Options* options)
{
osg::ref_ptr<osg::Object> object = readRefObjectFile(filename, options);
osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
return t;
}
template<class T>
inline osg::ref_ptr<T> readRefFile(const std::string& filename)
{
return readRefFile<T>(filename, Registry::instance()->getOptions());
}
/** Read an osg::Image from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
/** Read an osg::Image from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
{
return readRefImageFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::HeightField from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
/** Read an osg::HeightField from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
{
return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Node from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
/** Read an osg::Node from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
{
return readRefNodeFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* Does NOT ignore strings beginning with a dash '-' character. */
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFiles(std::vector<std::string>& fileList,const Options* options);
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.*/
inline osg::ref_ptr<osg::Node> readRefNodeFiles(std::vector<std::string>& fileList)
{
return readRefNodeFiles(fileList, Registry::instance()->getOptions());
}
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFiles(osg::ArgumentParser& parser,const Options* options);
/** Read an osg::Node subgraph from files, creating a osg::Group to contain the nodes if more
* than one subgraph has been loaded.*/
inline osg::ref_ptr<osg::Node> readRefNodeFiles(osg::ArgumentParser& parser)
{
return readRefNodeFiles(parser,Registry::instance()->getOptions());
}
/** Read an osg::Shader from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename,const Options* options);
/** Read an osg::Shader from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
{
return readRefShaderFile(filename, Registry::instance()->getOptions());
}
/** Read an osg::Shader from file and set to specified shader type.
* Return valid osg::Shader on success,
* return NULL on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options)
{
osg::ref_ptr<osg::Shader> shader = readRefShaderFile(filename, options);
if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type);
return shader;
}
/** Read an osg::Shader from file and set to specified shader type
* Return valid osg::Shader on success,
* return NULL on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename)
{
return readRefShaderFile(type, filename, Registry::instance()->getOptions());
}
/** Read an osg::Shader from file and set to specified shader type, if a shader isn't loaded fallback to specific shader source.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const Options* options, const char* fallback)
{
osg::ref_ptr<osg::Shader> shader = readRefShaderFile(filename, options);
if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type);
if (!shader) shader = new osg::Shader(type, fallback);
return shader;
}
/** Read an osg::Shader from file and set to specified shader type, if a shader isn't loaded fallback to specific shader source.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFileWithFallback(osg::Shader::Type type, const std::string& filename, const char* fallback)
{
return osgDB::readRefShaderFileWithFallback(type, filename, Registry::instance()->getOptions(), fallback);
}
/** Read an osg::Script from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename,const Options* options);
/** Read an osg::Script from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename)
{
return readRefScriptFile(filename,Registry::instance()->getOptions());
}
#ifdef OSG_PROVIDE_READFILE
/** Read an osg::Object from file.
* Return valid osg::Object on success,
* return NULL on failure.
@@ -49,7 +258,7 @@ inline osg::Object* readObjectFile(const std::string& filename)
template<typename T>
inline T* readFile(const std::string& filename, const Options* options)
{
osg::ref_ptr<osg::Object> object = readObjectFile(filename, options);
osg::ref_ptr<osg::Object> object = readRefObjectFile(filename, options);
osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
object = 0;
return t.release();
@@ -236,155 +445,9 @@ inline osg::Script* readScriptFile(const std::string& filename)
{
return readScriptFile(filename,Registry::instance()->getOptions());
}
#endif
/** Read an osg::Object from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename,const Options* options);
/** Read an osg::Object from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Object> readRefObjectFile(const std::string& filename)
{
return readRefObjectFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Image from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename,const Options* options);
/** Read an osg::Image from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Image> readRefImageFile(const std::string& filename)
{
return readRefImageFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::HeightField from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename,const Options* options);
/** Read an osg::HeightField from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::HeightField> readRefHeightFieldFile(const std::string& filename)
{
return readRefHeightFieldFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Node from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename,const Options* options);
/** Read an osg::Node from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Node> readRefNodeFile(const std::string& filename)
{
return readRefNodeFile(filename,Registry::instance()->getOptions());
}
/** Read an osg::Shader from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename,const Options* options);
/** Read an osg::Shader from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(const std::string& filename)
{
return readRefShaderFile(filename, Registry::instance()->getOptions());
}
/** Read an osg::Shader from file and set to specified shader type.
* Return valid osg::Shader on success,
* return NULL on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename, const Options* options)
{
osg::ref_ptr<osg::Shader> shader = readShaderFile(filename, options);
if (shader.valid() && type != osg::Shader::UNDEFINED) shader->setType(type);
return shader;
}
/** Read an osg::Shader from file and set to specified shader type
* Return valid osg::Shader on success,
* return NULL on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Shader> readRefShaderFile(osg::Shader::Type type, const std::string& filename)
{
return readRefShaderFile(type, filename, Registry::instance()->getOptions());
}
/** Read an osg::Script from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* Use the Options object to control cache operations and file search paths in osgDB::Registry.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
extern OSGDB_EXPORT osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename,const Options* options);
/** Read an osg::Script from file.
* Return an assigned osg::ref_ptr on success,
* return an osg::ref_ptr with a NULL pointer assigned to it on failure.
* The osgDB::Registry is used to load the appropriate ReaderWriter plugin
* for the filename extension, and this plugin then handles the request
* to read the specified file.*/
inline osg::ref_ptr<osg::Script> readRefScriptFile(const std::string& filename)
{
return readRefScriptFile(filename,Registry::instance()->getOptions());
}
}
#endif

View File

@@ -123,8 +123,12 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
ReadResult(ReadStatus status=FILE_NOT_HANDLED):_status(status) {}
ReadResult(const std::string& m):_status(ERROR_IN_READING_FILE),_message(m) {}
ReadResult(osg::Object* obj, ReadStatus status=FILE_LOADED):_status(status),_object(obj) {}
template<class T>
ReadResult(const osg::ref_ptr<T>& obj, ReadStatus status=FILE_LOADED):_status(status),_object(obj.get()) {}
ReadResult(const ReadResult& rr):_status(rr._status),_message(rr._message),_object(rr._object) {}
ReadResult& operator = (const ReadResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message;_object=rr._object; return *this; }

View File

@@ -563,8 +563,8 @@ public:
is >> hasObject;
if ( hasObject )
{
P* value = dynamic_cast<P*>( is.readObject() );
(object.*_setter)( value );
osg::ref_ptr<P> value = is.readObjectOfType<P>();
(object.*_setter)( value.get() );
}
}
else if ( is.matchString(ParentType::_name) )
@@ -573,8 +573,8 @@ public:
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
P* value = dynamic_cast<P*>( is.readObject() );
(object.*_setter)( value );
osg::ref_ptr<P> value = is.readObjectOfType<P>();
(object.*_setter)( value.get() );
is >> is.END_BRACKET;
}
}
@@ -639,7 +639,8 @@ public:
is >> hasObject;
if ( hasObject )
{
P* value = dynamic_cast<P*>( is.readImage() );
osg::ref_ptr<osg::Image> image = is.readImage();
P* value = dynamic_cast<P*>( image.get() );
(object.*_setter)( value );
}
}
@@ -649,7 +650,8 @@ public:
if ( hasObject )
{
is >> is.BEGIN_BRACKET;
P* value = dynamic_cast<P*>( is.readImage() );
osg::ref_ptr<osg::Image> image = is.readImage();
P* value = dynamic_cast<P*>( image.get() );
(object.*_setter)( value );
is >> is.END_BRACKET;
}
@@ -1457,7 +1459,7 @@ public:
bool ok = false; is >> ok; //code from user serialized ensuring backwards-compatibility
if ( !ok ) return true;
}
P mask;
is >> mask;
(object.*_setter)( mask );
@@ -1844,7 +1846,7 @@ protected:
#define END_ENUM_SERIALIZER() \
wrapper->addSerializer(serializer.get(), osgDB::BaseSerializer::RW_ENUM); }
/** defaults to uint bitfield type.*/
#define BEGIN_BITFLAGS_SERIALIZER(PROP, DEF) \
{ typedef osgDB::BitFlagsSerializer<MyClass> MySerializer; \

View File

@@ -204,6 +204,7 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform
* this dragger.
*/
virtual void setParentDragger(Dragger* parent) { _parentDragger = parent; }
Dragger* getParentDragger() { return _parentDragger; }
const Dragger* getParentDragger() const { return _parentDragger; }
@@ -236,7 +237,10 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform
typedef std::vector< osg::ref_ptr<Constraint> > Constraints;
void addConstraint(Constraint* constraint);
template<class T> void addConstraint(const osg::ref_ptr<T>& c) { addConstraint(c.get()); }
void removeConstraint(Constraint* constraint);
template<class T> void removeConstraint(const osg::ref_ptr<T>& c) { removeConstraint(c.get()); }
Constraints& getConstraints() { return _constraints; }
const Constraints& getConstraints() const { return _constraints; }
@@ -245,7 +249,10 @@ class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform
typedef std::vector< osg::ref_ptr<DraggerCallback> > DraggerCallbacks;
void addDraggerCallback(DraggerCallback* dc);
template<class T> void addDraggerCallback(const osg::ref_ptr<T>& dc) { addDraggerCallback(dc.get()); }
void removeDraggerCallback(DraggerCallback* dc);
template<class T> void removeDraggerCallback(const osg::ref_ptr<T>& dc) { removeDraggerCallback(dc.get()); }
DraggerCallbacks& getDraggerCallbacks() { return _draggerCallbacks; }
const DraggerCallbacks& getDraggerCallbacks() const { return _draggerCallbacks; }
@@ -320,11 +327,19 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
// Composite-specific methods below
virtual bool addDragger(Dragger* dragger);
template<class T> bool addDragger(const osg::ref_ptr<T>& dc) { return addDragger(dc.get()); }
virtual bool removeDragger(Dragger* dragger);
template<class T> bool removeDragger(const osg::ref_ptr<T>& dc) { return removeDragger(dc.get()); }
unsigned int getNumDraggers() const { return _draggerList.size(); }
Dragger* getDragger(unsigned int i) { return _draggerList[i].get(); }
const Dragger* getDragger(unsigned int i) const { return _draggerList[i].get(); }
bool containsDragger(const Dragger* dragger) const;
template<class T> bool containsDragger(const osg::ref_ptr<T>& dc) const { return containsDragger(dc.get()); }
DraggerList::iterator findDragger(const Dragger* dragger);
virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask);

View File

@@ -179,12 +179,15 @@ namespace osgParticle
/// Set the interpolator for computing size values.
inline void setSizeInterpolator(Interpolator* ri);
template<class T> void setSizeInterpolator(const osg::ref_ptr<T>& ri) { setSizeInterpolator(ri.get()); }
/// Set the interpolator for computing alpha values.
inline void setAlphaInterpolator(Interpolator* ai);
template<class T> void setAlphaInterpolator(const osg::ref_ptr<T>& ri) { setAlphaInterpolator(ri.get()); }
/// Set the interpolator for computing color values.
inline void setColorInterpolator(Interpolator* ci);
template<class T> void setColorInterpolator(const osg::ref_ptr<T>& ri) { setColorInterpolator(ri.get()); }
/** Set the physical radius of the particle.
For built-in operators to work correctly, lengths must be expressed in meters.
@@ -284,6 +287,7 @@ namespace osgParticle
/// Set the user-defined particle drawable
inline void setDrawable(osg::Drawable* d) { _drawable = d; }
template<class T> void setDrawable(const osg::ref_ptr<T>& ri) { setDrawable(ri.get()); }
/// Get the user-defined particle drawable
inline osg::Drawable* getDrawable() const { return _drawable.get(); }

View File

@@ -85,6 +85,8 @@ namespace osgParticle
virtual const Program* getProgram() const = 0;
void setParticleSystem(ParticleSystem* ps);
template<class T> void setParticleSystem(const osg::ref_ptr<T>& ri) { setParticleSystem(ri.get()); }
inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }

View File

@@ -478,7 +478,7 @@ public:
void addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData, const ScriptData& scriptData);
osg::Image* readImage(const std::string& filename, const ImageData& imageData);
osg::ref_ptr<osg::Image> readImage(const std::string& filename, const ImageData& imageData);
void addImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
@@ -488,7 +488,7 @@ public:
void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const std::string& password, const ScriptData& scriptData);
void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
osg::Image* addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
osg::ref_ptr<osg::Image> addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData, const ScriptData& scriptData);

View File

@@ -38,10 +38,14 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
virtual void traverse(osg::NodeVisitor& nv);
void setShadowSettings(ShadowSettings* ss);
template<class T> void setShadowSettings(const osg::ref_ptr<T>& ss) { setShadowSettings(ss.get()); }
ShadowSettings* getShadowSettings() { return _shadowSettings.get(); }
const ShadowSettings* getShadowSettings() const { return _shadowSettings.get(); }
void setShadowTechnique(ShadowTechnique* technique);
template<class T> void setShadowTechnique(const osg::ref_ptr<T>& ss) { setShadowTechnique(ss.get()); }
ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); }
const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); }

View File

@@ -32,7 +32,7 @@ class OSGSIM_EXPORT DatabaseCacheReadCallback : public osgUtil::IntersectionVisi
void pruneUnusedDatabaseCache();
virtual osg::Node* readNodeFile(const std::string& filename);
virtual osg::ref_ptr<osg::Node> readNodeFile(const std::string& filename);
protected:

View File

@@ -57,6 +57,8 @@ class OSGSIM_EXPORT OverlayNode : public osg::Group
/** Set the overlay subgraph which will be rendered to texture.*/
void setOverlaySubgraph(osg::Node* node);
template<class T> void setOverlaySubgraph(const osg::ref_ptr<T>& node) { setOverlaySubgraph(node.get()); }
/** Get the overlay subgraph which will be rendered to texture.*/
osg::Node* getOverlaySubgraph() { return _overlaySubgraph.get(); }

View File

@@ -60,6 +60,9 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object
std::string getCompoundName() const { return createCompoundSetNameAndFileName(getName(), getFileName()); }
void setLocator(Locator* locator) { _locator = locator; }
template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
Locator* getLocator() { return _locator.get(); }
const Locator* getLocator() const { return _locator.get(); }
@@ -314,6 +317,8 @@ class OSGTERRAIN_EXPORT ImageLayer : public Layer
void setImage(osg::Image* image);
template<class T> void setImage(const osg::ref_ptr<T>& image) { return setImage(image.get()); }
/** Return image associated with layer. */
virtual osg::Image* getImage() { return _image.get(); }
@@ -354,6 +359,9 @@ class OSGTERRAIN_EXPORT ContourLayer : public Layer
virtual bool transform(float offset, float scale);
void setTransferFunction(osg::TransferFunction1D* tf);
template<class T> void setTransferFunction(const osg::ref_ptr<T>& tf) { return setTransferFunction(tf.get()); }
osg::TransferFunction1D* getTransferFunction() { return _tf.get(); }
const osg::TransferFunction1D* getTransferFunction() const { return _tf.get(); }
@@ -401,6 +409,9 @@ class OSGTERRAIN_EXPORT HeightFieldLayer : public Layer
virtual bool transform(float offset, float scale);
void setHeightField(osg::HeightField* hf);
template<class T> void setHeightField(const osg::ref_ptr<T>& hf) { return setHeightField(hf.get()); }
osg::HeightField* getHeightField() { return _heightField.get(); }
const osg::HeightField* getHeightField() const { return _heightField.get(); }
@@ -516,14 +527,21 @@ class OSGTERRAIN_EXPORT CompositeLayer : public Layer
void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; }
template<class T> void setLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setLayer(i, layer.get()); }
Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; }
const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; }
void addLayer(const std::string& compoundname);
void addLayer(const std::string& setname, const std::string& filename);
void addLayer(Layer* layer) { _layers.push_back(CompoundNameLayer(layer->getName(),layer->getFileName(),layer)); }
template<class T> void addLayer(const osg::ref_ptr<T>& layer) { return addLayer(layer.get()); }
void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); }
unsigned int getNumLayers() const { return static_cast<unsigned int>(_layers.size()); }

View File

@@ -102,6 +102,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
/** Set the TerrainTechnique*/
void setTerrainTechnique(TerrainTechnique* terrainTechnique);
template<class T> void setTerrainTechnique(const osg::ref_ptr<T>& terrainTechnique) { setTerrainTechnique(terrainTechnique.get()); }
/** Get the TerrainTechnique*/
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
@@ -113,6 +115,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
* The locator takes non-dimensional s,t coordinates into the X,Y,Z world coords and back.*/
void setLocator(Locator* locator) { _locator = locator; }
template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
/** Get the coordinate frame locator of the terrain node.*/
Locator* getLocator() { return _locator.get(); }
@@ -122,6 +126,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
/** Set the layer to use to define the elevations of the terrain.*/
void setElevationLayer(Layer* layer);
template<class T> void setElevationLayer(const osg::ref_ptr<T>& layer) { setElevationLayer(layer.get()); }
/** Get the layer to use to define the elevations of the terrain.*/
Layer* getElevationLayer() { return _elevationLayer.get(); }
@@ -132,6 +138,8 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
/** Set a color layer with specified layer number.*/
void setColorLayer(unsigned int i, Layer* layer);
template<class T> void setColorLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setColorLayer(i, layer.get()); }
/** Get color layer with specified layer number.*/
Layer* getColorLayer(unsigned int i) { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
@@ -139,7 +147,7 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group
const Layer* getColorLayer(unsigned int i) const { return i<_colorLayers.size() ? _colorLayers[i].get() : 0; }
/** Get the number of colour layers.*/
unsigned int getNumColorLayers() const { return static_cast<unsigned int>(_colorLayers.size()); }
unsigned int getNumColorLayers() const { return _colorLayers.size(); }
/** Set hint to whether the TerrainTechnique should create per vertex normals for lighting purposes.*/

View File

@@ -28,6 +28,7 @@ namespace osgText {
// forward declare Font
class Font;
#ifdef OSG_PROVIDE_READFILE
/** Read a font from specified file. The filename may contain a path.
* It will search for the font file in the following places in this order:
* - In the current directory
@@ -51,6 +52,7 @@ extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgD
/** read a font from specified stream.*/
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
#endif
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);

View File

@@ -20,6 +20,7 @@ namespace osgText {
typedef Font Font3D;
#ifdef OSG_PROVIDE_READFILE
/** deprecated, use readFontFile() instead.*/
inline Font* readFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0)
{
@@ -31,6 +32,7 @@ inline Font* readFont3DStream(std::istream& stream, const osgDB::ReaderWriter::O
{
return readFontStream(stream, userOptions);
}
#endif
/** deprecated, use readRefFontFile() instead.*/
inline osg::ref_ptr<Font> readRefFont3DFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0)

View File

@@ -160,7 +160,7 @@ class OSGUTIL_EXPORT IntersectionVisitor : public osg::NodeVisitor
* tighter integration.*/
struct ReadCallback : public osg::Referenced
{
virtual osg::Node* readNodeFile(const std::string& filename) = 0;
virtual osg::ref_ptr<osg::Node> readNodeFile(const std::string& filename) = 0;
};

View File

@@ -122,10 +122,14 @@ class OSGUTIL_EXPORT Optimizer
* visitors, specified by the OptimizationOptions.*/
void optimize(osg::Node* node);
template<class T> void optimize(const osg::ref_ptr<T>& node) { optimize(node.get()); }
/** Traverse the node and its subgraph with a series of optimization
* visitors, specified by the OptimizationOptions.*/
virtual void optimize(osg::Node* node, unsigned int options);
template<class T> void optimize(const osg::ref_ptr<T>& node, unsigned int options) { optimize(node.get(), options); }
/** Callback for customizing what operations are permitted on objects in the scene graph.*/
struct IsOperationPermissibleForObjectCallback : public osg::Referenced

View File

@@ -51,7 +51,10 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase
void addView(osgViewer::View* view);
template<class T> void addView(const osg::ref_ptr<T>& view) { addView(view.get()); }
void removeView(osgViewer::View* view);
template<class T> void removeView(const osg::ref_ptr<T>& view) { removeView(view.get()); }
osgViewer::View* getView(unsigned i) { return _views[i].get(); }
const osgViewer::View* getView(unsigned i) const { return _views[i].get(); }
@@ -142,7 +145,7 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase
osg::observer_ptr<osg::Camera> _cameraWithFocus;
osg::observer_ptr<osgViewer::View> _viewWithFocus;
osg::ref_ptr<osgGA::GUIEventAdapter> _previousEvent;
};

View File

@@ -103,6 +103,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Set the scene graph that the View will use.*/
virtual void setSceneData(osg::Node* node);
template<class T> void setSceneData(const osg::ref_ptr<T>& node) { setSceneData(node.get()); }
/** Get the View's scene graph.*/
osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
@@ -113,6 +115,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Set the View's database pager.*/
void setDatabasePager(osgDB::DatabasePager* dp);
template<class T> void setDatabasePager(const osg::ref_ptr<T>& dp) { setDatabasePager(dp.get()); }
/** Get the View's database pager.*/
osgDB::DatabasePager* getDatabasePager();
@@ -123,6 +127,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Set the View's image pager.*/
void setImagePager(osgDB::ImagePager* ip);
template<class T> void setImagePager(const osg::ref_ptr<T>* ip) { setImagePager(ip.get()); }
/** Get the View's image pager.*/
osgDB::ImagePager* getImagePager();
@@ -134,9 +140,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
* The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
void addDevice(osgGA::Device* eventSource);
template<class T> void addDevice(const osg::ref_ptr<T>& eventSource) { addDevice(eventSource.get()); }
/** Remove a Device. /*/
void removeDevice(osgGA::Device* eventSource);
template<class T> void removeDevice(const osg::ref_ptr<T>& eventSource) { removeDevice(eventSource.get()); }
typedef std::vector< osg::ref_ptr<osgGA::Device> > Devices;
Devices& getDevices() { return _eventSources; }
@@ -146,6 +156,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/* Set the EventQueue that the View uses to integrate external non window related events.*/
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
template<class T> void setEventQueue(const osg::ref_ptr<T>& eventQueue) { setEventQueue(eventQueue.get()); }
/* Get the View's EventQueue.*/
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
@@ -156,6 +168,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
* The parameter resetPosition determines whether manipulator is set to its home position.*/
void setCameraManipulator(osgGA::CameraManipulator* manipulator, bool resetPosition = true);
template<class T> void setCameraManipulator(const osg::ref_ptr<T>& manipulator, bool resetPosition = true) { setCameraManipulator(manipulator.get(), resetPosition); }
/** Get the View's CameraManipulator.*/
osgGA::CameraManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
@@ -172,9 +186,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Add an EventHandler that adds handling of events to the View.*/
void addEventHandler(osgGA::EventHandler* eventHandler);
template<class T> void addEventHandler(const osg::ref_ptr<T>& eventHandler) { addEventHandler(eventHandler.get()); }
/** Remove an EventHandler from View.*/
void removeEventHandler(osgGA::EventHandler* eventHandler);
template<class T> void removeEventHandler(const osg::ref_ptr<T>& eventHandler) { removeEventHandler(eventHandler.get()); }
/** Get the View's list of EventHandlers.*/
EventHandlers& getEventHandlers() { return _eventHandlers; }
@@ -197,6 +215,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Set the DisplaySettings object associated with this view.*/
void setDisplaySettings(osg::DisplaySettings* ds) { _displaySettings = ds; }
template<class T> void setDisplaySettings(const osg::ref_ptr<T>& ds) { setDisplaySettings(ds.get()); }
/** Set the DisplaySettings object associated with this view.*/
osg::DisplaySettings* getDisplaySettings() { return _displaySettings.get(); }
@@ -220,6 +240,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Apply a viewer configuration to set up Cameras and Windowing. */
void apply(ViewConfig* config);
template<class T> void apply(const osg::ref_ptr<T>& config) { apply(config.get()); }
ViewConfig* getLastAppliedViewConfig() { return _lastAppliedViewConfig.get(); }
const ViewConfig* getLastAppliedViewConfig() const { return _lastAppliedViewConfig.get(); }
@@ -254,6 +276,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Return true if this view contains a specified camera.*/
bool containsCamera(const osg::Camera* camera) const;
template<class T> bool containsCamera(const osg::ref_ptr<T>& camera) const { return containsCamera(camera.get()); }
/** deprecated. */
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;

View File

@@ -64,6 +64,8 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
virtual void setStartTick(osg::Timer_t tick);
void setReferenceTime(double time=0.0);
using osgViewer::View::setSceneData;
/** Set the sene graph data that viewer with view.*/
virtual void setSceneData(osg::Node* node);

View File

@@ -71,6 +71,9 @@ class OSGVOLUME_EXPORT Layer : public osg::Object
virtual const std::string& getFileName() const { return _filename; }
void setLocator(Locator* locator) { _locator = locator; }
template<class T> void setLocator(const osg::ref_ptr<T>& locator) { setLocator(locator.get()); }
Locator* getLocator() { return _locator.get(); }
const Locator* getLocator() const { return _locator.get(); }
@@ -99,6 +102,8 @@ class OSGVOLUME_EXPORT Layer : public osg::Object
/** Set the Property (or Properties via the CompositeProperty) that informs the VolumeTechnique how this layer should be rendered.*/
void setProperty(Property* property) { _property = property; }
template<class T> void setProperty(const osg::ref_ptr<T>& p) { setProperty(p.get()); }
/** Get the Property that informs the VolumeTechnique how this layer should be rendered.*/
Property* getProperty() { return _property.get(); }
@@ -108,6 +113,7 @@ class OSGVOLUME_EXPORT Layer : public osg::Object
/** Add a property, automatically creating a CompositePorperty if one isn't already assigned.*/
void addProperty(Property* property);
template<class T> void addProperty(const osg::ref_ptr<T>& p) { addProperty(p.get()); }
/** Specify whether ImageLayer requires update traversal. */
virtual bool requiresUpdateTraversal() const { return false; }
@@ -156,6 +162,8 @@ class OSGVOLUME_EXPORT ImageLayer : public Layer
void setImage(osg::Image* image);
template<class T> void setImage(const osg::ref_ptr<T>& image) { setImage(image.get()); }
/** Return image associated with layer. */
virtual osg::Image* getImage() { return _image.get(); }
@@ -217,11 +225,17 @@ class OSGVOLUME_EXPORT CompositeLayer : public Layer
const std::string& getFileName(unsigned int i) const { return _layers[i].layer.valid() ? _layers[i].layer->getFileName() : _layers[i].filename; }
void setLayer(unsigned int i, Layer* layer) { if (i>=_layers.size()) _layers.resize(i+1); _layers[i].layer = layer; }
template<class T> void setLayer(unsigned int i, const osg::ref_ptr<T>& layer) { setLayer(i, layer.get()); }
Layer* getLayer(unsigned int i) { return i<_layers.size() ? _layers[i].layer.get() : 0; }
const Layer* getLayer(unsigned int i) const { return i<_layers.size() ? _layers[i].layer.get() : 0; }
void addLayer(Layer* layer) { _layers.push_back(NameLayer(layer->getFileName(),layer)); }
template<class T> void addLayer(const osg::ref_ptr<T>& layer) { addLayer(layer.get()); }
void removeLayer(unsigned int i) { _layers.erase(_layers.begin()+i); }
unsigned int getNumLayers() const { return _layers.size(); }

View File

@@ -83,6 +83,9 @@ class OSGVOLUME_EXPORT Locator : public osg::Object
};
void addCallback(LocatorCallback* callback);
template<class T> void addCallback(const osg::ref_ptr<T>& callback) { addCallback(callback.get()); }
void removeCallback(LocatorCallback* callback);
typedef std::vector< osg::ref_ptr<LocatorCallback> > LocatorCallbacks;

View File

@@ -126,12 +126,16 @@ class OSGVOLUME_EXPORT CompositeProperty : public Property
void setProperty(unsigned int i, Property* property) { if (i>=_properties.size()) _properties.resize(i+1); _properties[i] = property; }
template<class T> void setProperty(unsigned int i, const osg::ref_ptr<T>& p) { setProperty(i, p.get()); }
Property* getProperty(unsigned int i) { return i<_properties.size() ? _properties[i].get() : 0; }
const Property* getProperty(unsigned int i) const { return i<_properties.size() ? _properties[i].get() : 0; }
void addProperty(Property* property) { _properties.push_back(property); dirty(); }
template<class T> void addProperty(const osg::ref_ptr<T>& p) { addProperty(p.get()); }
void removeProperty(unsigned int i) { _properties.erase(_properties.begin()+i); }
unsigned int getNumProperties() const { return _properties.size(); }

View File

@@ -168,7 +168,7 @@ class OSGWIDGET_EXPORT Frame: public Table
static Frame* createSimpleFrameWithSingleTexture(
const std::string&,
osg::Image*,
osg::ref_ptr<osg::Image>,
point_type,
point_type,
unsigned int = 0,
@@ -177,7 +177,7 @@ class OSGWIDGET_EXPORT Frame: public Table
static Frame* createSimpleFrameFromTheme(
const std::string&,
osg::Image*,
osg::ref_ptr<osg::Image>,
point_type,
point_type,
unsigned int = 0,

View File

@@ -129,6 +129,10 @@ public:
void setTexCoordWrapVertical ();
bool setImage (osg::Image*, bool = false, bool = false);
template<class T> bool setImage(const osg::ref_ptr<T>& image, bool f1 = false, bool f2 = false) { return setImage(image.get(), f1, f2); }
bool setImage (const std::string&, bool = false, bool = false);
bool setTexture (osg::Texture*, bool = false, bool = false);