/* -*- 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
/*
 *
 * Copyright (C) 2007 Loic Dachary <loic@dachary.org>
 * Copyright (C) 2004, 2006 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Authors:
 *  Cedric PINSON <cpinson@freesheep.org>
 *  Loic Dachary <loic@gnu.org>
 *  Igor Kravtchenko <igor@tsarevitch.org>
 *
 */
#ifndef __OSGCAL__SUBMESHSOFTWARE_H__
#define __OSGCAL__SUBMESHSOFTWARE_H__

#include <osg/Version>
#include <osg/Geometry>
#include <osg/PrimitiveSet>
#include <osgCal/Export>

class CalSubmesh;
class CalRenderer;
class CalModel;

namespace osgCal {

class OSGCAL_EXPORT SubMeshSoftware : public osg::Geometry {
protected:
  virtual ~SubMeshSoftware();

public:
  META_Object(osgCal, SubMeshSoftware);

  SubMeshSoftware();
  SubMeshSoftware(CalModel* calModel, int meshId, int submeshId);
  SubMeshSoftware(const SubMeshSoftware&, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);

  bool create(void);
  bool update(void);

#if OSG_VERSION_MAJOR != 2
  virtual void drawImplementation(osg::State& arg) const;
#else // OSG_VERSION_MAJOR != 2
  virtual void drawImplementation(osg::RenderInfo& arg) const;
#endif // OSG_VERSION_MAJOR != 2
#if OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2
  virtual bool computeBound() const;
#else // OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2
  virtual osg::BoundingBox computeBound() const;
#endif // OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2

#if OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2
  inline virtual bool supports(osg::Drawable::PrimitiveFunctor&) const { return _supportsPrimitiveFunctor; }
#else // OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2
  inline virtual bool supports(osg::PrimitiveFunctor&) const { return _supportsPrimitiveFunctor; }
#endif // OSG_VERSION_RELEASE != 9 && OSG_VERSION_MAJOR != 1 && OSG_VERSION_MAJOR != 2

  // no bounding box, no picking if set to false (saves lots of computing)
  inline void setSupportsPrimitiveFunctor(bool supportsPrimitiveFunctor) { _supportsPrimitiveFunctor = supportsPrimitiveFunctor; }
  // the mesh is not drawn ()
  inline bool isInvisible() const { return _invisible; }
  inline void setInvisible(bool invisible) { _invisible = invisible; }

  const std::string& getName(void) const { return mName; }
  void setName(const std::string& name) { mName = name; }

  const std::string& getMaterialName(void) { return mMaterialName; }
  void setMaterialName(const std::string& materialName) { mMaterialName = materialName; }

  osg::BoundingBox _staticbbox;
protected:

  bool _supportsPrimitiveFunctor;
  bool _invisible;
  int _coreMeshId;
  int _coreSubmeshId;
  CalModel* _calModel;
  std::string mName;
  std::string mMaterialName;
};

};

#endif
