Show
Ignore:
Timestamp:
10/16/09 18:26:27 (5 years ago)
Author:
robert
Message:

Ported osg::Geometry across to supporting the aliasing of vertex, color and normal etc. calls to Vertex Attributes.

Added support for automatic aliasing of vertex, normal, color etc. arrays to Vertex Attribute equivelants.

Added new osg::GLBeginEndAdapter class for runtime conversion from glBegin/glEnd codes to vertex arrray equivelants.

Added automatic shader source conversion from gl_ to osg_ builtins.

Files:
1 modified

Legend:

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

    r10641 r10642  
    3232            osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 
    3333        { 
     34            _manualVertexAliasing = false; 
     35 
    3436            // mappings taken from http://www.opengl.org/registry/specs/NV/vertex_program.txt 
    3537            _vertexAlias = AttributeAlias(0, "osg_Vertex"); 
     
    5860            { 
    5961                source.insert(0, declarationPrefix + alias.second + std::string(";\n")); 
    60                 bindAttribute(program, alias); 
     62                if (_manualVertexAliasing) bindAttribute(program, alias); 
    6163            } 
    6264        } 
     
    7779            replace(source, "ftransform()", "gl_ModelViewProjectionMatrix * gl_Vertex"); 
    7880 
     81#if 1 
    7982            replaceAndBindAttrib(program, source, "gl_Normal", _normalAlias, "attribute vec3 "); 
    8083            replaceAndBindAttrib(program, source, "gl_Vertex", _vertexAlias, "attribute vec4 "); 
     
    9194            replaceAndBindAttrib(program, source, "gl_MultiTexCoord6", _texCoordAlias[6], "attribute vec4 "); 
    9295            replaceAndBindAttrib(program, source, "gl_MultiTexCoord7", _texCoordAlias[7], "attribute vec4 "); 
    93  
    94  
    95 #if 0 
    96             // replace the modelview and project matrices 
    97             replace(source, "gl_ModelViewMatrix", "osg_ModeViewMatrix"); 
    98             replace(source, "gl_ModelViewProjectionMatrix", "osg_ModelViewProjectionMatrix"); 
    99             replace(source, "gl_ProjectionMatrix", "osg_ProjectionMatrix"); 
    100 #else 
     96#endif 
     97 
     98#if 1 
    10199            // replace built in uniform 
    102100            replaceBuiltInUniform(source, "gl_ModelViewMatrix", "osg_ModeViewMatrix", "uniform mat4 "); 
     
    187185            _visited.insert(&stateset); 
    188186 
     187            return; 
     188 
    189189            osg::notify(osg::NOTICE)<<"Found stateset "<<&stateset<<std::endl; 
    190190            osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM)); 
     
    204204            geom.setUseDisplayList(false); 
    205205 
     206            if (!_manualVertexAliasing) return; 
     207 
    206208            osg::notify(osg::NOTICE)<<"Found geometry "<<&geom<<std::endl; 
    207209            if (geom.getVertexArray()) 
     
    213215            if (geom.getNormalArray()) 
    214216            { 
    215                 setVertexAttrib(geom, _normalAlias, geom.getNormalArray(), false, geom.getNormalBinding()); 
     217                setVertexAttrib(geom, _normalAlias, geom.getNormalArray(), true, geom.getNormalBinding()); 
    216218                geom.setNormalArray(0); 
    217219            } 
     
    232234            { 
    233235                // should we normalize the FogCoord array? Don't think so... 
    234                 setVertexAttrib(geom, _fogCoordAlias, geom.getFogCoordArray(), false, geom.getSecondaryColorBinding()); 
     236                setVertexAttrib(geom, _fogCoordAlias, geom.getFogCoordArray(), false, geom.getFogCoordBinding()); 
    235237                geom.setFogCoordArray(0); 
    236238            } 
     
    272274        Visited         _visited; 
    273275 
     276        bool           _manualVertexAliasing; 
    274277        AttributeAlias _vertexAlias; 
    275278        AttributeAlias _normalAlias; 
     
    335338    viewer.realize(); 
    336339 
    337     // switch on the uniforms that track the modelview and projection matrices 
    338     osgViewer::Viewer::Windows windows; 
    339     viewer.getWindows(windows); 
    340     for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); 
    341         itr != windows.end(); 
    342         ++itr) 
    343     { 
    344         (*itr)->getState()->setUseModelViewAndProjectionUniforms(true); 
     340 
     341    if (runConvertToVertexAttributes) 
     342    { 
     343        // switch on the uniforms that track the modelview and projection matrices 
     344        osgViewer::Viewer::Windows windows; 
     345        viewer.getWindows(windows); 
     346        for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); 
     347            itr != windows.end(); 
     348            ++itr) 
     349        { 
     350            (*itr)->getState()->setUseModelViewAndProjectionUniforms(true); 
     351            (*itr)->getState()->setUseVertexAttributeAliasing(true); 
     352        } 
    345353    } 
    346354