aboutsummaryrefslogtreecommitdiff
path: root/source/Texture.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-06 20:52:51 -0700
committerrtk0c <[email protected]>2022-04-06 20:52:51 -0700
commitf163e8f37123e651ea80b690793845b31ddb8639 (patch)
treee2c9f14d600f073533c9d01cfb90c4d60938127c /source/Texture.hpp
parent11edae3fbf770695d1b263712ca4f3a40bdd70e3 (diff)
Changeset: 2 Work on moving infrastruture to this project
Diffstat (limited to 'source/Texture.hpp')
-rw-r--r--source/Texture.hpp66
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;
+};