Geometry
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_GEOMETRY
#define OSG_GEOMETRY 1
#include <osg/Drawable>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Array>
#include <osg/PrimitiveSet>
// leave defined for OpenSceneGraph-3.2 release, post 3.2 associated methods will be only be available in deprecated_osg::Geometry
#define OSG_DEPRECATED_GEOMETRY_BINDING 1
namespace osg {
class OSG_EXPORT Geometry : public Drawable
{
public:
Geometry();
Geometry(const Geometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Geometry);
virtual Geometry* asGeometry() { return this; }
virtual const Geometry* asGeometry() const { return this; }
bool empty() const;
typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;
void setVertexArray(Array* array);
Array* getVertexArray() { return _vertexArray.get(); }
const Array* getVertexArray() const { return _vertexArray.get(); }
void setNormalArray(Array* array) { setNormalArray(array, osg::Array::BIND_UNDEFINED); }
void setNormalArray(Array* array, osg::Array::Binding binding);
Array* getNormalArray() { return _normalArray.get(); }
const Array* getNormalArray() const { return _normalArray.get(); }
void setColorArray(Array* array) { setColorArray(array, osg::Array::BIND_UNDEFINED); }
void setColorArray(Array* array, osg::Array::Binding binding);
Array* getColorArray() { return _colorArray.get(); }
const Array* getColorArray() const { return _colorArray.get(); }
void setSecondaryColorArray(Array* array) { setSecondaryColorArray(array, osg::Array::BIND_UNDEFINED); }
void setSecondaryColorArray(Array* array, osg::Array::Binding binding);
Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
void setFogCoordArray(Array* array) { setFogCoordArray(array, osg::Array::BIND_UNDEFINED); }
void setFogCoordArray(Array* array, osg::Array::Binding binding);
Array* getFogCoordArray() { return _fogCoordArray.get(); }
const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
void setTexCoordArray(unsigned int unit, Array* array) { setTexCoordArray(unit, array, osg::Array::BIND_UNDEFINED); }
void setTexCoordArray(unsigned int unit, Array* array, osg::Array::Binding binding);
Array* getTexCoordArray(unsigned int unit);
const Array* getTexCoordArray(unsigned int unit) const;
unsigned int getNumTexCoordArrays() const { return static_cast<unsigned int>(_texCoordList.size()); }
void setTexCoordArrayList(const ArrayList& arrrayList);
ArrayList& getTexCoordArrayList() { return _texCoordList; }
const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
void setVertexAttribArray(unsigned int index, Array* array) { setVertexAttribArray(index, array, osg::Array::BIND_UNDEFINED); }
void setVertexAttribArray(unsigned int index, Array* array, osg::Array::Binding binding);
Array *getVertexAttribArray(unsigned int index);
const Array *getVertexAttribArray(unsigned int index) const;
unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
void setVertexAttribArrayList(const ArrayList& arrayList);
ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
void setPrimitiveSetList(const PrimitiveSetList& primitives);
PrimitiveSetList& getPrimitiveSetList() { return _primitives; }
const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; }
unsigned int getNumPrimitiveSets() const { return static_cast<unsigned int>(_primitives.size()); }
PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
bool addPrimitiveSet(PrimitiveSet* primitiveset);
bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
void configureBufferObjects();
bool containsSharedArrays() const;
void duplicateSharedArrays();
virtual void setUseVertexBufferObjects(bool flag);
virtual void dirtyGLObjects();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(State* state=0) const;
bool getArrayList(ArrayList& arrayList) const;
typedef std::vector<osg::DrawElements*> DrawElementsList;
bool getDrawElementsList(DrawElementsList& drawElementsList) const;
osg::VertexBufferObject* getOrCreateVertexBufferObject();
osg::ElementBufferObject* getOrCreateElementBufferObject();
virtual unsigned int getGLObjectSizeHint() const;
virtual void compileGLObjects(RenderInfo& renderInfo) const;
virtual void drawImplementation(RenderInfo& renderInfo) const;
void drawVertexArraysImplementation(RenderInfo& renderInfo) const;
void drawPrimitivesImplementation(RenderInfo& renderInfo) const;
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
virtual void accept(Drawable::AttributeFunctor& af);
virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
virtual void accept(Drawable::ConstAttributeFunctor& af) const;
virtual bool supports(const PrimitiveFunctor&) const { return true; }
virtual void accept(PrimitiveFunctor& pf) const;
virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
virtual void accept(PrimitiveIndexFunctor& pf) const;
protected:
Geometry& operator = (const Geometry&) { return *this;}
virtual ~Geometry();
void addVertexBufferObjectIfRequired(osg::Array* array);
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
PrimitiveSetList _primitives;
osg::ref_ptr<Array> _vertexArray;
osg::ref_ptr<Array> _normalArray;
osg::ref_ptr<Array> _colorArray;
osg::ref_ptr<Array> _secondaryColorArray;
osg::ref_ptr<Array> _fogCoordArray;
ArrayList _texCoordList;
ArrayList _vertexAttribList;
bool _containsDeprecatedData;
virtual VertexArrayState* createVertexArrayStateImplementation(RenderInfo& renderInfo) const;
public:
bool containsDeprecatedData() const { return _containsDeprecatedData; }
bool checkForDeprecatedData();
void fixDeprecatedData();
#if defined(OSG_DEPRECATED_GEOMETRY_BINDING)
enum AttributeBinding
{
BIND_OFF=0,
BIND_OVERALL=1,
BIND_PER_PRIMITIVE_SET=2,
BIND_PER_VERTEX=4
};
void setNormalBinding(AttributeBinding ab);
void setColorBinding(AttributeBinding ab);
void setSecondaryColorBinding(AttributeBinding ab);
void setFogCoordBinding(AttributeBinding ab);
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
AttributeBinding getNormalBinding() const;
AttributeBinding getColorBinding() const;
AttributeBinding getSecondaryColorBinding() const;
AttributeBinding getFogCoordBinding() const;
AttributeBinding getVertexAttribBinding(unsigned int index) const;
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
GLboolean getVertexAttribNormalize(unsigned int index) const;
#endif
};
class ConfigureBufferObjectsVisitor : public osg::NodeVisitor
{
public:
ConfigureBufferObjectsVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
void apply(osg::Geometry& geometry)
{
geometry.configureBufferObjects();
}
};
extern OSG_EXPORT Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f)
{
return createTexturedQuadGeometry(corner,widthVec,heightVec, 0.0f, 0.0f, s, t);
}
} // namespace osg
#endif
Array
Drawable
PrimitiveSet
Vec2
Vec3
Vec4
osg::Array
Definition Array:61
osg::Array::Binding
Binding
The scope of applicability of the values in this array.
Definition Array:130
osg::Array::BIND_UNDEFINED
@ BIND_UNDEFINED
Definition Array:131
osg::ConfigureBufferObjectsVisitor::ConfigureBufferObjectsVisitor
ConfigureBufferObjectsVisitor()
Definition Geometry:286
osg::ConfigureBufferObjectsVisitor::apply
void apply(osg::Geometry &geometry)
Definition Geometry:289
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Drawable::AttributeFunctor
Definition Drawable:426
osg::Drawable::ConstAttributeFunctor
Definition Drawable:461
osg::Drawable::Drawable
Drawable()
osg::ElementBufferObject
Definition BufferObject:622
osg::Geometry
Definition Geometry:31
osg::Geometry::_fogCoordArray
osg::ref_ptr< Array > _fogCoordArray
Definition Geometry:230
osg::Geometry::META_Node
META_Node(osg, Geometry)
osg::Geometry::getVertexArray
Array * getVertexArray()
Definition Geometry:49
osg::Geometry::accept
virtual void accept(Drawable::AttributeFunctor &af)
osg::Geometry::getPrimitiveSet
const PrimitiveSet * getPrimitiveSet(unsigned int pos) const
Definition Geometry:111
osg::Geometry::getPrimitiveSetList
const PrimitiveSetList & getPrimitiveSetList() const
Definition Geometry:107
osg::Geometry::getSecondaryColorArray
Array * getSecondaryColorArray()
Definition Geometry:69
osg::Geometry::getGLObjectSizeHint
virtual unsigned int getGLObjectSizeHint() const
osg::Geometry::asGeometry
virtual const Geometry * asGeometry() const
Definition Geometry:42
osg::Geometry::getTexCoordArray
const Array * getTexCoordArray(unsigned int unit) const
osg::Geometry::setNormalArray
void setNormalArray(Array *array)
Definition Geometry:53
osg::Geometry::_primitives
PrimitiveSetList _primitives
Definition Geometry:225
osg::Geometry::setTexCoordArray
void setTexCoordArray(unsigned int unit, Array *array, osg::Array::Binding binding)
osg::Geometry::setVertexAttribArray
void setVertexAttribArray(unsigned int index, Array *array, osg::Array::Binding binding)
osg::Geometry::setFogCoordArray
void setFogCoordArray(Array *array)
Definition Geometry:73
osg::Geometry::getPrimitiveSetIndex
unsigned int getPrimitiveSetIndex(const PrimitiveSet *primitiveset) const
osg::Geometry::_normalArray
osg::ref_ptr< Array > _normalArray
Definition Geometry:227
osg::Geometry::dirtyGLObjects
virtual void dirtyGLObjects()
osg::Geometry::_containsDeprecatedData
bool _containsDeprecatedData
Definition Geometry:234
osg::Geometry::getPrimitiveSet
PrimitiveSet * getPrimitiveSet(unsigned int pos)
Definition Geometry:110
osg::Geometry::setPrimitiveSetList
void setPrimitiveSetList(const PrimitiveSetList &primitives)
osg::Geometry::setColorArray
void setColorArray(Array *array)
Definition Geometry:60
osg::Geometry::setTexCoordArray
void setTexCoordArray(unsigned int unit, Array *array)
Definition Geometry:79
osg::Geometry::drawVertexArraysImplementation
void drawVertexArraysImplementation(RenderInfo &renderInfo) const
osg::Geometry::_vertexArray
osg::ref_ptr< Array > _vertexArray
Definition Geometry:226
osg::Geometry::getColorArray
const Array * getColorArray() const
Definition Geometry:63
osg::Geometry::getNumTexCoordArrays
unsigned int getNumTexCoordArrays() const
Definition Geometry:84
osg::Geometry::asGeometry
virtual Geometry * asGeometry()
Definition Geometry:41
osg::Geometry::getFogCoordArray
const Array * getFogCoordArray() const
Definition Geometry:76
osg::Geometry::drawImplementation
virtual void drawImplementation(RenderInfo &renderInfo) const
osg::Geometry::getVertexAttribArray
Array * getVertexAttribArray(unsigned int index)
osg::Geometry::DrawElementsList
std::vector< osg::DrawElements * > DrawElementsList
Definition Geometry:160
osg::Geometry::setSecondaryColorArray
void setSecondaryColorArray(Array *array)
Definition Geometry:67
osg::Geometry::releaseGLObjects
virtual void releaseGLObjects(State *state=0) const
osg::Geometry::setVertexAttribNormalize
void setVertexAttribNormalize(unsigned int index, GLboolean norm)
osg::Geometry::setColorArray
void setColorArray(Array *array, osg::Array::Binding binding)
osg::Geometry::getOrCreateVertexBufferObject
osg::VertexBufferObject * getOrCreateVertexBufferObject()
osg::Geometry::getVertexAttribArrayList
const ArrayList & getVertexAttribArrayList() const
Definition Geometry:98
osg::Geometry::setNormalBinding
void setNormalBinding(AttributeBinding ab)
osg::Geometry::addElementBufferObjectIfRequired
void addElementBufferObjectIfRequired(osg::PrimitiveSet *primitiveSet)
osg::Geometry::getPrimitiveSetList
PrimitiveSetList & getPrimitiveSetList()
Definition Geometry:106
osg::Geometry::supports
virtual bool supports(const PrimitiveFunctor &) const
Definition Geometry:203
osg::Geometry::setVertexAttribArray
void setVertexAttribArray(unsigned int index, Array *array)
Definition Geometry:89
osg::Geometry::getVertexArray
const Array * getVertexArray() const
Definition Geometry:50
osg::Geometry::getTexCoordArrayList
ArrayList & getTexCoordArrayList()
Definition Geometry:86
osg::Geometry::addPrimitiveSet
bool addPrimitiveSet(PrimitiveSet *primitiveset)
osg::Geometry::_vertexAttribList
ArrayList _vertexAttribList
Definition Geometry:232
osg::Geometry::setTexCoordArrayList
void setTexCoordArrayList(const ArrayList &arrrayList)
osg::Geometry::getSecondaryColorArray
const Array * getSecondaryColorArray() const
Definition Geometry:70
osg::Geometry::getDrawElementsList
bool getDrawElementsList(DrawElementsList &drawElementsList) const
osg::Geometry::getFogCoordBinding
AttributeBinding getFogCoordBinding() const
osg::Geometry::getColorBinding
AttributeBinding getColorBinding() const
osg::Geometry::getVertexAttribNormalize
GLboolean getVertexAttribNormalize(unsigned int index) const
osg::Geometry::AttributeBinding
AttributeBinding
Definition Geometry:253
osg::Geometry::BIND_PER_VERTEX
@ BIND_PER_VERTEX
Definition Geometry:257
osg::Geometry::BIND_PER_PRIMITIVE_SET
@ BIND_PER_PRIMITIVE_SET
Definition Geometry:256
osg::Geometry::BIND_OFF
@ BIND_OFF
Definition Geometry:254
osg::Geometry::BIND_OVERALL
@ BIND_OVERALL
Definition Geometry:255
osg::Geometry::getNormalArray
Array * getNormalArray()
Definition Geometry:55
osg::Geometry::setFogCoordBinding
void setFogCoordBinding(AttributeBinding ab)
osg::Geometry::accept
virtual void accept(PrimitiveIndexFunctor &pf) const
osg::Geometry::getArrayList
bool getArrayList(ArrayList &arrayList) const
osg::Geometry::compileGLObjects
virtual void compileGLObjects(RenderInfo &renderInfo) const
osg::Geometry::PrimitiveSetList
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition Geometry:102
osg::Geometry::accept
virtual void accept(PrimitiveFunctor &pf) const
osg::Geometry::getNormalBinding
AttributeBinding getNormalBinding() const
osg::Geometry::getNumPrimitiveSets
unsigned int getNumPrimitiveSets() const
Definition Geometry:109
osg::Geometry::checkForDeprecatedData
bool checkForDeprecatedData()
osg::Geometry::duplicateSharedArrays
void duplicateSharedArrays()
osg::Geometry::supports
virtual bool supports(const Drawable::AttributeFunctor &) const
Definition Geometry:191
osg::Geometry::getFogCoordArray
Array * getFogCoordArray()
Definition Geometry:75
osg::Geometry::insertPrimitiveSet
bool insertPrimitiveSet(unsigned int i, PrimitiveSet *primitiveset)
osg::Geometry::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osg::Geometry::configureBufferObjects
void configureBufferObjects()
osg::Geometry::_colorArray
osg::ref_ptr< Array > _colorArray
Definition Geometry:228
osg::Geometry::~Geometry
virtual ~Geometry()
osg::Geometry::empty
bool empty() const
osg::Geometry::setVertexAttribArrayList
void setVertexAttribArrayList(const ArrayList &arrayList)
osg::Geometry::getNumVertexAttribArrays
unsigned int getNumVertexAttribArrays() const
Definition Geometry:95
osg::Geometry::containsDeprecatedData
bool containsDeprecatedData() const
Definition Geometry:242
osg::Geometry::accept
virtual void accept(Drawable::ConstAttributeFunctor &af) const
osg::Geometry::_texCoordList
ArrayList _texCoordList
Definition Geometry:231
osg::Geometry::getTexCoordArray
Array * getTexCoordArray(unsigned int unit)
osg::Geometry::fixDeprecatedData
void fixDeprecatedData()
osg::Geometry::setUseVertexBufferObjects
virtual void setUseVertexBufferObjects(bool flag)
osg::Geometry::Geometry
Geometry(const Geometry &geometry, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
osg::Geometry::getVertexAttribArrayList
ArrayList & getVertexAttribArrayList()
Definition Geometry:97
osg::Geometry::Geometry
Geometry()
osg::Geometry::setVertexAttribBinding
void setVertexAttribBinding(unsigned int index, AttributeBinding ab)
osg::Geometry::removePrimitiveSet
bool removePrimitiveSet(unsigned int i, unsigned int numElementsToRemove=1)
osg::Geometry::setVertexArray
void setVertexArray(Array *array)
osg::Geometry::getVertexAttribArray
const Array * getVertexAttribArray(unsigned int index) const
osg::Geometry::setFogCoordArray
void setFogCoordArray(Array *array, osg::Array::Binding binding)
osg::Geometry::drawPrimitivesImplementation
void drawPrimitivesImplementation(RenderInfo &renderInfo) const
osg::Geometry::getColorArray
Array * getColorArray()
Definition Geometry:62
osg::Geometry::ArrayList
std::vector< osg::ref_ptr< osg::Array > > ArrayList
Definition Geometry:46
osg::Geometry::setSecondaryColorArray
void setSecondaryColorArray(Array *array, osg::Array::Binding binding)
osg::Geometry::setNormalArray
void setNormalArray(Array *array, osg::Array::Binding binding)
osg::Geometry::getTexCoordArrayList
const ArrayList & getTexCoordArrayList() const
Definition Geometry:87
osg::Geometry::getOrCreateElementBufferObject
osg::ElementBufferObject * getOrCreateElementBufferObject()
osg::Geometry::_secondaryColorArray
osg::ref_ptr< Array > _secondaryColorArray
Definition Geometry:229
osg::Geometry::addVertexBufferObjectIfRequired
void addVertexBufferObjectIfRequired(osg::Array *array)
osg::Geometry::getVertexAttribBinding
AttributeBinding getVertexAttribBinding(unsigned int index) const
osg::Geometry::containsSharedArrays
bool containsSharedArrays() const
osg::Geometry::setPrimitiveSet
bool setPrimitiveSet(unsigned int i, PrimitiveSet *primitiveset)
osg::Geometry::supports
virtual bool supports(const PrimitiveIndexFunctor &) const
Definition Geometry:209
osg::Geometry::supports
virtual bool supports(const Drawable::ConstAttributeFunctor &) const
Definition Geometry:197
osg::Geometry::setSecondaryColorBinding
void setSecondaryColorBinding(AttributeBinding ab)
osg::Geometry::getSecondaryColorBinding
AttributeBinding getSecondaryColorBinding() const
osg::Geometry::createVertexArrayStateImplementation
virtual VertexArrayState * createVertexArrayStateImplementation(RenderInfo &renderInfo) const
osg::Geometry::getNormalArray
const Array * getNormalArray() const
Definition Geometry:56
osg::Geometry::setColorBinding
void setColorBinding(AttributeBinding ab)
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::TRAVERSE_ALL_CHILDREN
@ TRAVERSE_ALL_CHILDREN
Definition NodeVisitor:89
osg::NodeVisitor::NodeVisitor
NodeVisitor(TraversalMode tm=TRAVERSE_NONE)
osg::PrimitiveFunctor
Definition PrimitiveSet:54
osg::PrimitiveIndexFunctor
Definition PrimitiveSet:103
osg::PrimitiveSet
Definition PrimitiveSet:125
osg::RenderInfo
Definition RenderInfo:28
osg::State
Definition State:80
osg::VertexArrayState
Definition VertexArrayState:25
osg::VertexBufferObject
Definition BufferObject:599
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::createTexturedQuadGeometry
OSG_EXPORT Geometry * createTexturedQuadGeometry(const Vec3 &corner, const Vec3 &widthVec, const Vec3 &heightVec, float l, float b, float r, float t)
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39