diff --git a/include/osg/State b/include/osg/State index 569251ddb..a2fb20886 100644 --- a/include/osg/State +++ b/include/osg/State @@ -191,6 +191,7 @@ class OSG_EXPORT State : public Referenced, public Observer inline const osg::Matrix& getProjectionMatrix() const { return *_projection; } void applyModelViewMatrix(const osg::RefMatrix* matrix); + void applyModelViewMatrix(const osg::Matrix&); const osg::Matrix& getModelViewMatrix() const { return *_modelView; } @@ -1344,6 +1345,7 @@ class OSG_EXPORT State : public Referenced, public Observer ref_ptr _initialViewMatrix; ref_ptr _projection; ref_ptr _modelView; + ref_ptr _modelViewCache; bool _useModelViewAndProjectionUniforms; ref_ptr _modelViewMatrixUniform; @@ -1647,6 +1649,8 @@ class OSG_EXPORT State : public Referenced, public Observer bool getLastAppliedMode(const ModeMap& modeMap,StateAttribute::GLMode mode) const; const StateAttribute* getLastAppliedAttribute(const AttributeMap& attributeMap,StateAttribute::Type type, unsigned int member) const; + void loadModelViewMatrix(); + mutable bool _isSecondaryColorSupportResolved; mutable bool _isSecondaryColorSupported; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 6db766df4..9fd21148f 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -45,6 +45,7 @@ State::State(): _initialViewMatrix = _identity; _projection = _identity; _modelView = _identity; + _modelViewCache = new osg::RefMatrix; #if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) _useModelViewAndProjectionUniforms = true; @@ -1296,6 +1297,19 @@ void State::applyProjectionMatrix(const osg::RefMatrix* matrix) } } +void State::loadModelViewMatrix() +{ + if (_useModelViewAndProjectionUniforms) + { + if (_modelViewMatrixUniform.valid()) _modelViewMatrixUniform->set(*_modelView); + updateModelViewAndProjectionMatrixUniforms(); + } + +#ifdef OSG_GL_MATRICES_AVAILABLE + glLoadMatrix(_modelView->ptr()); +#endif +} + void State::applyModelViewMatrix(const osg::RefMatrix* matrix) { if (_modelView!=matrix) @@ -1309,18 +1323,18 @@ void State::applyModelViewMatrix(const osg::RefMatrix* matrix) _modelView=_identity; } - if (_useModelViewAndProjectionUniforms) - { - if (_modelViewMatrixUniform.valid()) _modelViewMatrixUniform->set(*_modelView); - updateModelViewAndProjectionMatrixUniforms(); - } - -#ifdef OSG_GL_MATRICES_AVAILABLE - glLoadMatrix(_modelView->ptr()); -#endif + loadModelViewMatrix(); } } +void State::applyModelViewMatrix(const osg::Matrix& matrix) +{ + _modelViewCache->set(matrix); + _modelView = _modelViewCache; + + loadModelViewMatrix(); +} + #include void State::updateModelViewAndProjectionMatrixUniforms() diff --git a/src/osgText/Text3D.cpp b/src/osgText/Text3D.cpp index 000429edb..d0a0dc7b0 100644 --- a/src/osgText/Text3D.cpp +++ b/src/osgText/Text3D.cpp @@ -505,16 +505,16 @@ void Text3D::drawImplementation(osg::RenderInfo& renderInfo) const // ** save the previous modelview matrix - osg::ref_ptr previous(new osg::RefMatrix(state.getModelViewMatrix())); + osg::Matrix previous(state.getModelViewMatrix()); // ** get the modelview for this context - osg::ref_ptr modelview(new osg::RefMatrix(_autoTransformCache[contextID]._matrix)); + osg::Matrix modelview(_autoTransformCache[contextID]._matrix); // ** mult previous by the modelview for this context - modelview->postMult(*previous.get()); + modelview.postMult(previous); // ** apply this new modelview matrix - state.applyModelViewMatrix(modelview.get()); + state.applyModelViewMatrix(modelview); osg::GLBeginEndAdapter& gl = (state.getGLBeginEndAdapter()); @@ -603,7 +603,7 @@ void Text3D::drawImplementation(osg::RenderInfo& renderInfo) const // restore the previous modelview matrix - state.applyModelViewMatrix(previous.get()); + state.applyModelViewMatrix(previous); } void Text3D::renderPerGlyph(osg::State & state) const @@ -619,9 +619,9 @@ void Text3D::renderPerGlyph(osg::State & state) const for (it = itLine->begin(); it!=end; ++it) { - osg::ref_ptr matrix = new osg::RefMatrix(original_modelview); - matrix->preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); - state.applyModelViewMatrix(matrix.get()); + osg::Matrix matrix(original_modelview); + matrix.preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); + state.applyModelViewMatrix(matrix); // ** apply the vertex array state.setVertexPointer(it->_glyph->getVertexArray()); @@ -670,9 +670,9 @@ void Text3D::renderPerFace(osg::State & state) const LineRenderInfo::const_iterator it, end = itLine->end(); for (it = itLine->begin(); it!=end; ++it) { - osg::ref_ptr matrix = new osg::RefMatrix(original_modelview); - matrix->preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); - state.applyModelViewMatrix(matrix.get()); + osg::Matrix matrix(original_modelview); + matrix.preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); + state.applyModelViewMatrix(matrix); state.setVertexPointer(it->_glyph->getVertexArray()); @@ -693,9 +693,9 @@ void Text3D::renderPerFace(osg::State & state) const LineRenderInfo::const_iterator it, end = itLine->end(); for (it = itLine->begin(); it!=end; ++it) { - osg::ref_ptr matrix = new osg::RefMatrix(original_modelview); - matrix->preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); - state.applyModelViewMatrix(matrix.get()); + osg::Matrix matrix(original_modelview); + matrix.preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); + state.applyModelViewMatrix(matrix); state.setVertexPointer(it->_glyph->getVertexArray()); state.setNormalPointer(it->_glyph->getNormalArray()); @@ -707,7 +707,7 @@ void Text3D::renderPerFace(osg::State & state) const } } } - + state.disableNormalPointer(); // ** render all back face of the text state.Normal(0.0f,0.0f,-1.0f); @@ -718,9 +718,9 @@ void Text3D::renderPerFace(osg::State & state) const LineRenderInfo::const_iterator it, end = itLine->end(); for (it = itLine->begin(); it!=end; ++it) { - osg::ref_ptr matrix = new osg::RefMatrix(state.getModelViewMatrix()); - matrix->preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); - state.applyModelViewMatrix(matrix.get()); + osg::Matrix matrix(original_modelview); + matrix.preMultTranslate(osg::Vec3d(it->_position.x(), it->_position.y(), it->_position.z())); + state.applyModelViewMatrix(matrix); state.setVertexPointer(it->_glyph->getVertexArray());