2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
#ifndef OSG_GEOMETRY
|
|
|
|
#define OSG_GEOMETRY 1
|
|
|
|
|
|
|
|
#include <osg/Drawable>
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
2002-06-27 18:50:19 +08:00
|
|
|
#include <osg/Array>
|
2002-09-20 22:51:59 +08:00
|
|
|
#include <osg/PrimitiveSet>
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2003-08-08 08:21:30 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Geometry : public Drawable
|
2002-06-22 00:45:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Geometry();
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
2002-07-26 20:49:19 +08:00
|
|
|
Geometry(const Geometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-12-16 21:40:58 +08:00
|
|
|
virtual Object* cloneType() const { return new Geometry(); }
|
2012-03-22 01:36:20 +08:00
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return new Geometry(*this,copyop); }
|
2002-06-22 00:45:45 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Geometry*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "Geometry"; }
|
|
|
|
|
2002-09-12 23:34:31 +08:00
|
|
|
virtual Geometry* asGeometry() { return this; }
|
|
|
|
virtual const Geometry* asGeometry() const { return this; }
|
|
|
|
|
2004-03-29 18:24:16 +08:00
|
|
|
bool empty() const;
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
enum AttributeBinding
|
|
|
|
{
|
2002-06-24 05:43:46 +08:00
|
|
|
BIND_OFF=0,
|
|
|
|
BIND_OVERALL,
|
2002-10-02 21:12:16 +08:00
|
|
|
BIND_PER_PRIMITIVE_SET,
|
2002-06-24 05:43:46 +08:00
|
|
|
BIND_PER_PRIMITIVE,
|
2002-06-28 16:47:23 +08:00
|
|
|
BIND_PER_VERTEX
|
2002-06-22 00:45:45 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
struct OSG_EXPORT ArrayData
|
2003-06-30 05:41:57 +08:00
|
|
|
{
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData():
|
|
|
|
binding(BIND_OFF),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(GL_FALSE) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-12-04 05:45:32 +08:00
|
|
|
ArrayData(const ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
|
|
|
array(a),
|
|
|
|
indices(0),
|
|
|
|
binding(b),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(n) {}
|
2003-09-10 06:18:35 +08:00
|
|
|
|
|
|
|
ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
|
|
|
array(a),
|
|
|
|
indices(i),
|
|
|
|
binding(b),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(n) {}
|
2003-09-10 06:18:35 +08:00
|
|
|
|
|
|
|
ArrayData& operator = (const ArrayData& rhs)
|
|
|
|
{
|
|
|
|
array = rhs.array;
|
|
|
|
indices = rhs.indices;
|
|
|
|
binding = rhs.binding;
|
|
|
|
normalize = rhs.normalize;
|
|
|
|
return *this;
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
inline bool empty() const { return !array.valid(); }
|
2003-09-10 06:18:35 +08:00
|
|
|
|
|
|
|
ref_ptr<Array> array;
|
|
|
|
ref_ptr<IndexArray> indices;
|
|
|
|
AttributeBinding binding;
|
|
|
|
GLboolean normalize;
|
2003-06-30 05:41:57 +08:00
|
|
|
};
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
struct OSG_EXPORT Vec3ArrayData
|
2003-09-10 06:18:35 +08:00
|
|
|
{
|
|
|
|
Vec3ArrayData():
|
|
|
|
binding(BIND_OFF),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(GL_FALSE) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-12-04 05:45:32 +08:00
|
|
|
Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
|
|
|
array(a),
|
|
|
|
indices(0),
|
|
|
|
binding(b),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(n) {}
|
2003-06-30 05:41:57 +08:00
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
|
|
|
array(a),
|
|
|
|
indices(i),
|
|
|
|
binding(b),
|
2007-05-02 02:03:32 +08:00
|
|
|
normalize(n) {}
|
2003-06-30 05:41:57 +08:00
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
Vec3ArrayData& operator = (const Vec3ArrayData& rhs)
|
|
|
|
{
|
|
|
|
array = rhs.array;
|
|
|
|
indices = rhs.indices;
|
|
|
|
binding = rhs.binding;
|
|
|
|
normalize = rhs.normalize;
|
|
|
|
return *this;
|
|
|
|
}
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
inline bool empty() const { return !array.valid(); }
|
2004-03-29 18:24:16 +08:00
|
|
|
|
2009-12-09 21:51:02 +08:00
|
|
|
ref_ptr<Vec3Array> array;
|
2003-09-10 06:18:35 +08:00
|
|
|
ref_ptr<IndexArray> indices;
|
|
|
|
AttributeBinding binding;
|
|
|
|
GLboolean normalize;
|
|
|
|
};
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Static ArrayData which is returned from getTexCoordData(i) const and getVertexAttribData(i) const
|
2004-09-13 23:14:11 +08:00
|
|
|
* when i is out of range.
|
|
|
|
*/
|
2003-09-10 06:18:35 +08:00
|
|
|
static const ArrayData s_InvalidArrayData;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
typedef std::vector< ArrayData > ArrayDataList;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setVertexArray(Array* array);
|
2003-09-10 06:18:35 +08:00
|
|
|
Array* getVertexArray() { return _vertexData.array.get(); }
|
|
|
|
const Array* getVertexArray() const { return _vertexData.array.get(); }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setVertexData(const ArrayData& arrayData);
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData& getVertexData() { return _vertexData; }
|
|
|
|
const ArrayData& getVertexData() const { return _vertexData; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2006-05-15 19:48:05 +08:00
|
|
|
void setNormalBinding(AttributeBinding ab);
|
2003-09-10 06:18:35 +08:00
|
|
|
AttributeBinding getNormalBinding() const { return _normalData.binding; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setNormalArray(Array* array);
|
2005-07-05 23:57:53 +08:00
|
|
|
Array* getNormalArray() { return _normalData.array.get(); }
|
|
|
|
const Array* getNormalArray() const { return _normalData.array.get(); }
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setNormalData(const ArrayData& arrayData);
|
2005-07-05 23:57:53 +08:00
|
|
|
ArrayData& getNormalData() { return _normalData; }
|
|
|
|
const ArrayData& getNormalData() const { return _normalData; }
|
2002-08-16 04:27:33 +08:00
|
|
|
|
2006-05-15 19:48:05 +08:00
|
|
|
void setColorBinding(AttributeBinding ab);
|
2003-09-10 06:18:35 +08:00
|
|
|
AttributeBinding getColorBinding() const { return _colorData.binding; }
|
2002-08-16 04:27:33 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setColorArray(Array* array);
|
2003-09-10 06:18:35 +08:00
|
|
|
Array* getColorArray() { return _colorData.array.get(); }
|
|
|
|
const Array* getColorArray() const { return _colorData.array.get(); }
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setColorData(const ArrayData& arrayData);
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData& getColorData() { return _colorData; }
|
|
|
|
const ArrayData& getColorData() const { return _colorData; }
|
2002-08-16 04:27:33 +08:00
|
|
|
|
|
|
|
|
2006-05-15 19:48:05 +08:00
|
|
|
void setSecondaryColorBinding(AttributeBinding ab);
|
2003-09-10 06:18:35 +08:00
|
|
|
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setSecondaryColorArray(Array* array);
|
2003-09-10 06:18:35 +08:00
|
|
|
Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); }
|
|
|
|
const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); }
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setSecondaryColorData(const ArrayData& arrayData);
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData& getSecondaryColorData() { return _secondaryColorData; }
|
|
|
|
const ArrayData& getSecondaryColorData() const { return _secondaryColorData; }
|
2003-06-30 05:41:57 +08:00
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
|
2006-05-15 19:48:05 +08:00
|
|
|
void setFogCoordBinding(AttributeBinding ab);
|
2003-09-10 06:18:35 +08:00
|
|
|
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
|
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setFogCoordArray(Array* array);
|
2003-09-10 06:18:35 +08:00
|
|
|
Array* getFogCoordArray() { return _fogCoordData.array.get(); }
|
|
|
|
const Array* getFogCoordArray() const { return _fogCoordData.array.get(); }
|
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void setFogCoordData(const ArrayData& arrayData);
|
2004-01-03 04:44:18 +08:00
|
|
|
ArrayData& getFogCoordData() { return _fogCoordData; }
|
|
|
|
const ArrayData& getFogCoordData() const { return _fogCoordData; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
void setTexCoordArray(unsigned int unit,Array*);
|
|
|
|
Array* getTexCoordArray(unsigned int unit);
|
|
|
|
const Array* getTexCoordArray(unsigned int unit) const;
|
2002-10-02 21:12:16 +08:00
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
void setTexCoordData(unsigned int index,const ArrayData& arrayData);
|
|
|
|
ArrayData& getTexCoordData(unsigned int index);
|
|
|
|
const ArrayData& getTexCoordData(unsigned int index) const;
|
|
|
|
|
2009-01-30 18:55:28 +08:00
|
|
|
unsigned int getNumTexCoordArrays() const { return static_cast<unsigned int>(_texCoordList.size()); }
|
2007-04-27 22:52:30 +08:00
|
|
|
ArrayDataList& getTexCoordArrayList() { return _texCoordList; }
|
|
|
|
const ArrayDataList& getTexCoordArrayList() const { return _texCoordList; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
|
2003-05-09 21:07:06 +08:00
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
void setVertexAttribArray(unsigned int index,Array* array);
|
2003-05-07 21:13:13 +08:00
|
|
|
Array *getVertexAttribArray(unsigned int index);
|
|
|
|
const Array *getVertexAttribArray(unsigned int index) const;
|
|
|
|
|
2003-09-10 06:18:35 +08:00
|
|
|
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
|
|
|
|
AttributeBinding getVertexAttribBinding(unsigned int index) const;
|
|
|
|
|
|
|
|
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
|
|
|
|
GLboolean getVertexAttribNormalize(unsigned int index) const;
|
|
|
|
|
|
|
|
void setVertexAttribData(unsigned int index,const ArrayData& arrayData);
|
|
|
|
ArrayData& getVertexAttribData(unsigned int index);
|
|
|
|
const ArrayData& getVertexAttribData(unsigned int index) const;
|
|
|
|
|
2009-01-30 18:55:28 +08:00
|
|
|
unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
|
2007-04-27 22:52:30 +08:00
|
|
|
ArrayDataList& getVertexAttribArrayList() { return _vertexAttribList; }
|
|
|
|
const ArrayDataList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
2003-05-07 21:13:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-02 21:12:16 +08:00
|
|
|
typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2010-11-02 01:05:53 +08:00
|
|
|
void setPrimitiveSetList(const PrimitiveSetList& primitives);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2002-10-02 21:12:16 +08:00
|
|
|
PrimitiveSetList& getPrimitiveSetList() { return _primitives; }
|
|
|
|
const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2009-01-30 18:55:28 +08:00
|
|
|
unsigned int getNumPrimitiveSets() const { return static_cast<unsigned int>(_primitives.size()); }
|
2002-10-02 21:12:16 +08:00
|
|
|
PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
|
|
|
|
const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Add a primitive set to the geometry. */
|
2002-11-21 17:07:11 +08:00
|
|
|
bool addPrimitiveSet(PrimitiveSet* primitiveset);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set a primitive set to the specified position in geometry's primitive set list. */
|
2002-11-21 17:07:11 +08:00
|
|
|
bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Insert a primitive set to the specified position in geometry's primitive set list. */
|
2002-11-21 17:07:11 +08:00
|
|
|
bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Remove primitive set(s) from the specified position in geometry's primitive set list. */
|
2002-11-21 17:07:11 +08:00
|
|
|
bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
|
|
|
|
|
|
|
|
/** Get the index number of a primitive set, return a value between
|
|
|
|
* 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet().
|
2004-09-13 23:14:11 +08:00
|
|
|
* When checking for a valid find value use if ((value=geometry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet())
|
|
|
|
*/
|
2002-11-21 17:07:11 +08:00
|
|
|
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-10-02 21:16:39 +08:00
|
|
|
|
2008-07-04 19:51:55 +08:00
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setVertexIndices(IndexArray* array);
|
|
|
|
IndexArray* getVertexIndices() { return _vertexData.indices.get(); }
|
|
|
|
const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-07-04 19:51:55 +08:00
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setNormalIndices(IndexArray* array);
|
|
|
|
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
|
|
|
|
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
|
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setColorIndices(IndexArray* array);
|
|
|
|
IndexArray* getColorIndices() { return _colorData.indices.get(); }
|
|
|
|
const IndexArray* getColorIndices() const { return _colorData.indices.get(); }
|
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setSecondaryColorIndices(IndexArray* array);
|
|
|
|
IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); }
|
|
|
|
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); }
|
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setFogCoordIndices(IndexArray* array);
|
|
|
|
IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); }
|
|
|
|
const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); }
|
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setTexCoordIndices(unsigned int unit,IndexArray*);
|
|
|
|
IndexArray* getTexCoordIndices(unsigned int unit);
|
|
|
|
const IndexArray* getTexCoordIndices(unsigned int unit) const;
|
|
|
|
|
|
|
|
/** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/
|
|
|
|
void setVertexAttribIndices(unsigned int index,IndexArray* array);
|
|
|
|
IndexArray* getVertexAttribIndices(unsigned int index);
|
|
|
|
const IndexArray* getVertexAttribIndices(unsigned int index) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
|
2007-04-27 22:52:30 +08:00
|
|
|
method to use OpenGL vertex buffer objects for rendering.*/
|
|
|
|
virtual void setUseVertexBufferObjects(bool flag);
|
|
|
|
|
|
|
|
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
|
|
|
|
virtual void dirtyDisplayList();
|
|
|
|
|
|
|
|
|
2007-05-02 02:03:32 +08:00
|
|
|
/** Resize any per context GLObject buffers to specified size. */
|
|
|
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
|
|
|
|
|
|
|
/** If State is non-zero, this function releases OpenGL objects for
|
2007-12-11 01:30:18 +08:00
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objects
|
2007-05-02 02:03:32 +08:00
|
|
|
* for all graphics contexts. */
|
|
|
|
virtual void releaseGLObjects(State* state=0) const;
|
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
typedef std::vector<osg::Array*> ArrayList;
|
2007-05-02 02:03:32 +08:00
|
|
|
bool getArrayList(ArrayList& arrayList) const;
|
2007-04-27 22:52:30 +08:00
|
|
|
|
|
|
|
typedef std::vector<osg::DrawElements*> DrawElementsList;
|
2007-05-02 02:03:32 +08:00
|
|
|
bool getDrawElementsList(DrawElementsList& drawElementsList) const;
|
2007-04-27 22:52:30 +08:00
|
|
|
|
|
|
|
osg::VertexBufferObject* getOrCreateVertexBufferObject();
|
|
|
|
|
2007-05-01 14:28:20 +08:00
|
|
|
osg::ElementBufferObject* getOrCreateElementBufferObject();
|
2007-04-27 22:52:30 +08:00
|
|
|
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Set whether fast paths should be used when supported. */
|
2003-08-09 08:46:48 +08:00
|
|
|
void setFastPathHint(bool on) { _fastPathHint = on; }
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Get whether fast paths should be used when supported. */
|
2003-08-09 08:46:48 +08:00
|
|
|
bool getFastPathHint() const { return _fastPathHint; }
|
|
|
|
|
2011-01-04 03:41:06 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return true if OpenGL fast paths will be used with drawing this Geometry.
|
2009-10-22 20:04:26 +08:00
|
|
|
* Fast paths directly use vertex arrays, and glDrawArrays/glDrawElements so have low CPU overhead.
|
|
|
|
* With Slow paths the osg::Geometry::drawImplementation has to dynamically assemble OpenGL
|
|
|
|
* compatible vertex arrays from the osg::Geometry arrays data and then dispatch these to OpenGL,
|
|
|
|
* so have higher CPU overhead than the Fast paths.
|
|
|
|
* Use of per primitive bindings or per vertex indexed arrays will drop the rendering path off the fast path.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2009-03-10 22:15:59 +08:00
|
|
|
inline bool areFastPathsUsed() const
|
|
|
|
{
|
|
|
|
if (_internalOptimizedGeometry.valid())
|
|
|
|
return _internalOptimizedGeometry->areFastPathsUsed();
|
|
|
|
else
|
|
|
|
return _fastPath && _fastPathHint;
|
|
|
|
}
|
2003-06-30 05:41:57 +08:00
|
|
|
|
|
|
|
bool computeFastPathsUsed();
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-10-02 21:12:16 +08:00
|
|
|
bool verifyBindings() const;
|
2003-09-24 23:54:22 +08:00
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
void computeCorrectBindingsAndArraySizes();
|
|
|
|
|
2011-01-04 03:41:06 +08:00
|
|
|
/** check whether the arrays, indices, bindings and primitives all match correctly, return false is .*/
|
|
|
|
bool verifyArrays(std::ostream& out) const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2003-08-08 08:21:30 +08:00
|
|
|
bool suitableForOptimization() const;
|
|
|
|
|
|
|
|
void copyToAndOptimize(Geometry& target);
|
|
|
|
|
2008-09-14 18:31:27 +08:00
|
|
|
|
|
|
|
bool containsSharedArrays() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-09-14 18:31:27 +08:00
|
|
|
void duplicateSharedArrays();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-09-14 18:31:27 +08:00
|
|
|
|
2003-08-08 08:21:30 +08:00
|
|
|
void computeInternalOptimizedGeometry();
|
|
|
|
|
|
|
|
void removeInternalOptimizedGeometry() { _internalOptimizedGeometry = 0; }
|
|
|
|
|
|
|
|
void setInternalOptimizedGeometry(osg::Geometry* geometry) { _internalOptimizedGeometry = geometry; }
|
|
|
|
|
|
|
|
osg::Geometry* getInternalOptimizedGeometry() { return _internalOptimizedGeometry.get(); }
|
|
|
|
|
|
|
|
const osg::Geometry* getInternalOptimizedGeometry() const { return _internalOptimizedGeometry.get(); }
|
|
|
|
|
|
|
|
|
2004-09-22 01:26:08 +08:00
|
|
|
/** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.
|
2007-12-11 01:30:18 +08:00
|
|
|
* This size is used a hint for reuse of deleted display lists/vertex buffer objects. */
|
2004-09-22 01:26:08 +08:00
|
|
|
virtual unsigned int getGLObjectSizeHint() const;
|
2009-12-09 21:51:02 +08:00
|
|
|
|
|
|
|
/** Immediately compile this \c Drawable into an OpenGL Display List/VertexBufferObjects.
|
|
|
|
* @note Operation is ignored if \c _useDisplayList is \c false or VertexBufferObjects are not used.
|
|
|
|
*/
|
|
|
|
virtual void compileGLObjects(RenderInfo& renderInfo) const;
|
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Draw Geometry directly ignoring an OpenGL display list which could be attached.
|
2002-06-21 03:54:08 +08:00
|
|
|
* This is the internal draw method which does the drawing itself,
|
|
|
|
* and is the method to override when deriving from Geometry for user-drawn objects.
|
2004-09-13 23:14:11 +08:00
|
|
|
*/
|
2007-03-28 19:30:38 +08:00
|
|
|
virtual void drawImplementation(RenderInfo& renderInfo) const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
/** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
|
|
|
|
virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual void accept(Drawable::AttributeFunctor& af);
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2007-03-06 01:34:36 +08:00
|
|
|
/** Return true, osg::Geometry does support accept(Drawable::ConstAttributeFunctor&). */
|
|
|
|
virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
|
2007-03-06 01:34:36 +08:00
|
|
|
virtual void accept(Drawable::ConstAttributeFunctor& af) const;
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return true, osg::Geometry does support accept(PrimitiveFunctor&). */
|
2005-03-18 10:42:59 +08:00
|
|
|
virtual bool supports(const PrimitiveFunctor&) const { return true; }
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void accept(PrimitiveFunctor& pf) const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2004-09-13 23:14:11 +08:00
|
|
|
/** Return true, osg::Geometry does support accept(PrimitiveIndexFunctor&). */
|
2005-03-18 10:42:59 +08:00
|
|
|
virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
|
2004-03-15 05:54:17 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
|
2004-03-15 05:54:17 +08:00
|
|
|
virtual void accept(PrimitiveIndexFunctor& pf) const;
|
2003-05-07 21:13:13 +08:00
|
|
|
|
|
|
|
|
2002-06-21 03:54:08 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
Geometry& operator = (const Geometry&) { return *this;}
|
|
|
|
|
|
|
|
virtual ~Geometry();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-24 23:54:22 +08:00
|
|
|
bool verifyBindings(const ArrayData& arrayData) const;
|
|
|
|
bool verifyBindings(const Vec3ArrayData& arrayData) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-24 23:54:22 +08:00
|
|
|
void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName);
|
|
|
|
void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-04-27 22:52:30 +08:00
|
|
|
void addVertexBufferObjectIfRequired(osg::Array* array);
|
2007-05-01 14:28:20 +08:00
|
|
|
void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-09-24 23:54:22 +08:00
|
|
|
|
2003-05-07 21:13:13 +08:00
|
|
|
PrimitiveSetList _primitives;
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData _vertexData;
|
2005-07-05 23:57:53 +08:00
|
|
|
ArrayData _normalData;
|
2003-09-10 06:18:35 +08:00
|
|
|
ArrayData _colorData;
|
|
|
|
ArrayData _secondaryColorData;
|
|
|
|
ArrayData _fogCoordData;
|
2007-04-27 22:52:30 +08:00
|
|
|
ArrayDataList _texCoordList;
|
|
|
|
ArrayDataList _vertexAttribList;
|
2003-09-10 06:18:35 +08:00
|
|
|
|
2003-05-07 21:13:13 +08:00
|
|
|
mutable bool _fastPath;
|
2003-08-09 08:46:48 +08:00
|
|
|
bool _fastPathHint;
|
|
|
|
|
2003-08-08 08:21:30 +08:00
|
|
|
ref_ptr<Geometry> _internalOptimizedGeometry;
|
2002-06-21 03:54:08 +08:00
|
|
|
};
|
|
|
|
|
2003-06-25 05:57:13 +08:00
|
|
|
/** Convenience function to be used for creating quad geometry with texture coords.
|
2004-09-13 23:14:11 +08:00
|
|
|
* Tex coords go from left bottom (l,b) to right top (r,t).
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
extern OSG_EXPORT Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
|
2004-07-12 09:01:00 +08:00
|
|
|
|
|
|
|
/** Convenience function to be used for creating quad geometry with texture coords.
|
2004-09-13 23:14:11 +08:00
|
|
|
* Tex coords go from bottom left (0,0) to top right (s,t).
|
|
|
|
*/
|
2004-07-12 09:01:00 +08:00
|
|
|
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);
|
|
|
|
}
|
2003-06-25 05:57:13 +08:00
|
|
|
|
|
|
|
|
2002-06-21 03:54:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|