//
//  SuperTuxKart - a fun racing game with go-kart
//  Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
//  Copyright (C) 2010-2015 Steve Baker, Joerg Henrichs
//
//  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 3
//  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.

#ifndef HEADER_MATERIAL_HPP
#define HEADER_MATERIAL_HPP

#include "../utils/no_copy.h"

#include <assert.h>
#include <map>
#include <string>
#include <vector>

namespace irr
{
    namespace video { class ITexture; class SMaterial; }
    namespace scene { class ISceneNode; class IMeshBuffer; }
}
using namespace irr;

class XMLNode;


/**
  * \ingroup graphics
  */
class Material : public NoCopy
{
public:
    enum ShaderType
    {
        SHADERTYPE_SOLID,
        SHADERTYPE_ALPHA_TEST,
        SHADERTYPE_ALPHA_BLEND,
        SHADERTYPE_ADDITIVE,
        SHADERTYPE_SOLID_UNLIT,
        /** Effect that makes grass wave as in the wind */
        SHADERTYPE_VEGETATION,
        SHADERTYPE_WATER,
        SHADERTYPE_SPHERE_MAP,
        SHADERTYPE_NORMAL_MAP,
        SHADERTYPE_DETAIL_MAP,
        SHADERTYPE_SPLATTING,
        SHADERTYPE_COUNT,
    };



private:

    /** Pointer to the texture. */
    video::ITexture *m_texture;

    /** Name of the texture. */
    std::string      m_texname;

    std::string      m_full_path;

    /** If true, the texture will not automatically be loaded and bound
     *  at load time, it must be loaded elsewhere. This is used to store
     *  material settings for font textures, without loading fonts for
     *  languages that might not be needed at all. */
    bool             m_lazy_load;


    ShaderType       m_shader_type;


    /** For normal maps */
    std::string      m_normal_map_tex;






    bool  m_deprecated;

    void  init    ();
    void  install (bool is_full_path=false, bool complain_if_not_found=true);

public:
          Material(const XMLNode *node, bool deprecated);
          Material(const std::string& fname,
                   bool is_full_path=false,
                   bool complain_if_not_found=true,
                   bool load_texture = true);
         ~Material ();

    void  setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
    void onMadeVisible(scene::IMeshBuffer* who);
    void onHidden(scene::IMeshBuffer* who);
    void isInitiallyHidden(scene::IMeshBuffer* who);

    /** Returns the ITexture associated with this material. */
    video::ITexture *getTexture() const
    {
        // Note that atm lazy load means that the textures are not loaded
        // via the material. So getTexture should only get called for non
        // lazily loaded textures (used atm for font textures.
        assert(!m_lazy_load);
        return m_texture;
    }   // getTexture
    // ------------------------------------------------------------------------
    const std::string&
          getTexFname        () const { return m_texname;            }
    // ------------------------------------------------------------------------
    const std::string&
          getTexFullPath     () const { return m_full_path;          }

    // ------------------------------------------------------------------------
    bool  isTransparent      () const
    {
        return m_shader_type == SHADERTYPE_ADDITIVE ||
               m_shader_type == SHADERTYPE_ALPHA_BLEND ||
               m_shader_type == SHADERTYPE_ALPHA_TEST;
    }

    // ------------------------------------------------------------------------
    ShaderType getShaderType() const { return m_shader_type; }
    // ------------------------------------------------------------------------
} ;


#endif

/* EOF */

