
#ifndef SPECTRE_GRAPHICS_TEXTURE_H
#define SPECTRE_GRAPHICS_TEXTURE_H

#include <Spectre/Core/NonCopyable.h>
#include <Spectre/Math/Vector2.h>
#include <Spectre/Graphics/PixelFormat.h>
#include <Spectre/Graphics/Image.h>
#include <string>

// Basic OpenGL Texture object.

class Texture : public NonCopyable
{
public:
	enum Filter {
		Nearest			= 0x2600,
		Linear			= 0x2601,
		NearestMipmapNearest	= 0x2700,
		NearestMipmapLinear	= 0x2702,
		LinearMipmapNearest	= 0x2701,
		LinearMipmapLinear	= 0x2703,
	};

	enum WrapMode {
		Repeat			= 0x2901,
		RepeatMirror		= 0x8370,
		ClampToEdge		= 0x812F,
		ClampToBorder		= 0x812D,
	};

	Texture();
	~Texture();

	void create(unsigned width, unsigned heigth, PixelFormat format = PixelFormat::PF_RGB);

	void create(const Vector2u& size, PixelFormat format = PixelFormat::PF_RGB);

	// Create texture from image.
	void create(const Image& image);

	// Create a texture from a image file on disk.
	void create(const std::string& filename, bool isTopDown = true);

	// Destroy the texture.
	void destroy();

	bool isEmpty() const;

	const Vector2u& getSize() const;

	void update();

	void update(vec2u pos, const Image& image);

	void update(const Image& image);

	// TODO: Fixme
	Image copyToImage() const;

	void setMinFilter(enum Filter filter);

	void setMagFilter(enum Filter filter);

	void setSmooth(bool value);

	void setWrapMode(enum WrapMode mode);

	void setRepeat(bool value);

	void enable() const;

	void disable() const;

	static unsigned int getMaxSize();

	// Operators
	bool operator<(const Texture* other) const;

	bool operator!=(const Texture* other) const;

protected :

	unsigned int	m_id;

	Vector2u	m_size;

	PixelFormat	m_format;
};

#endif /* SPECTRE_GRAPHICS_TEXTURE_H */
