Clean up up osg::Geometry, removing long deprecated support for array indices and BIND_PER_PRIMITIVE binding that forced OpenGL slow paths. osg::Geometry is now smaller and only supports OpenGL fasts paths.

New methods osg::Geometry::containsDeprecatedData() and osg::Geometry::fixDeprecatedData() provide a means for converting geometries that still use the array indices and BIND_PER_PRIMITIVE across to complient
versions.

Cleaned up the rest of the OSG where use of array indices and BIND_PER_PRIMITIVE were accessed or used.
This commit is contained in:
Robert Osfield
2013-06-18 11:18:28 +00:00
parent 05b72e9b4c
commit 7d40c7258f
35 changed files with 1379 additions and 2880 deletions

View File

@@ -44,7 +44,7 @@ class TemplateAttributeDispatch : public AttributeDispatch
TemplateAttributeDispatch(F functionPtr, unsigned int stride):
_functionPtr(functionPtr), _stride(stride), _array(0) {}
virtual void assign(const GLvoid* array, const IndexArray*)
virtual void assign(const GLvoid* array)
{
_array = reinterpret_cast<const T*>(array);
}
@@ -59,89 +59,6 @@ class TemplateAttributeDispatch : public AttributeDispatch
const T* _array;
};
template<typename T>
class TemplateAttributeWithIndicesDispatch : public AttributeDispatch
{
public:
typedef void (GL_APIENTRY * F) (const T*);
TemplateAttributeWithIndicesDispatch(F functionPtr, unsigned int stride):
_functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {}
virtual void assign(const GLvoid* array, const IndexArray* indices)
{
_array = reinterpret_cast<const T*>(array);
_indices = indices;
}
virtual void operator () (unsigned int pos)
{
_functionPtr(&(_array[_indices->index(pos) * _stride]));
}
F _functionPtr;
unsigned int _stride;
const T* _array;
const IndexArray* _indices;
};
template<typename T>
class TemplateBeginEndAttributeDispatch : public AttributeDispatch
{
public:
typedef void (GLBeginEndAdapter::*F) (const T*);
TemplateBeginEndAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride):
_glBeginEndAdapter(glBeginEndAdapter),
_functionPtr(functionPtr), _stride(stride), _array(0) {}
virtual void assign(const GLvoid* array, const IndexArray*)
{
_array = reinterpret_cast<const T*>(array);
}
virtual void operator () (unsigned int pos)
{
(_glBeginEndAdapter->*_functionPtr)(&(_array[pos*_stride]));
}
GLBeginEndAdapter* _glBeginEndAdapter;
F _functionPtr;
unsigned int _stride;
const T* _array;
};
template<typename T>
class TemplateBeginEndAttributeWithIndicesDispatch : public AttributeDispatch
{
public:
typedef void (GLBeginEndAdapter::*F) (const T*);
TemplateBeginEndAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride):
_glBeginEndAdapter(glBeginEndAdapter),
_functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {}
virtual void assign(const GLvoid* array, const IndexArray* indices)
{
_array = reinterpret_cast<const T*>(array);
_indices = indices;
}
virtual void operator () (unsigned int pos)
{
(_glBeginEndAdapter->*_functionPtr)(&(_array[_indices->index(pos) * _stride]));
}
GLBeginEndAdapter* _glBeginEndAdapter;
F _functionPtr;
unsigned int _stride;
const T* _array;
const IndexArray* _indices;
};
template<typename I, typename T>
class TemplateTargetAttributeDispatch : public AttributeDispatch
@@ -169,108 +86,18 @@ class TemplateTargetAttributeDispatch : public AttributeDispatch
const T* _array;
};
template<typename I, typename T>
class TemplateTargetAttributeWithIndicesDispatch : public AttributeDispatch
{
public:
typedef void (GL_APIENTRY * F) (I, const T*);
TemplateTargetAttributeWithIndicesDispatch(I target, F functionPtr, unsigned int stride):
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {}
virtual void assign(const GLvoid* array, const IndexArray* indices)
{
_array = reinterpret_cast<const T*>(array);
_indices = indices;
}
virtual void operator () (unsigned int pos)
{
_functionPtr(_target, &(_array[_indices->index(pos) * _stride]));
}
F _functionPtr;
I _target;
unsigned int _stride;
const T* _array;
const IndexArray* _indices;
};
template<typename I, typename T>
class TemplateBeginEndTargetAttributeDispatch : public AttributeDispatch
{
public:
typedef void (GLBeginEndAdapter::*F) (I, const T*);
TemplateBeginEndTargetAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride):
_glBeginEndAdapter(glBeginEndAdapter),
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0) {}
virtual void assign(const GLvoid* array, const IndexArray*)
{
_array = reinterpret_cast<const T*>(array);
}
virtual void operator () (unsigned int pos)
{
(_glBeginEndAdapter->*_functionPtr)(_target, &(_array[pos * _stride]));
}
GLBeginEndAdapter* _glBeginEndAdapter;
F _functionPtr;
I _target;
unsigned int _stride;
const T* _array;
};
template<typename I, typename T>
class TemplateBeginEndTargetAttributeWithIndicesDispatch : public AttributeDispatch
{
public:
typedef void (GLBeginEndAdapter::*F) (I, const T*);
TemplateBeginEndTargetAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride):
_glBeginEndAdapter(glBeginEndAdapter),
_functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {}
virtual void assign(const GLvoid* array, const IndexArray* indices)
{
_array = reinterpret_cast<const T*>(array);
_indices = indices;
}
virtual void operator () (unsigned int pos)
{
(_glBeginEndAdapter->*_functionPtr)(_target, &(_array[_indices->index(pos) * _stride]));
}
GLBeginEndAdapter* _glBeginEndAdapter;
F _functionPtr;
I _target;
unsigned int _stride;
const T* _array;
const IndexArray* _indices;
};
class AttributeDispatchMap
{
public:
AttributeDispatchMap(GLBeginEndAdapter* glBeginEndAdapter):
_glBeginEndAdapter(glBeginEndAdapter) {}
AttributeDispatchMap() {}
template<typename T>
void assign(Array::Type type, void (GL_APIENTRY *functionPtr) (const T*), unsigned int stride)
{
if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1);
_attributeDispatchList[type] = functionPtr ? new TemplateAttributeDispatch<T>(functionPtr, stride) : 0;
if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1);
_attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateAttributeWithIndicesDispatch<T>(functionPtr, stride) : 0;
}
template<typename I, typename T>
@@ -278,35 +105,11 @@ public:
{
if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1);
_attributeDispatchList[type] = functionPtr ? new TemplateTargetAttributeDispatch<I,T>(target, functionPtr, stride) : 0;
if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1);
_attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateTargetAttributeWithIndicesDispatch<I,T>(target, functionPtr, stride) : 0;
}
template<typename T>
void assignGLBeginEnd(Array::Type type, void (GLBeginEndAdapter::*functionPtr) (const T*), unsigned int stride)
AttributeDispatch* dispatcher(const Array* array)
{
if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1);
_glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndAttributeDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0;
if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1);
_glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndAttributeWithIndicesDispatch<T>(_glBeginEndAdapter, functionPtr, stride) : 0;
}
template<typename I, typename T>
void targetGLBeginEndAssign(I target, Array::Type type, void (GLBeginEndAdapter::*functionPtr) (I, const T*), unsigned int stride)
{
if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1);
_glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndTargetAttributeDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0;
if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1);
_glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndTargetAttributeWithIndicesDispatch<I,T>(_glBeginEndAdapter, target, functionPtr, stride) : 0;
}
AttributeDispatch* dispatcher(bool useGLBeginEndAdapter, const Array* array, const IndexArray* indices)
{
// OSG_NOTICE<<"dispatcher("<<useGLBeginEndAdapter<<", "<<array<<", "<<indices<<")"<<std::endl;
// OSG_NOTICE<<"dispatcher("<<array<<")"<<std::endl;
if (!array) return 0;
@@ -314,44 +117,17 @@ public:
AttributeDispatch* dispatcher = 0;
// OSG_NOTICE<<" array->getType()="<<type<<std::endl;
// OSG_NOTICE<<" _glBeginEndAttributeDispatchList.size()="<<_glBeginEndAttributeDispatchList.size()<<std::endl;
// OSG_NOTICE<<" _glBeginEndAttributeDispatchWithIndicesList.size()="<<_glBeginEndAttributeDispatchWithIndicesList.size()<<std::endl;
// OSG_NOTICE<<" _attributeDispatchIndicesList.size()="<<_attributeDispatchList.size()<<std::endl;
// OSG_NOTICE<<" _attributeDispatchWithIndicesList.size()="<<_attributeDispatchWithIndicesList.size()<<std::endl;
// OSG_NOTICE<<" _attributeDispatchList.size()="<<_attributeDispatchList.size()<<std::endl;
if (useGLBeginEndAdapter)
if ((unsigned int)type<_attributeDispatchList.size())
{
if (indices)
{
if ((unsigned int)type<_glBeginEndAttributeDispatchWithIndicesList.size())
{
dispatcher = _glBeginEndAttributeDispatchWithIndicesList[array->getType()].get();
}
}
else if ((unsigned int)type<_glBeginEndAttributeDispatchList.size())
{
dispatcher = _glBeginEndAttributeDispatchList[array->getType()].get();
}
}
else
{
if (indices)
{
if ((unsigned int)type<_attributeDispatchWithIndicesList.size())
{
dispatcher = _attributeDispatchWithIndicesList[array->getType()].get();
}
}
else if ((unsigned int)type<_attributeDispatchList.size())
{
dispatcher = _attributeDispatchList[array->getType()].get();
}
dispatcher = _attributeDispatchList[array->getType()].get();
}
if (dispatcher)
{
// OSG_NOTICE<<" returning dispatcher="<<dispatcher<<std::endl;
dispatcher->assign(array->getDataPointer(), indices);
dispatcher->assign(array->getDataPointer());
return dispatcher;
}
else
@@ -362,24 +138,18 @@ public:
}
typedef std::vector< ref_ptr<AttributeDispatch> > AttributeDispatchList;
GLBeginEndAdapter* _glBeginEndAdapter;
AttributeDispatchList _attributeDispatchList;
AttributeDispatchList _attributeDispatchWithIndicesList;
AttributeDispatchList _glBeginEndAttributeDispatchList;
AttributeDispatchList _glBeginEndAttributeDispatchWithIndicesList;
};
ArrayDispatchers::ArrayDispatchers():
_initialized(false),
_state(0),
_glBeginEndAdapter(0),
_vertexDispatchers(0),
_normalDispatchers(0),
_colorDispatchers(0),
_secondaryColorDispatchers(0),
_fogCoordDispatchers(0),
_useVertexAttribAlias(false),
_useGLBeginEndAdapter(false)
_useVertexAttribAlias(false)
{
}
@@ -410,7 +180,6 @@ ArrayDispatchers::~ArrayDispatchers()
void ArrayDispatchers::setState(osg::State* state)
{
_state = state;
_glBeginEndAdapter = &(state->getGLBeginEndAdapter());
}
void ArrayDispatchers::init()
@@ -419,21 +188,12 @@ void ArrayDispatchers::init()
_initialized = true;
_vertexDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
_normalDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
_colorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
_secondaryColorDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
_fogCoordDispatchers = new AttributeDispatchMap(&(_state->getGLBeginEndAdapter()));
_vertexDispatchers = new AttributeDispatchMap();
_normalDispatchers = new AttributeDispatchMap();
_colorDispatchers = new AttributeDispatchMap();
_secondaryColorDispatchers = new AttributeDispatchMap();
_fogCoordDispatchers = new AttributeDispatchMap();
_glBeginEndAdapter = &(_state->getGLBeginEndAdapter());
_useGLBeginEndAdapter = false;
_vertexDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Vertex3fv, 3);
_vertexDispatchers->assignGLBeginEnd<GLdouble>(Array::Vec3dArrayType, &GLBeginEndAdapter::Vertex3dv, 3);
_normalDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Normal3fv, 3);
_colorDispatchers->assignGLBeginEnd<GLubyte>(Array::Vec4ubArrayType, &GLBeginEndAdapter::Color4ubv, 4);
_colorDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::Color3fv, 3);
_colorDispatchers->assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::Color4fv, 4);
#ifdef OSG_GL_VERTEX_FUNCS_AVAILABLE
Drawable::Extensions* extensions = Drawable::getExtensions(_state->getContextID(),true);
@@ -469,53 +229,53 @@ void ArrayDispatchers::init()
//
// With inidices
//
AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::vertexDispatcher(Array* array)
{
return _useVertexAttribAlias ?
vertexAttribDispatcher(_state->getVertexAlias()._location, array, indices) :
_vertexDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
vertexAttribDispatcher(_state->getVertexAlias()._location, array) :
_vertexDispatchers->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::normalDispatcher(Array* array)
{
return _useVertexAttribAlias ?
vertexAttribDispatcher(_state->getNormalAlias()._location, array, indices) :
_normalDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
vertexAttribDispatcher(_state->getNormalAlias()._location, array) :
_normalDispatchers->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::colorDispatcher(Array* array)
{
return _useVertexAttribAlias ?
vertexAttribDispatcher(_state->getColorAlias()._location, array, indices) :
_colorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
vertexAttribDispatcher(_state->getColorAlias()._location, array) :
_colorDispatchers->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::secondaryColorDispatcher(Array* array)
{
return _useVertexAttribAlias ?
vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array, indices) :
_secondaryColorDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
vertexAttribDispatcher(_state->getSecondaryColorAlias()._location, array) :
_secondaryColorDispatchers->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::fogCoordDispatcher(Array* array)
{
return _useVertexAttribAlias ?
vertexAttribDispatcher(_state->getFogCoordAlias()._location, array, indices) :
_fogCoordDispatchers->dispatcher(_useGLBeginEndAdapter, array, indices);
vertexAttribDispatcher(_state->getFogCoordAlias()._location, array) :
_fogCoordDispatchers->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::texCoordDispatcher(unsigned int unit, Array* array)
{
if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array, indices);
if (_useVertexAttribAlias) return vertexAttribDispatcher(_state->getTexCoordAliasList()[unit]._location, array);
if (unit>=_texCoordDispatchers.size()) assignTexCoordDispatchers(unit);
return _texCoordDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices);
return _texCoordDispatchers[unit]->dispatcher(array);
}
AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices)
AttributeDispatch* ArrayDispatchers::vertexAttribDispatcher(unsigned int unit, Array* array)
{
if (unit>=_vertexAttribDispatchers.size()) assignVertexAttribDispatchers(unit);
return _vertexAttribDispatchers[unit]->dispatcher(_useGLBeginEndAdapter, array, indices);
return _vertexAttribDispatchers[unit]->dispatcher(array);
}
void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
@@ -526,7 +286,7 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
for(unsigned int i=_texCoordDispatchers.size(); i<=unit; ++i)
{
_texCoordDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter));
_texCoordDispatchers.push_back(new AttributeDispatchMap());
AttributeDispatchMap& texCoordDispatcher = *_texCoordDispatchers[i];
if (i==0)
{
@@ -536,10 +296,6 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
texCoordDispatcher.assign<GLfloat>(Array::Vec3ArrayType, glTexCoord3fv, 3);
texCoordDispatcher.assign<GLfloat>(Array::Vec4ArrayType, glTexCoord4fv, 4);
#endif
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::FloatArrayType, &GLBeginEndAdapter::TexCoord1fv, 1);
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec2ArrayType, &GLBeginEndAdapter::TexCoord2fv, 2);
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec3ArrayType, &GLBeginEndAdapter::TexCoord3fv, 3);
texCoordDispatcher.assignGLBeginEnd<GLfloat>(Array::Vec4ArrayType, &GLBeginEndAdapter::TexCoord4fv, 4);
}
else
{
@@ -549,10 +305,6 @@ void ArrayDispatchers::assignTexCoordDispatchers(unsigned int unit)
texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, extensions->_glMultiTexCoord3fv, 3);
texCoordDispatcher.targetAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, extensions->_glMultiTexCoord4fv, 4);
#endif
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::FloatArrayType, &GLBeginEndAdapter::MultiTexCoord1fv, 1);
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec2ArrayType, &GLBeginEndAdapter::MultiTexCoord2fv, 2);
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec3ArrayType, &GLBeginEndAdapter::MultiTexCoord3fv, 3);
texCoordDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>((GLenum)(GL_TEXTURE0+i), Array::Vec4ArrayType, &GLBeginEndAdapter::MultiTexCoord4fv, 4);
}
}
@@ -564,16 +316,12 @@ void ArrayDispatchers::assignVertexAttribDispatchers(unsigned int unit)
for(unsigned int i=_vertexAttribDispatchers.size(); i<=unit; ++i)
{
_vertexAttribDispatchers.push_back(new AttributeDispatchMap(_glBeginEndAdapter));
_vertexAttribDispatchers.push_back(new AttributeDispatchMap());
AttributeDispatchMap& vertexAttribDispatcher = *_vertexAttribDispatchers[i];
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::FloatArrayType, extensions->_glVertexAttrib1fv, 1);
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec2ArrayType, extensions->_glVertexAttrib2fv, 2);
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec3ArrayType, extensions->_glVertexAttrib3fv, 3);
vertexAttribDispatcher.targetAssign<GLuint, GLfloat>(i, Array::Vec4ArrayType, extensions->_glVertexAttrib4fv, 4);
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::FloatArrayType, &GLBeginEndAdapter::VertexAttrib1fv, 1);
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec2ArrayType, &GLBeginEndAdapter::VertexAttrib2fv, 2);
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec3ArrayType, &GLBeginEndAdapter::VertexAttrib3fv, 3);
vertexAttribDispatcher.targetGLBeginEndAssign<GLenum, GLfloat>(i, Array::Vec4ArrayType, &GLBeginEndAdapter::VertexAttrib4fv, 4);
}
}
@@ -583,9 +331,6 @@ void ArrayDispatchers::reset()
_useVertexAttribAlias = false;
_useGLBeginEndAdapter = false;
_glBeginEndAdapter->reset();
for(ActiveDispatchList::iterator itr = _activeDispatchList.begin();
itr != _activeDispatchList.end();
++itr)

View File

@@ -257,7 +257,6 @@ SET(TARGET_SRC
FrontFace.cpp
Geode.cpp
Geometry.cpp
GeometryNew.cpp
GL2Extensions.cpp
GLExtensions.cpp
GLBeginEndAdapter.cpp

View File

@@ -44,4 +44,6 @@
#cmakedefine OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE
#cmakedefine OSG_GL_FIXED_FUNCTION_AVAILABLE
#cmakedefine OSG_USE_DEPRECATED_GEOMETRY_METHODS
#endif

View File

@@ -11,6 +11,7 @@
* OpenSceneGraph Public License for more details.
*/
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Notify>
#include <stdio.h>
@@ -51,6 +52,10 @@ bool Geode::addDrawable( Drawable *drawable )
{
if (drawable /* && !containsDrawable(drawable)*/)
{
// fallback for handling geometry with deprecated data
osg::Geometry* geometry = drawable->asGeometry();
if (geometry && geometry->containsDeprecatedData()) geometry->fixDeprecatedData();
// note ref_ptr<> automatically handles incrementing drawable's reference count.
_drawables.push_back(drawable);

File diff suppressed because it is too large Load Diff

View File

@@ -52,7 +52,7 @@ void GeometryCostEstimator::calibrate(osg::RenderInfo& renderInfo)
CostPair GeometryCostEstimator::estimateCompileCost(const osg::Geometry* geometry) const
{
bool usesVBO = geometry->getUseVertexBufferObjects() && geometry->areFastPathsUsed();
bool usesVBO = geometry->getUseVertexBufferObjects();
bool usesDL = !usesVBO && geometry->getUseDisplayList() && geometry->getSupportsDisplayList();
if (usesVBO || usesDL)

View File

@@ -40,8 +40,6 @@ MorphGeometry::MorphGeometry(const osg::Geometry& b) :
setUpdateCallback(new UpdateVertex);
setDataVariance(osg::Object::DYNAMIC);
setUseVertexBufferObjects(true);
if (b.getInternalOptimizedGeometry())
computeInternalOptimizedGeometry();
}
MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) :
@@ -55,8 +53,6 @@ MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop)
{
setUseDisplayList(false);
setUseVertexBufferObjects(true);
if (b.getInternalOptimizedGeometry())
computeInternalOptimizedGeometry();
}
void MorphGeometry::transformSoftwareMethod()
@@ -65,8 +61,6 @@ void MorphGeometry::transformSoftwareMethod()
{
// See if we have an internal optimized geometry
osg::Geometry* morphGeometry = this;
if (_internalOptimizedGeometry.valid())
morphGeometry = _internalOptimizedGeometry.get();
osg::Vec3Array* pos = dynamic_cast<osg::Vec3Array*>(morphGeometry->getVertexArray());
if (pos && _positionSource.size() != pos->size())
@@ -134,9 +128,7 @@ void MorphGeometry::transformSoftwareMethod()
if (_morphTargets[i].getWeight() > 0)
{
// See if any the targets use the internal optimized geometry
osg::Geometry* targetGeometry = _morphTargets[i].getGeometry()->getInternalOptimizedGeometry();
if (!targetGeometry)
targetGeometry = _morphTargets[i].getGeometry();
osg::Geometry* targetGeometry = _morphTargets[i].getGeometry();
osg::Vec3Array* targetPos = dynamic_cast<osg::Vec3Array*>(targetGeometry->getVertexArray());
osg::Vec3Array* targetNormals = dynamic_cast<osg::Vec3Array*>(targetGeometry->getNormalArray());

View File

@@ -153,28 +153,28 @@ void RigGeometry::copyFrom(osg::Geometry& from)
if (!copyToSelf) target.setVertexArray(from.getVertexArray());
}
target.setNormalBinding(from.getNormalBinding());
if (from.getNormalArray())
{
if (!copyToSelf) target.setNormalArray(from.getNormalArray());
target.setNormalBinding(from.getNormalBinding());
}
target.setColorBinding(from.getColorBinding());
if (from.getColorArray())
{
if (!copyToSelf) target.setColorArray(from.getColorArray());
target.setColorBinding(from.getColorBinding());
}
target.setSecondaryColorBinding(from.getSecondaryColorBinding());
if (from.getSecondaryColorArray())
{
if (!copyToSelf) target.setSecondaryColorArray(from.getSecondaryColorArray());
target.setSecondaryColorBinding(from.getSecondaryColorBinding());
}
target.setFogCoordBinding(from.getFogCoordBinding());
if (from.getFogCoordArray())
{
if (!copyToSelf) target.setFogCoordArray(from.getFogCoordArray());
target.setFogCoordBinding(from.getFogCoordBinding());
}
for(unsigned int ti=0;ti<from.getNumTexCoordArrays();++ti)
@@ -185,13 +185,13 @@ void RigGeometry::copyFrom(osg::Geometry& from)
}
}
ArrayDataList& arrayList = from.getVertexAttribArrayList();
osg::Geometry::ArrayList& arrayList = from.getVertexAttribArrayList();
for(unsigned int vi=0;vi< arrayList.size();++vi)
{
ArrayData& arrayData = arrayList[vi];
if (arrayData.array.valid())
osg::Array* array = arrayList[vi].get();
if (array)
{
if (!copyToSelf) target.setVertexAttribData(vi,arrayData);
if (!copyToSelf) target.setVertexAttribArray(vi,array);
}
}
}

View File

@@ -250,7 +250,7 @@ bool RigTransformHardware::init(RigGeometry& geom)
std::stringstream ss;
ss << "boneWeight" << i;
program->addBindAttribLocation(ss.str(), attribIndex + i);
geom.setVertexAttribData(attribIndex + i, osg::Geometry::ArrayData(getVertexAttrib(i),osg::Geometry::BIND_PER_VERTEX));
geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i));
OSG_INFO << "set vertex attrib " << ss.str() << std::endl;
}
program->addShader(_shader.get());

View File

@@ -597,11 +597,11 @@ void BumpMapping::prepareGeometry(osg::Geometry* geo)
osg::ref_ptr<osgUtil::TangentSpaceGenerator> tsg = new osgUtil::TangentSpaceGenerator;
tsg->generate(geo, _normal_unit);
if (!geo->getVertexAttribArray(6))
geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_FALSE));
geo->setVertexAttribArray(6, tsg->getTangentArray());
if (!geo->getVertexAttribArray(7))
geo->setVertexAttribData(7, osg::Geometry::ArrayData(tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
geo->setVertexAttribArray(7, tsg->getBinormalArray());
if (!geo->getVertexAttribArray(15))
geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE));
geo->setVertexAttribArray(15, tsg->getNormalArray());
}
void BumpMapping::prepareNode(osg::Node* node)

View File

@@ -758,8 +758,8 @@ void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset)
if (NULL != pVertexArray)
{
const unsigned int iNumVertices = pVertexArray->getNumElements(); // size();
const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices();
const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0);
const osg::IndexArray *pVertexIndices = 0;
const osg::IndexArray * pTexIndices = 0;
const osg::Vec2 *pTexCoords = NULL;
fout << "OBJECT poly" << std::endl;
fout << "name \"" << getName() << "\"" << std::endl;

View File

@@ -129,40 +129,52 @@ void Geometry::write(DataOutputStream* out){
out->writeArray(getFogCoordIndices());
}
// Write texture coord arrays
Geometry::ArrayDataList& tcal = getTexCoordArrayList();
Geometry::ArrayList& tcal = getTexCoordArrayList();
out->writeInt(tcal.size());
unsigned int j;
for(j=0;j<tcal.size();j++)
{
// Write coords if valid
out->writeBool(tcal[j].array.valid());
if (tcal[j].array.valid()){
out->writeArray(tcal[j].array.get());
out->writeBool(tcal[j].valid());
if (tcal[j].valid()){
out->writeArray(tcal[j].get());
}
// Write indices if valid
out->writeBool(tcal[j].indices.valid());
if (tcal[j].indices.valid()){
out->writeArray(tcal[j].indices.get());
const osg::IndexArray* indices = getTexCoordIndices(j);
out->writeBool(indices!=0);
if (indices!=0){
out->writeArray(indices);
}
}
// Write vertex attributes
Geometry::ArrayDataList& vaal = getVertexAttribArrayList();
Geometry::ArrayList& vaal = getVertexAttribArrayList();
out->writeInt(vaal.size());
for(j=0;j<vaal.size();j++)
{
// Write coords if valid
const osg::Geometry::ArrayData& arrayData = vaal[j];
out->writeBinding(arrayData.binding);
out->writeBool(arrayData.normalize==GL_TRUE);
out->writeBool(arrayData.array.valid());
if (arrayData.array.valid()){
out->writeArray(arrayData.array.get());
const osg::Array* array = vaal[j].get();
if (array)
{
out->writeBinding(static_cast<osg::Geometry::AttributeBinding>(array->getBinding()));
out->writeBool(array->getNormalize());
out->writeBool(true);
out->writeArray(array);
// Write indices if valid
const osg::IndexArray* indices = getVertexAttribIndices(j);
out->writeBool(indices!=0);
if (indices!=0){
out->writeArray(indices);
}
}
// Write indices if valid
out->writeBool(arrayData.indices.valid());
if (arrayData.indices.valid()){
out->writeArray(arrayData.indices.get());
else
{
out->writeBinding(BIND_OFF);
out->writeBool(false);
out->writeBool(false);
out->writeBool(false);
}
}
}

View File

@@ -527,19 +527,6 @@ void POVWriterNodeVisitor::processGeometry( const Geometry *g,
if( g->getVertexArray() == NULL || g->getVertexArray()->getNumElements() == 0 )
return;
if(( g->getVertexIndices() != NULL &&
g->getVertexIndices()->getNumElements() != 0 ) ||
( g->getNormalIndices() != NULL &&
g->getNormalIndices()->getNumElements() != 0 ) ||
( g->getTexCoordIndices(0) != NULL &&
g->getTexCoordIndices(0)->getNumElements() != 0 ))
{
notify( WARN ) << "POV Writer WARNING: "
"Geometry with indices is not " << endl <<
"supported yet by POV plugin. Skipping geometry." << endl;
return;
}
// mesh2
_fout << "mesh2" << endl;
_fout << "{" << endl;

View File

@@ -448,14 +448,6 @@ void EdgeCollector::setGeometry(osg::Geometry* geometry)
{
_geometry = geometry;
// check to see if vertex attributes indices exists, if so expand them to remove them
if (_geometry->suitableForOptimization())
{
// removing coord indices
OSG_INFO<<"EdgeCollector::setGeometry(..): Removing attribute indices"<<std::endl;
_geometry->copyToAndOptimize(*_geometry);
}
unsigned int numVertices = geometry->getVertexArray()->getNumElements();
_originalPointList.resize(numVertices);

View File

@@ -279,17 +279,7 @@ void IndexMeshVisitor::makeMesh(Geometry& geom)
// nothing to index
if (!numSurfacePrimitives || !numNonIndexedPrimitives) return;
// check to see if vertex attributes indices exists, if so expand them to remove them
if (geom.suitableForOptimization())
{
// removing coord indices
OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"<<std::endl;
geom.copyToAndOptimize(geom);
}
// compute duplicate vertices
typedef std::vector<unsigned int> IndexList;
unsigned int numVertices = geom.getVertexArray()->getNumElements();
IndexList indices(numVertices);

View File

@@ -50,6 +50,7 @@
using namespace osgUtil;
// #define GEOMETRYDEPRECATED
void Optimizer::reset()
{
@@ -1684,33 +1685,18 @@ struct LessGeometry
if (lhs->getStateSet()<rhs->getStateSet()) return true;
if (rhs->getStateSet()<lhs->getStateSet()) return false;
if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; }
else if (lhs->getVertexIndices()) return false;
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; }
else if (lhs->getNormalIndices()) return false;
if (lhs->getColorBinding()<rhs->getColorBinding()) return true;
if (rhs->getColorBinding()<lhs->getColorBinding()) return false;
if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; }
else if (lhs->getColorIndices()) return false;
if (lhs->getSecondaryColorBinding()<rhs->getSecondaryColorBinding()) return true;
if (rhs->getSecondaryColorBinding()<lhs->getSecondaryColorBinding()) return false;
if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; }
else if (lhs->getSecondaryColorIndices()) return false;
if (lhs->getFogCoordBinding()<rhs->getFogCoordBinding()) return true;
if (rhs->getFogCoordBinding()<lhs->getFogCoordBinding()) return false;
if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; }
else if (lhs->getFogCoordIndices()) return false;
if (lhs->getNumTexCoordArrays()<rhs->getNumTexCoordArrays()) return true;
if (rhs->getNumTexCoordArrays()<lhs->getNumTexCoordArrays()) return false;
@@ -1724,9 +1710,6 @@ struct LessGeometry
if (!lhs->getTexCoordArray(i)) return true;
}
else if (lhs->getTexCoordArray(i)) return false;
if (rhs->getTexCoordIndices(i)) { if (!lhs->getTexCoordIndices(i)) return true; }
else if (lhs->getTexCoordIndices(i)) return false;
}
for(i=0;i<lhs->getNumVertexAttribArrays();++i)
@@ -1736,9 +1719,6 @@ struct LessGeometry
if (!lhs->getVertexAttribArray(i)) return true;
}
else if (lhs->getVertexAttribArray(i)) return false;
if (rhs->getVertexAttribIndices(i)) { if (!lhs->getVertexAttribIndices(i)) return true; }
else if (lhs->getVertexAttribIndices(i)) return false;
}
@@ -1828,7 +1808,10 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode)
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
if (geom && isOperationPermissibleForObject(geom))
{
geom->computeCorrectBindingsAndArraySizes();
#ifdef GEOMETRYDEPRECATED
geom1829
->computeCorrectBindingsAndArraySizes();
#endif
}
}
}
@@ -1836,6 +1819,7 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode)
void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode)
{
// GeometryDeprecated CAN REMOVED
if (isOperationPermissibleForObject(&geode))
{
for(unsigned int i=0;i<geode.getNumDrawables();++i)
@@ -1843,9 +1827,9 @@ void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode)
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
if (geom && isOperationPermissibleForObject(geom))
{
if (!geom->areFastPathsUsed() && !geom->getInternalOptimizedGeometry())
if (geom->checkForDeprecatedData())
{
geom->computeInternalOptimizedGeometry();
geom->fixDeprecatedData();
}
}
}
@@ -2457,7 +2441,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
MergeArrayVisitor merger;
unsigned int base = 0;
unsigned int vbase = lhs.getVertexArray() ? lhs.getVertexArray()->getNumElements() : 0;
if (lhs.getVertexArray() && rhs.getVertexArray())
{
@@ -2473,23 +2456,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
lhs.setVertexArray(rhs.getVertexArray());
}
if (lhs.getVertexIndices() && rhs.getVertexIndices())
{
base = lhs.getVertexIndices()->getNumElements();
if (!merger.merge(lhs.getVertexIndices(),rhs.getVertexIndices(),vbase))
{
OSG_DEBUG << "MergeGeometry: vertex indices not merged. Some data may be lost." <<std::endl;
}
}
else if (rhs.getVertexIndices())
{
base = 0;
lhs.setVertexIndices(rhs.getVertexIndices());
}
unsigned int nbase = lhs.getNormalArray() ? lhs.getNormalArray()->getNumElements() : 0;
if (lhs.getNormalArray() && rhs.getNormalArray() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getNormalArray(),rhs.getNormalArray()))
@@ -2502,21 +2469,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
lhs.setNormalArray(rhs.getNormalArray());
}
if (lhs.getNormalIndices() && rhs.getNormalIndices() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getNormalIndices(),rhs.getNormalIndices(),nbase))
{
OSG_DEBUG << "MergeGeometry: Vertex Array not merged. Some data may be lost." <<std::endl;
}
}
else if (rhs.getNormalIndices())
{
// this assignment makes the assumption that lhs.NormalArray is empty as well and NormalIndices
lhs.setNormalIndices(rhs.getNormalIndices());
}
unsigned int cbase = lhs.getColorArray() ? lhs.getColorArray()->getNumElements() : 0;
if (lhs.getColorArray() && rhs.getColorArray() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getColorArray(),rhs.getColorArray()))
@@ -2529,20 +2482,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
lhs.setColorArray(rhs.getColorArray());
}
if (lhs.getColorIndices() && rhs.getColorIndices() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getColorIndices(),rhs.getColorIndices(),cbase))
{
OSG_DEBUG << "MergeGeometry: color indices not merged. Some data may be lost." <<std::endl;
}
}
else if (rhs.getColorIndices())
{
// this assignment makes the assumption that lhs.ColorArray is empty as well and ColorIndices
lhs.setColorIndices(rhs.getColorIndices());
}
unsigned int scbase = lhs.getSecondaryColorArray() ? lhs.getSecondaryColorArray()->getNumElements() : 0;
if (lhs.getSecondaryColorArray() && rhs.getSecondaryColorArray() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getSecondaryColorArray(),rhs.getSecondaryColorArray()))
@@ -2555,20 +2494,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
lhs.setSecondaryColorArray(rhs.getSecondaryColorArray());
}
if (lhs.getSecondaryColorIndices() && rhs.getSecondaryColorIndices() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getSecondaryColorIndices(),rhs.getSecondaryColorIndices(),scbase))
{
OSG_DEBUG << "MergeGeometry: secondary color indices not merged. Some data may be lost." <<std::endl;
}
}
else if (rhs.getSecondaryColorIndices())
{
// this assignment makes the assumption that lhs.SecondaryColorArray is empty as well and SecondaryColorIndices
lhs.setSecondaryColorIndices(rhs.getSecondaryColorIndices());
}
unsigned int fcbase = lhs.getFogCoordArray() ? lhs.getFogCoordArray()->getNumElements() : 0;
if (lhs.getFogCoordArray() && rhs.getFogCoordArray() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getFogCoordArray(),rhs.getFogCoordArray()))
@@ -2581,53 +2506,22 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
lhs.setFogCoordArray(rhs.getFogCoordArray());
}
if (lhs.getFogCoordIndices() && rhs.getFogCoordIndices() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL)
{
if (!merger.merge(lhs.getFogCoordIndices(),rhs.getFogCoordIndices(),fcbase))
{
OSG_DEBUG << "MergeGeometry: fog coord indices not merged. Some data may be lost." <<std::endl;
}
}
else if (rhs.getFogCoordIndices())
{
// this assignment makes the assumption that lhs.FogCoordArray is empty as well and FogCoordIndices
lhs.setFogCoordIndices(rhs.getFogCoordIndices());
}
unsigned int unit;
for(unit=0;unit<lhs.getNumTexCoordArrays();++unit)
{
unsigned int tcbase = lhs.getTexCoordArray(unit) ? lhs.getTexCoordArray(unit)->getNumElements() : 0;
if (!merger.merge(lhs.getTexCoordArray(unit),rhs.getTexCoordArray(unit)))
{
OSG_DEBUG << "MergeGeometry: tex coord array not merged. Some data may be lost." <<std::endl;
}
if (lhs.getTexCoordIndices(unit) && rhs.getTexCoordIndices(unit))
{
if (!merger.merge(lhs.getTexCoordIndices(unit),rhs.getTexCoordIndices(unit),tcbase))
{
OSG_DEBUG << "MergeGeometry: tex coord indices not merged. Some data may be lost." <<std::endl;
}
}
}
for(unit=0;unit<lhs.getNumVertexAttribArrays();++unit)
{
unsigned int vabase = lhs.getVertexAttribArray(unit) ? lhs.getVertexAttribArray(unit)->getNumElements() : 0;
if (!merger.merge(lhs.getVertexAttribArray(unit),rhs.getVertexAttribArray(unit)))
{
OSG_DEBUG << "MergeGeometry: vertex attrib array not merged. Some data may be lost." <<std::endl;
}
if (lhs.getVertexAttribIndices(unit) && rhs.getVertexAttribIndices(unit))
{
if (!merger.merge(lhs.getVertexAttribIndices(unit),rhs.getVertexAttribIndices(unit),vabase))
{
OSG_DEBUG << "MergeGeometry: vertex attrib indices not merged. Some data may be lost." <<std::endl;
}
}
}

View File

@@ -543,8 +543,7 @@ bool RenderBin::getStats(Statistics& stats) const
const Geometry* geom = dw->asGeometry();
if (geom)
{
if (geom->areFastPathsUsed())
stats.addFastDrawable();
stats.addFastDrawable();
}
if (rl->_modelview.get())
@@ -576,8 +575,7 @@ bool RenderBin::getStats(Statistics& stats) const
const Geometry* geom = dw->asGeometry();
if (geom)
{
if (geom->areFastPathsUsed())
stats.addFastDrawable();
stats.addFastDrawable();
}
if (rl->_modelview.get()) stats.addMatrix(); // number of matrices

View File

@@ -1419,14 +1419,6 @@ void EdgeCollapse::setGeometry(osg::Geometry* geometry, const Simplifier::IndexL
{
_geometry = geometry;
// check to see if vertex attributes indices exists, if so expand them to remove them
if (_geometry->suitableForOptimization())
{
// removing coord indices
OSG_INFO<<"EdgeCollapse::setGeometry(..): Removing attribute indices"<<std::endl;
_geometry->copyToAndOptimize(*_geometry);
}
// check to see if vertex attributes indices exists, if so expand them to remove them
if (_geometry->containsSharedArrays())
{

View File

@@ -143,10 +143,8 @@ static void smooth_old(osg::Geometry& geom)
nitr->normalize();
}
geom.setNormalArray( normals );
geom.setNormalIndices( geom.getVertexIndices() );
geom.setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
geom.dirtyDisplayList();
}

View File

@@ -278,11 +278,8 @@ void StatsVisitor::apply(osg::Drawable& drawable)
++_numInstancedGeometry;
_geometrySet.insert(geometry);
if (geometry->areFastPathsUsed())
{
++_numInstancedFastGeometry;
_fastGeometrySet.insert(geometry);
}
++_numInstancedFastGeometry;
_fastGeometrySet.insert(geometry);
}
}

View File

@@ -11,6 +11,9 @@ TangentSpaceGenerator::TangentSpaceGenerator()
B_(new osg::Vec4Array),
N_(new osg::Vec4Array)
{
T_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
B_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
N_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false);
}
TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator &copy, const osg::CopyOp &copyop)
@@ -23,14 +26,6 @@ TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator &copy,
void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit)
{
// check to see if vertex attributes indices exists, if so expand them to remove them
if (geo->suitableForOptimization())
{
// removing coord indices so we don't have to deal with them in the binormal code.
OSG_INFO<<"TangentSpaceGenerator::generate(Geometry*,int): Removing attribute indices"<<std::endl;
geo->copyToAndOptimize(*geo);
}
const osg::Array *vx = geo->getVertexArray();
const osg::Array *nx = geo->getNormalArray();
const osg::Array *tx = geo->getTexCoordArray(normal_map_tex_unit);
@@ -39,21 +34,9 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit
unsigned int vertex_count = vx->getNumElements();
if (geo->getVertexIndices() == NULL) {
T_->assign(vertex_count, osg::Vec4());
B_->assign(vertex_count, osg::Vec4());
N_->assign(vertex_count, osg::Vec4());
} else {
unsigned int index_count = geo->getVertexIndices()->getNumElements();
T_->assign(index_count, osg::Vec4());
B_->assign(index_count, osg::Vec4());
N_->assign(index_count, osg::Vec4());
indices_ = new osg::UIntArray();
unsigned int i;
for (i=0;i<index_count;i++) {
indices_->push_back(i);
}
}
T_->assign(vertex_count, osg::Vec4());
B_->assign(vertex_count, osg::Vec4());
N_->assign(vertex_count, osg::Vec4());
unsigned int i; // VC6 doesn't like for-scoped variables
@@ -163,9 +146,6 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit
// normalize basis vectors and force the normal vector to match
// the triangle normal's direction
unsigned int attrib_count = vx->getNumElements();
if (geo->getVertexIndices() != NULL) {
attrib_count = geo->getVertexIndices()->getNumElements();
}
for (i=0; i<attrib_count; ++i) {
osg::Vec4 &vT = (*T_)[i];
osg::Vec4 &vB = (*B_)[i];

View File

@@ -182,20 +182,6 @@ void Tessellator::retessellatePolygons(osg::Geometry &geom)
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;
}
if (_ttype==TESS_TYPE_POLYGONS || _ttype==TESS_TYPE_DRAWABLE) _numberVerts=0; // 09.04.04 GWM reset Tessellator
// the reset is needed by the flt loader which reuses a Tessellator for triangulating polygons.
// as such it might be reset by other loaders/developers in future.
@@ -470,14 +456,14 @@ void Tessellator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &ver
arrays.push_back(geom.getFogCoordArray());
}
osg::Geometry::ArrayDataList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayDataList::iterator tcalItr=tcal.begin();
osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin();
tcalItr!=tcal.end();
++tcalItr)
{
if (tcalItr->array.valid())
if (tcalItr->valid())
{
arrays.push_back(tcalItr->array.get());
arrays.push_back(tcalItr->get());
}
}

View File

@@ -230,14 +230,6 @@ void TriStripVisitor::stripify(Geometry& geom)
// no point tri stripping if we don't have enough vertices.
if (!geom.getVertexArray() || geom.getVertexArray()->getNumElements()<3) return;
// check to see if vertex attributes indices exists, if so expand them to remove them
if (geom.suitableForOptimization())
{
// removing coord indices
OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"<<std::endl;
geom.copyToAndOptimize(geom);
}
// check for the existence of surface primitives
unsigned int numSurfacePrimitives = 0;
unsigned int numNonSurfacePrimitives = 0;

View File

@@ -132,7 +132,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
Geometry::AttributeBinding normalBinding=Geometry::BIND_OFF;
if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding))
{
geom.setNormalBinding(normalBinding);
fr+=2;
iteratorAdvanced = true;
}
@@ -182,6 +181,8 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
}
iteratorAdvanced = true;
}
geom.setNormalBinding(normalBinding);
}
if (fr[0].matchWord("NormalIndices"))
{
@@ -197,7 +198,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
Geometry::AttributeBinding colorBinding=Geometry::BIND_OFF;
if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))
{
geom.setColorBinding(colorBinding);
fr+=2;
iteratorAdvanced = true;
}
@@ -209,6 +209,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
if (colors)
{
geom.setColorArray(colors);
geom.setColorBinding(colorBinding);
}
iteratorAdvanced = true;
}
@@ -228,7 +229,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF;
if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
{
geom.setSecondaryColorBinding(secondaryColorBinding);
fr+=2;
iteratorAdvanced = true;
}
@@ -240,6 +240,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
if (colors)
{
geom.setSecondaryColorArray(colors);
geom.setSecondaryColorBinding(secondaryColorBinding);
}
iteratorAdvanced = true;
}
@@ -259,7 +260,6 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF;
if (fr[0].matchWord("FogCoordBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding))
{
geom.setFogCoordBinding(fogCoordBinding);
fr+=2;
iteratorAdvanced = true;
}
@@ -271,6 +271,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
if (fogcoords)
{
geom.setFogCoordArray(fogcoords);
geom.setFogCoordBinding(fogCoordBinding);
}
iteratorAdvanced = true;
}
@@ -1361,43 +1362,48 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
Array_writeLocalData(*geom.getFogCoordIndices(),fw);
}
const Geometry::ArrayDataList& tcal=geom.getTexCoordArrayList();
const Geometry::ArrayList& tcal=geom.getTexCoordArrayList();
unsigned int i;
for(i=0;i<tcal.size();++i)
{
if (tcal[i].array.valid())
const osg::Array* array = tcal[i].get();
if (array)
{
fw.indent()<<"TexCoordArray "<<i<<" ";
Array_writeLocalData(*(tcal[i].array),fw);
Array_writeLocalData(*array,fw);
}
if (tcal[i].indices.valid())
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
if (indices)
{
fw.indent()<<"TexCoordIndices "<<i<<" ";
Array_writeLocalData(*(tcal[i].indices),fw);
Array_writeLocalData(*indices,fw);
}
}
const Geometry::ArrayDataList& vaal=geom.getVertexAttribArrayList();
const Geometry::ArrayList& vaal=geom.getVertexAttribArrayList();
for(i=0;i<vaal.size();++i)
{
const osg::Geometry::ArrayData& arrayData = vaal[i];
const osg::Array* array = vaal[i].get();
if (arrayData.array.valid())
if (array)
{
fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(arrayData.binding)<<std::endl;
fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(static_cast<osg::Geometry::AttributeBinding>(array->getBinding()))<<std::endl;
if (arrayData.normalize)
if (array->getNormalize())
fw.indent()<<"VertexAttribNormalize "<<i<<" TRUE"<<std::endl;
else
fw.indent()<<"VertexAttribNormalize "<<i<<" FALSE"<<std::endl;
fw.indent()<<"VertexAttribArray "<<i<<" ";
Array_writeLocalData(*(arrayData.array),fw);
fw.indent()<<"VertexAttribArray "<<i<<" ";
Array_writeLocalData(*array,fw);
}
if (arrayData.indices.valid())
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
if (indices)
{
fw.indent()<<"VertexAttribIndices "<<i<<" ";
Array_writeLocalData(*(arrayData.indices),fw);
Array_writeLocalData(*indices,fw);
}
}

View File

@@ -1,4 +1,5 @@
#include <osg/Geode>
#include <osg/Geometry>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
@@ -14,7 +15,10 @@ static bool readDrawables( osgDB::InputStream& is, osg::Geode& node )
for ( unsigned int i=0; i<size; ++i )
{
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>( is.readObject() );
if ( drawable ) node.addDrawable( drawable );
if ( drawable )
{
node.addDrawable( drawable );
}
}
is >> is.END_BRACKET;
return true;

View File

@@ -14,88 +14,98 @@ END_USER_TABLE()
USER_READ_FUNC( AttributeBinding, readAttributeBinding )
USER_WRITE_FUNC( AttributeBinding, writeAttributeBinding )
static void readArrayData( osgDB::InputStream& is, osg::Geometry::ArrayData& data )
static osg::Array* readArray( osgDB::InputStream& is)
{
osg::ref_ptr<osg::Array> array;
bool hasArray = false;
is >> is.PROPERTY("Array") >> hasArray;
if ( hasArray ) data.array = is.readArray();
if ( hasArray ) array = is.readArray();
bool hasIndices = false;
is >> is.PROPERTY("Indices") >> hasIndices;
if ( hasIndices ) data.indices = dynamic_cast<osg::IndexArray*>( is.readArray() );
if ( hasIndices )
{
osg::ref_ptr<osg::Array> indices_array = is.readArray();
osg::ref_ptr<osg::IndexArray> indices = dynamic_cast<osg::IndexArray*>( indices_array.get() );
if (array.valid() && indices.valid()) array->setUserData(indices.get());
}
is >> is.PROPERTY("Binding");
data.binding = (osg::Geometry::AttributeBinding)readAttributeBinding(is);
int binding = readAttributeBinding(is);
if (array.valid()) array->setBinding(static_cast<osg::Array::Binding>(binding));
int normalizeValue = 0;
is >> is.PROPERTY("Normalize") >> normalizeValue;
data.normalize = normalizeValue;
if (array.valid()) array->setNormalize(normalizeValue!=0);
return array.release();
}
static void writeArrayData( osgDB::OutputStream& os, const osg::Geometry::ArrayData& data )
static void writeArray( osgDB::OutputStream& os, const osg::Array* array)
{
os << os.PROPERTY("Array") << data.array.valid();
if ( data.array.valid() ) os << data.array.get();
os << os.PROPERTY("Array") << (array!=0);
if ( array!=0 ) os << array;
else os << std::endl;
os << os.PROPERTY("Indices") << data.indices.valid();
if ( data.indices.valid() ) os << data.indices.get();
const osg::IndexArray* indices = (array!=0) ? dynamic_cast<const osg::IndexArray*>(array->getUserData()) : 0;
os << os.PROPERTY("Indices") << (indices!=0);
if ( indices!=0 ) os << indices;
else os << std::endl;
os << os.PROPERTY("Binding"); writeAttributeBinding(os, data.binding); os << std::endl;
os << os.PROPERTY("Normalize") << (int)data.normalize << std::endl;
os << os.PROPERTY("Binding"); writeAttributeBinding(os, (array!=0) ? static_cast<osg::Geometry::AttributeBinding>(array->getBinding()) : osg::Geometry::BIND_OFF); os << std::endl;
os << os.PROPERTY("Normalize") << ((array!=0 && array->getNormalize()) ? 1:0) << std::endl;
}
#define ADD_ARRAYDATA_FUNCTIONS( PROP ) \
static bool check##PROP( const osg::Geometry& geom ) \
{ return geom.get##PROP().array.valid(); } \
static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
osg::Geometry::ArrayData data; \
is >> is.BEGIN_BRACKET; readArrayData(is, data); \
#define ADD_ARRAYDATA_FUNCTIONS( ORIGINAL_PROP, PROP ) \
static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \
{ return geom.get##PROP()!=0; } \
static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
is >> is.BEGIN_BRACKET; \
osg::Array* array = readArray(is); \
geom.set##PROP(array); \
is >> is.END_BRACKET; \
geom.set##PROP(data); \
return true; \
} \
static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
os << os.BEGIN_BRACKET << std::endl; \
writeArrayData(os, geom.get##PROP()); \
writeArray(os, geom.get##PROP()); \
os << os.END_BRACKET << std::endl; \
return true; \
}
ADD_ARRAYDATA_FUNCTIONS( VertexData )
ADD_ARRAYDATA_FUNCTIONS( NormalData )
ADD_ARRAYDATA_FUNCTIONS( ColorData )
ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData )
ADD_ARRAYDATA_FUNCTIONS( FogCoordData )
ADD_ARRAYDATA_FUNCTIONS( VertexData, VertexArray )
ADD_ARRAYDATA_FUNCTIONS( NormalData, NormalArray )
ADD_ARRAYDATA_FUNCTIONS( ColorData, ColorArray )
ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData, SecondaryColorArray )
ADD_ARRAYDATA_FUNCTIONS( FogCoordData, FogCoordArray )
#define ADD_ARRAYLIST_FUNCTIONS( PROP, LISTNAME ) \
static bool check##PROP( const osg::Geometry& geom ) \
#define ADD_ARRAYLIST_FUNCTIONS( ORIGINAL_PROP, PROP, LISTNAME ) \
static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \
{ return geom.get##LISTNAME().size()>0; } \
static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; \
for ( unsigned int i=0; i<size; ++i ) { \
osg::Geometry::ArrayData data; \
is >> is.PROPERTY("Data") >> is.BEGIN_BRACKET; \
readArrayData(is, data); \
is >> is.END_BRACKET; geom.set##PROP(i, data); } \
osg::Array* array = readArray(is); \
geom.set##PROP(i, array); \
is >> is.END_BRACKET; } \
is >> is.END_BRACKET; \
return true; \
} \
static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
const osg::Geometry::ArrayDataList& LISTNAME = geom.get##LISTNAME(); \
static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \
const osg::Geometry::ArrayList& LISTNAME = geom.get##LISTNAME(); \
os.writeSize(LISTNAME.size()); os << os.BEGIN_BRACKET << std::endl; \
for ( osg::Geometry::ArrayDataList::const_iterator itr=LISTNAME.begin(); \
for ( osg::Geometry::ArrayList::const_iterator itr=LISTNAME.begin(); \
itr!=LISTNAME.end(); ++itr ) { \
os << os.PROPERTY("Data") << os.BEGIN_BRACKET << std::endl; \
writeArrayData(os, *itr); os << os.END_BRACKET << std::endl; \
writeArray(os, *itr); os << os.END_BRACKET << std::endl; \
} \
os << os.END_BRACKET << std::endl; \
return true; \
}
ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArrayList )
ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArrayList )
ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArray, TexCoordArrayList )
ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArray, VertexAttribArrayList )
struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCallback
{
@@ -110,6 +120,26 @@ struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCall
}
};
// implement backwards compatibility with reading/writing the FastPathHint
static bool checkFastPathHint( const osg::Geometry& geom ) { return false; }
static bool readFastPathHint( osgDB::InputStream& is, osg::Geometry& geom )
{
bool value = false;
if ( is.isBinary() )
{
is >> value;
}
else if ( is.matchString("FastPathHint") )
{
is >> value;
}
return true;
}
static bool writeFastPathHint( osgDB::OutputStream& os, const osg::Geometry& geom )
{
return true;
}
REGISTER_OBJECT_WRAPPER( Geometry,
new osg::Geometry,
osg::Geometry,
@@ -123,8 +153,8 @@ REGISTER_OBJECT_WRAPPER( Geometry,
ADD_USER_SERIALIZER( FogCoordData ); // _fogCoordData
ADD_USER_SERIALIZER( TexCoordData ); // _texCoordList
ADD_USER_SERIALIZER( VertexAttribData ); // _vertexAttribList
ADD_BOOL_SERIALIZER( FastPathHint, true ); // _fastPathHint
//ADD_OBJECT_SERIALIZER( InternalOptimizedGeometry, osg::Geometry, NULL ); // _internalOptimizedGeometry
ADD_USER_SERIALIZER( FastPathHint ); // _fastPathHint
wrapper->addFinishedObjectReadCallback( new GeometryFinishedObjectReadCallback() );
}