CoriEngine
Loading...
Searching...
No Matches
Texture.hpp
Go to the documentation of this file.
1#pragma once
2#include "Image.hpp"
4
5namespace Cori {
6 class AssetManager;
7
8 namespace Graphics {
9 struct UVs {
10 glm::vec2 UVmin{ 0.0f, 0.0f };
11 glm::vec2 UVmax{ 1.0f, 1.0f };
12
13 explicit operator glm::vec4() const { return { UVmin, UVmax }; }
14 };
15
19 class Texture {
20 public:
27
34
38 enum Filter {
40 };
41
60
61 virtual ~Texture() = default;
62
67 [[nodiscard]] virtual uint32_t GetWidth() const = 0;
68
73 [[nodiscard]] virtual uint32_t GetHeight() const = 0;
74
79 [[nodiscard]] virtual bool HasSemiTransparency() const = 0;
80
86 virtual void Bind(uint32_t slot) const = 0;
87
89 return m_Status;
90 }
91
92 protected:
94 };
95
99 class Texture2D : public Texture {
100 public:
105 public:
111 constexpr Descriptor(std::string name, std::filesystem::path imagePath)
112 : m_ImagePath(std::move(imagePath)),
113 m_Name(std::move(name)),
114 m_RuntimeID(s_NextRuntimeID.fetch_add(1, std::memory_order_relaxed))
115 { }
116
118
119 [[nodiscard]] uint32_t GetRuntimeID() const { return m_RuntimeID; }
120
121 constexpr bool operator==(const Descriptor& other) const {
122 return m_RuntimeID == other.m_RuntimeID;
123 }
124
125 struct Hasher {
126 std::size_t operator()(const Descriptor& descriptor) const {
127 return std::hash<uint32_t>{}(descriptor.m_RuntimeID);
128 }
129 };
130
131 const std::filesystem::path m_ImagePath;
132 const std::string m_Name;
133
134 private:
135 const uint32_t m_RuntimeID{ 0 };
136 inline static std::atomic<uint32_t> s_NextRuntimeID{ 1 };
137 };
138
144 [[nodiscard]] static std::shared_ptr<Texture2D> Create(const std::shared_ptr<Image>& image);
145
154 [[nodiscard]] static std::shared_ptr<Texture2D> Create(const void* pixelData, const uint32_t width, const uint32_t height, const Params& params);
155
156 private:
157 friend AssetManager;
158 virtual void Upload(const void* pixelData, const uint32_t width, const uint32_t height, const Params& params) = 0;
159
160 [[nodiscard]] static std::shared_ptr<Texture2D> Create(const Descriptor& descriptor);
161 };
162 }
163}
Used when you want to manually control the asset lifetime, loading, preloading, unloading.
const std::filesystem::path m_ImagePath
Definition Texture.hpp:131
constexpr bool operator==(const Descriptor &other) const
Definition Texture.hpp:121
constexpr Descriptor(std::string name, std::filesystem::path imagePath)
Constructs a descriptor.
Definition Texture.hpp:111
A regular 2D texture with 1 layer.
Definition Texture.hpp:99
static std::shared_ptr< Texture2D > Create(const std::shared_ptr< Image > &image)
Creates a Texture2D from the Image.
Definition Texture.cpp:7
Abstract class for textures.
Definition Texture.hpp:19
virtual ~Texture()=default
virtual void Bind(uint32_t slot) const =0
Binds the texture to the slot.
WrapMode
Available wrap modes.
Definition Texture.hpp:31
virtual uint32_t GetHeight() const =0
Gives the texture height.
PixelFormat
Available pixel formats.
Definition Texture.hpp:24
AssetStatus GetStatus() const
Definition Texture.hpp:88
virtual bool HasSemiTransparency() const =0
Checks if texture has semi transparency.
Filter
Available filtering options.
Definition Texture.hpp:38
virtual uint32_t GetWidth() const =0
Gives the texture width.
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
Global engine namespace.
std::size_t operator()(const Descriptor &descriptor) const
Definition Texture.hpp:126
Params to use when creating a texture.
Definition Texture.hpp:45
int32_t m_UnpackAlignment
Generally you want to leave this by default if you're creating a texture from an image,...
Definition Texture.hpp:53
bool m_HasSemiTransparency
Whether or no to flag the texture as semi transparent.
Definition Texture.hpp:58