diff --git a/include/osg/GLBeginEndAdapter b/include/osg/GLBeginEndAdapter index 29c80592e..813193c9d 100644 --- a/include/osg/GLBeginEndAdapter +++ b/include/osg/GLBeginEndAdapter @@ -157,9 +157,6 @@ class OSG_EXPORT GLBeginEndAdapter osg::ref_ptr _colors; VertexArrayList _texCoordsList; VertexArrayList _vertexAttribsList; - - typedef std::vector UShortArray; - UShortArray _indexArray; }; } diff --git a/src/osg/GLBeginEndAdapter.cpp b/src/osg/GLBeginEndAdapter.cpp index 805a6b3b6..583e95fd9 100644 --- a/src/osg/GLBeginEndAdapter.cpp +++ b/src/osg/GLBeginEndAdapter.cpp @@ -282,27 +282,7 @@ void GLBeginEndAdapter::End() if (_primitiveMode==GL_QUADS) { - unsigned int numQuads = _vertices->size()/4; - unsigned int numIndices = numQuads * 6; - if (numIndices > _indexArray.size()) - { - // we need to expand the _indexArray to be big enough to cope with all the quads required. - unsigned int numExistingQuads = _indexArray.size()/6; - _indexArray.reserve(numIndices); - for(unsigned int i=numExistingQuads; idrawQuads(0, _vertices->size()); } else if (_primitiveMode==GL_QUAD_STRIP) { diff --git a/src/osg/PrimitiveSet.cpp b/src/osg/PrimitiveSet.cpp index 784b3f2b4..728e30e4d 100644 --- a/src/osg/PrimitiveSet.cpp +++ b/src/osg/PrimitiveSet.cpp @@ -37,8 +37,28 @@ unsigned int PrimitiveSet::getNumPrimitives() const void DrawArrays::draw(State& state, bool) const { +#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + GLenum mode = _mode; + if (_mode==GL_QUADS) + { + state.drawQuads(_first, _count, _numInstances); + return; + } + else if (mode==GL_POLYGON) + { + mode = GL_TRIANGLE_FAN; + } + else if (mode==GL_QUAD_STRIP) + { + mode = GL_TRIANGLE_STRIP; + } + + if (_numInstances>=1) state.glDrawArraysInstanced(mode,_first,_count, _numInstances); + else glDrawArrays(mode,_first,_count); +#else if (_numInstances>=1) state.glDrawArraysInstanced(_mode,_first,_count, _numInstances); else glDrawArrays(_mode,_first,_count); +#endif } void DrawArrays::accept(PrimitiveFunctor& functor) const @@ -69,16 +89,36 @@ unsigned int DrawArrayLengths::getNumPrimitives() const return 0; } -void DrawArrayLengths::draw(State&, bool) const +void DrawArrayLengths::draw(State& state, bool) const { + GLenum mode = _mode; + #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + if (_mode==GL_QUADS) + { + GLint first = _first; + for(vector_type::const_iterator itr=begin(); + itr!=end(); + ++itr) + { + state.drawQuads(first, *itr, _numInstances); + first += *itr; + } + + return; + } + if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; + if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP; + #endif + GLint first = _first; for(vector_type::const_iterator itr=begin(); itr!=end(); ++itr) { - glDrawArrays(_mode,first,*itr); + glDrawArrays(mode,first,*itr); first += *itr; } + } void DrawArrayLengths::accept(PrimitiveFunctor& functor) const @@ -124,25 +164,31 @@ DrawElementsUByte::~DrawElementsUByte() void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const { + GLenum mode = _mode; + #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; + if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP; + #endif + if (useVertexBufferObjects) { GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID()); state.bindElementBufferObject(ebo); if (ebo) { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_BYTE, &front()); } } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_BYTE, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_BYTE, &front()); } } @@ -174,25 +220,31 @@ DrawElementsUShort::~DrawElementsUShort() void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const { + GLenum mode = _mode; + #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; + if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP; + #endif + if (useVertexBufferObjects) { GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID()); state.bindElementBufferObject(ebo); if (ebo) { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_SHORT, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_SHORT, &front()); } } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_SHORT, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_SHORT, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_SHORT, &front()); } } @@ -224,25 +276,31 @@ DrawElementsUInt::~DrawElementsUInt() void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const { + GLenum mode = _mode; + #if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) + if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN; + if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP; + #endif + if (useVertexBufferObjects) { GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID()); state.bindElementBufferObject(ebo); if (ebo) { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex()))); } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_INT, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_INT, &front()); } } else { - if (_numInstances>=1) state.glDrawElementsInstanced(_mode, size(), GL_UNSIGNED_INT, &front(), _numInstances); - else glDrawElements(_mode, size(), GL_UNSIGNED_INT, &front()); + if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, &front(), _numInstances); + else glDrawElements(mode, size(), GL_UNSIGNED_INT, &front()); } } diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index a449c225c..a3aba04ae 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -1326,11 +1326,16 @@ void StateSet::setThreadSafeRefUnref(bool threadSafe) void StateSet::compileGLObjects(State& state) const { + bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE; for(AttributeList::const_iterator itr = _attributeList.begin(); itr!=_attributeList.end(); ++itr) { itr->second.first->compileGLObjects(state); + if (checkForGLErrors && state.checkGLErrors("StateSet::compileGLObejcts() compiling attribute")) + { + osg::notify(osg::NOTICE)<<" GL Error when compiling "<second.first->className()<second.first->compileGLObjects(state); + if (checkForGLErrors && state.checkGLErrors("StateSet::compileGLObejcts() compiling texture attribute")) + { + osg::notify(osg::NOTICE)<<" GL Error when compiling "<second.first->className()<