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)