Changeset 10730

Show
Ignore:
Timestamp:
11/10/09 12:36:07 (4 years ago)
Author:
robert
Message:

Added support for mapping GL_QUADS, GL_QUAD_STRIP and GL_POLYGONS to GL_TRIANGLE equivalents.

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osg/GLBeginEndAdapter

    r10681 r10730  
    158158        VertexArrayList                     _texCoordsList; 
    159159        VertexArrayList                     _vertexAttribsList; 
     160 
     161        typedef std::vector<unsigned short> UShortArray; 
     162        UShortArray                         _indexArray; 
    160163}; 
    161164 
  • OpenSceneGraph/trunk/src/osg/GLBeginEndAdapter.cpp

    r10668 r10730  
    281281    _state->applyDisablingOfVertexAttributes(); 
    282282 
    283     glDrawArrays(_primitiveMode, 0, _vertices->size()); 
    284 } 
     283    if (_primitiveMode==GL_QUADS)  
     284    { 
     285        unsigned int numQuads = _vertices->size()/4; 
     286        unsigned int numIndices = numQuads * 6; 
     287        if (numIndices > _indexArray.size()) 
     288        { 
     289            // we need to expand the _indexArray to be big enough to cope with all the quads required. 
     290            unsigned int numExistingQuads = _indexArray.size()/6; 
     291            _indexArray.reserve(numIndices); 
     292            for(unsigned int i=numExistingQuads; i<numQuads; ++i) 
     293            { 
     294                unsigned int base = i*4; 
     295                _indexArray.push_back(base); 
     296                _indexArray.push_back(base+2); 
     297                _indexArray.push_back(base+1); 
     298                 
     299                _indexArray.push_back(base); 
     300                _indexArray.push_back(base+3); 
     301                _indexArray.push_back(base+2); 
     302            } 
     303        } 
     304 
     305        glDrawElements(GL_TRIANGLES, numQuads*6, GL_UNSIGNED_SHORT, &(_indexArray.front())); 
     306    } 
     307    else if (_primitiveMode==GL_QUAD_STRIP) 
     308    { 
     309        // will the winding be wrong? Do we need to swap it? 
     310        glDrawArrays(GL_TRIANGLE_STRIP, 0, _vertices->size()); 
     311    } 
     312    else if (_primitiveMode==GL_POLYGON) glDrawArrays(GL_TRIANGLE_FAN, 0, _vertices->size()); 
     313    else glDrawArrays(_primitiveMode, 0, _vertices->size()); 
     314}