#pragma once #include "GraphicsTags.hpp" #include "Image.hpp" #include "Ires.hpp" #include "RcPtr.hpp" #include #include #include #include // TODO abstract texture traits such as component sizes from OpenGL struct Subregion { float u0 = 0.0f; float v0 = 0.0f; float u1 = 0.0f; float v1 = 0.0f; }; struct TextureInfo { glm::ivec2 size; Tags::TexFilter minifyingFilter = Tags::TF_Linear; Tags::TexFilter magnifyingFilter = Tags::TF_Linear; }; class Texture : public RefCounted { friend class TextureStitcher; private: TextureInfo mInfo; GLuint mHandle = 0; public: Texture() = default; ~Texture(); Texture(const Texture&) = delete; Texture& operator=(const Texture&) = delete; Texture(Texture&&) = default; Texture& operator=(Texture&&) = default; enum ErrorCode { EC_Success, EC_AlreadyInitialized, EC_FileIoFailed, EC_InvalidImage, }; ErrorCode InitFromFile(const char* filePath); ErrorCode InitFromImage(const Image& image); struct AtlasSource { std::string name; Image image; }; struct AltasElement { std::string name; Subregion subregion; glm::ivec2 subregionSize; }; enum PackingMode { PM_KeepSquare, PM_VerticalExtension, PM_HorizontalExtension, }; struct AtlasInput { std::span sources; PackingMode packingMode; }; struct AtlasOutput { std::vector elements; }; ErrorCode InitAtlas(const AtlasInput& in, AtlasOutput* out = nullptr); const TextureInfo& GetInfo() const; GLuint GetHandle() const; bool IsValid() const; }; class IresTexture : public IresObject { public: RcPtr mInstance; public: IresTexture() : IresObject(KD_Texture) {} Texture* CreateInstance() const; Texture* GetInstance(); void Write(rapidjson::Value& value, rapidjson::Document& root) const override; void Read(const rapidjson::Value& value) override; };