From 4c62cfe6e5bd5b3c4e28acfdc57f072da53c7daf Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 31 Aug 2003 22:08:22 +0000 Subject: [PATCH] Added experiment Tempated fast path implemenation, #if 0 out right now. --- src/osg/Geometry.cpp | 616 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 616 insertions(+) diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index e5deb4d52..9f996332d 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -2515,3 +2515,619 @@ Geometry* osg::createTexturedQuadGeometry(const osg::Vec3& corner,const osg::Vec 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