/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program 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 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser 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, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */

#ifndef KEOS_TEXTURE_H
#define KEOS_TEXTURE_H

#include "KeosTextureBase.h"
#include "KeosRectangle.h"

namespace Keos
{   
    //-----------------------------------------------------------------------
    /** Wrapper class for the ITextureBase.
     *
     */
    class KEOS_EXPORT CTexture
    {
    public :

        /** Create an empty texture.
         *  @param Size Dimensions.
         *  @param Format Pixel format.
         *  @param nFlags Load options (default 0).
         *  @param strName Name associated to the texture (default "").
         */
        void Create(const TVector2I& Size, TPixelFormat Format, ulong nFlags = 0, const String& strName = "");

        /** Create texture from a file.
         *  @param strFilename Path of the file.
         *  @param Format Pixel format.
         *  @param nFlags Load options (default 0).
         */
        void CreateFromFile(const String& strFilename, TPixelFormat Format, ulong nFlags = 0);

        /** Create texture from an image.
         *  @param Image Image to be loaded.
         *  @param Format Pixel format.
         *  @param nFlags Load options (default 0).
         *  @param strName Name associated to the texture (default "").
         */
        void CreateFromImage(const CImage& Image, TPixelFormat Format, ulong nFlags = 0, const String& strName = "");

        /** Save the texture in a file.
         *  @param strFilename Path of the target file.
         */
        void SaveToFile(const String& strFilename) const;

        /** Update the pixels of the texture.
         *  @param Rect Rectangle to update in the texture (default (-1,-1,-1,-1)).
         */
        void Update(const CRectangle& Rect = CRectangle(-1, -1, -1, -1));

        /** Return an image with the pixels of the texture.
         */
        CImage& GetPixels();

        /** Return the dimensions of the texture.
         */
        const TVector2I& GetSize() const;

        /** Return the format of the texture.
         */
        TPixelFormat GetFormat() const;

        /** Return the name associated to the texture.
         */
        const String& GetName() const;

        /** Return a pointer on the intern texture.
         */
        const ITextureBase* GetTexture() const;

        /** == operator.
         */
        bool operator ==(const CTexture& Texture) const;

        /** != operator.
         */
        bool operator !=(const CTexture& Texture) const;

    private :

        /** Create the texture and fills it with pixels spent in parameter.
         *  @param Image Pixels to be copied in the texture.
         *  @param Format Pixel format.
         *  @param nFlags Load options.
         *  @param strName Name associated to the texture.
         */
        void Load(const CImage& Image, TPixelFormat Format, ulong nFlags, const String& strName);

        //! Pointer on the texture
        CSmartPtr<ITextureBase, CCOMRefCounted> m_Texture;
    };

} // namespace Keos


#endif // KEOS_TEXTURE_H
