#pragma once
#include "texture.h"

struct rw_texture2d_data : texture_data {
	void* data_ptr;
	virtual sg_image_data get_image_data() const override {
		const auto& pixel_info = sg_query_pixelformat(pixel_format);
		sg_image_data data{};
		data.subimage[0][0].ptr  = data_ptr;
		data.subimage[0][0].size = size.x() * size.y() * pixel_info.bytes_per_pixel;
		return data;
	}
};

class rw_texture2d : public texture {
public:
	void create(const texture_data& in_data) override;
	void update(const sg_image_data& in_data) override;
	void resize(const Eigen::Vector2i& in_size) override;

	void sub_update(const sg_range& in_data, const rect_t<int32_t>& in_rect, uint32_t src_row_pitch = 0);
	std::vector<std::byte> read() const;
};
