diff options
author | rtk0c <[email protected]> | 2023-10-19 22:50:07 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2025-08-16 11:31:16 -0700 |
commit | 297232d21594b138bb368a42b5b0d085ff9ed6aa (patch) | |
tree | 075d5407e1e12a9d35cbee6e4c20ad34e0765c42 /src/brussel.engine/Texture.hpp | |
parent | d5cd34ff69f7fd134d5450696f298af1a864afbc (diff) |
The great renaming: switch to "module style"
Diffstat (limited to 'src/brussel.engine/Texture.hpp')
-rw-r--r-- | src/brussel.engine/Texture.hpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/brussel.engine/Texture.hpp b/src/brussel.engine/Texture.hpp new file mode 100644 index 0000000..108dfa7 --- /dev/null +++ b/src/brussel.engine/Texture.hpp @@ -0,0 +1,99 @@ +#pragma once + +#include "GraphicsTags.hpp" +#include "Image.hpp" +#include "Ires.hpp" +#include "RcPtr.hpp" + +#include <glad/glad.h> +#include <cstdint> +#include <glm/glm.hpp> +#include <span> + +// 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<AtlasSource> sources; + PackingMode packingMode; + }; + struct AtlasOutput { + std::vector<AltasElement> 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<Texture> mInstance; + +public: + IresTexture() + : IresObject(KD_Texture) {} + + Texture* CreateInstance() const; + Texture* GetInstance(); + + void Write(IresWritingContext& ctx, rapidjson::Value& value, rapidjson::Document& root) const override; + void Read(IresLoadingContext& ctx, const rapidjson::Value& value) override; +}; |