crash issues + fixes
This commit is contained in:
@@ -31,12 +31,24 @@ using namespace anm2ed::util::math;
|
||||
using namespace anm2ed::util;
|
||||
using namespace glm;
|
||||
|
||||
namespace anm2ed::resource::texture
|
||||
{
|
||||
std::vector<GLuint> retiredTextureIds{};
|
||||
}
|
||||
|
||||
namespace anm2ed::resource
|
||||
{
|
||||
bool Texture::is_valid() const { return id != 0; }
|
||||
|
||||
size_t Texture::pixel_size_get() const { return size.x * size.y * CHANNELS; }
|
||||
|
||||
void Texture::release()
|
||||
{
|
||||
if (!is_valid()) return;
|
||||
texture::retiredTextureIds.push_back(id);
|
||||
id = 0;
|
||||
}
|
||||
|
||||
void Texture::upload(const uint8_t* data)
|
||||
{
|
||||
if (!data || size.x <= 0 || size.y <= 0) return;
|
||||
@@ -59,10 +71,7 @@ namespace anm2ed::resource
|
||||
|
||||
Texture::Texture() = default;
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
if (is_valid()) glDeleteTextures(1, &id);
|
||||
}
|
||||
Texture::~Texture() { release(); }
|
||||
|
||||
Texture::Texture(const Texture& other) { *this = other; }
|
||||
|
||||
@@ -72,7 +81,7 @@ namespace anm2ed::resource
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (is_valid()) glDeleteTextures(1, &id);
|
||||
release();
|
||||
size = other.size;
|
||||
filter = other.filter;
|
||||
channels = other.channels;
|
||||
@@ -86,7 +95,7 @@ namespace anm2ed::resource
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (is_valid()) glDeleteTextures(1, &id);
|
||||
release();
|
||||
id = other.id;
|
||||
size = other.size;
|
||||
filter = other.filter;
|
||||
@@ -97,6 +106,13 @@ namespace anm2ed::resource
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Texture::garbage_collect()
|
||||
{
|
||||
if (texture::retiredTextureIds.empty()) return;
|
||||
glDeleteTextures((GLsizei)texture::retiredTextureIds.size(), texture::retiredTextureIds.data());
|
||||
texture::retiredTextureIds.clear();
|
||||
}
|
||||
|
||||
Texture::Texture(const char* svgData, size_t svgDataLength, ivec2 svgSize)
|
||||
{
|
||||
if (!svgData) return;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace anm2ed::resource
|
||||
|
||||
bool is_valid() const;
|
||||
size_t pixel_size_get() const;
|
||||
void release();
|
||||
void upload();
|
||||
void upload(const uint8_t*);
|
||||
glm::vec4 pixel_read(glm::vec2) const;
|
||||
@@ -40,6 +41,7 @@ namespace anm2ed::resource
|
||||
Texture(const char*, size_t, glm::ivec2);
|
||||
Texture(const std::filesystem::path&);
|
||||
bool write_png(const std::filesystem::path&);
|
||||
static void garbage_collect();
|
||||
static bool write_pixels_png(const std::filesystem::path&, glm::ivec2, const uint8_t*);
|
||||
static Texture merge_append(const Texture&, const Texture&, bool);
|
||||
void pixel_set(glm::ivec2, glm::vec4);
|
||||
|
||||
Reference in New Issue
Block a user