#pragma once
#include "sokol_gfx.h"
#include "geometry/rect.h"
#include <Eigen/Eigen>

#include "texture_map_types.h"

struct texture_data {
	virtual               ~texture_data() = default;

	Eigen::Vector2i       size;
	sg_pixel_format       pixel_format;
	virtual sg_image_data get_image_data() const = 0;
};

class texture {
public:
	virtual      ~texture() = default;

	void create_from_desc(const sg_image_desc& in_desc);

	virtual void create(const texture_data& in_data) = 0;
	virtual void update(const sg_image_data& in_data) = 0;
	virtual void resize(const Eigen::Vector2i& in_size) = 0;


	void                      clear();

	[[nodiscard]] bool        is_valid() const { return image_.id != SG_INVALID_ID; }
	[[nodiscard]] const auto& get_image() const { return image_; }
	[[nodiscard]] auto        get_image_desc() const { return sg_query_image_desc(image_); }

	[[nodiscard]] Eigen::Vector2i get_size() const;
	[[nodiscard]] sg_pixel_format get_pixel_format() const;
	[[nodiscard]] int32_t get_bytes_per_pixel() const;
protected:
	void set_image(const sg_image& in_image) { image_ = in_image; }
private:
	sg_image image_{};
};
