Moved the new osg::IndexedGeometry class over the top of the the existing
osg::Geometry class, and removed the temporary IndexedGeometry. Port the rest of the OSG across to account for the change in method calls - osg::Geometry::addPrimitive(..) becomes osg::addPrimitiveSet(..)
This commit is contained in:
@@ -9,11 +9,8 @@
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osg/Geometry>
|
||||
#include <osg/IndexedGeometry>
|
||||
#include <osg/ShadeModel>
|
||||
|
||||
//#include <osg/mem_ptr>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
GeoSet::GeoSet()
|
||||
@@ -945,19 +942,13 @@ Geometry* GeoSet::convertToGeometry()
|
||||
{
|
||||
// will need to add flat shading to primitive.
|
||||
|
||||
StateSet* stateset = geom->getStateSet();
|
||||
if (!stateset)
|
||||
{
|
||||
stateset = osgNew StateSet;
|
||||
geom->setStateSet(stateset);
|
||||
}
|
||||
StateSet* stateset = geom->getOrCreateStateSet();
|
||||
ShadeModel* shademodel = dynamic_cast<ShadeModel*>(stateset->getAttribute(StateAttribute::SHADEMODEL));
|
||||
if (!shademodel)
|
||||
{
|
||||
shademodel = osgNew osg::ShadeModel;
|
||||
stateset->setAttribute(shademodel,StateAttribute::OVERRIDE);
|
||||
stateset->setAttribute(shademodel);
|
||||
}
|
||||
|
||||
shademodel->setMode( ShadeModel::FLAT );
|
||||
}
|
||||
|
||||
@@ -999,378 +990,6 @@ Geometry* GeoSet::convertToGeometry()
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (_fast_path)
|
||||
{
|
||||
// will easily convert into a Geometry.
|
||||
|
||||
if (_coords) geom->setVertexArray(osgNew Vec3Array(_numcoords,_coords));
|
||||
|
||||
if (_normals) geom->setNormalArray(osgNew Vec3Array(_numnormals,_normals));
|
||||
|
||||
if (_colors) geom->setColorArray(osgNew Vec4Array(_numcolors,_colors));
|
||||
|
||||
if (_tcoords) geom->setTexCoordArray(0,osgNew Vec2Array(_numtcoords,_tcoords));
|
||||
|
||||
if( _needprimlen ) // LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
||||
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
||||
{
|
||||
int index = 0;
|
||||
if( _primLengths == (int *)0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( _cindex.valid() )
|
||||
{
|
||||
|
||||
for( int i = 0; i < _numprims; i++ )
|
||||
{
|
||||
DrawElementsUShort* n = new DrawElementsUShort;
|
||||
geom->addPrimitive(n);
|
||||
|
||||
if (_cindex._is_ushort)
|
||||
geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] ));
|
||||
else
|
||||
geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _primLengths[i], &_cindex._ptr._uint[index] ));
|
||||
|
||||
index += _primLengths[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_numprims==1)
|
||||
{
|
||||
DrawArrays* da = new DrawArrays(_oglprimtype,0,_primLengths[0]);
|
||||
geom->addPrimitive(da);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawArrayLengths* dal = new DrawArrayLengths(_oglprimtype,0,_numprims);
|
||||
geom->addPrimitive(dal);
|
||||
for( int i = 0; i < _numprims; i++ )
|
||||
{
|
||||
(*dal)[i] = _primLengths[i];
|
||||
index += _primLengths[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else // POINTS, LINES, TRIANGLES, QUADS
|
||||
{
|
||||
if( _cindex.valid())
|
||||
{
|
||||
if (_cindex._is_ushort)
|
||||
geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort ));
|
||||
else
|
||||
geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint ));
|
||||
}
|
||||
else
|
||||
geom->addPrimitive(new DrawArrays( (GLenum)_oglprimtype, 0, _numcoords ));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if( _needprimlen )
|
||||
{
|
||||
// slow path, and needing handling of primlen array.
|
||||
//
|
||||
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
||||
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
||||
// FLAT_LINE_STRIP, FLAT_TRIANGLE_STRIP, FLAT_TRIANGLE_FAN
|
||||
|
||||
int i, j;
|
||||
int index = 0;
|
||||
int ai = 0;
|
||||
int ci = 0;
|
||||
int ni = 0;
|
||||
int ti = 0;
|
||||
|
||||
if( _primLengths == (int *)0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Vec3Array* coords = osgNew Vec3Array;
|
||||
Vec3Array* normals = 0;
|
||||
Vec4Array* colors = 0;
|
||||
Vec2Array* texcoords = 0;
|
||||
|
||||
if (_colors) colors = osgNew Vec4Array;
|
||||
if (_normals) normals = osgNew Vec3Array;
|
||||
if (_tcoords) texcoords = osgNew Vec2Array;
|
||||
|
||||
geom->setVertexArray(coords);
|
||||
geom->setColorArray(colors);
|
||||
geom->setNormalArray(normals);
|
||||
geom->setTexCoordArray(0,texcoords);
|
||||
|
||||
if (_color_binding == BIND_OVERALL)
|
||||
{
|
||||
if( _colindex.valid() )
|
||||
colors->push_back( _colors[_colindex[0]] );
|
||||
else
|
||||
colors->push_back( _colors[0] );
|
||||
}
|
||||
|
||||
if (_normal_binding == BIND_OVERALL)
|
||||
{
|
||||
if( _nindex.valid() )
|
||||
normals->push_back( _normals[0] );
|
||||
else
|
||||
normals->push_back( _normals[0] );
|
||||
}
|
||||
|
||||
for( i = 0; i < _numprims; i++ )
|
||||
{
|
||||
if (_color_binding == BIND_PERPRIM && colors)
|
||||
{
|
||||
if( _colindex.valid() )
|
||||
colors->push_back( _colors[_colindex[ci++]] );
|
||||
else
|
||||
colors->push_back( _colors[ci++] );
|
||||
}
|
||||
|
||||
if (_normal_binding == BIND_PERPRIM && normals)
|
||||
{
|
||||
if( _nindex.valid() )
|
||||
normals->push_back( _normals[_nindex[ni++]] );
|
||||
else
|
||||
normals->push_back( _normals[ni++] );
|
||||
}
|
||||
|
||||
unsigned int first = coords->size();
|
||||
unsigned int count = 0;
|
||||
|
||||
|
||||
for( j = 0; j < _primLengths[i]; j++ )
|
||||
{
|
||||
if( j >= _flat_shaded_skip )
|
||||
{
|
||||
if( _color_binding == BIND_PERVERTEX && colors)
|
||||
{
|
||||
if( (_colindex.valid()) )
|
||||
colors->push_back( _colors[_colindex[ci++]] );
|
||||
else
|
||||
colors->push_back( _colors[ci++] );
|
||||
}
|
||||
|
||||
if( _normal_binding == BIND_PERVERTEX && normals)
|
||||
{
|
||||
if(_nindex.valid())
|
||||
normals->push_back( _normals[_nindex[ni++]] );
|
||||
else
|
||||
normals->push_back( _normals[ni++] );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// note don't increment ci & ni as we want to make multiple copies it when in _flat_shaded_skip
|
||||
if( _color_binding == BIND_PERVERTEX && colors)
|
||||
{
|
||||
if( (_colindex.valid()) )
|
||||
colors->push_back( _colors[_colindex[ci]] );
|
||||
else
|
||||
colors->push_back( _colors[ci] );
|
||||
}
|
||||
|
||||
if( _normal_binding == BIND_PERVERTEX && normals )
|
||||
{
|
||||
if(_nindex.valid())
|
||||
normals->push_back( _normals[_nindex[ni]] );
|
||||
else
|
||||
normals->push_back( _normals[ni] );
|
||||
}
|
||||
}
|
||||
|
||||
if( _texture_binding == BIND_PERVERTEX && texcoords)
|
||||
{
|
||||
if( _tindex.valid() )
|
||||
texcoords->push_back( _tcoords[_tindex[ti++]] );
|
||||
else
|
||||
texcoords->push_back( _tcoords[ti++] );
|
||||
}
|
||||
|
||||
if( _cindex.valid() )
|
||||
coords->push_back( _coords[_cindex[ai++]] );
|
||||
else
|
||||
coords->push_back( _coords[ai++] );
|
||||
|
||||
++count;
|
||||
|
||||
}
|
||||
|
||||
geom->addPrimitive(osgNew DrawArrays(_oglprimtype,first,count));
|
||||
|
||||
index += _primLengths[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// POINTS, LINES, TRIANGLES, QUADS
|
||||
|
||||
Vec3Array* coords = osgNew Vec3Array;
|
||||
Vec3Array* normals = 0;
|
||||
Vec4Array* colors = 0;
|
||||
Vec2Array* texcoords = 0;
|
||||
|
||||
if (_colors) colors = osgNew Vec4Array;
|
||||
if (_normals) normals = osgNew Vec3Array;
|
||||
if (_tcoords) texcoords = osgNew Vec2Array;
|
||||
|
||||
geom->setVertexArray(coords);
|
||||
geom->setColorArray(colors);
|
||||
geom->setNormalArray(normals);
|
||||
geom->setTexCoordArray(0,texcoords);
|
||||
|
||||
if (_color_binding == BIND_OVERALL)
|
||||
{
|
||||
if( _colindex.valid() )
|
||||
colors->push_back( _colors[_colindex[0]] );
|
||||
else
|
||||
colors->push_back( _colors[0] );
|
||||
}
|
||||
|
||||
if (_normal_binding == BIND_OVERALL)
|
||||
{
|
||||
if( _nindex.valid() )
|
||||
normals->push_back( _normals[_nindex[0]] );
|
||||
else
|
||||
normals->push_back( _normals[0] );
|
||||
}
|
||||
|
||||
for(int i = 0; i < _numprims; i++ )
|
||||
{
|
||||
if (_color_binding == BIND_PERPRIM && colors)
|
||||
{
|
||||
if( _colindex.valid() )
|
||||
colors->push_back( _colors[_colindex[i]] );
|
||||
else
|
||||
colors->push_back( _colors[i] );
|
||||
}
|
||||
|
||||
if (_normal_binding == BIND_PERPRIM && normals)
|
||||
{
|
||||
if( _nindex.valid() )
|
||||
normals->push_back( _normals[_nindex[i]] );
|
||||
else
|
||||
normals->push_back( _normals[i] );
|
||||
}
|
||||
|
||||
unsigned int first = coords->size();
|
||||
unsigned int count = 0;
|
||||
|
||||
for(int j = 0; j < _primlength; j++ )
|
||||
{
|
||||
if( _color_binding == BIND_PERVERTEX && colors)
|
||||
{
|
||||
if( (_colindex.valid()) )
|
||||
colors->push_back( _colors[_colindex[i*_primlength+j]] );
|
||||
else
|
||||
colors->push_back( _colors[i*_primlength+j] );
|
||||
}
|
||||
|
||||
if( _normal_binding == BIND_PERVERTEX && normals )
|
||||
{
|
||||
if(_nindex.valid())
|
||||
normals->push_back( _normals[_nindex[i*_primlength+j]] );
|
||||
else
|
||||
normals->push_back( _normals[i*_primlength+j] );
|
||||
}
|
||||
|
||||
if( _texture_binding == BIND_PERVERTEX && texcoords)
|
||||
{
|
||||
if( _tindex.valid() )
|
||||
texcoords->push_back( _tcoords[_tindex[i*_primlength+j]] );
|
||||
else
|
||||
texcoords->push_back( _tcoords[i*_primlength+j] );
|
||||
}
|
||||
|
||||
if( _cindex.valid() )
|
||||
coords->push_back( _coords[_cindex[i*_primlength+j]] );
|
||||
else
|
||||
coords->push_back( _coords[i*_primlength+j] );
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
geom->addPrimitive(osgNew DrawArrays(_oglprimtype,first,count));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return geom.take();
|
||||
|
||||
|
||||
}
|
||||
|
||||
IndexedGeometry* GeoSet::convertToIndexedGeometry()
|
||||
{
|
||||
set_fast_path();
|
||||
computeNumVerts();
|
||||
|
||||
ref_ptr<IndexedGeometry> geom = osgNew IndexedGeometry;
|
||||
geom->setStateSet(getStateSet());
|
||||
|
||||
if (_flat_shaded_skip)
|
||||
{
|
||||
// will need to add flat shading to primitive.
|
||||
|
||||
StateSet* stateset = geom->getOrCreateStateSet();
|
||||
ShadeModel* shademodel = dynamic_cast<ShadeModel*>(stateset->getAttribute(StateAttribute::SHADEMODEL));
|
||||
if (!shademodel)
|
||||
{
|
||||
shademodel = osgNew osg::ShadeModel;
|
||||
stateset->setAttribute(shademodel);
|
||||
}
|
||||
shademodel->setMode( ShadeModel::FLAT );
|
||||
}
|
||||
|
||||
switch(_normal_binding)
|
||||
{
|
||||
case(BIND_OFF):
|
||||
geom->setNormalBinding(IndexedGeometry::BIND_OFF);
|
||||
break;
|
||||
case(BIND_OVERALL):
|
||||
geom->setNormalBinding(IndexedGeometry::BIND_OVERALL);
|
||||
break;
|
||||
case(BIND_PERPRIM):
|
||||
geom->setNormalBinding(IndexedGeometry::BIND_PER_PRIMITIVE);
|
||||
break;
|
||||
case(BIND_PERVERTEX):
|
||||
geom->setNormalBinding(IndexedGeometry::BIND_PER_VERTEX);
|
||||
break;
|
||||
default:
|
||||
geom->setNormalBinding(IndexedGeometry::BIND_OFF);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(_color_binding)
|
||||
{
|
||||
case(BIND_OFF):
|
||||
geom->setColorBinding(IndexedGeometry::BIND_OFF);
|
||||
break;
|
||||
case(BIND_OVERALL):
|
||||
geom->setColorBinding(IndexedGeometry::BIND_OVERALL);
|
||||
break;
|
||||
case(BIND_PERPRIM):
|
||||
geom->setColorBinding(IndexedGeometry::BIND_PER_PRIMITIVE);
|
||||
break;
|
||||
case(BIND_PERVERTEX):
|
||||
geom->setColorBinding(IndexedGeometry::BIND_PER_VERTEX);
|
||||
break;
|
||||
default:
|
||||
geom->setColorBinding(IndexedGeometry::BIND_OFF);
|
||||
break;
|
||||
}
|
||||
|
||||
if (_coords)
|
||||
{
|
||||
geom->setVertexArray(osgNew Vec3Array(_numcoords,_coords));
|
||||
@@ -1542,6 +1161,3 @@ IndexedGeometry* GeoSet::convertToIndexedGeometry()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user