Source

dbsdev / sources / opengl2_samples / test7_simplerenderer / GLMesh.cpp

Full commit
// /////////////////////////////////////////////////////////////////////// //
// Copyright (c) 2012, Davide Bacchet (davide.bacchet@gmail.com)           //
// All rights reserved.                                                    //
//                                                                         //
// The software is released under the Creative Commons Attribution         //
// NonCommercial (CC BY-NC) license. The full license text is available    //
// at http://creativecommons.org/licenses/by-nc/3.0/legalcode              //
//                                                                         //
// You are free to distribute and adapt the work under the conditions:     //
// * Redistributions of source code must retain the above copyright notice //
// * You must attribute the work in the manner specified by the author     //
// * You may not use this work for commercial purposes.                    //
//                                                                         //
// Commercial Usage:                                                       //
// To use this software as part of a commercial product, you must          //
// obtain a written agreement from the author.                             //
// /////////////////////////////////////////////////////////////////////// //

// BF mesh class

#include <vector>
#include <string>

#include "GLMaterial.h"
#include "GLMesh.h"
    
// standard constructor
GLSubMesh::GLSubMesh()
{
    init();
}


// copy constructor
GLSubMesh::GLSubMesh(const GLSubMesh &sm)
{
    init();
    material  = sm.material;
    indices   = sm.indices;
    vertices  = sm.vertices;
}


// destructor
GLSubMesh::~GLSubMesh()
{
}
    

// basic initialization
void GLSubMesh::init( void )
{
    // default values
    indices.clear();
    vertices.clear();
    material = NULL;
}




// //////// //
//   MESH   //
// //////// //



/// standard constructor
GLMesh::GLMesh()
{
    init();
}


// copy constructor
GLMesh::GLMesh(const GLMesh &mesh)
{
    submeshes = mesh.submeshes;
}


// destructor
GLMesh::~GLMesh()
{
    
}


// basic initialization
void GLMesh::init( void )
{
    submeshes.clear();
}


// add a submesh
bool GLMesh::addSubMesh( const GLSubMesh &sm )
{
    submeshes.push_back(sm);
    return true;
}

    
// remove a submesh by index
bool GLMesh::removeSubMeshByIndex( unsigned int idx )
{
    if (idx>=submeshes.size())
        return false;
    submeshes.erase(submeshes.begin()+idx);
    return true;
}