From 1b1c5bbdd1192e895ce67f4a314b408181e6ca44 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 4 Dec 2007 14:46:46 +0000 Subject: [PATCH] Added support for new double Vec*Array classes in various functors. --- include/osg/Drawable | 31 +++ include/osg/PrimitiveSet | 22 ++ include/osg/TemplatePrimitiveFunctor | 15 ++ include/osg/TriangleFunctor | 14 ++ include/osg/TriangleIndexFunctor | 12 + include/osgUtil/Statistics | 3 + src/osg/Drawable.cpp | 250 ++++++++++++++------ src/osg/Geometry.cpp | 107 +++++++++ src/osgPlugins/obj/OBJWriterNodeVisitor.cpp | 8 +- src/osgUtil/Optimizer.cpp | 5 + 10 files changed, 396 insertions(+), 71 deletions(-) diff --git a/include/osg/Drawable b/include/osg/Drawable index 34e49a9c7..c3ae2f807 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -501,6 +501,11 @@ class OSG_EXPORT Drawable : public Object virtual void apply(AttributeType,unsigned int,Vec3*) {} virtual void apply(AttributeType,unsigned int,Vec4*) {} virtual void apply(AttributeType,unsigned int,Vec4ub*) {} + + virtual void apply(AttributeType,unsigned int,double*) {} + virtual void apply(AttributeType,unsigned int,Vec2d*) {} + virtual void apply(AttributeType,unsigned int,Vec3d*) {} + virtual void apply(AttributeType,unsigned int,Vec4d*) {} }; @@ -532,6 +537,11 @@ class OSG_EXPORT Drawable : public Object virtual void apply(AttributeType,unsigned int,const Vec3*) {} virtual void apply(AttributeType,unsigned int,const Vec4*) {} virtual void apply(AttributeType,unsigned int,const Vec4ub*) {} + + virtual void apply(AttributeType,unsigned int,const double*) {} + virtual void apply(AttributeType,unsigned int,const Vec2d*) {} + virtual void apply(AttributeType,unsigned int,const Vec3d*) {} + virtual void apply(AttributeType,unsigned int,const Vec4d*) {} }; /** Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).*/ @@ -608,11 +618,20 @@ class OSG_EXPORT Drawable : public Object void glMultiTexCoord3fv(GLenum target,const GLfloat* coord) const; void glMultiTexCoord4fv(GLenum target,const GLfloat* coord) const; + void glMultiTexCoord1d(GLenum target,GLdouble coord) const; + void glMultiTexCoord2dv(GLenum target,const GLdouble* coord) const; + void glMultiTexCoord3dv(GLenum target,const GLdouble* coord) const; + void glMultiTexCoord4dv(GLenum target,const GLdouble* coord) const; + void glVertexAttrib1s(unsigned int index, GLshort s) const; void glVertexAttrib1f(unsigned int index, GLfloat f) const; + void glVertexAttrib1d(unsigned int index, GLdouble f) const; void glVertexAttrib2fv(unsigned int index, const GLfloat * v) const; void glVertexAttrib3fv(unsigned int index, const GLfloat * v) const; void glVertexAttrib4fv(unsigned int index, const GLfloat * v) const; + void glVertexAttrib2dv(unsigned int index, const GLdouble * v) const; + void glVertexAttrib3dv(unsigned int index, const GLdouble * v) const; + void glVertexAttrib4dv(unsigned int index, const GLdouble * v) const; void glVertexAttrib4ubv(unsigned int index, const GLubyte * v) const; void glVertexAttrib4Nubv(unsigned int index, const GLubyte * v) const; @@ -654,7 +673,9 @@ class OSG_EXPORT Drawable : public Object typedef void (APIENTRY * VertexAttrib1sProc) (unsigned int index, GLshort s); typedef void (APIENTRY * VertexAttrib1fProc) (unsigned int index, GLfloat f); + typedef void (APIENTRY * VertexAttrib1dProc) (unsigned int index, GLdouble f); typedef void (APIENTRY * VertexAttribfvProc) (unsigned int index, const GLfloat * v); + typedef void (APIENTRY * VertexAttribdvProc) (unsigned int index, const GLdouble * v); typedef void (APIENTRY * VertexAttribubvProc) (unsigned int index, const GLubyte * v); typedef void (APIENTRY * SecondaryColor3ubvProc) (const GLubyte* coord); @@ -662,6 +683,8 @@ class OSG_EXPORT Drawable : public Object typedef void (APIENTRY * MultiTexCoord1fProc) (GLenum target,GLfloat coord); typedef void (APIENTRY * MultiTexCoordfvProc) (GLenum target,const GLfloat* coord); + typedef void (APIENTRY * MultiTexCoord1dProc) (GLenum target,GLdouble coord); + typedef void (APIENTRY * MultiTexCoorddvProc) (GLenum target,const GLdouble* coord); typedef void (APIENTRY * GenBuffersProc) (GLsizei n, GLuint *buffers); @@ -712,9 +735,13 @@ class OSG_EXPORT Drawable : public Object VertexAttrib1sProc _glVertexAttrib1s; VertexAttrib1fProc _glVertexAttrib1f; + VertexAttrib1dProc _glVertexAttrib1d; VertexAttribfvProc _glVertexAttrib2fv; VertexAttribfvProc _glVertexAttrib3fv; VertexAttribfvProc _glVertexAttrib4fv; + VertexAttribdvProc _glVertexAttrib2dv; + VertexAttribdvProc _glVertexAttrib3dv; + VertexAttribdvProc _glVertexAttrib4dv; VertexAttribubvProc _glVertexAttrib4ubv; VertexAttribubvProc _glVertexAttrib4Nubv; @@ -722,6 +749,10 @@ class OSG_EXPORT Drawable : public Object MultiTexCoordfvProc _glMultiTexCoord2fv; MultiTexCoordfvProc _glMultiTexCoord3fv; MultiTexCoordfvProc _glMultiTexCoord4fv; + MultiTexCoord1dProc _glMultiTexCoord1d; + MultiTexCoorddvProc _glMultiTexCoord2dv; + MultiTexCoorddvProc _glMultiTexCoord3dv; + MultiTexCoorddvProc _glMultiTexCoord4dv; GenBuffersProc _glGenBuffers; BindBufferProc _glBindBuffer; diff --git a/include/osg/PrimitiveSet b/include/osg/PrimitiveSet index 354013513..9175e128e 100644 --- a/include/osg/PrimitiveSet +++ b/include/osg/PrimitiveSet @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include @@ -114,6 +117,21 @@ public: */ virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0; + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ + virtual void setVertexArray(unsigned int count,const Vec2d* vertices) = 0; + + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ + virtual void setVertexArray(unsigned int count,const Vec3d* vertices) = 0; + + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ + virtual void setVertexArray(unsigned int count,const Vec4d* vertices) = 0; + /// Mimics the OpenGL \c glDrawArrays() function. virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0; @@ -161,6 +179,10 @@ public: virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0; virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0; + virtual void setVertexArray(unsigned int count,const Vec2d* vertices) = 0; + virtual void setVertexArray(unsigned int count,const Vec3d* vertices) = 0; + virtual void setVertexArray(unsigned int count,const Vec4d* vertices) = 0; + virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0; virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0; virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0; diff --git a/include/osg/TemplatePrimitiveFunctor b/include/osg/TemplatePrimitiveFunctor index 46711017e..3e875e461 100644 --- a/include/osg/TemplatePrimitiveFunctor +++ b/include/osg/TemplatePrimitiveFunctor @@ -71,6 +71,21 @@ namespace osg { notify(WARN)<<"Triangle Functor does not support Vec4* vertex arrays"< #include #include +#include #include #include @@ -700,105 +701,104 @@ void Drawable::setEventCallback(EventCallback* ac) struct ComputeBound : public PrimitiveFunctor { - ComputeBound() { _vertices = 0; _vertices4 = 0;} - - virtual void setVertexArray(unsigned int,const Vec2*) + ComputeBound() { - notify(WARN)<<"ComputeBound does not support Vec2* vertex arrays"< + void _drawArrays(T* vert, T* end) + { + for(;vert + void _drawElements(T* vert, I* indices, I* end) + { + for(;indices0;--count,++vert) - { - _bb.expandBy(*vert); - } - } - - if (_vertices4) - { - const osg::Vec4* vert = _vertices4+first; - for(;count>0;--count,++vert) - { - _bb.expandBy(*((Vec3*) vert)); - } - } + if (_vertices3f) _drawArrays(_vertices3f+first, _vertices3f+(first+count)); + else if (_vertices2f) _drawArrays(_vertices2f+first, _vertices2f+(first+count)); + else if (_vertices4f) _drawArrays(_vertices4f+first, _vertices4f+(first+count)); + else if (_vertices2d) _drawArrays(_vertices2d+first, _vertices2d+(first+count)); + else if (_vertices3d) _drawArrays(_vertices3d+first, _vertices3d+(first+count)); + else if (_vertices4d) _drawArrays(_vertices4d+first, _vertices4d+(first+count)); } virtual void drawElements(GLenum,GLsizei count,const GLubyte* indices) { - if (_vertices) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(_vertices[*indices]); - } - } - - if (_vertices4) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(*((Vec3*)&_vertices4[*indices])); - } - } + if (_vertices3f) _drawElements(_vertices3f, indices, indices + count); + else if (_vertices2f) _drawElements(_vertices2f, indices, indices + count); + else if (_vertices4f) _drawElements(_vertices4f, indices, indices + count); + else if (_vertices2d) _drawElements(_vertices2d, indices, indices + count); + else if (_vertices3d) _drawElements(_vertices3d, indices, indices + count); + else if (_vertices4d) _drawElements(_vertices4d, indices, indices + count); } virtual void drawElements(GLenum,GLsizei count,const GLushort* indices) { - if (_vertices) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(_vertices[*indices]); - } - } - - if (_vertices4) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(*((Vec3*)&_vertices4[*indices])); - } - } + if (_vertices3f) _drawElements(_vertices3f, indices, indices + count); + else if (_vertices2f) _drawElements(_vertices2f, indices, indices + count); + else if (_vertices4f) _drawElements(_vertices4f, indices, indices + count); + else if (_vertices2d) _drawElements(_vertices2d, indices, indices + count); + else if (_vertices3d) _drawElements(_vertices3d, indices, indices + count); + else if (_vertices4d) _drawElements(_vertices4d, indices, indices + count); } virtual void drawElements(GLenum,GLsizei count,const GLuint* indices) { - if (_vertices) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(_vertices[*indices]); - } - } - - if (_vertices4) - { - for(;count>0;--count,++indices) - { - _bb.expandBy(*((Vec3*)&_vertices4[*indices])); - } - } + if (_vertices3f) _drawElements(_vertices3f, indices, indices + count); + else if (_vertices2f) _drawElements(_vertices2f, indices, indices + count); + else if (_vertices4f) _drawElements(_vertices4f, indices, indices + count); + else if (_vertices2d) _drawElements(_vertices2d, indices, indices + count); + else if (_vertices3d) _drawElements(_vertices3d, indices, indices + count); + else if (_vertices4d) _drawElements(_vertices4d, indices, indices + count); } virtual void begin(GLenum) {} virtual void vertex(const Vec2& vert) { _bb.expandBy(osg::Vec3(vert[0],vert[1],0.0f)); } virtual void vertex(const Vec3& vert) { _bb.expandBy(vert); } virtual void vertex(const Vec4& vert) { if (vert[3]!=0.0f) _bb.expandBy(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); } + virtual void vertex(const Vec2d& vert) { _bb.expandBy(osg::Vec3(vert[0],vert[1],0.0f)); } + virtual void vertex(const Vec3d& vert) { _bb.expandBy(vert); } + virtual void vertex(const Vec4d& vert) { if (vert[3]!=0.0f) _bb.expandBy(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); } virtual void vertex(float x,float y) { _bb.expandBy(x,y,1.0f); } virtual void vertex(float x,float y,float z) { _bb.expandBy(x,y,z); } virtual void vertex(float x,float y,float z,float w) { if (w!=0.0f) _bb.expandBy(x/w,y/w,z/w); } + virtual void vertex(double x,double y) { _bb.expandBy(x,y,1.0f); } + virtual void vertex(double x,double y,double z) { _bb.expandBy(x,y,z); } + virtual void vertex(double x,double y,double z,double w) { if (w!=0.0f) _bb.expandBy(x/w,y/w,z/w); } virtual void end() {} - const Vec3* _vertices; - const Vec4* _vertices4; + const Vec2* _vertices2f; + const Vec3* _vertices3f; + const Vec4* _vertices4f; + const Vec2d* _vertices2d; + const Vec3d* _vertices3d; + const Vec4d* _vertices4d; BoundingBox _bb; }; @@ -808,6 +808,12 @@ BoundingBox Drawable::computeBound() const Drawable* non_const_this = const_cast(this); non_const_this->accept(cb); + +#if 0 + osg::notify(osg::NOTICE)<<"computeBound() "<(_vertices)))[pos]); break; + case(Array::Vec3dArrayType): + apply((*(static_cast(_vertices)))[pos]); + break; + case(Array::Vec2dArrayType): + apply((*(static_cast(_vertices)))[pos]); + break; + case(Array::Vec4dArrayType): + apply((*(static_cast(_vertices)))[pos]); + break; default: break; } @@ -69,6 +78,9 @@ class DrawVertex 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; @@ -244,6 +256,18 @@ public: { _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; @@ -2056,6 +2080,10 @@ class AttributeFunctorArrayVisitor : public ArrayVisitor virtual void apply(Vec2Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } virtual void apply(Vec3Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } virtual void apply(Vec4Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(DoubleArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(Vec2dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(Vec3dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(Vec4dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } inline void applyArray(Drawable::AttributeType type,Array* array) @@ -2112,6 +2140,10 @@ class ConstAttributeFunctorArrayVisitor : public ConstArrayVisitor virtual void apply(const Vec2Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } virtual void apply(const Vec3Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } virtual void apply(const Vec4Array& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(const DoubleArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(const Vec2dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(const Vec3dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } + virtual void apply(const Vec4dArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } inline void applyArray(Drawable::AttributeType type,const Array* array) @@ -2165,6 +2197,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); break; + case(Array::Vec2dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; + case(Array::Vec3dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; + case(Array::Vec4dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; default: notify(WARN)<<"Warning: Geometry::accept(PrimtiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<getType(); switch(type) { @@ -2194,6 +2238,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): vec4Array = static_cast(_vertexData.array.get()); break; + case(Array::Vec2dArrayType): + vec2dArray = static_cast(_vertexData.array.get()); + break; + case(Array::Vec3dArrayType): + vec3dArray = static_cast(_vertexData.array.get()); + break; + case(Array::Vec4dArrayType): + vec4dArray = static_cast(_vertexData.array.get()); + break; default: notify(WARN)<<"Warning: Geometry::accept(PrimtiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<index(vindex)]); break; + case(Array::Vec2dArrayType): + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec3dArrayType): + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec4dArrayType): + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); + break; default: break; } @@ -2263,6 +2325,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; + case(Array::Vec2dArrayType): + functor.vertex((*vec2Array)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec3dArrayType): + functor.vertex((*vec3Array)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec4dArrayType): + functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); + break; default: break; } @@ -2296,6 +2367,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; + case(Array::Vec2dArrayType): + functor.vertex((*vec2dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec3dArrayType): + functor.vertex((*vec3dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec4dArrayType): + functor.vertex((*vec4dArray)[_vertexData.indices->index(vindex)]); + break; default: break; } @@ -2325,6 +2405,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; + case(Array::Vec2dArrayType): + functor.vertex((*vec2dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec3dArrayType): + functor.vertex((*vec3dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec4dArrayType): + functor.vertex((*vec4dArray)[_vertexData.indices->index(vindex)]); + break; default: break; } @@ -2354,6 +2443,15 @@ void Geometry::accept(PrimitiveFunctor& functor) const case(Array::Vec4ArrayType): functor.vertex((*vec4Array)[_vertexData.indices->index(vindex)]); break; + case(Array::Vec2dArrayType): + functor.vertex((*vec2dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec3dArrayType): + functor.vertex((*vec3dArray)[_vertexData.indices->index(vindex)]); + break; + case(Array::Vec4dArrayType): + functor.vertex((*vec4dArray)[_vertexData.indices->index(vindex)]); + break; default: break; } @@ -2387,6 +2485,15 @@ void Geometry::accept(PrimitiveIndexFunctor& functor) const case(Array::Vec4ArrayType): functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); break; + case(Array::Vec2dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; + case(Array::Vec3dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; + case(Array::Vec4dArrayType): + functor.setVertexArray(_vertexData.array->getNumElements(),static_cast(_vertexData.array->getDataPointer())); + break; default: notify(WARN)<<"Warning: Geometry::accept(PrimtiveIndexFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<getPrimitiveSet(i); - PrimitiveIndexWriter pif(_fout, geo, normalIndex, _lastVertexIndex, _lastNormalIndex, _lastTexIndex); + PrimitiveIndexWriter pif(_fout, geo, normalIndex, _lastVertexIndex, _lastNormalIndex, _lastTexIndex); ps->accept(pif); if(geo->getNormalArray() && geo->getNormalBinding() == osg::Geometry::BIND_PER_PRIMITIVE_SET) diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 5a3bc6643..6c985b019 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -2234,6 +2234,11 @@ class MergeArrayVisitor : public osg::ArrayVisitor virtual void apply(osg::Vec3Array& rhs) { _merge(rhs); } virtual void apply(osg::Vec4Array& rhs) { _merge(rhs); } + virtual void apply(osg::DoubleArray& rhs) { _merge(rhs); } + virtual void apply(osg::Vec2dArray& rhs) { _merge(rhs); } + virtual void apply(osg::Vec3dArray& rhs) { _merge(rhs); } + virtual void apply(osg::Vec4dArray& rhs) { _merge(rhs); } + virtual void apply(osg::Vec2bArray& rhs) { _merge(rhs); } virtual void apply(osg::Vec3bArray& rhs) { _merge(rhs); } virtual void apply(osg::Vec4bArray& rhs) { _merge(rhs); }