Added osg::Drawable::PrimitiveFunctor and TriangleFunctor subclass for

querrying the primitive data inside Drawables.  Moved various support
classes over from being osg::GeoSet based to osg::Geometry based.
This commit is contained in:
Robert Osfield
2002-06-25 20:27:51 +00:00
parent 336c47e5fe
commit cbeeeefdab
20 changed files with 737 additions and 651 deletions

View File

@@ -979,8 +979,55 @@ bool GeoSet::getStats(Statistics &stat)
return true;
}
void GeoSet::applyPrimitiveOperation(PrimitiveFunctor& functor)
{
// will easily convert into a Geometry.
if (!_coords || !_numcoords) return;
functor.setVertexArray(_numcoords,_coords);
if( _needprimlen )
{
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
int index = 0;
if( _primLengths == (int *)0 )
{
return;
}
for( int i = 0; i < _numprims; i++ )
{
if( _cindex.valid() )
{
if (_cindex._is_ushort)
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
else
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
}
else
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
index += _primLengths[i];
}
}
else // POINTS, LINES, TRIANGLES, QUADS
{
if( _cindex.valid())
{
if (_cindex._is_ushort)
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort );
else
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint );
}
else
functor.drawArrays( (GLenum)_oglprimtype, 0, _numcoords );
}
}
Geometry* GeoSet::convertToGeometry()
{

View File

@@ -73,6 +73,8 @@ void Geometry::setTexCoordArray(unsigned int unit,AttributeArray* array)
_texCoordList.resize(unit+1,0);
_texCoordList[unit] = array;
dirtyDisplayList();
}
AttributeArray* Geometry::getTexCoordArray(unsigned int unit)
@@ -245,6 +247,22 @@ Drawable::AttributeBitMask Geometry::applyAttributeOperation(AttributeFunctor& )
return 0;
}
void Geometry::applyPrimitiveOperation(PrimitiveFunctor& functor)
{
if (!_vertexArray.valid() || _vertexArray->empty()) return;
functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front()));
for(PrimitiveList::iterator itr=_primitives.begin();
itr!=_primitives.end();
++itr)
{
(*itr)->applyPrimitiveOperation(functor);
}
}
const bool Geometry::computeBound() const
{
_bbox.init();

View File

@@ -5,7 +5,7 @@
#include <osg/Notify>
#include <osg/Geode>
#include <osg/GeoSet>
#include <osg/Geometry>
#include <osg/StateSet>
#include <osg/Texture>
@@ -491,35 +491,33 @@ Geode* osg::createGeodeForImage(osg::Image* image,const float s,const float t)
dstate->setAttributeAndModes(texture,osg::StateAttribute::ON);
// set up the geoset.
osg::GeoSet* gset = osgNew osg::GeoSet;
gset->setStateSet(dstate);
Geometry* geom = osgNew Geometry;
geom->setStateSet(dstate);
osg::Vec3* coords = osgNew Vec3[4];
coords[0].set(-x,0.0f,y);
coords[1].set(-x,0.0f,-y);
coords[2].set(x,0.0f,-y);
coords[3].set(x,0.0f,y);
gset->setCoords(coords);
Vec3Array* coords = osgNew Vec3Array(4);
(*coords)[0].set(-x,0.0f,y);
(*coords)[1].set(-x,0.0f,-y);
(*coords)[2].set(x,0.0f,-y);
(*coords)[3].set(x,0.0f,y);
geom->setVertexArray(coords);
osg::Vec2* tcoords = osgNew Vec2[4];
tcoords[0].set(0.0f,1.0f);
tcoords[1].set(0.0f,0.0f);
tcoords[2].set(1.0f,0.0f);
tcoords[3].set(1.0f,1.0f);
gset->setTextureCoords(tcoords);
gset->setTextureBinding(osg::GeoSet::BIND_PERVERTEX);
Vec2Array* tcoords = osgNew Vec2Array(4);
(*tcoords)[0].set(0.0f,1.0f);
(*tcoords)[1].set(0.0f,0.0f);
(*tcoords)[2].set(1.0f,0.0f);
(*tcoords)[3].set(1.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
osg::Vec4* colours = osgNew Vec4[1];
colours->set(1.0f,1.0f,1.0,1.0f);
gset->setColors(colours);
gset->setColorBinding(osg::GeoSet::BIND_OVERALL);
osg::Vec4Array* colours = osgNew osg::Vec4Array(1);
(*colours)[0].set(1.0f,1.0f,1.0,1.0f);
geom->setColorArray(colours);
geom->setColorBinding(Geometry::BIND_OVERALL);
gset->setNumPrims(1);
gset->setPrimType(osg::GeoSet::QUADS);
geom->addPrimitive(osgNew DrawArrays(Primitive::QUADS,0,4));
// set up the geode.
osg::Geode* geode = osgNew osg::Geode;
geode->addDrawable(gset);
geode->addDrawable(geom);
return geode;

View File

@@ -6,7 +6,7 @@
#include <math.h>
#include <float.h>
#include <osg/GeoSet>
#include <osg/Geometry>
#include <osg/ImpostorSprite>
#include <osg/Texture>
#include <osg/TexEnv>

View File

@@ -3,7 +3,6 @@
#include <osg/Group>
#include <osg/Geode>
#include <osg/GeoSet>
using namespace osg;
@@ -163,59 +162,7 @@ float computePolytopeVolume(const PointList& front, const PointList& back)
return volume;
}
Drawable* createOccluderDrawable(const PointList& front, const PointList& back)
{
// create a drawable for occluder.
osg::GeoSet* geoset = osgNew osg::GeoSet;
int totalNumber = front.size()+back.size();
osg::Vec3* coords = osgNew osg::Vec3[front.size()+back.size()];
osg::Vec3* cptr = coords;
for(PointList::const_iterator fitr=front.begin();
fitr!=front.end();
++fitr)
{
*cptr = fitr->second;
++cptr;
}
for(PointList::const_iterator bitr=back.begin();
bitr!=back.end();
++bitr)
{
*cptr = bitr->second;
++cptr;
}
geoset->setCoords(coords);
osg::Vec4* color = osgNew osg::Vec4[1];
color[0].set(1.0f,1.0f,1.0f,0.5f);
geoset->setColors(color);
geoset->setColorBinding(osg::GeoSet::BIND_OVERALL);
geoset->setPrimType(osg::GeoSet::POINTS);
geoset->setNumPrims(totalNumber);
//cout << "totalNumber = "<<totalNumber<<endl;
osg::Geode* geode = osgNew osg::Geode;
geode->addDrawable(geoset);
osg::StateSet* stateset = osgNew osg::StateSet;
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
geoset->setStateSet(stateset);
return geoset;
}
bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,CullStack& cullStack,bool createDrawables)
bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const ConvexPlanerOccluder& occluder,CullStack& cullStack,bool /*createDrawables*/)
{
@@ -291,24 +238,6 @@ bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const Convex
_volume = computePolytopeVolume(points,farPoints)/volumeview;
if (createDrawables && !nodePath.empty())
{
osg::Group* group = dynamic_cast<osg::Group*>(nodePath.back());
if (group)
{
osg::Matrix invMV;
invMV.invert(MV);
transform(points,invMV);
transform(farPoints,invMV);
osg::Geode* geode = osgNew osg::Geode;
group->addChild(geode);
geode->addDrawable(createOccluderDrawable(points,farPoints));
}
}
for(ConvexPlanerOccluder::HoleList::const_iterator hitr=occluder.getHoleList().begin();
hitr!=occluder.getHoleList().end();
@@ -350,24 +279,6 @@ bool ShadowVolumeOccluder::computeOccluder(const NodePath& nodePath,const Convex
// remove the hole's volume from the occluder volume.
_volume -= computePolytopeVolume(points,farPoints)/volumeview;
if (createDrawables && !nodePath.empty())
{
osg::Group* group = dynamic_cast<osg::Group*>(nodePath.back());
if (group)
{
osg::Matrix invMV;
invMV.invert(MV);
transform(points,invMV);
transform(farPoints,invMV);
osg::Geode* geode = osgNew osg::Geode;
group->addChild(geode);
geode->addDrawable(createOccluderDrawable(points,farPoints));
}
}
}
}