Mountain  1.0.0
Simple C++ 2D Game Framework
shader.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Mountain/core.hpp"
4 
5 #include <array>
6 
7 #include "Mountain/file/file.hpp"
8 #include "Mountain/rendering/graphics.hpp"
9 #include "Mountain/resource/shader_base.hpp"
11 
14 
15 namespace Mountain
16 {
18  struct ShaderCode
19  {
21  std::string code;
23  Graphics::ShaderType type;
24  };
25 
27  class Shader final : public ShaderBase
28  {
29  public:
31  MOUNTAIN_API static constexpr std::array VertexFileExtensions
32  {
33  ".vert",
34  ".vertex",
35  ".vs"
36  };
37 
39  MOUNTAIN_API static constexpr std::array FragmentFileExtensions
40  {
41  ".frag",
42  ".fragment",
43  ".fs"
44  };
45 
50  [[nodiscard]]
51  static Graphics::ShaderType FileExtensionToType(const std::string& extension);
52 
53  using ShaderBase::ShaderBase;
54 
55  using ShaderBase::SetSourceData;
56 
60  MOUNTAIN_API bool_t SetSourceData(const Pointer<File>& shader) override;
61 
66  MOUNTAIN_API bool_t Load(const char_t* buffer, int64_t length, Graphics::ShaderType type);
67 
69  MOUNTAIN_API void Load() override;
70 
72  MOUNTAIN_API void Unload() override;
73 
75  MOUNTAIN_API void ResetSourceData() override;
76 
77  MOUNTAIN_API bool_t Reload(bool_t reloadInBackend = true) override;
78 
79  MOUNTAIN_API bool_t Reload(const Pointer<File>& file, bool_t reloadInBackend = true) override;
80 
81  [[nodiscard]]
82  MOUNTAIN_API std::array<Pointer<File>, magic_enum::enum_count<Graphics::ShaderType>()>& GetFiles();
83 
84  [[nodiscard]]
85  MOUNTAIN_API const std::array<Pointer<File>, magic_enum::enum_count<Graphics::ShaderType>()>& GetFiles() const;
86 
87  [[nodiscard]]
88  MOUNTAIN_API std::array<ShaderCode, magic_enum::enum_count<Graphics::ShaderType>()>& GetCode();
89 
90  [[nodiscard]]
91  MOUNTAIN_API const std::array<ShaderCode, magic_enum::enum_count<Graphics::ShaderType>()>& GetCode() const;
92 
94  MOUNTAIN_API void Use() const;
95 
97  MOUNTAIN_API void Unuse() const;
98 
99  private:
100  std::array<Pointer<File>, magic_enum::enum_count<Graphics::ShaderType>()> m_Files;
101  std::array<ShaderCode, magic_enum::enum_count<Graphics::ShaderType>()> m_Code;
102 
103  bool_t CheckCompileError(uint32_t id, Graphics::ShaderType type) const; // NOLINT(modernize-use-nodiscard)
104  };
105 }
Defines the Mountain::File class.
std::string code
Pointer to raw code.
Definition: shader.hpp:21
Graphics::ShaderType type
Shader type.
Definition: shader.hpp:23
Encapsulates shader code information.
Definition: shader.hpp:18
Custom Mountain smart pointer. Represents both a std::shared_ptr and a std::weak_ptr.
Defines the Mountain::Pointer class.
Encapsulates a GPU shader.
Definition: shader.hpp:27
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22