/* -*- c++ -*-
   Copyright (C) 2003 <ryu@gpul.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


*/
/*
 *
 * Copyright (C) 2004 Mekensleep
 *
 *	Mekensleep
 *	24 rue vieille du temple
 *	75004 Paris
 *       licensing@mekensleep.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Authors:
 *  Cedric PINSON <cpinson@freesheep.org>
 *  Loic Dachary <loic@gnu.org>
 *
 */

#ifndef __OSGCAL__CORE_MODEL_H__
#define __OSGCAL__CORE_MODEL_H__

#include <vector>
#include <map>

#include <cal3d/cal3d.h>

#include <osg/Texture2D>
#include <osg/Referenced>
#include <osgCal/Export>

namespace osgCal {

  class OSGCAL_EXPORT CoreModel: public osg::Object {
   public:
    typedef std::vector<osg::ref_ptr<osg::Texture2D> > Textures2D;
    typedef std::map<int, Textures2D > CoreMaterialId2Textures2D;
    typedef std::map<std::string, std::string> Name2Filename;

    META_Object(osgCal, CoreModel);

    CoreModel() {}
    CoreModel(const CoreModel&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  protected:
    virtual ~CoreModel();
  public:

    CalCoreModel* getCalCoreModel(void) { return &_calCoreModel; }

    void garbageCollect(void);

    Textures2D* getTextures2D(const std::string& strFilename);
    Textures2D* getTextures2D(int materialId);

    void setMeshName2Filename(const Name2Filename& meshName2Filename) { _meshName2Filename = meshName2Filename; }
    const Name2Filename& getMeshName2Filename(void) { return _meshName2Filename; }

    void SubUsingMeshId(int coreMeshId);
    void AddUsingMeshId(int coreMeshId);

  protected:
    CalCoreModel _calCoreModel;
    CoreMaterialId2Textures2D _coreMaterialId2Textures;
    Name2Filename _meshName2Filename;
    std::map<int,int> _mReferenceCountCoreMeshIds;
  };

}; // namespace osgCal

#endif
