diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index ae4a82f6b..cbf0e694f 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -20,386 +20,6 @@ using namespace osg; const Geometry::ArrayData Geometry::s_InvalidArrayData; -// #define USE_OLD_DRAW_IMPLEMENTATOIN - -#ifdef USE_OLD_DRAW_IMPLEMENTATOIN -class DrawVertex -{ - public: - - DrawVertex(const Array* vertices,const IndexArray* indices): - _vertices(vertices), - _indices(indices) - { - _verticesType = _vertices?_vertices->getType():Array::ArrayType; - _indicesType = _indices?_indices->getType():Array::ArrayType; - } - - inline unsigned int index(unsigned int pos) - { - if (_indices) - { - return _indices->index(pos); - } - else - { - return 0; - } - } - - inline void operator () (unsigned int pos) - { - if (_indices) pos = index(pos); - - switch(_verticesType) - { - case(Array::Vec3ArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - case(Array::Vec2ArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - case(Array::Vec4ArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - case(Array::Vec3dArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - case(Array::Vec2dArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - case(Array::Vec4dArrayType): - apply(static_cast(_vertices->getDataPointer())[pos]); - break; - default: - break; - } - - } - - inline void apply(const Vec2& v) { glVertex2fv(v.ptr()); } - inline void apply(const Vec3& v) { glVertex3fv(v.ptr()); } - inline void apply(const Vec4& v) { glVertex4fv(v.ptr()); } - inline void apply(const Vec2d& v) { glVertex2dv(v.ptr()); } - inline void apply(const Vec3d& v) { glVertex3dv(v.ptr()); } - inline void apply(const Vec4d& v) { glVertex4dv(v.ptr()); } - - const Array* _vertices; - const IndexArray* _indices; - Array::Type _verticesType; - Array::Type _indicesType; -}; - -class DrawNormal -{ - public: - - DrawNormal(const Array* normals,const IndexArray* indices): - _normals(normals), - _indices(indices) - { - _normalsType = normals?normals->getType():Array::ArrayType; - } - - void operator () (unsigned int pos) - { - switch(_normalsType) - { - case (Array::Vec3ArrayType): - { - const Vec3* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3fv(normals[_indices->index(pos)].ptr()); - else glNormal3fv(normals[pos].ptr()); - } - break; - case (Array::Vec3sArrayType): - { - const Vec3s* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr()); - else glNormal3sv(normals[pos].ptr()); - } - break; - case (Array::Vec4sArrayType): - { - const Vec4s* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3sv(normals[_indices->index(pos)].ptr()); - else glNormal3sv(normals[pos].ptr()); - } - break; - case (Array::Vec3bArrayType): - { - const Vec3b* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3bv((const GLbyte*)normals[_indices->index(pos)].ptr()); - else glNormal3bv((const GLbyte*)normals[pos].ptr()); - } - break; - case (Array::Vec4bArrayType): - { - const Vec4b* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3bv((const GLbyte*)normals[_indices->index(pos)].ptr()); - else glNormal3bv((const GLbyte*)normals[pos].ptr()); - } - break; - case (Array::Vec3dArrayType): - { - const Vec3d* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3dv(normals[_indices->index(pos)].ptr()); - else glNormal3dv(normals[pos].ptr()); - } - break; - case (Array::Vec4dArrayType): - { - const Vec4d* normals(static_cast(_normals->getDataPointer())); - if (_indices) glNormal3dv(normals[_indices->index(pos)].ptr()); - else glNormal3dv(normals[pos].ptr()); - } - break; - default: - break; - - } - } - - const Array* _normals; - const IndexArray* _indices; - Array::Type _normalsType; -}; - -class DrawColor -{ - public: - - DrawColor(const Array* colors,const IndexArray* indices): - _colors(colors), - _indices(indices) - { - _colorsType = _colors?_colors->getType():Array::ArrayType; - _indicesType = _indices?_indices->getType():Array::ArrayType; - } - - inline unsigned int index(unsigned int pos) - { - if (_indices) { - return _indices->index(pos); - } - else { - return 0; - } - } - - inline void operator () (unsigned int pos) - { - if (_indices) pos = index(pos); - - switch(_colorsType) - { - case(Array::Vec4ArrayType): - apply(static_cast(_colors->getDataPointer())[pos]); - break; - case(Array::Vec4ubArrayType): - apply(static_cast(_colors->getDataPointer())[pos]); - break; - case(Array::Vec3ArrayType): - apply(static_cast(_colors->getDataPointer())[pos]); - break; - case(Array::Vec3dArrayType): - apply(static_cast(_colors->getDataPointer())[pos]); - break; - case(Array::Vec4dArrayType): - apply(static_cast(_colors->getDataPointer())[pos]); - break; - default: - break; - } - } - - inline void apply(const Vec4ub& v) { glColor4ubv(v.ptr()); } - inline void apply(const Vec3& v) { glColor3fv(v.ptr()); } - inline void apply(const Vec4& v) { glColor4fv(v.ptr()); } - - const Array* _colors; - const IndexArray* _indices; - Array::Type _colorsType; - Array::Type _indicesType; -}; - -class DrawVertexAttrib : public osg::Referenced, public osg::ConstValueVisitor -{ -public: - - DrawVertexAttrib(const Drawable::Extensions * extensions,unsigned int vertAttribIndex,GLboolean normalized,const Array* attribcoords,const IndexArray* indices): - _vertAttribIndex(vertAttribIndex), - _normalized(normalized), - _extensions(extensions), - _attribcoords(attribcoords), - _indices(indices), - _index(0) {;} - - inline void applyAndIncrement() { operator()(_index++); } - - inline void operator () (unsigned int pos) - { - if (_indices) _attribcoords->accept(_indices->index(pos),*this); - else _attribcoords->accept(pos,*this); - } - - virtual void apply(const GLshort& s) - { - _extensions->glVertexAttrib1s( _vertAttribIndex, s ); - } - virtual void apply(const GLfloat& f) - { - _extensions->glVertexAttrib1f( _vertAttribIndex, f ); - } - virtual void apply(const Vec4ub& v) - { - if( _normalized ) - { - _extensions->glVertexAttrib4Nubv( _vertAttribIndex, v.ptr() ); - } - else - { - _extensions->glVertexAttrib4ubv( _vertAttribIndex, v.ptr() ); - } - } - virtual void apply(const Vec2& v) - { - _extensions->glVertexAttrib2fv( _vertAttribIndex, v.ptr() ); - } - virtual void apply(const Vec3& v) - { - _extensions->glVertexAttrib3fv( _vertAttribIndex, v.ptr() ); - } - virtual void apply(const Vec4& v) - { - _extensions->glVertexAttrib4fv( _vertAttribIndex, v.ptr() ); - } - virtual void apply(const Vec2d& v) - { - _extensions->glVertexAttrib2dv( _vertAttribIndex, v.ptr() ); - } - virtual void apply(const Vec3d& v) - { - _extensions->glVertexAttrib3dv( _vertAttribIndex, v.ptr() ); - } - virtual void apply(const Vec4d& v) - { - _extensions->glVertexAttrib4dv( _vertAttribIndex, v.ptr() ); - } - - unsigned int _vertAttribIndex; - GLboolean _normalized; - const Drawable::Extensions* _extensions; - const Array* _attribcoords; - const IndexArray* _indices; - unsigned int _index; -}; - -class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor -{ - public: - - DrawTexCoord(const Array* texcoords,const IndexArray* indices): - _texcoords(texcoords), - _indices(indices) {} - - inline void operator () (unsigned int pos) - { - if (_indices) _texcoords->accept(_indices->index(pos),*this); - else _texcoords->accept(pos,*this); - } - - virtual void apply(const GLfloat& v){ glTexCoord1f(v); } - virtual void apply(const Vec2& v) { glTexCoord2fv(v.ptr()); } - virtual void apply(const Vec3& v) { glTexCoord3fv(v.ptr()); } - virtual void apply(const Vec4& v) { glTexCoord4fv(v.ptr()); } - - const Array* _texcoords; - const IndexArray* _indices; -}; - -class DrawMultiTexCoord : public osg::Referenced, public osg::ConstValueVisitor -{ - public: - - DrawMultiTexCoord(GLenum target,const Array* texcoords,const IndexArray* indices, - const Drawable::Extensions * extensions): - _target(target), - _texcoords(texcoords), - _indices(indices), - _extensions(extensions) {} - - inline void operator () (unsigned int pos) - { - if (_indices) _texcoords->accept(_indices->index(pos),*this); - else _texcoords->accept(pos,*this); - } - - virtual void apply(const GLfloat& v){ _extensions->glMultiTexCoord1f(_target,v); } - virtual void apply(const Vec2& v) { _extensions->glMultiTexCoord2fv(_target,v.ptr()); } - virtual void apply(const Vec3& v) { _extensions->glMultiTexCoord3fv(_target,v.ptr()); } - virtual void apply(const Vec4& v) { _extensions->glMultiTexCoord4fv(_target,v.ptr()); } - - GLenum _target; - const Array* _texcoords; - const IndexArray* _indices; - - const Drawable::Extensions * _extensions; -}; - - -class DrawSecondaryColor : public osg::ConstValueVisitor -{ - public: - - DrawSecondaryColor(const Array* colors,const IndexArray* indices, - const Drawable::Extensions * extensions): - _colors(colors), - _indices(indices), - _extensions(extensions) - {} - - inline void operator () (unsigned int pos) - { - if (_indices) _colors->accept(_indices->index(pos),*this); - else _colors->accept(pos,*this); - } - - virtual void apply(const Vec4ub& v) { _extensions->glSecondaryColor3ubv(v.ptr()); } - virtual void apply(const Vec3& v) { _extensions->glSecondaryColor3fv(v.ptr()); } - virtual void apply(const Vec4& v) { _extensions->glSecondaryColor3fv(v.ptr()); } - - const Array* _colors; - const IndexArray* _indices; - - const Drawable::Extensions * _extensions; -}; - -class DrawFogCoord : public osg::ConstValueVisitor -{ - public: - - DrawFogCoord(const Array* fogcoords,const IndexArray* indices,const Drawable::Extensions * extensions): - _fogcoords(fogcoords), - _indices(indices), - _extensions(extensions) {} - - inline void operator () (unsigned int pos) - { - if (_indices) _fogcoords->accept(_indices->index(pos),*this); - else _fogcoords->accept(pos,*this); - } - - virtual void apply(const GLfloat& v) { _extensions->glFogCoordfv(&v); } - - const Array* _fogcoords; - const IndexArray* _indices; - - const Drawable::Extensions * _extensions; -}; -#endif - - Geometry::ArrayData::ArrayData(const ArrayData& data,const CopyOp& copyop): array(copyop(data.array.get())), indices(dynamic_cast(copyop(data.indices.get()))), @@ -1284,7 +904,6 @@ void Geometry::releaseGLObjects(State* state) const } -#ifndef USE_OLD_DRAW_IMPLEMENTATOIN void Geometry::drawImplementation(RenderInfo& renderInfo) const { State& state = *renderInfo.getState(); @@ -1541,904 +1160,6 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const } } } -#else -void Geometry::drawImplementation(RenderInfo& renderInfo) const -{ - State& state = *renderInfo.getState(); - bool vertexAttribAlias = state.getUseVertexAttributeAliasing(); - - -// unsigned int contextID = state.getContextID(); - - // osg::notify(osg::NOTICE)<<"Geometry::drawImplementation"<drawImplementation(renderInfo); - return; - } - - const Extensions* extensions = getExtensions(state.getContextID(),true); - - if( !( ( _vertexData.array.valid() && _vertexData.array->getNumElements() != 0 ) || - ( _vertexAttribList.size() > 0 && - _vertexAttribList[0].array.valid() && - _vertexAttribList[0].array->getNumElements() != 0 ) ) ) - { - return; - } - - if( ( _vertexData.indices.valid() && _vertexData.indices->getNumElements() == 0 ) || - ( _vertexAttribList.size() > 0 && - _vertexAttribList[0].indices.valid() && - _vertexAttribList[0].indices->getNumElements() == 0 ) ) - { - return; - } - - AttributeBinding normalBinding = _normalData.binding; - AttributeBinding colorBinding = _colorData.binding; - - DrawNormal drawNormal(vertexAttribAlias?0:_normalData.array.get(),vertexAttribAlias?0:_normalData.indices.get()); - DrawColor drawColor(vertexAttribAlias?0:_colorData.array.get(),vertexAttribAlias?0:_colorData.indices.get()); - DrawSecondaryColor drawSecondaryColor(vertexAttribAlias?0:_secondaryColorData.array.get(),vertexAttribAlias?0:_secondaryColorData.indices.get(),extensions); - DrawFogCoord drawFogCoord(vertexAttribAlias?0:_fogCoordData.array.get(),vertexAttribAlias?0:_fogCoordData.indices.get(),extensions); - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up secondary color if required. - // - AttributeBinding secondaryColorBinding = _secondaryColorData.binding; - if (secondaryColorBinding!=BIND_OFF && !extensions->isSecondaryColorSupported()) - { - // switch off if not supported or have a valid data. - secondaryColorBinding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up fog coord if required. - // - AttributeBinding fogCoordBinding = _fogCoordData.binding; - if (fogCoordBinding!=BIND_OFF && !extensions->isFogCoordSupported()) - { - // switch off if not supported or have a valid data. - fogCoordBinding = BIND_OFF; - } - - - - unsigned int normalIndex = 0; - unsigned int colorIndex = 0; - unsigned int secondaryColorIndex = 0; - unsigned int fogCoordIndex = 0; - -#if USE_DEFAULT_NORMAL - // if no values are defined for normal and color provide some defaults... - if (_normalData.binding==BIND_OFF) glNormal3f(0.0f,0.0f,1.0f); -#endif - -#if USE_DEFAULT_COLOUR - if (_colorData.binding==BIND_OFF) glColor4f(1.0f,1.0f,1.0f,1.0f); -#endif - - typedef std::vector< ref_ptr > DrawVertexAttribList; - typedef std::map< Geometry::AttributeBinding, DrawVertexAttribList> DrawVertexAttribMap; - DrawVertexAttribMap drawVertexAttribMap; - - bool vertexVertexAttributesSupported = extensions->isVertexProgramSupported(); - bool handleVertexAttributes = (vertexAttribAlias || !_vertexAttribList.empty()) && vertexVertexAttributesSupported; - - bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); - - - if (vertexAttribAlias) - { - if (normalBinding!=BIND_OFF && normalBinding!=BIND_PER_VERTEX) - { - drawVertexAttribMap[normalBinding].push_back( new DrawVertexAttrib(extensions,2,false,_normalData.array.get(),_normalData.indices.get()) ); - normalBinding = BIND_OFF; - } - - if (colorBinding!=BIND_OFF && colorBinding!=BIND_PER_VERTEX) - { - drawVertexAttribMap[colorBinding].push_back( new DrawVertexAttrib(extensions,3,false,_colorData.array.get(),_colorData.indices.get()) ); - colorBinding = BIND_OFF; - } - - secondaryColorBinding = BIND_OFF; - fogCoordBinding = BIND_OFF; - } - - // force the use of the slow path code to test the glBegin/glEnd replacement codes. - bool forceSlowPath = true; - - if (areFastPathsUsed() && !forceSlowPath) - { - -#define USE_LAZY_DISABLING - -#ifdef USE_LAZY_DISABLING - state.lazyDisablingOfVertexAttributes(); -#endif - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // fast path. - // - if (usingVertexBufferObjects) - { - // osg::notify(osg::NOTICE)<<"Geometry::drawImplementation() Using VertexBufferObjects"<getNumElements() > 0 ) - { - drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,indexArray) ); - } - else - { - drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,0) ); - } - } - -#ifndef USE_LAZY_DISABLING - state.disableVertexAttribPointer( index ); -#endif - } - } -#ifndef USE_LAZY_DISABLING - state.disableVertexAttribPointersAboveAndIncluding( index ); -#endif - } -#ifndef USE_LAZY_DISABLING - else if (vertexVertexAttributesSupported) - { - state.disableVertexAttribPointersAboveAndIncluding( 0 ); - } -#endif - } - else - { - // osg::notify(osg::NOTICE)<<"none VertexBuffer path"<getDataSize(),_vertexData.array->getDataType(),0,_vertexData.array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableVertexPointer(); -#endif - - if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid()) - state.setNormalPointer(_normalData.array->getDataType(),0,_normalData.array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableNormalPointer(); -#endif - - if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid()) - state.setColorPointer(_colorData.array->getDataSize(),_colorData.array->getDataType(),0,_colorData.array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableColorPointer(); -#endif - - if (secondaryColorBinding==BIND_PER_VERTEX && _secondaryColorData.array.valid()) - state.setSecondaryColorPointer(_secondaryColorData.array->getDataSize(),_secondaryColorData.array->getDataType(),0,_secondaryColorData.array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableSecondaryColorPointer(); -#endif - - if (fogCoordBinding==BIND_PER_VERTEX && _fogCoordData.array.valid()) - state.setFogCoordPointer(GL_FLOAT,0,_fogCoordData.array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableFogCoordPointer(); -#endif - - unsigned int unit; - for(unit=0;unit<_texCoordList.size();++unit) - { - const Array* array = _texCoordList[unit].array.get(); - if (array) - state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); -#ifndef USE_LAZY_DISABLING - else - state.disableTexCoordPointer(unit); -#endif - } -#ifndef USE_LAZY_DISABLING - state.disableTexCoordPointersAboveAndIncluding(unit); -#endif - - if( handleVertexAttributes ) - { - unsigned int index; - for( index = 0; index < _vertexAttribList.size(); ++index ) - { - const Array* array = _vertexAttribList[index].array.get(); - const AttributeBinding ab = _vertexAttribList[index].binding; - - if( ab == BIND_PER_VERTEX && array ) - { - state.setVertexAttribPointer( index, array->getDataSize(), array->getDataType(), - _vertexAttribList[index].normalize, 0, array->getDataPointer() ); - } - else - { - if( array ) - { - const IndexArray* indexArray = _vertexAttribList[index].indices.get(); - - if( indexArray && indexArray->getNumElements() > 0 ) - { - drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,indexArray) ); - } - else - { - drawVertexAttribMap[ab].push_back( - new DrawVertexAttrib(extensions,index,_vertexAttribList[index].normalize,array,0) ); - } - } - -#ifndef USE_LAZY_DISABLING - state.disableVertexAttribPointer( index ); -#endif - } - } -#ifndef USE_LAZY_DISABLING - state.disableVertexAttribPointersAboveAndIncluding( index ); -#endif - } -#ifndef USE_LAZY_DISABLING - else if (vertexVertexAttributesSupported) - { - state.disableVertexAttribPointersAboveAndIncluding( 0 ); - } -#endif - } - -#ifdef USE_LAZY_DISABLING - state.applyDisablingOfVertexAttributes(); -#endif - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // pass the overall binding values onto OpenGL. - // - if (normalBinding==BIND_OVERALL) drawNormal(normalIndex++); - if (colorBinding==BIND_OVERALL) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_OVERALL]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - for(PrimitiveSetList::const_iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - - if (normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE_SET]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - (*itr)->draw(state, usingVertexBufferObjects); - - } - - if (usingVertexBufferObjects) - { -#if 1 - state.unbindVertexBufferObject(); - state.unbindElementBufferObject(); -#endif - } - - } - else - { - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // slow path. - // - - - typedef std::vector< ref_ptr > DrawTexCoordList; - DrawTexCoordList drawTexCoordList; - drawTexCoordList.reserve(_texCoordList.size()); - - // fallback if multitexturing not supported. - ref_ptr drawTextCoord; - - if (extensions->isMultiTexSupported() && _texCoordList.size()>1) - { - // multitexture supported.. - for(unsigned int unit=0;unit!=_texCoordList.size();++unit) - { - const ArrayData& texcoordData = _texCoordList[unit]; - if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) - { - if (texcoordData.indices.valid() && texcoordData.indices->getNumElements()>0) - { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordData.array.get(),texcoordData.indices.get(), - extensions)); - } - else - { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordData.array.get(),0, - extensions)); - } - } - } - } - else - { - if (!_texCoordList.empty()) - { - const ArrayData& texcoordData = _texCoordList[0]; - if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) - { - if (texcoordData.indices.valid()) - { - if (texcoordData.indices->getNumElements()>0) - { - drawTextCoord = new DrawTexCoord(texcoordData.array.get(),texcoordData.indices.get()); - } - } - else - { - drawTextCoord = new DrawTexCoord(texcoordData.array.get(),0); - } - } - } - } - - if(handleVertexAttributes) - { - unsigned int index; - for( index = 1; index < _vertexAttribList.size(); ++index ) - { - const ArrayData& vertAttribData = _vertexAttribList[index]; - - if( vertAttribData.array.valid() && vertAttribData.array->getNumElements() > 0 ) - { - if( vertAttribData.indices.valid() && vertAttribData.indices->getNumElements() > 0 ) - { - drawVertexAttribMap[vertAttribData.binding].push_back( - new DrawVertexAttrib(extensions,index,vertAttribData.normalize,vertAttribData.array.get(),vertAttribData.indices.get() )); - } - else - { - drawVertexAttribMap[vertAttribData.binding].push_back( - new DrawVertexAttrib(extensions,index,vertAttribData.normalize,vertAttribData.array.get(),0) ); - } - } - } - } - - // disable all the vertex arrays in the slow path as we are - // sending everything using glVertex etc. - state.disableAllVertexArrays(); - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // pass the overall binding values onto OpenGL. - // - if (_normalData.binding==BIND_OVERALL) drawNormal(normalIndex++); - if (_colorData.binding==BIND_OVERALL) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_OVERALL]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - // set up vertex functor. - DrawVertex drawVertex(_vertexData.array.get(),_vertexData.indices.get()); - - bool useVertexAttrib = _vertexAttribList.size() > 0 && - _vertexAttribList[0].array.valid() && - _vertexAttribList[0].array->getNumElements()!=0; - - ref_ptr drawVertexAttribZero; - if( useVertexAttrib ) - { - drawVertexAttribZero = new DrawVertexAttrib(extensions,0, - _vertexAttribList[0].normalize,_vertexAttribList[0].array.get(), - _vertexAttribList[0].indices.get()); - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - for(PrimitiveSetList::const_iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - if (_normalData.binding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); - if (_colorData.binding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE_SET]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - const PrimitiveSet* primitiveset = itr->get(); - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - switch(mode) - { - case(GL_POINTS): primLength=1; break; - case(GL_LINES): primLength=2; break; - case(GL_TRIANGLES): primLength=3; break; - case(GL_QUADS): primLength=4; break; - default: primLength=0; break; // compute later when =0. - } - - // draw primitives by the more flexible "slow" path, - // sending OpenGL glBegin/glVertex.../glEnd(). - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawArrays* drawArray = static_cast(primitiveset); - glBegin(mode); - - unsigned int primCount=0; - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); - vindexapplyAndIncrement(); - } - } - } - - if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); - if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); - if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_VERTEX]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); - texItr!=drawTexCoordList.end(); - ++texItr) - { - (*(*texItr))(vindex); - } - if (drawTextCoord.valid()) (*drawTextCoord)(vindex); - - if( useVertexAttrib ) - { - (*drawVertexAttribZero)(vindex); - } - else - { - drawVertex(vindex); - } - } - - glEnd(); - break; - } - case(PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - - const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - unsigned int localPrimLength; - if (primLength==0) localPrimLength=*primItr; - else localPrimLength=primLength; - - glBegin(mode); - - for(GLsizei primCount=0;primCount<*primItr;++primCount) - { - if ((primCount%localPrimLength)==0) - { - if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - } - - if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); - if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); - if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_VERTEX]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); - texItr!=drawTexCoordList.end(); - ++texItr) - { - (*(*texItr))(vindex); - } - if (drawTextCoord.valid()) (*drawTextCoord)(vindex); - - if( useVertexAttrib ) - { - (*drawVertexAttribZero)(vindex); - } - else - { - drawVertex(vindex); - } - - ++vindex; - } - - glEnd(); - - } - break; - } - case(PrimitiveSet::DrawElementsUBytePrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUByte* drawElements = static_cast(primitiveset); - glBegin(mode); - - unsigned int primCount=0; - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - - if ((primCount%primLength)==0) - { - if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - } - - unsigned int vindex=*primItr; - - if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); - if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); - if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); - if ( extensions->isVertexProgramSupported() ) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_VERTEX]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); - texItr!=drawTexCoordList.end(); - ++texItr) - { - (*(*texItr))(vindex); - } - if (drawTextCoord.valid()) (*drawTextCoord)(vindex); - - if( useVertexAttrib ) - { - (*drawVertexAttribZero)(vindex); - } - else - { - drawVertex(vindex); - } - } - - glEnd(); - break; - } - case(PrimitiveSet::DrawElementsUShortPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUShort* drawElements = static_cast(primitiveset); - glBegin(mode); - - unsigned int primCount=0; - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - - if ((primCount%primLength)==0) - { - if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - } - - unsigned int vindex=*primItr; - - if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); - if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); - if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); - if (handleVertexAttributes) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_VERTEX]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); - texItr!=drawTexCoordList.end(); - ++texItr) - { - (*(*texItr))(vindex); - } - if (drawTextCoord.valid()) (*drawTextCoord)(vindex); - - if( useVertexAttrib ) - { - (*drawVertexAttribZero)(vindex); - } - else - { - drawVertex(vindex); - } - } - - glEnd(); - break; - } - case(PrimitiveSet::DrawElementsUIntPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUInt* drawElements = static_cast(primitiveset); - glBegin(mode); - - unsigned int primCount=0; - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - - if ((primCount%primLength)==0) - { - if (_normalData.binding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (_colorData.binding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - if ( extensions->isVertexProgramSupported() ) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_PRIMITIVE]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - } - - unsigned int vindex=*primItr; - - if (_normalData.binding==BIND_PER_VERTEX) drawNormal(vindex); - if (_colorData.binding==BIND_PER_VERTEX) drawColor(vindex); - if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); - if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); - if ( extensions->isVertexProgramSupported() ) - { - DrawVertexAttribList &list = drawVertexAttribMap[BIND_PER_VERTEX]; - - for( unsigned int i = 0; i < list.size(); ++i ) - { - list[i]->applyAndIncrement(); - } - } - - for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); - texItr!=drawTexCoordList.end(); - ++texItr) - { - (*(*texItr))(vindex); - } - if (drawTextCoord.valid()) (*drawTextCoord)(vindex); - - if( useVertexAttrib ) - { - (*drawVertexAttribZero)(vindex); - } - else - { - drawVertex(vindex); - } - } - - glEnd(); - break; - } - default: - { - break; - } - } - } - } - -} -#endif class AttributeFunctorArrayVisitor : public ArrayVisitor { @@ -3063,7 +1784,7 @@ unsigned int _computeNumberOfPrimitives(const osg::Geometry& geom) } // draw primitives by the more flexible "slow" path, - // sending OpenGL glBegin/glVertex.../glEnd(). + // sending OpenGL Begin/glVertex.../End(). switch(primitiveset->getType()) { case(PrimitiveSet::DrawArrayLengthsPrimitiveType): @@ -3683,623 +2404,6 @@ Geometry* osg::createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVe geom->setNormalBinding(Geometry::BIND_OVERALL); geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4)); - + return geom; } - - - - -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// - - -// experimental templated rendering code, please ignore... -// will move to osg::Geometry once complete. -// Robert Osfield, August 2003. -#if 0 - - struct DrawAttributeArrays - { - virtual bool valid() const = 0; - virtual void set(osg::Geometry* geometry) = 0; - virtual unsigned int draw(unsigned int index, unsigned int count) const = 0; - }; - - struct V3 - { - V3():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[index].ptr()); - } - - osg::Vec3* _array; - }; - - struct V3USI - { - V3USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[_indices[index]].ptr()); - } - - osg::Vec3* _array; - unsigned short* _indices; - }; - - ////////////////////////////// - - struct N3 - { - N3():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - } - - inline void draw(unsigned int index) const - { - glNormal3fv(_array[index].ptr()); - } - - osg::Vec3* _array; - }; - - struct N3USI - { - N3USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getVertexArray(); - if (array && array->getType()==osg::Array::Vec3ArrayType) - { - osg::Vec3Array* vec3array = static_cast(array); - if (!vec3array->empty()) _array = &(vec3array->front()); - } - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); - } - } - - inline void draw(unsigned int index) const - { - glNormal3fv(_array[_indices[index]].ptr()); - } - - osg::Vec3* _array; - unsigned short* _indices; - }; - - ////////////////////////////// - - struct C4 - { - C4():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getColorArray(); - if (array && array->getType()==osg::Array::Vec4ArrayType) - { - osg::Vec4Array* vec4array = static_cast(array); - if (!vec4array->empty()) _array = &(vec4array->front()); - } - } - - inline void draw(unsigned int index) const - { - glVertex3fv(_array[index].ptr()); - } - - osg::Vec4* _array; - }; - - struct C4USI - { - C4USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getColorArray(); - if (array && array->getType()==osg::Array::Vec4ArrayType) - { - osg::Vec4Array* vec4array = static_cast(array); - if (!vec4array->empty()) _array = &(vec4array->front()); - } - - _indices = 0; - osg::IndexArray* indices = geometry->getColorIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); - } - } - - inline void draw(unsigned int index) const - { - glColor4fv(_array[_indices[index]].ptr()); - } - - osg::Vec4* _array; - unsigned short* _indices; - }; - - ////////////////////////////// - - struct T2 - { - T2():_array(0) {} - - bool valid() const { return _array!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getTexCoordArray(0); - if (array && array->getType()==osg::Array::Vec2ArrayType) - { - osg::Vec2Array* vec2array = static_cast(array); - if (!vec2array->empty()) _array = &(vec2array->front()); - } - } - - inline void draw(unsigned int index) const - { - glTexCoord2fv(_array[index].ptr()); - } - - osg::Vec2* _array; - }; - - struct T2USI - { - T2USI():_array(0),_indices(0) {} - - bool valid() const { return _array!=0 && _indices!=0; } - - void set(osg::Geometry* geometry) - { - _array = 0; - osg::Array* array = geometry->getTexCoordArray(0); - if (array && array->getType()==osg::Array::Vec2ArrayType) - { - osg::Vec2Array* vec2array = static_cast(array); - if (!vec2array->empty()) _array = &(vec2array->front()); - } - - _indices = 0; - osg::IndexArray* indices = geometry->getTexCoordIndices(0); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushortarray = static_cast(array); - if (!ushortarray->empty()) _indices = &(ushortarray->front()); - } - } - - inline void draw(unsigned int index) const - { - glTexCoord2fv(_array[_indices[index]].ptr()); - } - - osg::Vec2* _array; - unsigned short* _indices; - }; - - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - template < class T1 > - struct DrawAttributeArrays_T : public DrawAttributeArrays - { - DrawAttributeArrays_T(osg::Geometry* geometry) - { - - } - - virtual bool valid() const { return _t1.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TT : public DrawAttributeArrays - { - DrawAttributeArrays_TT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TTT : public DrawAttributeArrays - { - DrawAttributeArrays_TTT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TTTT : public DrawAttributeArrays - { - DrawAttributeArrays_TTTT() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid(); } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - _t4.set(geometry); - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TT_USI : public DrawAttributeArrays - { - DrawAttributeArrays_TT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); - } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TTT_USI : public DrawAttributeArrays - { - DrawAttributeArrays_TTT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); - } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i - struct DrawAttributeArrays_TTTT_USI : public DrawAttributeArrays - { - DrawAttributeArrays_TTTT_USI() - { - } - - virtual bool valid() const { return _t1.valid() && _t2.valid() && _t3.valid() && _t4.valid() && _indices!=0; } - - virtual void set(osg::Geometry* geometry) - { - _t1.set(geometry); - _t2.set(geometry); - _t3.set(geometry); - _t4.set(geometry); - - _indices = 0; - osg::IndexArray* indices = geometry->getVertexIndices(); - if (indices && indices->getType()==osg::Array::UShortArrayType) - { - osg::UShortArray* ushort3array = static_cast(array); - if (!ushort3array->empty()) _indices = &(ushort3array->front()); - } - } - - virtual unsigned int draw(unsigned int index, unsigned int count) const - { - for(unsigned int i=0;i DrawAttributeArrays_V3; - typedef DrawAttributeArrays_T DrawAttributeArrays_V3i; - - // Two attributes x 15 - - typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_N3V3i; - typedef DrawAttributeArrays_TT DrawAttributeArrays_N3iV3i; - - typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_N3V3_i; - - typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_C4V3i; - typedef DrawAttributeArrays_TT DrawAttributeArrays_C4iV3i; - - typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_C4V3_i; - - typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3; - typedef DrawAttributeArrays_TT DrawAttributeArrays_T2V3i; - typedef DrawAttributeArrays_TT DrawAttributeArrays_T2iV3i; - - typedef DrawAttributeArrays_TT_USI DrawAttributeArrays_T2V3_i; - - // Three attributes x 27 - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3; - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4N3iV3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_C4iN3iV3i; - - typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_C4N3V3_i; - - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3; - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iN3iV3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2N3iV3i; - - typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2N3V3_i; - - - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3; - - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4V3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2C4iV3i; - typedef DrawAttributeArrays_TTT DrawAttributeArrays_T2iC4iV3i; - - typedef DrawAttributeArrays_TTT_USI DrawAttributeArrays_T2C4V3_t; - - - // Four attributes x 17 - - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3; - - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3; - - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3V3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3V3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3V3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3V3i; - - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4N3iV3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4N3iV3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2C4iN3iV3i; - typedef DrawAttributeArrays_TTTT DrawAttributeArrays_T2iC4iN3iV3i; - - typedef DrawAttributeArrays_TTTT_USI DrawAttributeArrays_T2C4N3V3_i; - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -#endif