Mountain  1.0.0
Simple C++ 2D Game Framework
texture.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 
5 #include <Maths/vector2i.hpp>
6 
7 #include "Mountain/core.hpp"
8 #include "Mountain/rendering/gpu_texture.hpp"
9 #include "Mountain/rendering/graphics.hpp"
11 
14 
15 namespace Mountain
16 {
18  class Texture : public Resource
19  {
20  public:
22  MOUNTAIN_API static constexpr std::array FileExtensions
23  {
24  ".jpg",
25  ".jpeg",
26  ".png"
27  };
28 
29  // Same constructor from base class
30  using Resource::Resource;
31 
32  DELETE_COPY_MOVE_OPERATIONS(Texture)
33 
34  // We keep both function overloads and only override one
35  using Resource::SetSourceData;
36 
37  MOUNTAIN_API ~Texture() override;
38 
39  MOUNTAIN_API bool_t SetSourceData(const uint8_t* buffer, int64_t length) override;
40 
41  MOUNTAIN_API void Load() override;
42 
43  MOUNTAIN_API void Unload() override;
44 
45  MOUNTAIN_API void ResetSourceData() override;
46 
50  template <typename T = char_t>
51  [[nodiscard]]
52  const T* GetData() const;
53 
57  template <typename T = char_t>
58  [[nodiscard]]
59  T* GetData();
60 
63  [[nodiscard]]
64  MOUNTAIN_API Vector2i GetSize() const;
65 
66  MOUNTAIN_API void SetSize(Vector2i newSize);
67 
68  [[nodiscard]]
69  MOUNTAIN_API Graphics::MagnificationFilter GetFilter() const;
70  MOUNTAIN_API void SetFilter(Graphics::MagnificationFilter newFilter);
71 
73  MOUNTAIN_API void Use() const;
74 
76  MOUNTAIN_API void Unuse() const;
77 
79  [[nodiscard]]
80  MOUNTAIN_API uint32_t GetId() const;
81 
83  [[nodiscard]]
84  MOUNTAIN_API Graphics::GpuTexture GetGpuTexture() const;
85 
86  private:
87  uint8_t* m_Data = nullptr;
88  Vector2i m_Size;
89  Graphics::GpuTexture m_GpuTexture;
90  Graphics::MagnificationFilter m_Filter = Graphics::MagnificationFilter::Nearest;
91  };
92 }
93 
94 #include "Mountain/resource/texture.inl"
MOUNTAIN_API void Use() const
Binds the texture.
MOUNTAIN_API Graphics::GpuTexture GetGpuTexture() const
Gets the underlying GpuTexture.
static MOUNTAIN_API constexpr std::array FileExtensions
Allowed extensions for texture files.
Definition: texture.hpp:23
Defines the Mountain::Resource class.
MOUNTAIN_API uint32_t GetId() const
Get the ID of this texture on the GPU.
Low-level interface for OpenGL textures.
Definition: gpu_texture.hpp:12
Represents an image in memory.
Definition: texture.hpp:18
const T * GetData() const
Gets the raw data of the texture.
MOUNTAIN_API Vector2i GetSize() const
Gets the size of the texture.
MOUNTAIN_API void Unuse() const
Unbinds the texture.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22