Futher work on the IndexedGeometry class. Indexed coordinates should now
work.
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
namespace osg {
|
||||
|
||||
class ArrayVisitor;
|
||||
class ConstArrayVisitor;
|
||||
|
||||
class ValueVisitor;
|
||||
class ConstValueVisitor;
|
||||
|
||||
class SG_EXPORT Array : public Object
|
||||
{
|
||||
@@ -54,14 +58,18 @@ class SG_EXPORT Array : public Object
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const;
|
||||
|
||||
virtual void accept(ArrayVisitor&) {}
|
||||
virtual void accept(ArrayVisitor&) = 0;
|
||||
virtual void accept(ConstArrayVisitor&) const = 0;
|
||||
|
||||
virtual void accept(unsigned int index,ValueVisitor&) = 0;
|
||||
virtual void accept(unsigned int index,ConstValueVisitor&) const = 0;
|
||||
|
||||
Type getType() const { return _arrayType; }
|
||||
GLint getDataSize() const { return _dataSize; }
|
||||
GLenum getDataType() const { return _dataType; }
|
||||
virtual const GLvoid* getDataPointer() const = 0;
|
||||
virtual unsigned int getNumElements() const = 0;
|
||||
virtual bool empty() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -72,8 +80,6 @@ class SG_EXPORT Array : public Object
|
||||
GLenum _dataType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
|
||||
class TemplateArray : public Array, public std::vector<T>
|
||||
{
|
||||
@@ -100,24 +106,96 @@ class TemplateArray : public Array, public std::vector<T>
|
||||
|
||||
virtual Object* cloneType() const { return osgNew TemplateArray(); }
|
||||
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); }
|
||||
virtual void accept(ArrayVisitor& av) { av.apply(*this); }
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { if (!empty()) return &front(); else return 0; }
|
||||
virtual void accept(ArrayVisitor& av) { av.apply(*this); }
|
||||
virtual void accept(ConstArrayVisitor& av) const { av.apply(*this); }
|
||||
|
||||
virtual void accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
|
||||
virtual void accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { if (!std::vector<T>::empty()) return &front(); else return 0; }
|
||||
virtual unsigned int getNumElements() const { return size(); }
|
||||
|
||||
virtual bool empty() const { return std::vector<T>::empty(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TemplateArray() {}
|
||||
};
|
||||
|
||||
typedef TemplateArray<GLbyte,Array::ByteArrayType,1,GL_BYTE> ByteArray;
|
||||
typedef TemplateArray<GLshort,Array::ShortArrayType,1,GL_SHORT> ShortArray;
|
||||
typedef TemplateArray<GLint,Array::IntArrayType,1,GL_INT> IntArray;
|
||||
typedef TemplateArray<GLubyte,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
|
||||
typedef TemplateArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
|
||||
typedef TemplateArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
|
||||
class SG_EXPORT IndexArray : public Array
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
IndexArray(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
|
||||
Array(arrayType,dataSize,dataType) {}
|
||||
|
||||
IndexArray(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Array(array,copyop) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const IndexArray*>(obj)!=NULL; }
|
||||
|
||||
virtual unsigned int index(unsigned int pos) const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~IndexArray() {}
|
||||
};
|
||||
|
||||
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
|
||||
class TemplateIndexArray : public IndexArray, public std::vector<T>
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateIndexArray() : IndexArray(ARRAYTYPE,DataSize,DataType) {}
|
||||
|
||||
TemplateIndexArray(const TemplateIndexArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
IndexArray(ta,copyop),
|
||||
std::vector<T>(ta) {}
|
||||
|
||||
TemplateIndexArray(unsigned int no) :
|
||||
IndexArray(ARRAYTYPE,DataSize,DataType),
|
||||
std::vector<T>(no) {}
|
||||
|
||||
TemplateIndexArray(unsigned int no,T* ptr) :
|
||||
IndexArray(ARRAYTYPE,DataSize,DataType),
|
||||
std::vector<T>(ptr,ptr+no) {}
|
||||
|
||||
template <class InputIterator>
|
||||
TemplateIndexArray(InputIterator first,InputIterator last) :
|
||||
IndexArray(ARRAYTYPE,DataSize,DataType),
|
||||
std::vector<T>(first,last) {}
|
||||
|
||||
virtual Object* cloneType() const { return osgNew TemplateIndexArray(); }
|
||||
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateIndexArray(*this,copyop); }
|
||||
|
||||
virtual void accept(ArrayVisitor& av) { av.apply(*this); }
|
||||
virtual void accept(ConstArrayVisitor& av) const { av.apply(*this); }
|
||||
|
||||
virtual void accept(unsigned int index,ValueVisitor& vv) { vv.apply( (*this)[index] ); }
|
||||
virtual void accept(unsigned int index,ConstValueVisitor& vv) const { vv.apply( (*this)[index] );}
|
||||
|
||||
virtual const GLvoid* getDataPointer() const { if (!std::vector<T>::empty()) return &front(); else return 0; }
|
||||
virtual unsigned int getNumElements() const { return size(); }
|
||||
|
||||
virtual bool empty() const { return std::vector<T>::empty(); }
|
||||
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TemplateIndexArray() {}
|
||||
};
|
||||
|
||||
typedef TemplateIndexArray<GLbyte,Array::ByteArrayType,1,GL_BYTE> ByteArray;
|
||||
typedef TemplateIndexArray<GLshort,Array::ShortArrayType,1,GL_SHORT> ShortArray;
|
||||
typedef TemplateIndexArray<GLint,Array::IntArrayType,1,GL_INT> IntArray;
|
||||
typedef TemplateIndexArray<GLubyte,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
|
||||
typedef TemplateIndexArray<GLushort,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
|
||||
typedef TemplateIndexArray<GLuint,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
|
||||
|
||||
typedef TemplateArray<GLfloat,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
|
||||
typedef TemplateArray<UByte4,Array::UByte4ArrayType,4,GL_UNSIGNED_BYTE> UByte4Array;
|
||||
typedef TemplateArray<float,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
|
||||
typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT> Vec2Array;
|
||||
typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array;
|
||||
typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array;
|
||||
@@ -139,9 +217,65 @@ class ArrayVisitor
|
||||
virtual void apply(Vec2Array&) {}
|
||||
virtual void apply(Vec3Array&) {}
|
||||
virtual void apply(Vec4Array&) {}
|
||||
|
||||
};
|
||||
|
||||
class ConstArrayVisitor
|
||||
{
|
||||
public:
|
||||
ConstArrayVisitor() {}
|
||||
|
||||
virtual void apply(const Array&) {}
|
||||
virtual void apply(const ByteArray&) {}
|
||||
virtual void apply(const ShortArray&) {}
|
||||
virtual void apply(const IntArray&) {}
|
||||
virtual void apply(const UByteArray&) {}
|
||||
virtual void apply(const UShortArray&) {}
|
||||
virtual void apply(const UIntArray&) {}
|
||||
virtual void apply(const UByte4Array&) {}
|
||||
virtual void apply(const FloatArray&) {}
|
||||
virtual void apply(const Vec2Array&) {}
|
||||
virtual void apply(const Vec3Array&) {}
|
||||
virtual void apply(const Vec4Array&) {}
|
||||
};
|
||||
|
||||
|
||||
class ValueVisitor
|
||||
{
|
||||
public:
|
||||
ValueVisitor() {}
|
||||
|
||||
virtual void apply(GLbyte&) {}
|
||||
virtual void apply(GLshort&) {}
|
||||
virtual void apply(GLint&) {}
|
||||
virtual void apply(GLushort&) {}
|
||||
virtual void apply(GLubyte&) {}
|
||||
virtual void apply(GLuint&) {}
|
||||
virtual void apply(GLfloat&) {}
|
||||
virtual void apply(UByte4&) {}
|
||||
virtual void apply(Vec2&) {}
|
||||
virtual void apply(Vec3&) {}
|
||||
virtual void apply(Vec4&) {}
|
||||
};
|
||||
|
||||
class ConstValueVisitor
|
||||
{
|
||||
public:
|
||||
ConstValueVisitor() {}
|
||||
|
||||
virtual void apply(const GLbyte&) {}
|
||||
virtual void apply(const GLshort&) {}
|
||||
virtual void apply(const GLint&) {}
|
||||
virtual void apply(const GLushort&) {}
|
||||
virtual void apply(const GLubyte&) {}
|
||||
virtual void apply(const GLuint&) {}
|
||||
virtual void apply(const GLfloat&) {}
|
||||
virtual void apply(const UByte4&) {}
|
||||
virtual void apply(const Vec2&) {}
|
||||
virtual void apply(const Vec3&) {}
|
||||
virtual void apply(const Vec4&) {}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -46,9 +46,9 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
Vec3Array* getVertexArray() { return _vertexArray.get(); }
|
||||
const Vec3Array* getVertexArray() const { return _vertexArray.get(); }
|
||||
|
||||
void setVertexIndices(Array* array) { _vertexIndices = array; dirtyDisplayList(); dirtyBound(); }
|
||||
Array* getVertexIndices() { return _vertexIndices.get(); }
|
||||
const Array* getVertexIndices() const { return _vertexIndices.get(); }
|
||||
void setVertexIndices(IndexArray* array) { _vertexIndices = array; dirtyDisplayList(); dirtyBound(); }
|
||||
IndexArray* getVertexIndices() { return _vertexIndices.get(); }
|
||||
const IndexArray* getVertexIndices() const { return _vertexIndices.get(); }
|
||||
|
||||
|
||||
void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); }
|
||||
@@ -58,9 +58,9 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
Vec3Array* getNormalArray() { return _normalArray.get(); }
|
||||
const Vec3Array* getNormalArray() const { return _normalArray.get(); }
|
||||
|
||||
void setNormalIndices(Array* array) { _normalIndices = array; dirtyDisplayList(); }
|
||||
Array* getNormalIndices() { return _normalIndices.get(); }
|
||||
const Array* getNormalIndices() const { return _normalIndices.get(); }
|
||||
void setNormalIndices(IndexArray* array) { _normalIndices = array; dirtyDisplayList(); }
|
||||
IndexArray* getNormalIndices() { return _normalIndices.get(); }
|
||||
const IndexArray* getNormalIndices() const { return _normalIndices.get(); }
|
||||
|
||||
|
||||
void setColorBinding(AttributeBinding ab) { _colorBinding = ab; }
|
||||
@@ -70,9 +70,9 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
Array* getColorArray() { return _colorArray.get(); }
|
||||
const Array* getColorArray() const { return _colorArray.get(); }
|
||||
|
||||
void setColorIndices(Array* array) { _colorIndices = array; dirtyDisplayList(); }
|
||||
Array* getColorIndices() { return _colorIndices.get(); }
|
||||
const Array* getColorIndices() const { return _colorIndices.get(); }
|
||||
void setColorIndices(IndexArray* array) { _colorIndices = array; dirtyDisplayList(); }
|
||||
IndexArray* getColorIndices() { return _colorIndices.get(); }
|
||||
const IndexArray* getColorIndices() const { return _colorIndices.get(); }
|
||||
|
||||
|
||||
void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; }
|
||||
@@ -82,9 +82,9 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
|
||||
|
||||
void setSecondaryColorIndices(Array* array) { _secondaryColorIndices = array; dirtyDisplayList(); }
|
||||
Array* getSecondaryColorIndices() { return _secondaryColorIndices.get(); }
|
||||
const Array* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); }
|
||||
void setSecondaryColorIndices(IndexArray* array) { _secondaryColorIndices = array; dirtyDisplayList(); }
|
||||
IndexArray* getSecondaryColorIndices() { return _secondaryColorIndices.get(); }
|
||||
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); }
|
||||
|
||||
|
||||
void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; }
|
||||
@@ -95,13 +95,13 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
const FloatArray* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
|
||||
|
||||
void setFogCoordIndices(Array* array) { _fogCoordIndices = array; dirtyDisplayList(); }
|
||||
Array* getFogCoordIndices() { return _fogCoordIndices.get(); }
|
||||
const Array* getFogCoordIndices() const { return _fogCoordIndices.get(); }
|
||||
void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); }
|
||||
IndexArray* getFogCoordIndices() { return _fogCoordIndices.get(); }
|
||||
const IndexArray* getFogCoordIndices() const { return _fogCoordIndices.get(); }
|
||||
|
||||
|
||||
|
||||
typedef std::pair< ref_ptr<Array>, ref_ptr<Array> > TexCoordArrayPair;
|
||||
typedef std::pair< ref_ptr<Array>, ref_ptr<IndexArray> > TexCoordArrayPair;
|
||||
typedef std::vector< TexCoordArrayPair > TexCoordArrayList;
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
const Array* getTexCoordArray(unsigned int unit) const;
|
||||
|
||||
void setTexCoordIndices(unsigned int unit,Array*);
|
||||
Array* getTexCoordIndices(unsigned int unit);
|
||||
const Array* getTexCoordIndices(unsigned int unit) const;
|
||||
IndexArray* getTexCoordIndices(unsigned int unit);
|
||||
const IndexArray* getTexCoordIndices(unsigned int unit) const;
|
||||
|
||||
unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); }
|
||||
TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; }
|
||||
@@ -157,23 +157,23 @@ class SG_EXPORT IndexedGeometry : public Drawable
|
||||
PrimitiveSetList _primitives;
|
||||
|
||||
ref_ptr<Vec3Array> _vertexArray;
|
||||
ref_ptr<Array> _vertexIndices;
|
||||
ref_ptr<IndexArray> _vertexIndices;
|
||||
|
||||
AttributeBinding _normalBinding;
|
||||
ref_ptr<Vec3Array> _normalArray;
|
||||
ref_ptr<Array> _normalIndices;
|
||||
ref_ptr<IndexArray> _normalIndices;
|
||||
|
||||
AttributeBinding _colorBinding;
|
||||
ref_ptr<Array> _colorArray;
|
||||
ref_ptr<Array> _colorIndices;
|
||||
ref_ptr<IndexArray> _colorIndices;
|
||||
|
||||
AttributeBinding _secondaryColorBinding;
|
||||
ref_ptr<Array> _secondaryColorArray;
|
||||
ref_ptr<Array> _secondaryColorIndices;
|
||||
ref_ptr<IndexArray> _secondaryColorIndices;
|
||||
|
||||
AttributeBinding _fogCoordBinding;
|
||||
ref_ptr<FloatArray> _fogCoordArray;
|
||||
ref_ptr<Array> _fogCoordIndices;
|
||||
ref_ptr<IndexArray> _fogCoordIndices;
|
||||
|
||||
TexCoordArrayList _texCoordList;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user