MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_texture.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_TEXTURE_H_1608421676
12#define INCGUARD_MGL_TEXTURE_H_1608421676
13
15
16namespace MGL::Render
17{
20{
21public:
22 /* ------------------------------------------------------------------------- */
26 /* ------------------------------------------------------------------------- */
27 constexpr Texture() noexcept
28 : _resource(nullptr)
29 , _withKey(false)
30 , _key()
31 {
32 }
33
34 Texture(SharedTextureResource resource) noexcept;
35 Texture(TextureKey key) noexcept;
36 Texture(TextureKey key, const File::PathView &imagePath, bool isAsync, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
37 Texture(TextureKey key, const void *imageData, size_t dataSize, bool isAsync, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
38 Texture(const File::PathView &imagePath, bool isAsync, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
39 Texture(const void *imageData, size_t dataSize, bool isAsync, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
40
41 bool Load(TextureKey key) noexcept;
42 bool Load(TextureKey key, const File::PathView &imagePath, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
43 bool LoadAsync(TextureKey key, const File::PathView &imagePath, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
44 bool Load(TextureKey key, const void *imageData, size_t dataSize, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
45 bool LoadAsync(TextureKey key, const void *imageData, size_t dataSize, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
46
47 bool Load(const File::PathView &imagePath, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
48 bool LoadAsync(const File::PathView &imagePath, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
49 bool Load(const void *imageData, size_t dataSize, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
50 bool LoadAsync(const void *imageData, size_t dataSize, TextureLoaderKey loaderKey = TextureStorage::kDefaultLoaderKey) noexcept;
51
52 bool Create(TextureKey key, const void *pixelData, PixelFormat pixelFormat, uint32_t width, uint32_t height) noexcept;
53 bool Create(const void *pixelData, PixelFormat pixelFormat, uint32_t width, uint32_t height) noexcept;
54
55 bool CreateRenderTarget(TextureKey key, uint32_t width, uint32_t height) noexcept;
56 bool CreateRenderTarget(uint32_t width, uint32_t height) noexcept;
57
58 [[nodiscard]] SharedTextureResource GetResource() const noexcept;
59
60 [[nodiscard]] bool IsValid() const noexcept;
61 [[nodiscard]] bool IsLoading() const noexcept;
62
63 /* ------------------------------------------------------------------------- */
69 /* ------------------------------------------------------------------------- */
70 explicit operator bool() const noexcept
71 {
72 return IsValid();
73 }
74
75 /* ------------------------------------------------------------------------- */
81 /* ------------------------------------------------------------------------- */
82 bool operator!() const noexcept
83 {
84 return !IsValid();
85 }
86
87 [[nodiscard]] Vector2 GetSize() const noexcept;
88
89 /* ------------------------------------------------------------------------- */
95 /* ------------------------------------------------------------------------- */
96 bool Destroy() noexcept
97 {
98 if (IsValid() && _withKey)
99 {
100 return Destroy(_key);
101 }
102
103 return false;
104 }
105
106 /* ------------------------------------------------------------------------- */
113 /* ------------------------------------------------------------------------- */
114 static bool Destroy(TextureKey key) noexcept
115 {
116 return RendererSet::GetInstance().GetTextureStorage().Destroy(key);
117 }
118
119 /* ------------------------------------------------------------------------- */
128 /* ------------------------------------------------------------------------- */
129 template <class LoaderClass, class... Args>
130 constexpr static bool RegisterLoader(TextureLoaderKey loaderKey, Args... args) noexcept
131 {
132 return RendererSet::GetInstance().GetTextureStorage().RegisterLoader(
133 loaderKey,
134 STL::make_unique<LoaderClass>(args...));
135 }
136
137 /* ------------------------------------------------------------------------- */
142 /* ------------------------------------------------------------------------- */
143 static void SetDefaultLoader(TextureLoaderKey loaderKey) noexcept
144 {
145 RendererSet::GetInstance().GetTextureStorage().SetDefaultLoader(loaderKey);
146 }
147
148private:
149 SharedTextureResource _resource;
150 bool _withKey;
151 TextureKey _key;
152};
153} // namespace MGL::Render
154
155#endif // INCGUARD_MGL_TEXTURE_H_1608421676
156
157// vim: et ts=4 sw=4 sts=4
文字列の参照のみを行うファイルパスクラス
Definition mgl_file_path_view.h:20
MGL テクスチャクラス
Definition mgl_texture.h:20
bool Load(TextureKey key) noexcept
テクスチャをテクスチャストレージから読み込み
Definition mgl_texture.cc:154
bool operator!() const noexcept
有効状態を否定演算子で取得
Definition mgl_texture.h:82
constexpr Texture() noexcept
コンストラクタ
Definition mgl_texture.h:27
static bool Destroy(TextureKey key) noexcept
テクスチャリソースを破棄
Definition mgl_texture.h:114
bool LoadAsync(TextureKey key, const File::PathView &imagePath, TextureLoaderKey loaderKey=TextureStorage::kDefaultLoaderKey) noexcept
テクスチャをファイルから非同期で読み込み
Definition mgl_texture.cc:199
bool CreateRenderTarget(TextureKey key, uint32_t width, uint32_t height) noexcept
レンダーターゲットの生成
Definition mgl_texture.cc:400
Vector2 GetSize() const noexcept
テクスチャのサイズを取得
Definition mgl_texture.cc:501
bool Destroy() noexcept
テクスチャリソースを破棄
Definition mgl_texture.h:96
static constexpr bool RegisterLoader(TextureLoaderKey loaderKey, Args... args) noexcept
テクスチャローダー登録用テンプレート
Definition mgl_texture.h:130
bool IsValid() const noexcept
テクスチャが有効かを取得
Definition mgl_texture.cc:466
bool Create(TextureKey key, const void *pixelData, PixelFormat pixelFormat, uint32_t width, uint32_t height) noexcept
テクスチャをピクセルデータから生成
Definition mgl_texture.cc:357
static void SetDefaultLoader(TextureLoaderKey loaderKey) noexcept
デフォルトのテクスチャローダーを設定
Definition mgl_texture.h:143
SharedTextureResource GetResource() const noexcept
テクスチャリソースの取得
Definition mgl_texture.cc:448
bool IsLoading() const noexcept
テクスチャが読み込み中かを取得
Definition mgl_texture.cc:484
static constexpr TextureLoaderKey kDefaultLoaderKey
デフォルトのテクスチャローダーを表すキー
Definition mgl_texture_storage.h:51
static RendererSet & GetInstance() noexcept
Definition mgl_singleton.h:74
PixelFormat
ピクセルフォーマット
Definition mgl_render_types.h:37
MGL レンダラセット
uint32_t TextureLoaderKey
テクスチャローダーのキー
Definition mgl_texture_loader.h:23
std::shared_ptr< MGL::Render::TextureResource > SharedTextureResource
共有するテクスチャリソースの型
Definition mgl_texture_resource.h:145
TextureKey
テクスチャにアクセスするキーの型
Definition mgl_texture_storage.h:27
2Dベクトル
Definition mgl_vector2.h:23