Changeset 10621

Show
Ignore:
Timestamp:
10/09/09 15:39:11 (4 years ago)
Author:
robert
Message:

Introduced new uniforms for tracking the modelview and project matrices in shaders using non built-ins.

Location:
OpenSceneGraph/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgvertexattributes/osgvertexattributes.cpp

    r10620 r10621  
    5252        } 
    5353 
    54         void replaceAndBind(osg::Program& program, std::string& source, const std::string& originalStr, const AttributeAlias& alias, const std::string& declarationPrefix) 
     54        void replaceAndBindAttrib(osg::Program& program, std::string& source, const std::string& originalStr, const AttributeAlias& alias, const std::string& declarationPrefix) 
    5555        { 
    5656            if (replace(source, originalStr, alias.second)) 
     
    6161        } 
    6262 
     63        void replaceBuiltInUniform(std::string& source, const std::string& originalStr, const std::string& newStr, const std::string& declarationPrefix) 
     64        { 
     65            if (replace(source, originalStr, newStr)) 
     66            { 
     67                source.insert(0, declarationPrefix + newStr + std::string(";\n")); 
     68            } 
     69        } 
     70 
    6371        void convertVertexShader(osg::Program& program, osg::Shader& shader) 
    6472        { 
     
    6876            replace(source, "ftransform()", "gl_ModelViewProjectionMatrix * gl_Vertex"); 
    6977 
    70             replaceAndBind(program, source, "gl_Normal", _normalAlias, "attribute vec3 "); 
    71             replaceAndBind(program, source, "gl_Vertex", _vertexAlias, "attribute vec4 "); 
    72             replaceAndBind(program, source, "gl_Color", _colorAlias, "attribute vec4 "); 
    73             replaceAndBind(program, source, "gl_SecondaryColor", _secondaryColorAlias, "attribute vec4 "); 
    74             replaceAndBind(program, source, "gl_FogCoord", _fogCoordAlias, "attribute float "); 
    75  
    76             replaceAndBind(program, source, "gl_MultiTexCoord0", _texCoordAlias[0], "attribute vec4 "); 
    77             replaceAndBind(program, source, "gl_MultiTexCoord1", _texCoordAlias[1], "attribute vec4 "); 
    78             replaceAndBind(program, source, "gl_MultiTexCoord2", _texCoordAlias[2], "attribute vec4 "); 
    79             replaceAndBind(program, source, "gl_MultiTexCoord3", _texCoordAlias[3], "attribute vec4 "); 
    80             replaceAndBind(program, source, "gl_MultiTexCoord4", _texCoordAlias[4], "attribute vec4 "); 
    81             replaceAndBind(program, source, "gl_MultiTexCoord5", _texCoordAlias[5], "attribute vec4 "); 
    82             replaceAndBind(program, source, "gl_MultiTexCoord6", _texCoordAlias[6], "attribute vec4 "); 
    83             replaceAndBind(program, source, "gl_MultiTexCoord7", _texCoordAlias[7], "attribute vec4 "); 
     78            replaceAndBindAttrib(program, source, "gl_Normal", _normalAlias, "attribute vec3 "); 
     79            replaceAndBindAttrib(program, source, "gl_Vertex", _vertexAlias, "attribute vec4 "); 
     80            replaceAndBindAttrib(program, source, "gl_Color", _colorAlias, "attribute vec4 "); 
     81            replaceAndBindAttrib(program, source, "gl_SecondaryColor", _secondaryColorAlias, "attribute vec4 "); 
     82            replaceAndBindAttrib(program, source, "gl_FogCoord", _fogCoordAlias, "attribute float "); 
     83 
     84            replaceAndBindAttrib(program, source, "gl_MultiTexCoord0", _texCoordAlias[0], "attribute vec4 "); 
     85            replaceAndBindAttrib(program, source, "gl_MultiTexCoord1", _texCoordAlias[1], "attribute vec4 "); 
     86            replaceAndBindAttrib(program, source, "gl_MultiTexCoord2", _texCoordAlias[2], "attribute vec4 "); 
     87            replaceAndBindAttrib(program, source, "gl_MultiTexCoord3", _texCoordAlias[3], "attribute vec4 "); 
     88            replaceAndBindAttrib(program, source, "gl_MultiTexCoord4", _texCoordAlias[4], "attribute vec4 "); 
     89            replaceAndBindAttrib(program, source, "gl_MultiTexCoord5", _texCoordAlias[5], "attribute vec4 "); 
     90            replaceAndBindAttrib(program, source, "gl_MultiTexCoord6", _texCoordAlias[6], "attribute vec4 "); 
     91            replaceAndBindAttrib(program, source, "gl_MultiTexCoord7", _texCoordAlias[7], "attribute vec4 "); 
    8492 
    8593 
     
    8997            replace(source, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix"); 
    9098            replace(source, "gl_ProjectionMatrix", "osg_ProjectionMatrix"); 
     99#else 
     100            // replace built in uniform 
     101            replaceBuiltInUniform(source, "gl_ModelViewMatrix", "osg_ModeViewMatrix", "uniform mat4 "); 
     102            replaceBuiltInUniform(source, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix", "uniform mat4 "); 
     103            replaceBuiltInUniform(source, "gl_ProjectionMatrix", "osg_ProjectionMatrix", "uniform mat4 "); 
    91104#endif 
    92105            shader.setShaderSource(source); 
  • OpenSceneGraph/trunk/include/osg/State

    r10601 r10621  
    167167            if (_projection!=matrix) 
    168168            { 
     169                if (matrix) 
     170                { 
     171                    _projection=matrix; 
     172                } 
     173                else 
     174                { 
     175                    _projection=_identity; 
     176                } 
     177 
     178                if (_projectionMatrixUniform.valid()) _projectionMatrixUniform->set(*_projection); 
     179                if (_modelViewProjectionMatrixUniform.valid()) _modelViewProjectionMatrixUniform->set((*_modelView) * (*_projection)); 
     180 
    169181                glMatrixMode( GL_PROJECTION ); 
     182                    glLoadMatrix(_projection->ptr()); 
     183                glMatrixMode( GL_MODELVIEW ); 
     184            } 
     185        } 
     186 
     187        inline const osg::Matrix& getProjectionMatrix() const 
     188        { 
     189            return *_projection; 
     190        } 
     191 
     192        inline void applyModelViewMatrix(const osg::RefMatrix* matrix) 
     193        { 
     194            if (_modelView!=matrix) 
     195            { 
    170196                if (matrix) 
    171197                { 
    172                     _projection=matrix; 
    173                     glLoadMatrix(matrix->ptr()); 
     198                    _modelView=matrix; 
    174199                } 
    175200                else 
    176201                { 
    177                     _projection=_identity; 
    178                     glLoadIdentity(); 
    179                 } 
    180                 glMatrixMode( GL_MODELVIEW ); 
    181             } 
    182         } 
    183  
    184         inline const osg::Matrix& getProjectionMatrix() const 
    185         { 
    186             return *_projection; 
    187         } 
    188  
    189         inline void applyModelViewMatrix(const osg::RefMatrix* matrix) 
    190         { 
    191             if (_modelView!=matrix) 
    192             { 
    193                 if (matrix) 
    194                 { 
    195                     _modelView=matrix; 
    196                     glLoadMatrix(matrix->ptr()); 
    197                 } 
    198                 else 
    199                 { 
    200202                    _modelView=_identity; 
    201                     glLoadIdentity(); 
    202                 } 
     203                } 
     204 
     205                if (_modelViewMatrixUniform.valid()) _modelViewMatrixUniform->set(*_modelView); 
     206                if (_modelViewProjectionMatrixUniform.valid()) _modelViewProjectionMatrixUniform->set((*_modelView) * (*_projection)); 
     207 
     208                glLoadMatrix(_modelView->ptr()); 
    203209            } 
    204210        } 
     
    208214            return *_modelView; 
    209215        } 
     216 
     217        void applyModelViewAndProjectionUniformsIfRequired(); 
     218 
     219        osg::Uniform* getModelViewMatrixUniform() { return _modelViewMatrixUniform.get(); } 
     220        osg::Uniform* getProjectionMatrixUniform() { return _projectionMatrixUniform.get(); } 
     221        osg::Uniform* getModelViewProjectionMatrixUniform() { return _modelViewProjectionMatrixUniform.get(); } 
    210222 
    211223 
     
    10881100        ref_ptr<const RefMatrix>    _projection; 
    10891101        ref_ptr<const RefMatrix>    _modelView; 
     1102 
     1103        ref_ptr<Uniform>            _modelViewMatrixUniform; 
     1104        ref_ptr<Uniform>            _projectionMatrixUniform; 
     1105        ref_ptr<Uniform>            _modelViewProjectionMatrixUniform; 
    10901106 
    10911107        Matrix                      _initialInverseViewMatrix; 
  • OpenSceneGraph/trunk/src/osg/Geometry.cpp

    r10615 r10621  
    21152115    AttributeFunctorArrayVisitor afav(af); 
    21162116 
    2117     afav.applyArray(VERTICES,_vertexData.array.get()); 
     2117    if (_vertexData.array.valid()) 
     2118    { 
     2119        afav.applyArray(VERTICES,_vertexData.array.get()); 
     2120    } 
     2121    else if (_vertexAttribList.size()>0) 
     2122    { 
     2123        osg::notify(osg::INFO)<<"Geometry::accept(AttributeFunctor& af): Using vertex attribute instead"<<std::endl; 
     2124        afav.applyArray(VERTICES,_vertexAttribList[0].array.get()); 
     2125    } 
     2126 
    21182127    afav.applyArray(NORMALS,_normalData.array.get()); 
    21192128    afav.applyArray(COLORS,_colorData.array.get()); 
     
    21792188    ConstAttributeFunctorArrayVisitor afav(af); 
    21802189     
    2181     afav.applyArray(VERTICES,_vertexData.array.get()); 
     2190    if (_vertexData.array.valid()) 
     2191    { 
     2192        afav.applyArray(VERTICES,_vertexData.array.get()); 
     2193    } 
     2194    else if (_vertexAttribList.size()>0) 
     2195    { 
     2196        osg::notify(osg::INFO)<<"Geometry::accept(ConstAttributeFunctor& af): Using vertex attribute instead"<<std::endl; 
     2197        afav.applyArray(VERTICES,_vertexAttribList[0].array.get()); 
     2198    } 
     2199 
    21822200    afav.applyArray(NORMALS,_normalData.array.get()); 
    21832201    afav.applyArray(COLORS,_colorData.array.get()); 
     
    21982216void Geometry::accept(PrimitiveFunctor& functor) const 
    21992217{ 
    2200     if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) return; 
    2201  
    2202     if (!_vertexData.indices.valid()) 
    2203     { 
    2204         switch(_vertexData.array->getType()) 
     2218    const osg::Array* vertices = _vertexData.array.get(); 
     2219    const osg::IndexArray* indices = _vertexData.indices.get(); 
     2220 
     2221    if (!vertices && _vertexAttribList.size()>0) 
     2222    { 
     2223        osg::notify(osg::INFO)<<"Using vertex attribute instead"<<std::endl; 
     2224        vertices = _vertexAttribList[0].array.get(); 
     2225        indices = _vertexAttribList[0].indices.get(); 
     2226    } 
     2227 
     2228    if (!vertices || vertices->getNumElements()==0) return; 
     2229 
     2230    if (!indices) 
     2231    { 
     2232        switch(vertices->getType()) 
    22052233        { 
    22062234        case(Array::Vec2ArrayType):  
    2207             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2*>(_vertexData.array->getDataPointer())); 
     2235            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2*>(vertices->getDataPointer())); 
    22082236            break; 
    22092237        case(Array::Vec3ArrayType):  
    2210             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3*>(_vertexData.array->getDataPointer())); 
     2238            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3*>(vertices->getDataPointer())); 
    22112239            break; 
    22122240        case(Array::Vec4ArrayType):  
    2213             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4*>(_vertexData.array->getDataPointer())); 
     2241            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4*>(vertices->getDataPointer())); 
    22142242            break; 
    22152243        case(Array::Vec2dArrayType):  
    2216             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2d*>(_vertexData.array->getDataPointer())); 
     2244            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2d*>(vertices->getDataPointer())); 
    22172245            break; 
    22182246        case(Array::Vec3dArrayType):  
    2219             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3d*>(_vertexData.array->getDataPointer())); 
     2247            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3d*>(vertices->getDataPointer())); 
    22202248            break; 
    22212249        case(Array::Vec4dArrayType):  
    2222             functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4d*>(_vertexData.array->getDataPointer())); 
     2250            functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4d*>(vertices->getDataPointer())); 
    22232251            break; 
    22242252        default: 
    2225             notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl; 
     2253            notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl; 
    22262254            return; 
    22272255        } 
     
    22422270        const Vec3d* vec3dArray = 0; 
    22432271        const Vec4d* vec4dArray = 0; 
    2244         Array::Type type = _vertexData.array->getType(); 
     2272        Array::Type type = vertices->getType(); 
    22452273        switch(type) 
    22462274        { 
    22472275        case(Array::Vec2ArrayType):  
    2248             vec2Array = static_cast<const Vec2*>(_vertexData.array->getDataPointer()); 
     2276            vec2Array = static_cast<const Vec2*>(vertices->getDataPointer()); 
    22492277            break; 
    22502278        case(Array::Vec3ArrayType):  
    2251             vec3Array = static_cast<const Vec3*>(_vertexData.array->getDataPointer()); 
     2279            vec3Array = static_cast<const Vec3*>(vertices->getDataPointer()); 
    22522280            break; 
    22532281        case(Array::Vec4ArrayType):  
    2254             vec4Array = static_cast<const Vec4*>(_vertexData.array->getDataPointer()); 
     2282            vec4Array = static_cast<const Vec4*>(vertices->getDataPointer()); 
    22552283            break; 
    22562284        case(Array::Vec2dArrayType):  
    2257             vec2dArray = static_cast<const Vec2d*>(_vertexData.array->getDataPointer()); 
     2285            vec2dArray = static_cast<const Vec2d*>(vertices->getDataPointer()); 
    22582286            break; 
    22592287        case(Array::Vec3dArrayType):  
    2260             vec3dArray = static_cast<const Vec3d*>(_vertexData.array->getDataPointer()); 
     2288            vec3dArray = static_cast<const Vec3d*>(vertices->getDataPointer()); 
    22612289            break; 
    22622290        case(Array::Vec4dArrayType):  
    2263             vec4dArray = static_cast<const Vec4d*>(_vertexData.array->getDataPointer()); 
     2291            vec4dArray = static_cast<const Vec4d*>(vertices->getDataPointer()); 
    22642292            break; 
    22652293        default: 
    2266             notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl; 
     2294            notify(WARN)<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl; 
    22672295            return; 
    22682296        } 
    22692297 
    2270      
    22712298        for(PrimitiveSetList::const_iterator itr=_primitives.begin(); 
    22722299            itr!=_primitives.end(); 
     
    23122339 
    23132340                    } 
    2314                      
     2341 
    23152342                    functor.end(); 
    23162343                    break; 
     
    23552382                            ++vindex; 
    23562383                        } 
    2357                          
     2384 
    23582385                        functor.end(); 
    23592386 
     
    24882515void Geometry::accept(PrimitiveIndexFunctor& functor) const 
    24892516{ 
    2490     if (!_vertexData.array.valid() || _vertexData.array->getNumElements()==0) return; 
    2491  
    2492     switch(_vertexData.array->getType()) 
     2517    const osg::Array* vertices = _vertexData.array.get(); 
     2518    const osg::IndexArray* indices = _vertexData.indices.get(); 
     2519 
     2520    if (!vertices && _vertexAttribList.size()>0) 
     2521    { 
     2522        osg::notify(osg::INFO)<<"Geometry::accept(PrimitiveIndexFunctor& functor): Using vertex attribute instead"<<std::endl; 
     2523        vertices = _vertexAttribList[0].array.get(); 
     2524        indices = _vertexAttribList[0].indices.get(); 
     2525    } 
     2526 
     2527    if (!vertices || vertices->getNumElements()==0) return; 
     2528 
     2529    switch(vertices->getType()) 
    24932530    { 
    24942531    case(Array::Vec2ArrayType):  
    2495         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2*>(_vertexData.array->getDataPointer())); 
     2532        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2*>(vertices->getDataPointer())); 
    24962533        break; 
    24972534    case(Array::Vec3ArrayType):  
    2498         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3*>(_vertexData.array->getDataPointer())); 
     2535        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3*>(vertices->getDataPointer())); 
    24992536        break; 
    25002537    case(Array::Vec4ArrayType):  
    2501         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4*>(_vertexData.array->getDataPointer())); 
     2538        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4*>(vertices->getDataPointer())); 
    25022539        break; 
    25032540    case(Array::Vec2dArrayType):  
    2504         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec2d*>(_vertexData.array->getDataPointer())); 
     2541        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec2d*>(vertices->getDataPointer())); 
    25052542        break; 
    25062543    case(Array::Vec3dArrayType):  
    2507         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec3d*>(_vertexData.array->getDataPointer())); 
     2544        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec3d*>(vertices->getDataPointer())); 
    25082545        break; 
    25092546    case(Array::Vec4dArrayType):  
    2510         functor.setVertexArray(_vertexData.array->getNumElements(),static_cast<const Vec4d*>(_vertexData.array->getDataPointer())); 
     2547        functor.setVertexArray(vertices->getNumElements(),static_cast<const Vec4d*>(vertices->getDataPointer())); 
    25112548        break; 
    25122549    default: 
    2513         notify(WARN)<<"Warning: Geometry::accept(PrimitiveIndexFunctor&) cannot handle Vertex Array type"<<_vertexData.array->getType()<<std::endl; 
     2550        notify(WARN)<<"Warning: Geometry::accept(PrimitiveIndexFunctor&) cannot handle Vertex Array type"<<vertices->getType()<<std::endl; 
    25142551        return; 
    25152552    } 
  • OpenSceneGraph/trunk/src/osg/State.cpp

    r10614 r10621  
    4545    _modelView = _identity; 
    4646 
     47    _modelViewMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewMatrix"); 
     48    _projectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ProjectionMatrix"); 
     49    _modelViewProjectionMatrixUniform = new Uniform(Uniform::FLOAT_MAT4,"osg_ModelViewProjectionMatrix"); 
     50 
    4751    _abortRenderingPtr = false;     
    4852 
     
    9195    _maxTexturePoolSize = 0; 
    9296    _maxBufferObjectPoolSize = 0; 
     97 
     98 
    9399} 
    94100 
     
    421427    //popStateSet(); 
    422428    //return; 
    423      
     429 
    424430    if (dstate) 
    425431    { 
     
    441447                if (unit<ds_textureModeList.size()) applyModeList(getOrCreateTextureModeMap(unit),ds_textureModeList[unit]); 
    442448                else if (unit<_textureModeMapList.size()) applyModeMap(_textureModeMapList[unit]); 
    443                  
     449 
    444450                if (unit<ds_textureAttributeList.size()) applyAttributeList(getOrCreateTextureAttributeMap(unit),ds_textureAttributeList[unit]); 
    445451                else if (unit<_textureAttributeMapList.size()) applyAttributeMap(_textureAttributeMapList[unit]); 
    446452            } 
    447453        } 
    448          
    449 #if 1         
     454 
    450455        applyUniformList(_uniformMap,dstate->getUniformList()); 
    451 #else                 
    452         if (_lastAppliedProgramObject) 
    453         { 
    454             for(StateSetStack::iterator sitr=_stateStateStack.begin(); 
    455                 sitr!=_stateStateStack.end(); 
    456                 ++sitr) 
    457             { 
    458                 const StateSet* stateset = *sitr; 
    459                 const StateSet::UniformList& uniformList = stateset->getUniformList(); 
    460                 for(StateSet::UniformList::const_iterator itr=uniformList.begin(); 
    461                     itr!=uniformList.end(); 
    462                     ++itr) 
    463                 { 
    464                     _lastAppliedProgramObject->apply(*(itr->second.first)); 
    465                 } 
    466             } 
    467  
    468             const StateSet::UniformList& uniformList = dstate->getUniformList(); 
    469             for(StateSet::UniformList::const_iterator itr=uniformList.begin(); 
    470                 itr!=uniformList.end(); 
    471                 ++itr) 
    472             { 
    473                 _lastAppliedProgramObject->apply(*(itr->second.first)); 
    474             } 
    475         } 
    476 #endif 
    477  
    478456    } 
    479457    else 
     
    509487    } 
    510488 
    511 #if 1         
    512489    applyUniformMap(_uniformMap); 
    513 #else         
    514     if (_lastAppliedProgramObject && !_stateStateStack.empty()) 
    515     { 
    516         for(StateSetStack::iterator sitr=_stateStateStack.begin(); 
    517             sitr!=_stateStateStack.end(); 
    518             ++sitr) 
    519         { 
    520             const StateSet* stateset = *sitr; 
    521             const StateSet::UniformList& uniformList = stateset->getUniformList(); 
    522             for(StateSet::UniformList::const_iterator itr=uniformList.begin(); 
    523                 itr!=uniformList.end(); 
    524                 ++itr) 
    525             { 
    526                 _lastAppliedProgramObject->apply(*(itr->second.first)); 
    527             } 
    528         } 
    529     } 
    530 #endif 
    531  
    532490 
    533491    if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors("end of State::apply()"); 
     
    1034992 
    1035993 
     994void State::applyModelViewAndProjectionUniformsIfRequired() 
     995{ 
     996    if (!_lastAppliedProgramObject) return; 
     997 
     998    if (_modelViewMatrixUniform.valid()) _lastAppliedProgramObject->apply(*_modelViewMatrixUniform); 
     999    if (_projectionMatrixUniform) _lastAppliedProgramObject->apply(*_projectionMatrixUniform); 
     1000    if (_modelViewProjectionMatrixUniform) _lastAppliedProgramObject->apply(*_modelViewProjectionMatrixUniform); 
     1001} 
  • OpenSceneGraph/trunk/src/osgUtil/RenderLeaf.cpp

    r7328 r10621  
    5555 
    5656        } 
    57          
     57 
     58        // if we are using osg::Program which requires OSG's generated uniforms to track 
     59        // modelview and projection matrices then apply them now. 
     60        state.applyModelViewAndProjectionUniformsIfRequired(); 
    5861 
    5962        // draw the drawable 
     
    7174        state.apply(_parent->getStateSet()); 
    7275 
     76        // if we are using osg::Program which requires OSG's generated uniforms to track 
     77        // modelview and projection matrices then apply them now. 
     78        state.applyModelViewAndProjectionUniformsIfRequired(); 
     79 
    7380        // draw the drawable 
    7481        _drawable->draw(renderInfo);