chore: remove stb as dependency
This commit is contained in:
		
							parent
							
								
									f47afbdbcc
								
							
						
					
					
						commit
						b570653c82
					
				
					 4 changed files with 0 additions and 74 deletions
				
			
		| 
						 | 
					@ -30,7 +30,6 @@ class LightRecipe(ConanFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def requirements(self):
 | 
					    def requirements(self):
 | 
				
			||||||
        self.requires("entt/3.15.0")
 | 
					        self.requires("entt/3.15.0")
 | 
				
			||||||
        self.requires("stb/cci.20240531")
 | 
					 | 
				
			||||||
        self.requires("lz4/1.10.0")
 | 
					        self.requires("lz4/1.10.0")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def layout(self):
 | 
					    def layout(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,5 @@ add_executable_module(
 | 
				
			||||||
target_link_libraries(
 | 
					target_link_libraries(
 | 
				
			||||||
    asset_baker
 | 
					    asset_baker
 | 
				
			||||||
    PRIVATE asset_parser
 | 
					    PRIVATE asset_parser
 | 
				
			||||||
    PRIVATE stb::stb
 | 
					 | 
				
			||||||
    PRIVATE logger
 | 
					    PRIVATE logger
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,9 +7,6 @@
 | 
				
			||||||
#include <string_view>
 | 
					#include <string_view>
 | 
				
			||||||
#include <unordered_set>
 | 
					#include <unordered_set>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define STB_IMAGE_IMPLEMENTATION
 | 
					 | 
				
			||||||
#include <stb_image.h>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace lt {
 | 
					namespace lt {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Loader
 | 
					class Loader
 | 
				
			||||||
| 
						 | 
					@ -42,78 +39,11 @@ public:
 | 
				
			||||||
	    = 0;
 | 
						    = 0;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
class StbLoader: public TextureLoader
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
	StbLoader() = default;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	void load(std::filesystem::path path);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[[nodiscard]] static auto get_supported_extensions() -> std::unordered_set<std::string_view>
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		return { ".png" };
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[[nodiscard]] auto get_name() const -> std::string_view override
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		return "StbLoader";
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[[nodiscard]] auto load(std::filesystem::path file_path) const
 | 
					 | 
				
			||||||
	    -> Assets::TextureAsset::PackageData override
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		auto width = int {};
 | 
					 | 
				
			||||||
		auto height = int {};
 | 
					 | 
				
			||||||
		auto channels = int {};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		auto *pixels = stbi_load(file_path.string().c_str(), &width, &height, &channels, 4);
 | 
					 | 
				
			||||||
		if (!pixels)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			throw std::runtime_error {
 | 
					 | 
				
			||||||
				std::format("Failed to load image file at: {} using stbi_load", file_path.string()),
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		const auto metadata = Assets::Asset::Metadata {
 | 
					 | 
				
			||||||
			.type = Assets::Asset::Type::Texture,
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		const auto texture_metadata = Assets::TextureAsset::Metadata {
 | 
					 | 
				
			||||||
            .format = Assets::TextureAsset::Format::RGBA8,
 | 
					 | 
				
			||||||
            .num_components = static_cast<uint32_t>(channels),
 | 
					 | 
				
			||||||
            .pixel_size = {
 | 
					 | 
				
			||||||
                static_cast<uint32_t>(width),
 | 
					 | 
				
			||||||
                static_cast<uint32_t>(height),
 | 
					 | 
				
			||||||
                {},
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		auto pixels_blob = Assets::Blob {};
 | 
					 | 
				
			||||||
		pixels_blob.resize(static_cast<size_t>(width) * height * channels);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// TODO(Light): figure out if it's possible to directly populate a blob with stbi functions
 | 
					 | 
				
			||||||
		memcpy(pixels_blob.data(), pixels, pixels_blob.size());
 | 
					 | 
				
			||||||
		stbi_image_free(pixels);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return Assets::TextureAsset::PackageData {
 | 
					 | 
				
			||||||
			.metadata = metadata,
 | 
					 | 
				
			||||||
			.texture_metadata = texture_metadata,
 | 
					 | 
				
			||||||
			.pixels = std::move(pixels_blob),
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class TextureLoaderFactory
 | 
					class TextureLoaderFactory
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	static auto create(std::string_view file_extension) -> std::unique_ptr<TextureLoader>
 | 
						static auto create(std::string_view file_extension) -> std::unique_ptr<TextureLoader>
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (StbLoader::get_supported_extensions().contains(file_extension))
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return std::make_unique<StbLoader>();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return {};
 | 
							return {};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,2 @@
 | 
				
			||||||
find_package(stb REQUIRED)
 | 
					 | 
				
			||||||
find_package(yaml-cpp REQUIRED)
 | 
					 | 
				
			||||||
find_package(EnTT REQUIRED)
 | 
					find_package(EnTT REQUIRED)
 | 
				
			||||||
find_package(lz4 REQUIRED)
 | 
					find_package(lz4 REQUIRED)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue