raylib-cpp
C++ object-oriented wrapper library for raylib.
Shader.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
2 #define RAYLIB_CPP_INCLUDE_SHADER_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "Texture.hpp"
9 
10 namespace raylib {
14 class Shader : public ::Shader {
15  public:
16  Shader(const ::Shader& shader) {
17  set(shader);
18  }
19 
20  Shader(unsigned int id, int* locs = nullptr) : ::Shader{id, locs} {}
21 
22  Shader(const std::string& vsFileName, const std::string& fsFileName) {
23  set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
24  }
25 
26  Shader(const Shader&) = delete;
27 
28  Shader(Shader&& other) {
29  set(other);
30 
31  other.id = 0;
32  other.locs = nullptr;
33  }
34 
38  static ::Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
39  return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
40  }
41 
42  static ::Shader LoadFromMemory(const std::string& vsCode, const std::string& fsCode) {
43  return ::LoadShaderFromMemory(vsCode.c_str(), fsCode.c_str());
44  }
45 
46  GETTERSETTER(unsigned int, Id, id)
47  GETTERSETTER(int*, Locs, locs)
48 
49  Shader& operator=(const ::Shader& shader) {
50  set(shader);
51  return *this;
52  }
53 
54  Shader& operator=(const Shader&) = delete;
55 
56  Shader& operator=(Shader&& other) {
57  if (this != &other) {
58  return *this;
59  }
60 
61  Unload();
62  set(other);
63 
64  other.id = 0;
65  other.locs = nullptr;
66 
67  return *this;
68  }
69 
70  ~Shader() {
71  Unload();
72  }
73 
74  void Unload() {
75  if (locs != nullptr) {
76  ::UnloadShader(*this);
77  }
78  }
79 
83  inline Shader& BeginMode() {
84  ::BeginShaderMode(*this);
85  return *this;
86  }
87 
91  inline Shader& EndMode() {
92  ::EndShaderMode();
93  return *this;
94  }
95 
101  inline int GetLocation(const std::string& uniformName) const {
102  return ::GetShaderLocation(*this, uniformName.c_str());
103  }
104 
110  inline int GetLocationAttrib(const std::string& attribName) const {
111  return ::GetShaderLocationAttrib(*this, attribName.c_str());
112  }
113 
119  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
120  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
121  return *this;
122  }
123 
129  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
130  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
131  return *this;
132  }
133 
139  inline Shader& SetValue(int uniformLoc, const ::Matrix& mat) {
140  ::SetShaderValueMatrix(*this, uniformLoc, mat);
141  return *this;
142  }
143 
149  inline Shader& SetValue(int uniformLoc, const ::Texture2D& texture) {
150  ::SetShaderValueTexture(*this, uniformLoc, texture);
151  return *this;
152  }
153 
154  private:
155  inline void set(const ::Shader& shader) {
156  id = shader.id;
157  locs = shader.locs;
158  }
159 };
160 } // namespace raylib
161 
162 #endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType)
Set shader uniform value.
Definition: Shader.hpp:119
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Definition: Shader.hpp:139
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:101
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType, int count)
Set shader uniform value vector.
Definition: Shader.hpp:129
raylib::Shader::EndMode
Shader & EndMode()
End custom shader drawing (use default shader).
Definition: Shader.hpp:91
raylib::Shader
Shader type (generic)
Definition: Shader.hpp:14
raylib::Shader::BeginMode
Shader & BeginMode()
Begin custom shader drawing.
Definition: Shader.hpp:83
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Get shader attribute location.
Definition: Shader.hpp:110
raylib::Shader::Load
::Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Load shader from files and bind default locations.
Definition: Shader.hpp:38
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Texture2D &texture)
Set shader uniform value for texture.
Definition: Shader.hpp:149