#ifndef __WFX_SCENE_TEXTUREMANAGER_H__
#define __WFX_SCENE_TEXTUREMANAGER_H__

#include <WFX/WFXIncludes.h>
#include <WFX/lang/Singleton.h>
#include <WFX/io/File.h>

namespace WFX {

    namespace scene {

        class Texture {
            public:
                Texture(const WFX::io::File& f, UInt Handle);
                Texture(const WFX::io::File& f, UInt Handle, const std::string& name);
                Texture();
                ~Texture();

                /** getters/setters */
                inline UInt getHandle() const {
                    return Handle;
                }
                inline const WFX::io::File& getFile() const {
                    return File;
                }
                inline const std::string& getName() const {
                    return Name;
                }
                inline bool isLoaded() const {
                    return Loaded;
                }
                inline void setLoaded(bool b) {
                    Loaded = b;
                }
                
                /** increases the user count */
                void incUsers();
            protected:
                /** File */
                WFX::io::File File;
                /** Handle */
                UInt Handle;
                /** name */
                std::string Name;
                /** number of users */
                UInt UserCount;
                /** loaded ?*/
                bool Loaded;
            private:
        };
       

        /**
         * basic texture manager
         * TODO: implement LRU-Cache
         * TODO: implement unloading of textures
         */
        class TextureManager : public WFX::lang::Singleton<TextureManager> {
            public:
                /** Ctor */
                TextureManager();
                virtual ~TextureManager();

                /**
                 * register a Texture
                 */
//                UInt regTexture(const WFX::io::File& f);
                UInt regTexture(const std::string& name);

                /**
                 * bind a Texture,
                 * implementations need to do the actual binding here...
                 */
                virtual void bindTexture(UInt h);

                /**
                 * free a texture
                 */
                void freeTexture(UInt h);
                    
            protected:
                friend class SceneGraphSerializer;
                /** max # of textures */
                static const UInt MaxTextures;
                /** The Texture store */
                std::vector<Texture> Textures;
                /** Texture count */
                UInt TexCount;

                /** 
                 * reserves a free texture handle and returns it
                 */
                virtual UInt nextHandle();
                /** loads a texture */
                virtual bool loadTexture(const WFX::scene::Texture& t);
                /** checks whether a texture already exists */
                UInt findTexture(const WFX::io::File& f);
                
                
                
            private:
        };
        
    }
}

#endif //GUARD
