diff --git a/include/osg/GeometryNew b/include/osg/GeometryNew deleted file mode 100644 index 5b41817ab..000000000 --- a/include/osg/GeometryNew +++ /dev/null @@ -1,258 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#ifndef OSG_GEOMETRYNEW -#define OSG_GEOMETRYNEW 1 - -#include -#include -#include -#include -#include -#include - -namespace osg { - -class OSG_EXPORT GeometryNew : public Drawable -{ - public: - - GeometryNew(); - - /** Copy constructor using CopyOp to manage deep vs shallow copy. */ - GeometryNew(const GeometryNew& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY); - - virtual Object* cloneType() const { return new GeometryNew(); } - virtual Object* clone(const CopyOp& copyop) const { return new GeometryNew(*this,copyop); } - virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } - virtual const char* libraryName() const { return "osg"; } - virtual const char* className() const { return "GeometryNew"; } - -#if 0 - virtual Geometry* asGeometry() { return this; } - virtual const Geometry* asGeometry() const { return this; } -#endif - - bool empty() const; - - /** Same values as Array::Binding.*/ - enum AttributeBinding - { - BIND_OFF=0, - BIND_OVERALL=1, - BIND_PER_PRIMITIVE_SET=2, - BIND_PER_PRIMITIVE=3, /// deprecated - BIND_PER_VERTEX=4 - }; - - typedef std::vector< osg::ref_ptr > ArrayList; - - void setVertexArray(Array* array); - Array* getVertexArray() { return _vertexArray.get(); } - const Array* getVertexArray() const { return _vertexArray.get(); } - - - void setNormalBinding(AttributeBinding ab); - AttributeBinding getNormalBinding() const; - - void setNormalArray(Array* array); - Array* getNormalArray() { return _normalArray.get(); } - const Array* getNormalArray() const { return _normalArray.get(); } - - - void setColorBinding(AttributeBinding ab); - AttributeBinding getColorBinding() const; - - void setColorArray(Array* array); - Array* getColorArray() { return _colorArray.get(); } - const Array* getColorArray() const { return _colorArray.get(); } - - - void setSecondaryColorBinding(AttributeBinding ab); - AttributeBinding getSecondaryColorBinding() const; - - void setSecondaryColorArray(Array* array); - Array* getSecondaryColorArray() { return _secondaryColorArray.get(); } - const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); } - - - void setFogCoordBinding(AttributeBinding ab); - AttributeBinding getFogCoordBinding() const; - - void setFogCoordArray(Array* array); - Array* getFogCoordArray() { return _fogCoordArray.get(); } - const Array* getFogCoordArray() const { return _fogCoordArray.get(); } - - - void setTexCoordArray(unsigned int unit,Array*); - Array* getTexCoordArray(unsigned int unit); - const Array* getTexCoordArray(unsigned int unit) const; - - unsigned int getNumTexCoordArrays() const { return static_cast(_texCoordList.size()); } - ArrayList& getTexCoordArrayList() { return _texCoordList; } - const ArrayList& getTexCoordArrayList() const { return _texCoordList; } - - - - void setVertexAttribArray(unsigned int index,Array* array); - Array *getVertexAttribArray(unsigned int index); - const Array *getVertexAttribArray(unsigned int index) const; - - void setVertexAttribBinding(unsigned int index,AttributeBinding ab); - AttributeBinding getVertexAttribBinding(unsigned int index) const; - - void setVertexAttribNormalize(unsigned int index,GLboolean norm); - GLboolean getVertexAttribNormalize(unsigned int index) const; - - unsigned int getNumVertexAttribArrays() const { return static_cast(_vertexAttribList.size()); } - ArrayList& getVertexAttribArrayList() { return _vertexAttribList; } - const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; } - - - - typedef std::vector< ref_ptr > PrimitiveSetList; - - void setPrimitiveSetList(const PrimitiveSetList& primitives); - - PrimitiveSetList& getPrimitiveSetList() { return _primitives; } - const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; } - - unsigned int getNumPrimitiveSets() const { return static_cast(_primitives.size()); } - PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); } - const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); } - - /** Add a primitive set to the geometry. */ - bool addPrimitiveSet(PrimitiveSet* primitiveset); - - /** Set a primitive set to the specified position in geometry's primitive set list. */ - bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset); - - /** Insert a primitive set to the specified position in geometry's primitive set list. */ - bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset); - - /** Remove primitive set(s) from the specified position in geometry's primitive set list. */ - bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1); - - /** Get the index number of a primitive set, return a value between - * 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet(). - * When checking for a valid find value use if ((value=geometry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet()) - */ - unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const; - - - - - /** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation - method to use OpenGL vertex buffer objects for rendering.*/ - virtual void setUseVertexBufferObjects(bool flag); - - /** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/ - virtual void dirtyDisplayList(); - - - /** Resize any per context GLObject buffers to specified size. */ - virtual void resizeGLObjectBuffers(unsigned int maxSize); - - /** If State is non-zero, this function releases OpenGL objects for - * the specified graphics context. Otherwise, releases OpenGL objects - * for all graphics contexts. */ - virtual void releaseGLObjects(State* state=0) const; - - bool getArrayList(ArrayList& arrayList) const; - - typedef std::vector DrawElementsList; - bool getDrawElementsList(DrawElementsList& drawElementsList) const; - - osg::VertexBufferObject* getOrCreateVertexBufferObject(); - osg::ElementBufferObject* getOrCreateElementBufferObject(); - - - - /** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable. - * This size is used a hint for reuse of deleted display lists/vertex buffer objects. */ - virtual unsigned int getGLObjectSizeHint() const; - - /** Immediately compile this \c Drawable into an OpenGL Display List/VertexBufferObjects. - * @note Operation is ignored if \c _useDisplayList is \c false or VertexBufferObjects are not used. - */ - virtual void compileGLObjects(RenderInfo& renderInfo) const; - - /** Draw Geometry directly ignoring an OpenGL display list which could be attached. - * This is the internal draw method which does the drawing itself, - * and is the method to override when deriving from Geometry for user-drawn objects. - */ - virtual void drawImplementation(RenderInfo& renderInfo) const; - - /** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */ - virtual bool supports(const Drawable::AttributeFunctor&) const { return true; } - - /** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */ - virtual void accept(Drawable::AttributeFunctor& af); - - /** Return true, osg::Geometry does support accept(Drawable::ConstAttributeFunctor&). */ - virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; } - - /** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */ - virtual void accept(Drawable::ConstAttributeFunctor& af) const; - - /** Return true, osg::Geometry does support accept(PrimitiveFunctor&). */ - virtual bool supports(const PrimitiveFunctor&) const { return true; } - - /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */ - virtual void accept(PrimitiveFunctor& pf) const; - - /** Return true, osg::Geometry does support accept(PrimitiveIndexFunctor&). */ - virtual bool supports(const PrimitiveIndexFunctor&) const { return true; } - - /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */ - virtual void accept(PrimitiveIndexFunctor& pf) const; - - - protected: - - GeometryNew& operator = (const GeometryNew&) { return *this;} - - virtual ~GeometryNew(); - - - void addVertexBufferObjectIfRequired(osg::Array* array); - void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet); - - - PrimitiveSetList _primitives; - osg::ref_ptr _vertexArray; - osg::ref_ptr _normalArray; - osg::ref_ptr _colorArray; - osg::ref_ptr _secondaryColorArray; - osg::ref_ptr _fogCoordArray; - ArrayList _texCoordList; - ArrayList _vertexAttribList; -}; - -/** Convenience function to be used for creating quad geometry with texture coords. - * Tex coords go from left bottom (l,b) to right top (r,t). -*/ -extern OSG_EXPORT GeometryNew* createTexturedQuadGeometryNew(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t); - -/** Convenience function to be used for creating quad geometry with texture coords. - * Tex coords go from bottom left (0,0) to top right (s,t). -*/ -inline GeometryNew* createTexturedQuadGeometryNew(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f) -{ - return createTexturedQuadGeometryNew(corner,widthVec,heightVec, 0.0f, 0.0f, s, t); -} - - -} - -#endif diff --git a/src/osg/GeometryNew.cpp b/src/osg/GeometryNew.cpp deleted file mode 100644 index bdc58181a..000000000 --- a/src/osg/GeometryNew.cpp +++ /dev/null @@ -1,1146 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ -#include - -#include -#include -#include - -using namespace osg; - -GeometryNew::GeometryNew() -{ - // temporary test - // setSupportsDisplayList(false); -} - -GeometryNew::GeometryNew(const GeometryNew& geometry,const CopyOp& copyop): - Drawable(geometry,copyop), - _vertexArray(copyop(geometry._vertexArray.get())), - _normalArray(copyop(geometry._normalArray.get())), - _colorArray(copyop(geometry._colorArray.get())), - _secondaryColorArray(copyop(geometry._secondaryColorArray.get())), - _fogCoordArray(copyop(geometry._fogCoordArray.get())) -{ - // temporary test - // setSupportsDisplayList(false); - - for(PrimitiveSetList::const_iterator pitr=geometry._primitives.begin(); - pitr!=geometry._primitives.end(); - ++pitr) - { - PrimitiveSet* primitive = copyop(pitr->get()); - if (primitive) _primitives.push_back(primitive); - } - - for(ArrayList::const_iterator titr=geometry._texCoordList.begin(); - titr!=geometry._texCoordList.end(); - ++titr) - { - _texCoordList.push_back(copyop(titr->get())); - } - - for(ArrayList::const_iterator vitr=geometry._vertexAttribList.begin(); - vitr!=geometry._vertexAttribList.end(); - ++vitr) - { - _vertexAttribList.push_back(copyop(vitr->get())); - } - - if ((copyop.getCopyFlags() & osg::CopyOp::DEEP_COPY_ARRAYS)) - { - if (_useVertexBufferObjects) - { - // copying of arrays doesn't set up buffer objects so we'll need to force - // Geometry to assign these, we'll do this by switching off VBO's then renabling them. - setUseVertexBufferObjects(false); - setUseVertexBufferObjects(true); - } - } - -} - -GeometryNew::~GeometryNew() -{ - // do dirty here to keep the getGLObjectSizeHint() estimate on the ball - dirtyDisplayList(); - - // no need to delete, all automatically handled by ref_ptr :-) -} - -#define ARRAY_NOT_EMPTY(array) (array!=0 && array->getNumElements()!=0) - -bool GeometryNew::empty() const -{ - if (!_primitives.empty()) return false; - if (ARRAY_NOT_EMPTY(_vertexArray.get())) return false; - if (ARRAY_NOT_EMPTY(_normalArray.get())) return false; - if (ARRAY_NOT_EMPTY(_colorArray.get())) return false; - if (ARRAY_NOT_EMPTY(_secondaryColorArray.get())) return false; - if (ARRAY_NOT_EMPTY(_fogCoordArray.get())) return false; - if (!_texCoordList.empty()) return false; - if (!_vertexAttribList.empty()) return false; - return true; -} - -void GeometryNew::setVertexArray(Array* array) -{ - _vertexArray = array; - - dirtyDisplayList(); - dirtyBound(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -void GeometryNew::setNormalArray(Array* array) -{ - _normalArray = array; - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -void GeometryNew::setColorArray(Array* array) -{ - _colorArray = array; - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -void GeometryNew::setSecondaryColorArray(Array* array) -{ - _secondaryColorArray = array; - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -void GeometryNew::setFogCoordArray(Array* array) -{ - _fogCoordArray = array; - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -#define SET_BINDING(array)\ - if (!array) \ - { \ - OSG_NOTICE<<"Warning, can't assign attribute binding as no has been array assigned to set binding for."<getBinding() == static_cast(ab)) return; \ - array->setBinding(static_cast(ab)); - - -#define GET_BINDING(array) (array!=0 ? static_cast(array->getBinding()) : BIND_OFF) - - -void GeometryNew::setNormalBinding(AttributeBinding ab) -{ - SET_BINDING(_normalArray.get()) - - dirtyDisplayList(); -} - -GeometryNew::AttributeBinding GeometryNew::getNormalBinding() const -{ - return GET_BINDING(_normalArray.get()); -} - -void GeometryNew::setColorBinding(AttributeBinding ab) -{ - SET_BINDING(_colorArray.get()) - - dirtyDisplayList(); -} - -GeometryNew::AttributeBinding GeometryNew::getColorBinding() const -{ - return GET_BINDING(_colorArray.get()); -} - -void GeometryNew::setSecondaryColorBinding(AttributeBinding ab) -{ - SET_BINDING(_secondaryColorArray.get()) - - dirtyDisplayList(); -} - -GeometryNew::AttributeBinding GeometryNew::getSecondaryColorBinding() const -{ - return GET_BINDING(_secondaryColorArray.get()); -} - -void GeometryNew::setFogCoordBinding(AttributeBinding ab) -{ - SET_BINDING(_fogCoordArray.get()) - - dirtyDisplayList(); -} - -GeometryNew::AttributeBinding GeometryNew::getFogCoordBinding() const -{ - return GET_BINDING(_fogCoordArray.get()); -} - - -void GeometryNew::setTexCoordArray(unsigned int index,Array* array) -{ - if (_texCoordList.size()<=index) - _texCoordList.resize(index+1); - - _texCoordList[index] = array; - - // do we set to array BIND_PER_VERTEX? - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) - { - addVertexBufferObjectIfRequired(array); - } -} - -Array* GeometryNew::getTexCoordArray(unsigned int index) -{ - if (index<_texCoordList.size()) return _texCoordList[index].get(); - else return 0; -} - -const Array* GeometryNew::getTexCoordArray(unsigned int index) const -{ - if (index<_texCoordList.size()) return _texCoordList[index].get(); - else return 0; -} - - -void GeometryNew::setVertexAttribArray(unsigned int index, Array* array) -{ - if (_vertexAttribList.size()<=index) - _vertexAttribList.resize(index+1); - - _vertexAttribList[index] = array; - - dirtyDisplayList(); - - if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); -} - -Array *GeometryNew::getVertexAttribArray(unsigned int index) -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].get(); - else return 0; -} - -const Array *GeometryNew::getVertexAttribArray(unsigned int index) const -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].get(); - else return 0; -} - -void GeometryNew::setVertexAttribBinding(unsigned int index,AttributeBinding ab) -{ - if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) - { - if (_vertexAttribList[index]->getBinding()==static_cast(ab)) return; - - _vertexAttribList[index]->setBinding(static_cast(ab)); - - dirtyDisplayList(); - } - else - { - OSG_NOTICE<<"Warning, can't assign attribute binding as no has been array assigned to set binding for."<(_vertexAttribList[index]->getBinding()); - else return BIND_OFF; -} - -void GeometryNew::setVertexAttribNormalize(unsigned int index,GLboolean norm) -{ - if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) - { - _vertexAttribList[index]->setNormalize(norm); - - dirtyDisplayList(); - } -} - -GLboolean GeometryNew::getVertexAttribNormalize(unsigned int index) const -{ - if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) return _vertexAttribList[index]->getNormalize(); - else return GL_FALSE; -} - -bool GeometryNew::addPrimitiveSet(PrimitiveSet* primitiveset) -{ - if (primitiveset) - { - if (_useVertexBufferObjects) addElementBufferObjectIfRequired(primitiveset); - - _primitives.push_back(primitiveset); - dirtyDisplayList(); - dirtyBound(); - return true; - } - OSG_WARN<<"Warning: invalid index i or primitiveset passed to osg::GeometryNew::addPrimitiveSet(i,primitiveset), ignoring call."<getTotalDataSize(); - - if (_normalArray.valid()) totalSize += _normalArray->getTotalDataSize(); - - if (_colorArray.valid()) totalSize += _colorArray->getTotalDataSize(); - - if (_secondaryColorArray.valid()) totalSize += _secondaryColorArray->getTotalDataSize(); - - if (_fogCoordArray.valid()) totalSize += _fogCoordArray->getTotalDataSize(); - - - unsigned int unit; - for(unit=0;unit<_texCoordList.size();++unit) - { - const Array* array = _texCoordList[unit].get(); - if (array) totalSize += array->getTotalDataSize(); - - } - - bool handleVertexAttributes = true; - if (handleVertexAttributes) - { - unsigned int index; - for( index = 0; index < _vertexAttribList.size(); ++index ) - { - const Array* array = _vertexAttribList[index].get(); - if (array) totalSize += array->getTotalDataSize(); - } - } - - for(PrimitiveSetList::const_iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - - totalSize += 4*(*itr)->getNumIndices(); - - } - - - // do a very simply mapping of display list size proportional to vertex datasize. - return totalSize; -} - -bool GeometryNew::getArrayList(ArrayList& arrayList) const -{ - unsigned int startSize = arrayList.size(); - - if (_vertexArray.valid()) arrayList.push_back(_vertexArray.get()); - if (_normalArray.valid()) arrayList.push_back(_normalArray.get()); - if (_colorArray.valid()) arrayList.push_back(_colorArray.get()); - if (_secondaryColorArray.valid()) arrayList.push_back(_secondaryColorArray.get()); - if (_fogCoordArray.valid()) arrayList.push_back(_fogCoordArray.get()); - - for(unsigned int unit=0;unit<_texCoordList.size();++unit) - { - Array* array = _texCoordList[unit].get(); - if (array) arrayList.push_back(array); - } - - for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) - { - Array* array = _vertexAttribList[index].get(); - if (array) arrayList.push_back(array); - } - - return arrayList.size()!=startSize; -} - -bool GeometryNew::getDrawElementsList(DrawElementsList& drawElementsList) const -{ - unsigned int startSize = drawElementsList.size(); - - for(PrimitiveSetList::const_iterator itr = _primitives.begin(); - itr != _primitives.end(); - ++itr) - { - osg::DrawElements* de = (*itr)->getDrawElements(); - if (de) drawElementsList.push_back(de); - } - - return drawElementsList.size()!=startSize; -} - -void GeometryNew::addVertexBufferObjectIfRequired(osg::Array* array) -{ - if (_useVertexBufferObjects) - { - if (!array->getVertexBufferObject()) - { - array->setVertexBufferObject(getOrCreateVertexBufferObject()); - } - } -} - -void GeometryNew::addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet) -{ - if (_useVertexBufferObjects) - { - osg::DrawElements* drawElements = primitiveSet->getDrawElements(); - if (drawElements && !drawElements->getElementBufferObject()) - { - drawElements->setElementBufferObject(getOrCreateElementBufferObject()); - } - } -} - -osg::VertexBufferObject* GeometryNew::getOrCreateVertexBufferObject() -{ - ArrayList arrayList; - getArrayList(arrayList); - - ArrayList::iterator vitr; - for(vitr = arrayList.begin(); - vitr != arrayList.end(); - ++vitr) - { - osg::Array* array = vitr->get(); - if (array->getVertexBufferObject()) return array->getVertexBufferObject(); - } - - return new osg::VertexBufferObject; -} - -osg::ElementBufferObject* GeometryNew::getOrCreateElementBufferObject() -{ - DrawElementsList drawElementsList; - getDrawElementsList(drawElementsList); - - DrawElementsList::iterator deitr; - for(deitr = drawElementsList.begin(); - deitr != drawElementsList.end(); - ++deitr) - { - osg::DrawElements* elements = *deitr; - if (elements->getElementBufferObject()) return elements->getElementBufferObject(); - } - - return new osg::ElementBufferObject; -} - -void GeometryNew::setUseVertexBufferObjects(bool flag) -{ - // flag = true; - - // OSG_NOTICE<<"GeometryNew::setUseVertexBufferObjects("< VertexBufferObjectList; - typedef std::vector ElementBufferObjectList; - - if (_useVertexBufferObjects) - { - if (!arrayList.empty()) - { - - VertexBufferObjectList vboList; - - osg::ref_ptr vbo; - - ArrayList::iterator vitr; - for(vitr = arrayList.begin(); - vitr != arrayList.end() && !vbo; - ++vitr) - { - osg::Array* array = vitr->get(); - if (array->getVertexBufferObject()) vbo = array->getVertexBufferObject(); - } - - if (!vbo) vbo = new osg::VertexBufferObject; - - for(vitr = arrayList.begin(); - vitr != arrayList.end(); - ++vitr) - { - osg::Array* array = vitr->get(); - if (!array->getVertexBufferObject()) array->setVertexBufferObject(vbo.get()); - } - } - - if (!drawElementsList.empty()) - { - ElementBufferObjectList eboList; - - osg::ref_ptr ebo; - - DrawElementsList::iterator deitr; - for(deitr = drawElementsList.begin(); - deitr != drawElementsList.end(); - ++deitr) - { - osg::DrawElements* elements = *deitr; - if (elements->getElementBufferObject()) ebo = elements->getElementBufferObject(); - } - - if (!ebo) ebo = new osg::ElementBufferObject; - - for(deitr = drawElementsList.begin(); - deitr != drawElementsList.end(); - ++deitr) - { - osg::DrawElements* elements = *deitr; - if (!elements->getElementBufferObject()) elements->setElementBufferObject(ebo.get()); - } - } - } - else - { - for(ArrayList::iterator vitr = arrayList.begin(); - vitr != arrayList.end(); - ++vitr) - { - osg::Array* array = vitr->get(); - if (array->getVertexBufferObject()) array->setVertexBufferObject(0); - } - - for(DrawElementsList::iterator deitr = drawElementsList.begin(); - deitr != drawElementsList.end(); - ++deitr) - { - osg::DrawElements* elements = *deitr; - if (elements->getElementBufferObject()) elements->setElementBufferObject(0); - } - } -} - -void GeometryNew::dirtyDisplayList() -{ - Drawable::dirtyDisplayList(); -} - -void GeometryNew::resizeGLObjectBuffers(unsigned int maxSize) -{ - Drawable::resizeGLObjectBuffers(maxSize); - - ArrayList arrays; - if (getArrayList(arrays)) - { - for(ArrayList::iterator itr = arrays.begin(); - itr != arrays.end(); - ++itr) - { - (*itr)->resizeGLObjectBuffers(maxSize); - } - } - - DrawElementsList drawElements; - if (getDrawElementsList(drawElements)) - { - for(DrawElementsList::iterator itr = drawElements.begin(); - itr != drawElements.end(); - ++itr) - { - (*itr)->resizeGLObjectBuffers(maxSize); - } - } -} - -void GeometryNew::releaseGLObjects(State* state) const -{ - Drawable::releaseGLObjects(state); - - ArrayList arrays; - if (getArrayList(arrays)) - { - for(ArrayList::iterator itr = arrays.begin(); - itr != arrays.end(); - ++itr) - { - (*itr)->releaseGLObjects(state); - } - } - - DrawElementsList drawElements; - if (getDrawElementsList(drawElements)) - { - for(DrawElementsList::iterator itr = drawElements.begin(); - itr != drawElements.end(); - ++itr) - { - (*itr)->releaseGLObjects(state); - } - } - -} - -void GeometryNew::compileGLObjects(RenderInfo& renderInfo) const -{ - bool useVertexArrays = _supportsVertexBufferObjects && - _useVertexBufferObjects && - renderInfo.getState()->isVertexBufferObjectSupported(); - if (useVertexArrays) - { - // OSG_NOTICE<<"GeometryNew::compileGLObjects() use VBO's "< BufferObjects; - BufferObjects bufferObjects; - - // first collect all the active unique BufferObjects - if (_vertexArray.valid() && _vertexArray->getBufferObject()) bufferObjects.insert(_vertexArray->getBufferObject()); - if (_normalArray.valid() && _normalArray->getBufferObject()) bufferObjects.insert(_normalArray->getBufferObject()); - if (_colorArray.valid() && _colorArray->getBufferObject()) bufferObjects.insert(_colorArray->getBufferObject()); - if (_secondaryColorArray.valid() && _secondaryColorArray->getBufferObject()) bufferObjects.insert(_secondaryColorArray->getBufferObject()); - if (_fogCoordArray.valid() && _fogCoordArray->getBufferObject()) bufferObjects.insert(_fogCoordArray->getBufferObject()); - - for(ArrayList::const_iterator itr = _texCoordList.begin(); - itr != _texCoordList.end(); - ++itr) - { - if (itr->valid() && (*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject()); - } - - for(ArrayList::const_iterator itr = _vertexAttribList.begin(); - itr != _vertexAttribList.end(); - ++itr) - { - if (itr->valid() && (*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject()); - } - - for(PrimitiveSetList::const_iterator itr = _primitives.begin(); - itr != _primitives.end(); - ++itr) - { - if ((*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject()); - } - - //osg::ElapsedTime timer; - - // now compile any buffer objects that require it. - for(BufferObjects::iterator itr = bufferObjects.begin(); - itr != bufferObjects.end(); - ++itr) - { - GLBufferObject* glBufferObject = (*itr)->getOrCreateGLBufferObject(contextID); - if (glBufferObject && glBufferObject->isDirty()) - { - // OSG_NOTICE<<"Compile buffer "<compileBuffer(); - } - } - - // OSG_NOTICE<<"Time to compile "<glBindBuffer(GL_ARRAY_BUFFER_ARB,0); - extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0); - - } - else - { - Drawable::compileGLObjects(renderInfo); - } -} - -void GeometryNew::drawImplementation(RenderInfo& renderInfo) const -{ - State& state = *renderInfo.getState(); - - bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE; - if (checkForGLErrors) state.checkGLErrors("start of GeometryNew::drawImplementation()"); - - bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); - bool handleVertexAttributes = !_vertexAttribList.empty(); - - ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers(); - - arrayDispatchers.reset(); - arrayDispatchers.setUseVertexAttribAlias(state.getUseVertexAttributeAliasing()); - arrayDispatchers.setUseGLBeginEndAdapter(false); - - arrayDispatchers.activateNormalArray(_normalArray.get()); - arrayDispatchers.activateColorArray(_colorArray.get()); - arrayDispatchers.activateSecondaryColorArray(_secondaryColorArray.get()); - arrayDispatchers.activateFogCoordArray(_fogCoordArray.get()); - - if (handleVertexAttributes) - { - for(unsigned int unit=0;unit<_vertexAttribList.size();++unit) - { - arrayDispatchers.activateVertexAttribArray(unit, _vertexAttribList[unit].get()); - } - } - - // dispatch any attributes that are bound overall - arrayDispatchers.dispatch(BIND_OVERALL,0); - - state.lazyDisablingOfVertexAttributes(); - - // set up arrays - if( _vertexArray.valid() ) - state.setVertexPointer(_vertexArray.get()); - - if (_normalArray.valid() && _normalArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setNormalPointer(_normalArray.get()); - - if (_colorArray.valid() && _colorArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setColorPointer(_colorArray.get()); - - if (_secondaryColorArray.valid() && _secondaryColorArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setSecondaryColorPointer(_secondaryColorArray.get()); - - if (_fogCoordArray.valid() && _fogCoordArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setFogCoordPointer(_fogCoordArray.get()); - - for(unsigned int unit=0;unit<_texCoordList.size();++unit) - { - const Array* array = _texCoordList[unit].get(); - if (array) state.setTexCoordPointer(unit,array); - } - - if( handleVertexAttributes ) - { - for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) - { - const Array* array = _vertexAttribList[index].get(); - if(array && array->getBinding()==osg::Array::BIND_PER_VERTEX) - { - state.setVertexAttribPointer( index, array, _vertexAttribList[index]->getNormalize() ); - } - } - } - - state.applyDisablingOfVertexAttributes(); - - bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET); - - if (checkForGLErrors) state.checkGLErrors("GeometryNew::drawImplementation() after vertex arrays setup."); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - for(unsigned int primitiveSetNum=0; primitiveSetNum!=_primitives.size(); ++primitiveSetNum) - { - // dispatch any attributes that are bound per primitive - if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum); - - const PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get(); - - primitiveset->draw(state, usingVertexBufferObjects); - } - - // unbind the VBO's if any are used. - state.unbindVertexBufferObject(); - state.unbindElementBufferObject(); - - if (checkForGLErrors) state.checkGLErrors("end of GeometryNew::drawImplementation()."); -} - -class AttributeFunctorArrayVisitor : public ArrayVisitor -{ - public: - - AttributeFunctorArrayVisitor(Drawable::AttributeFunctor& af): - _af(af), - _type(0) {} - - virtual ~AttributeFunctorArrayVisitor() {} - - virtual void apply(ByteArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(ShortArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(IntArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(UByteArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(UShortArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(UIntArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(Vec4ubArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - virtual void apply(FloatArray& array) { if (!array.empty()) _af.apply(_type,array.size(),&(array.front())); } - 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) - { - if (array) - { - _type = type; - array->accept(*this); - } - } - - protected: - - AttributeFunctorArrayVisitor& operator = (const AttributeFunctorArrayVisitor&) { return *this; } - Drawable::AttributeFunctor& _af; - Drawable::AttributeType _type; -}; - -void GeometryNew::accept(AttributeFunctor& af) -{ - AttributeFunctorArrayVisitor afav(af); - - if (_vertexArray.valid()) - { - afav.applyArray(VERTICES,_vertexArray.get()); - } - else if (_vertexAttribList.size()>0) - { - OSG_INFO<<"GeometryNew::accept(AttributeFunctor& af): Using vertex attribute instead"<accept(*this); - } - } - -protected: - - ConstAttributeFunctorArrayVisitor& operator = (const ConstAttributeFunctorArrayVisitor&) { return *this; } - - Drawable::ConstAttributeFunctor& _af; - Drawable::AttributeType _type; -}; - -void GeometryNew::accept(ConstAttributeFunctor& af) const -{ - ConstAttributeFunctorArrayVisitor afav(af); - - if (_vertexArray.valid()) - { - afav.applyArray(VERTICES,_vertexArray.get()); - } - else if (_vertexAttribList.size()>0) - { - OSG_INFO<<"GeometryNew::accept(ConstAttributeFunctor& af): Using vertex attribute instead"<0) - { - OSG_INFO<<"Using vertex attribute instead"<getNumElements()==0) return; - - switch(vertices->getType()) - { - case(Array::Vec2ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec2dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - default: - OSG_WARN<<"Warning: GeometryNew::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<getType()<accept(functor); - } -} - -void GeometryNew::accept(PrimitiveIndexFunctor& functor) const -{ - const osg::Array* vertices = _vertexArray.get(); - - if (!vertices && _vertexAttribList.size()>0) - { - OSG_INFO<<"GeometryNew::accept(PrimitiveIndexFunctor& functor): Using vertex attribute instead"<getNumElements()==0) return; - - switch(vertices->getType()) - { - case(Array::Vec2ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec2dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - default: - OSG_WARN<<"Warning: GeometryNew::accept(PrimitiveIndexFunctor&) cannot handle Vertex Array type"<getType()<accept(functor); - } -} - -GeometryNew* osg::createTexturedQuadGeometryNew(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t) -{ - GeometryNew* geom = new GeometryNew; - - Vec3Array* coords = new Vec3Array(4); - (*coords)[0] = corner+heightVec; - (*coords)[1] = corner; - (*coords)[2] = corner+widthVec; - (*coords)[3] = corner+widthVec+heightVec; - geom->setVertexArray(coords); - - Vec2Array* tcoords = new Vec2Array(4); - (*tcoords)[0].set(l,t); - (*tcoords)[1].set(l,b); - (*tcoords)[2].set(r,b); - (*tcoords)[3].set(r,t); - geom->setTexCoordArray(0,tcoords); - - osg::Vec4Array* colours = new osg::Vec4Array(1); - (*colours)[0].set(1.0f,1.0f,1.0,1.0f); - geom->setColorArray(colours); - geom->setColorBinding(GeometryNew::BIND_OVERALL); - - osg::Vec3Array* normals = new osg::Vec3Array(1); - (*normals)[0] = widthVec^heightVec; - (*normals)[0].normalize(); - geom->setNormalArray(normals); - geom->setNormalBinding(GeometryNew::BIND_OVERALL); - -#if defined(OSG_GLES1_AVAILABLE) || !defined(OSG_GLES2_AVAILABLE) - DrawElementsUByte* elems = new DrawElementsUByte(PrimitiveSet::TRIANGLES); - elems->push_back(0); - elems->push_back(1); - elems->push_back(2); - - elems->push_back(2); - elems->push_back(3); - elems->push_back(0); - geom->addPrimitiveSet(elems); -#else - geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS,0,4)); -#endif - - return geom; -}