Added texture packer for automatically creating texture atlas on build.
This commit is contained in:
47
private/texture_packer/packer.hpp
Normal file
47
private/texture_packer/packer.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(SDL_GPU_TEST_PRIVATE_TEXTURE_PACKER_PACKER_HPP_INCLUDED)
|
||||
#define SDL_GPU_TEST_PRIVATE_TEXTURE_PACKER_PACKER_HPP_INCLUDED 1
|
||||
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace sdl_gpu_test
|
||||
{
|
||||
struct FreeDeleter
|
||||
{
|
||||
void operator()(void* ptr) noexcept
|
||||
{
|
||||
std::free(ptr);
|
||||
}
|
||||
};
|
||||
|
||||
class Packer
|
||||
{
|
||||
private:
|
||||
struct Pixel
|
||||
{
|
||||
std::uint8_t r;
|
||||
std::uint8_t g;
|
||||
std::uint8_t b;
|
||||
std::uint8_t a;
|
||||
};
|
||||
struct ImageData
|
||||
{
|
||||
std::string name;
|
||||
std::unique_ptr<Pixel[], FreeDeleter> data;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
};
|
||||
|
||||
std::vector<ImageData> mImages;
|
||||
public:
|
||||
void addImage(const fs::path& path);
|
||||
void pack(const fs::path& outputPath);
|
||||
};
|
||||
} // namespace sdl_gpu_test
|
||||
|
||||
#endif // !defined(SDL_GPU_TEST_PRIVATE_TEXTURE_PACKER_PACKER_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user