Exemplo n.º 1
0
void create_glod_object_from_vertex_buffers(S32 object, S32 group, std::vector<LLPointer <LLVertexBuffer> >& vertex_buffers)
{
	glodNewGroup(group);
	stop_gloderror();
	glodNewObject(object, group, GLOD_DISCRETE);
	stop_gloderror();

	for (U32 i = 0; i < vertex_buffers.size(); ++i)
	{
		vertex_buffers[i]->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
		
		U32 num_indices = vertex_buffers[i]->getNumIndices();
		
		if (num_indices > 2)
		{
			glodInsertElements(object, i, GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT,
							   vertex_buffers[i]->getIndicesPointer(), 0, 0.f);
		}
		stop_gloderror();
	}
	
	glodBuildObject(object);
	stop_gloderror();
}
Exemplo n.º 2
0
void GLODMesh::buildObjectTrianlge( const osg::PrimitiveSet* p_set, const osg::IndexArray* p_indices )
{
    GLvoid* p_indexdata = p_indices ? const_cast< GLvoid* >( p_indices->getDataPointer() ) : const_cast< GLvoid* >( p_set->getDataPointer() );
    if ( !p_indexdata )
    {
        log_warning << "cannot create LOD, no index array available" << std::endl;
        return;
    }

    //! FIXME: it seems that there is no simple way to determine which array data type is used in PrimitiveSet, currently we assume short
    GLenum  indextype   = p_indices ? p_indices->getType() : GL_SHORT;

    // apply the LOD settings to mesh
    _p_lodSettings->apply( this );

    unsigned int numindices = p_set->getNumIndices();

    // enable all arrays and feed them to GLOD
    glEnableClientState( GL_VERTEX_ARRAY );
    osg::Array* p_verts = _p_geometry->getVertexArray();
    glVertexPointer( p_verts->getDataSize(), p_verts[ 0 ].getDataType(), 0, p_verts->getDataPointer() );
  
    osg::Array* p_normals = _p_geometry->getNormalArray();
    if ( p_normals && p_normals->getNumElements() )
    {
        glEnableClientState( GL_NORMAL_ARRAY );
        glNormalPointer( p_normals->getDataType(), 0, p_normals->getDataPointer() );
    }

    //! TODO: GLOD cannot handle 4 component color arrays :-(
    //osg::Array* p_colors = _p_geometry->getColorArray();
    //if ( p_colors && p_colors->getNumElements() )
    //{
    //    glEnableClientState( GL_COLOR_ARRAY );
    //    glColorPointer( p_colors->getDataSize(), p_colors->getDataType(), 0, p_colors->getDataPointer() );
    //}

    osg::Array* p_texcoords0 = _p_geometry->getTexCoordArray( 0 );
    if ( p_texcoords0 && p_texcoords0->getNumElements() )
    {
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        glTexCoordPointer( p_texcoords0->getDataSize(), p_texcoords0->getDataType(), 0, p_texcoords0->getDataPointer() );
    }

    glodInsertElements( _lodObjectName, _lodPatchName, GL_TRIANGLES, numindices, indextype, p_indexdata, 0, 0.0f );

    // remove arrays from geometry ( they are not longer needed now ), also disable gl arrays
    _p_geometry->setVertexArray( NULL );
    glDisableClientState( GL_VERTEX_ARRAY );
    if ( p_normals && p_normals->getNumElements() )
    {
        glDisableClientState( GL_NORMAL_ARRAY );
        _p_geometry->setNormalArray( NULL );
    }
    //if ( p_colors && p_colors->getNumElements() )
    //{
    //    glDisableClientState( GL_COLOR_ARRAY );
    //    _p_geometry->setColorArray( NULL );
    //}
    if ( p_texcoords0 && p_texcoords0->getNumElements() )
    {
        glDisableClientState( GL_TEXTURE_COORD_ARRAY );
        _p_geometry->setTexCoordArray( 0, NULL );
    }

    // build lod hierarchy
    glodBuildObject( _lodObjectName );

    if ( glodGetError() )
        log_warning << "error occured during LOD creation: " << std::endl; 

    ++_lodPatchName;
}