MOS
texture_2d.hpp
1 #pragma once
2 
3 #include <atomic>
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 #include <glm/glm.hpp>
9 #include <mos/gfx/texture.hpp>
10 
11 namespace mos::gfx {
12 
13 class Texture_2D;
14 using Shared_texture_2D = std::shared_ptr<Texture_2D>;
15 
17 class Texture_2D final : public Texture {
18 public:
19  template <class T>
20  Texture_2D(T begin, T end, int width, int height,
21  const gli::format &format = gli::format::FORMAT_RGBA8_SRGB_PACK8,
22  const Filter &filter = Filter::Linear,
23  const Wrap &wrap = Wrap::Repeat, const bool mipmaps = true)
24  : Texture(filter, wrap, mipmaps),
25  texture_(format, gli::extent2d(width, height)) {
26  std::memcpy(texture_.data(), begin, std::distance(begin, end));
27  }
28 
29  Texture_2D(int width, int height,
30  const gli::format &format = gli::format::FORMAT_RGBA8_SRGB_PACK8,
31  const Filter &filter = Filter::Linear,
32  const Wrap &wrap = Wrap::Repeat, bool mipmaps = true);
33 
35  static auto load(const std::string &path, bool color_data = true,
36  bool generate_mipmaps = true,
37  const Filter &filter = Filter::Linear,
38  const Wrap &wrap = Wrap::Repeat) -> Texture_2D;
39 
40  auto width() const -> int;
41  auto height() const -> int;
42  const void *data() const;
43  gli::format format() const;
44  gli::swizzles swizzles() const;
45 
46 private:
47  gli::texture2d texture_;
48 };
49 } // namespace mos::gfx
Definition: assets.hpp:17
Texture in two dimension.
Definition: texture_2d.hpp:17
Texture base.
Definition: texture.hpp:21
static auto load(const std::string &path, bool color_data=true, bool generate_mipmaps=true, const Filter &filter=Filter::Linear, const Wrap &wrap=Wrap::Repeat) -> Texture_2D
Create from file.