assets-related refactor

This commit is contained in:
MihailRis
2024-04-10 17:44:17 +03:00
parent 216e38e411
commit befc9cf09c
14 changed files with 242 additions and 202 deletions
+3 -8
View File
@@ -343,18 +343,13 @@ ImageData* _png_load(const char* file){
ImageData* png::load_image(std::string filename) {
ImageData* image (_png_load(filename.c_str()));
if (image == nullptr) {
std::cerr << "Could not load image " << filename << std::endl;
return nullptr;
throw std::runtime_error("could not load image "+filename);
}
return image;
}
Texture* png::load_texture(std::string filename) {
std::unique_ptr<ImageData> image (_png_load(filename.c_str()));
if (image == nullptr){
std::cerr << "Could not load texture " << filename << std::endl;
return nullptr;
}
std::unique_ptr<ImageData> image (load_image(filename));
auto texture = Texture::from(image.get());
texture->setNearestFilter();
return texture;
@@ -362,4 +357,4 @@ Texture* png::load_texture(std::string filename) {
void png::write_image(std::string filename, const ImageData* image) {
_png_write(filename.c_str(), image->getWidth(), image->getHeight(), (const ubyte*)image->getData(), image->getFormat() == ImageFormat::rgba8888);
}
}