...Anm2Ed 2.0
This commit is contained in:
@@ -29,9 +29,9 @@ using namespace glm;
|
||||
|
||||
namespace anm2ed::resource
|
||||
{
|
||||
bool Texture::is_valid() { return id != 0; }
|
||||
bool Texture::is_valid() const { return id != 0; }
|
||||
|
||||
size_t Texture::pixel_size_get() { return size.x * size.y * CHANNELS; }
|
||||
size_t Texture::pixel_size_get() const { return size.x * size.y * CHANNELS; }
|
||||
|
||||
void Texture::upload(const uint8_t* data)
|
||||
{
|
||||
@@ -133,6 +133,20 @@ namespace anm2ed::resource
|
||||
|
||||
bool Texture::write_png(const std::filesystem::path& path) { return write_png(path.string()); }
|
||||
|
||||
vec4 Texture::pixel_read(vec2 position) const
|
||||
{
|
||||
if (pixels.size() < CHANNELS || size.x <= 0 || size.y <= 0) return vec4(0.0f);
|
||||
|
||||
int x = glm::clamp((int)(position.x), 0, size.x - 1);
|
||||
int y = glm::clamp((int)(position.y), 0, size.y - 1);
|
||||
|
||||
auto index = ((size_t)(y) * (size_t)(size.x) + (size_t)(x)) * CHANNELS;
|
||||
if (index + CHANNELS > pixels.size()) return vec4(0.0f);
|
||||
|
||||
return vec4(uint8_to_float(pixels[index + 0]), uint8_to_float(pixels[index + 1]), uint8_to_float(pixels[index + 2]),
|
||||
uint8_to_float(pixels[index + 3]));
|
||||
}
|
||||
|
||||
void Texture::pixel_set(ivec2 position, vec4 color)
|
||||
{
|
||||
if (position.x < 0 || position.y < 0 || position.x >= size.x || position.y >= size.y) return;
|
||||
|
||||
@@ -23,10 +23,11 @@ namespace anm2ed::resource
|
||||
int channels{};
|
||||
std::vector<uint8_t> pixels{};
|
||||
|
||||
bool is_valid();
|
||||
size_t pixel_size_get();
|
||||
bool is_valid() const;
|
||||
size_t pixel_size_get() const;
|
||||
void upload();
|
||||
void upload(const uint8_t*);
|
||||
glm::vec4 pixel_read(glm::vec2) const;
|
||||
|
||||
Texture();
|
||||
~Texture();
|
||||
@@ -40,6 +41,7 @@ namespace anm2ed::resource
|
||||
Texture(const std::filesystem::path&);
|
||||
bool write_png(const std::string&);
|
||||
bool write_png(const std::filesystem::path&);
|
||||
static bool write_pixels_png(const std::filesystem::path&, glm::ivec2, const uint8_t*);
|
||||
void pixel_set(glm::ivec2, glm::vec4);
|
||||
void pixel_line(glm::ivec2, glm::ivec2, glm::vec4);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user