Addd new experimental osg::Geometry Drawable which will eventually replace
GeoSet. Currently doesn't draw anything, and is very much in the early design stages.
This commit is contained in:
parent
d763a47d2e
commit
476f931eaa
@ -197,6 +197,10 @@ SOURCE=..\..\src\osg\Geode.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Geometry.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\GeoSet.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -493,6 +497,10 @@ SOURCE=..\..\Include\Osg\Geode
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Geometry
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\GeoSet
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
200
include/osg/Geometry
Normal file
200
include/osg/Geometry
Normal file
@ -0,0 +1,200 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_GEOMETRY
|
||||
#define OSG_GEOMETRY 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec4>
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
class AttributeArray : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
AttributeArray(GLint dataSize=0,GLenum dataType=0):_dataSize(dataSize),_dataType(dataType) {}
|
||||
|
||||
AttributeArray(const AttributeArray& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(array,copyop),
|
||||
_dataSize(array._dataSize),
|
||||
_dataType(array._dataType) {}
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const AttributeArray*>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return "AttributeArray"; }
|
||||
|
||||
|
||||
GLint dataSize() const { return _dataSize; }
|
||||
GLenum dataType() const { return _dataType; }
|
||||
virtual const GLvoid* dataPointer() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~AttributeArray() {}
|
||||
|
||||
GLint _dataSize;
|
||||
GLenum _dataType;
|
||||
};
|
||||
|
||||
static char* s_classNames[] = {
|
||||
"ByteArray", // 0
|
||||
"ShortArray", // 1
|
||||
"IntArray", // 2
|
||||
"UByteArray", // 3
|
||||
"UShortArray", // 4
|
||||
"UIntArray", // 5
|
||||
"FloatArray", // 6
|
||||
"Vec2Array", // 7
|
||||
"Vec3Array", // 8
|
||||
"Vec4Array" // 9
|
||||
};
|
||||
|
||||
template<typename T,int DataSize,int DataType,unsigned int ClassName>
|
||||
class TemplateArray : public AttributeArray, public std::vector<T>
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateArray() : TemplateArray(DataSize,DataType) {}
|
||||
|
||||
TemplateArray(const T& t,const CopyOp& copyop=CopyOp::SHALLOW_COPY) : AttributeArray(t,copyop), std::vector<T>(t) {}
|
||||
|
||||
virtual Object* cloneType() const { return osgNew TemplateArray(); }
|
||||
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); }
|
||||
virtual const char* libraryName() const { return "osg"; }
|
||||
virtual const char* className() const { return s_classNames[ClassName]; }
|
||||
|
||||
virtual const GLvoid* dataPointer() const { if (!empty()) return &(*begin()); else return 0; }
|
||||
};
|
||||
|
||||
typedef TemplateArray<char,1,GL_BYTE,0> ByteArray;
|
||||
typedef TemplateArray<short,1,GL_SHORT,1> ShortArray;
|
||||
typedef TemplateArray<int,1,GL_INT,2> IntArray;
|
||||
typedef TemplateArray<unsigned char,1,GL_UNSIGNED_BYTE,3> UByteArray;
|
||||
typedef TemplateArray<unsigned short,1,GL_UNSIGNED_SHORT,4> UShortArray;
|
||||
typedef TemplateArray<unsigned int,1,GL_UNSIGNED_INT,5> UIntArray;
|
||||
typedef TemplateArray<float,1,GL_FLOAT,6> FloatArray;
|
||||
typedef TemplateArray<Vec2,2,GL_FLOAT,7> Vec2Array;
|
||||
typedef TemplateArray<Vec3,3,GL_FLOAT,8> Vec3Array;
|
||||
typedef TemplateArray<Vec4,4,GL_FLOAT,9> Vec4Array;
|
||||
|
||||
|
||||
/** Experiemntal replacement for GeoSet.
|
||||
*/
|
||||
class SG_EXPORT Geometry : public Drawable
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
Geometry();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Geometry(const Geometry& Geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual Object* cloneType() const { return osgNew Geometry(); }
|
||||
virtual Object* clone(const CopyOp& copyop) const { return osgNew Geometry(*this,copyop); }
|
||||
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"; }
|
||||
|
||||
enum PrimitiveType
|
||||
{
|
||||
POINTS = GL_POINTS,
|
||||
LINES = GL_LINES,
|
||||
LINE_STRIP = GL_LINE_STRIP,
|
||||
LINE_LOOP = GL_LINE_LOOP,
|
||||
TRIANGLES = GL_TRIANGLES,
|
||||
TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN = GL_TRIANGLE_FAN,
|
||||
QUADS = GL_QUADS,
|
||||
QUAD_STRIP = GL_QUAD_STRIP,
|
||||
POLYGON = GL_POLYGON
|
||||
};
|
||||
|
||||
enum AttributeType
|
||||
{
|
||||
PRIMITIVES,
|
||||
COORDS,
|
||||
NORMALS,
|
||||
COLORS,
|
||||
TEX_COORDS,
|
||||
TEX_COORDS_0 = TEX_COORDS,
|
||||
TEX_COORDS_1,
|
||||
TEX_COORDS_2,
|
||||
TEX_COORDS_3,
|
||||
TEX_COORDS_4,
|
||||
TEX_COORDS_5,
|
||||
TEX_COORDS_6,
|
||||
TEX_COORDS_7
|
||||
};
|
||||
|
||||
void setAttribute(AttributeType type,AttributeArray* array);
|
||||
|
||||
void setAttribute(AttributeType type,AttributeArray* array,AttributeArray* indices);
|
||||
|
||||
AttributeArray* getAttribute(AttributeType type);
|
||||
|
||||
void setIndices(AttributeType type,AttributeArray* indices);
|
||||
|
||||
AttributeArray* getIndices(AttributeType type);
|
||||
|
||||
|
||||
/** draw Geometry directly ignoring an OpenGL display list which could be attached.
|
||||
* 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.
|
||||
*/
|
||||
virtual void drawImmediateMode(State& state);
|
||||
|
||||
/** Statistics collection for each drawable- 26.09.01
|
||||
*/
|
||||
bool getStats(Statistics &);
|
||||
|
||||
|
||||
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
|
||||
virtual AttributeBitMask suppportsAttributeOperation() const;
|
||||
|
||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
||||
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Geometry& operator = (const Geometry&) { return *this;}
|
||||
|
||||
virtual ~Geometry();
|
||||
|
||||
virtual const bool computeBound() const;
|
||||
|
||||
void setTexCoordArray(unsigned int pos,AttributeArray*);
|
||||
AttributeArray* getTexCoordArray(unsigned int pos);
|
||||
|
||||
void setTexCoordIndicesArray(unsigned int pos,AttributeArray*);
|
||||
AttributeArray* getTexCoordIndicesArray(unsigned int pos);
|
||||
|
||||
typedef std::vector< ref_ptr<AttributeArray> > TexCoordList;
|
||||
|
||||
ref_ptr<AttributeArray> _primitives;
|
||||
|
||||
ref_ptr<AttributeArray> _coords;
|
||||
ref_ptr<AttributeArray> _coordIndices;
|
||||
|
||||
ref_ptr<AttributeArray> _normals;
|
||||
ref_ptr<AttributeArray> _normalIndices;
|
||||
|
||||
ref_ptr<AttributeArray> _colors;
|
||||
ref_ptr<AttributeArray> _colorIndices;
|
||||
|
||||
TexCoordList _texCoordList;
|
||||
TexCoordList _texCoordIndicesList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
230
src/osg/Geometry.cpp
Normal file
230
src/osg/Geometry.cpp
Normal file
@ -0,0 +1,230 @@
|
||||
#include <osg/Geometry>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Geometry::Geometry()
|
||||
{
|
||||
}
|
||||
|
||||
Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
|
||||
Drawable(geometry,copyop),
|
||||
_coords(geometry._coords),
|
||||
_coordIndices(geometry._coordIndices),
|
||||
_normals(geometry._normals),
|
||||
_normalIndices(geometry._normalIndices),
|
||||
_colors(geometry._colors),
|
||||
_colorIndices(geometry._colorIndices),
|
||||
_texCoordList(geometry._texCoordList),
|
||||
_texCoordIndicesList(geometry._texCoordIndicesList)
|
||||
{
|
||||
}
|
||||
|
||||
Geometry::~Geometry()
|
||||
{
|
||||
// no need to delete, all automatically handled by ref_ptr :-)
|
||||
}
|
||||
|
||||
void Geometry::setTexCoordArray(unsigned int pos,AttributeArray* array)
|
||||
{
|
||||
if (_texCoordList.size()<=pos)
|
||||
_texCoordList.resize(pos+1,0);
|
||||
|
||||
_texCoordList[pos] = array;
|
||||
}
|
||||
|
||||
AttributeArray* Geometry::getTexCoordArray(unsigned int pos)
|
||||
{
|
||||
if (pos<_texCoordList.size()) return _texCoordList[pos].get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void Geometry::setTexCoordIndicesArray(unsigned int pos,AttributeArray* array)
|
||||
{
|
||||
if (_texCoordList.size()<=pos)
|
||||
_texCoordList.resize(pos+1,0);
|
||||
|
||||
_texCoordIndicesList[pos] = array;
|
||||
}
|
||||
|
||||
AttributeArray* Geometry::getTexCoordIndicesArray(unsigned int pos)
|
||||
{
|
||||
if (pos<_texCoordIndicesList.size()) return _texCoordIndicesList[pos].get();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
void Geometry::setAttribute(AttributeType type,AttributeArray* array)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case(PRIMITIVES):
|
||||
_primitives = array;
|
||||
break;
|
||||
case(COORDS):
|
||||
_coords = array;
|
||||
break;
|
||||
case(NORMALS):
|
||||
_normals = array;
|
||||
break;
|
||||
case(COLORS):
|
||||
_colors = array;
|
||||
break;
|
||||
default:
|
||||
if (type>=TEX_COORDS_0)
|
||||
{
|
||||
setTexCoordArray(type-TEX_COORDS_0,array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Geometry::setAttribute(AttributeType type,AttributeArray* array,AttributeArray* indices)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case(PRIMITIVES):
|
||||
_primitives = array;
|
||||
// indices not appropriate!
|
||||
break;
|
||||
case(COORDS):
|
||||
_coords = array;
|
||||
_coordIndices = indices;
|
||||
break;
|
||||
case(NORMALS):
|
||||
_normals = array;
|
||||
_normalIndices = indices;
|
||||
break;
|
||||
case(COLORS):
|
||||
_colors = array;
|
||||
_colorIndices = indices;
|
||||
break;
|
||||
default:
|
||||
if (type>=TEX_COORDS_0)
|
||||
{
|
||||
setTexCoordArray(type-TEX_COORDS_0,array);
|
||||
setTexCoordIndicesArray(type-TEX_COORDS_0,indices);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AttributeArray* Geometry::getAttribute(AttributeType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case(PRIMITIVES):
|
||||
return _primitives.get();
|
||||
break;
|
||||
case(COORDS):
|
||||
return _coords.get();
|
||||
break;
|
||||
case(NORMALS):
|
||||
return _normals.get();
|
||||
break;
|
||||
case(COLORS):
|
||||
return _colors.get();
|
||||
break;
|
||||
default:
|
||||
if (type>=TEX_COORDS_0)
|
||||
{
|
||||
return getTexCoordArray(type-TEX_COORDS_0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Geometry::setIndices(AttributeType type,AttributeArray* indices)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case(PRIMITIVES):
|
||||
// indices not appropriate!
|
||||
break;
|
||||
case(COORDS):
|
||||
_coordIndices = indices;
|
||||
break;
|
||||
case(NORMALS):
|
||||
_normalIndices = indices;
|
||||
break;
|
||||
case(COLORS):
|
||||
_colorIndices = indices;
|
||||
break;
|
||||
default:
|
||||
if (type>=TEX_COORDS_0)
|
||||
{
|
||||
setTexCoordIndicesArray(type-TEX_COORDS_0,indices);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AttributeArray* Geometry::getIndices(AttributeType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case(COORDS):
|
||||
return _coordIndices.get();
|
||||
break;
|
||||
case(NORMALS):
|
||||
return _normalIndices.get();
|
||||
break;
|
||||
case(COLORS):
|
||||
return _colorIndices.get();
|
||||
break;
|
||||
default:
|
||||
if (type>=TEX_COORDS_0)
|
||||
{
|
||||
return getTexCoordIndicesArray(type-TEX_COORDS_0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Geometry::drawImmediateMode(State& /*state*/)
|
||||
{
|
||||
}
|
||||
|
||||
/** Statistics collection for each drawable- 26.09.01
|
||||
*/
|
||||
bool Geometry::getStats(Statistics &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Drawable::AttributeBitMask Geometry::suppportsAttributeOperation() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
||||
Drawable::AttributeBitMask Geometry::applyAttributeOperation(AttributeFunctor& )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const bool Geometry::computeBound() const
|
||||
{
|
||||
_bbox.init();
|
||||
|
||||
const Vec3Array* coords = dynamic_cast<const Vec3Array*>(_coords.get());
|
||||
if (coords)
|
||||
{
|
||||
for(Vec3Array::const_iterator itr=coords->begin();
|
||||
itr!=coords->end();
|
||||
++itr)
|
||||
{
|
||||
_bbox.expandBy(*itr);
|
||||
}
|
||||
}
|
||||
_bbox_computed = true;
|
||||
|
||||
return _bbox.valid();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ CXXFILES =\
|
||||
FrameStamp.cpp\
|
||||
FrontFace.cpp\
|
||||
GLExtensions.cpp\
|
||||
Geometry.cpp\
|
||||
GeoSet.cpp\
|
||||
GeoSet_ogl.cpp\
|
||||
Geode.cpp\
|
||||
|
Loading…
Reference in New Issue
Block a user