diff --git a/include/osg/GLBeginEndAdapter b/include/osg/GLBeginEndAdapter index c3abbef88..2cee4eeea 100644 --- a/include/osg/GLBeginEndAdapter +++ b/include/osg/GLBeginEndAdapter @@ -70,6 +70,7 @@ class OSG_EXPORT GLBeginEndAdapter void Color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + _overallColorAssigned = true; _colorAssigned = true; _color.set(red,green,blue,alpha); } @@ -80,6 +81,7 @@ class OSG_EXPORT GLBeginEndAdapter void Normal3f(GLfloat x, GLfloat y, GLfloat z) { + _overallNormalAssigned = true; _normalAssigned = true; _normal.set(x,y,z); } @@ -125,6 +127,8 @@ class OSG_EXPORT GLBeginEndAdapter void Begin(GLenum mode); void End(); + void reset(); + protected: State* _state; @@ -140,6 +144,8 @@ class OSG_EXPORT GLBeginEndAdapter bool _colorAssigned; osg::Vec4f _color; + bool _overallNormalAssigned; + bool _overallColorAssigned; osg::Vec3f _overallNormal; osg::Vec4f _overallColor; diff --git a/src/osg/ArrayDispatchers.cpp b/src/osg/ArrayDispatchers.cpp index 0b2c43fdf..b8fad399c 100644 --- a/src/osg/ArrayDispatchers.cpp +++ b/src/osg/ArrayDispatchers.cpp @@ -578,7 +578,9 @@ void ArrayDispatchers::reset() if (!_initialized) init(); _useVertexAttribAlias = false; - _useGLBeginEndAdapter = false; + + _useGLBeginEndAdapter = false; + _glBeginEndAdapter->reset(); for(ActiveDispatchList::iterator itr = _activeDispatchList.begin(); itr != _activeDispatchList.end(); diff --git a/src/osg/GLBeginEndAdapter.cpp b/src/osg/GLBeginEndAdapter.cpp index ae6ca8f3d..0a7782682 100644 --- a/src/osg/GLBeginEndAdapter.cpp +++ b/src/osg/GLBeginEndAdapter.cpp @@ -25,6 +25,8 @@ GLBeginEndAdapter::GLBeginEndAdapter(State* state): _normal(0.0f,0.0f,1.0f), _colorAssigned(false), _color(1.0f,1.0f,1.0f,1.0f), + _overallNormalAssigned(false), + _overallColorAssigned(false), _primitiveMode(0) { } @@ -249,7 +251,7 @@ void GLBeginEndAdapter::End() { _state->setColorPointer(_colors.get()); } - else + else if (_overallColorAssigned) { _state->Color(_overallColor.r(), _overallColor.g(), _overallColor.b(), _overallColor.a()); } @@ -258,7 +260,7 @@ void GLBeginEndAdapter::End() { _state->setNormalPointer(_normals.get()); } - else + else if (_overallNormalAssigned) { _state->Normal(_overallNormal.x(), _overallNormal.y(), _overallNormal.z()); } @@ -296,3 +298,9 @@ void GLBeginEndAdapter::End() else if (_primitiveMode==GL_POLYGON) glDrawArrays(GL_TRIANGLE_FAN, 0, _vertices->size()); else glDrawArrays(_primitiveMode, 0, _vertices->size()); } + +void GLBeginEndAdapter::reset() +{ + _overallNormalAssigned = false; + _overallColorAssigned = false; +}