#include "texture.h"

void texture::create_from_desc(const sg_image_desc& in_desc) {
	set_image(sg_make_image(in_desc));
}

void texture::clear() {
	if (sg_isvalid()) {
		if (const auto& image = get_image(); image.id != SG_INVALID_ID)
			sg_destroy_image(image);
		image_.id = SG_INVALID_ID;
	}
}

Eigen::Vector2i texture::get_size() const {
	const auto& desc = get_image_desc();
	return Eigen::Vector2i(desc.width, desc.height);
}

sg_pixel_format texture::get_pixel_format() const {
	const auto& desc = get_image_desc();
	return desc.pixel_format;
}

int32_t texture::get_bytes_per_pixel() const {
	const auto& pixel_info = sg_query_pixelformat(get_pixel_format());
	return pixel_info.bytes_per_pixel;
}
