diff options
author | hnOsmium0001 <[email protected]> | 2022-04-06 20:52:51 -0700 |
---|---|---|
committer | hnOsmium0001 <[email protected]> | 2022-04-06 20:52:51 -0700 |
commit | 3fdc6eb4f2cbeffce9b250beec4d3a2d52a3f534 (patch) | |
tree | 05991741844aa2814b3ac71e2c843ebe07244845 /source/Texture.hpp | |
parent | ebd42760caaec8330a3c028f31adc7bc0b339d16 (diff) |
Work on moving infrastruture to this project
Diffstat (limited to 'source/Texture.hpp')
-rw-r--r-- | source/Texture.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/source/Texture.hpp b/source/Texture.hpp new file mode 100644 index 0000000..c372998 --- /dev/null +++ b/source/Texture.hpp @@ -0,0 +1,66 @@ +#pragma once + +#include "RcPtr.hpp" + +#include <glad/glad.h> +#include <glm/glm.hpp> +#include <memory> + +// TODO abstract texture traits such as component sizes from OpenGL + +class TextureInfo { +public: + glm::ivec2 size; + bool isAtlas = false; +}; + +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 Filtering { + LinearFilter, + NearestFilter, + }; + + struct TextureProperties { + Filtering minifyingFilter = LinearFilter; + Filtering magnifyingFilter = LinearFilter; + }; + + bool InitFromFile(const char* filePath, const TextureProperties& props, bool flipVertically = false); + // bool InitFromImage(const Image& image, const TextureProperties& props, bool flipVertically = false); + + const TextureInfo& GetInfo() const; + GLuint GetHandle() const; + + bool IsValid() const; +}; + +/// A pure numerical subregion of a texture. u0/v0 are the UV coordinates of bottom left +/// corner, and u1/v1 are the top left corner. +struct Subregion { + /// Bottom left corner + float u0 = 0.0f; + float v0 = 0.0f; + /// Top right corner + float u1 = 0.0f; + float v1 = 0.0f; +}; + +/// A subregion of a specific texture. +struct TextureSubregion : public Subregion { + RcPtr<Texture> atlasTexture; +}; |