Fixes to smoothing visitor and tesselator to handle indexed Geometry.

This commit is contained in:
Robert Osfield 2002-10-09 15:43:56 +00:00
parent 88ecacfd7a
commit 16291da3b0
4 changed files with 76 additions and 15 deletions

View File

@ -125,9 +125,27 @@ class PrimitiveSet : public Object
virtual void accept(Drawable::PrimitiveFunctor&) {}
virtual unsigned int index(unsigned int pos) const = 0;
virtual unsigned int getNumIndices() const = 0;
virtual void offsetIndices(int offset) = 0;
virtual unsigned int getNumIndices() = 0;
virtual unsigned int getNumPrimitives() const
{
switch(_mode)
{
case(POINTS): return getNumIndices();
case(LINES): return getNumIndices()/2;
case(TRIANGLES): return getNumIndices()/3;
case(QUADS): return getNumIndices()/4;
case(LINE_STRIP):
case(LINE_LOOP):
case(TRIANGLE_STRIP):
case(TRIANGLE_FAN):
case(QUAD_STRIP):
case(POLYGON): return 1;
}
return 0;
}
protected:
@ -183,10 +201,10 @@ class SG_EXPORT DrawArrays : public PrimitiveSet
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual unsigned int getNumIndices() const { return _count; }
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
virtual void offsetIndices(int offset) { _first += offset; }
virtual unsigned int getNumIndices() { return _count; }
protected:
GLint _first;
@ -236,9 +254,27 @@ class SG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual unsigned int getNumIndices() const;
virtual unsigned int index(unsigned int pos) const { return _first+pos; }
virtual void offsetIndices(int offset) { _first += offset; }
virtual unsigned int getNumIndices();
virtual unsigned int getNumPrimitives() const
{
switch(_mode)
{
case(POINTS): return getNumIndices();
case(LINES): return getNumIndices()/2;
case(TRIANGLES): return getNumIndices()/3;
case(QUADS): return getNumIndices()/4;
case(LINE_STRIP):
case(LINE_LOOP):
case(TRIANGLE_STRIP):
case(TRIANGLE_FAN):
case(QUAD_STRIP):
case(POLYGON): return size();
}
return 0;
}
protected:
@ -279,9 +315,9 @@ class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
virtual void offsetIndices(int offset);
virtual unsigned int getNumIndices() { return size(); }
};
@ -319,9 +355,9 @@ class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
virtual void offsetIndices(int offset);
virtual unsigned int getNumIndices() { return size(); }
};
class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
@ -358,9 +394,9 @@ class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt
virtual void accept(Drawable::PrimitiveFunctor& functor);
virtual unsigned int getNumIndices() const { return size(); }
virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; }
virtual void offsetIndices(int offset);
virtual unsigned int getNumIndices() { return size(); }
};
}

View File

@ -36,10 +36,10 @@ void DrawArrayLengths::accept(Drawable::PrimitiveFunctor& functor)
}
}
unsigned int DrawArrayLengths::getNumIndices()
unsigned int DrawArrayLengths::getNumIndices() const
{
unsigned int count = 0;
for(VectorSizei::iterator itr=begin();
for(VectorSizei::const_iterator itr=begin();
itr!=end();
++itr)
{
@ -48,7 +48,6 @@ unsigned int DrawArrayLengths::getNumIndices()
return count;
}
void DrawElementsUByte::draw() const
{
glDrawElements(_mode,size(),GL_UNSIGNED_BYTE,&front());

View File

@ -121,6 +121,7 @@ void SmoothingVisitor::smooth(osg::Geometry& geom)
}
geom.setNormalArray( normals );
geom.setNormalIndices( geom.getVertexIndices() );
geom.setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

View File

@ -137,11 +137,26 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom)
Vec3Array* vertices = geom.getVertexArray();
if (!vertices || vertices->empty() || geom.getPrimitiveSetList().empty()) return;
// we currently don't handle geometry which use indices...
if (geom.getVertexIndices() ||
geom.getNormalIndices() ||
geom.getColorIndices() ||
geom.getSecondaryColorIndices() ||
geom.getFogCoordIndices()) return;
// not even text coord indices don't handle geometry which use indices...
for(unsigned int unit=0;unit<geom.getNumTexCoordArrays();++unit)
{
if (geom.getTexCoordIndices(unit)) return;
}
// process the primitives
int noPrimitiveAtStart = geom.getPrimitiveSetList().size();
for(int primNo=0;primNo<noPrimitiveAtStart;++primNo)
{
osg::PrimitiveSet* primitive = geom.getPrimitiveSetList()[primNo].get();
if (primitive->getMode()==osg::PrimitiveSet::POLYGON)
if (primitive->getMode()==osg::PrimitiveSet::POLYGON && primitive->getNumIndices()>3)
{
beginTesselation();
beginContour();
@ -225,6 +240,16 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom)
arrays.push_back(geom.getColorArray());
}
if (geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_VERTEX)
{
arrays.push_back(geom.getSecondaryColorArray());
}
if (geom.getFogCoordBinding()==osg::Geometry::BIND_PER_VERTEX)
{
arrays.push_back(geom.getFogCoordArray());
}
osg::Geometry::TexCoordArrayList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::TexCoordArrayList::iterator tcalItr=tcal.begin();
tcalItr!=tcal.end();