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 
68  ~Shader() {
69  Unload();
70  }
71 
72  void Unload() {
73  if (locs != nullptr) {
74  ::UnloadShader(*this);
75  }
76  }
77 
81  inline Shader& BeginMode() {
82  ::BeginShaderMode(*this);
83  return *this;
84  }
85 
89  inline Shader& EndMode() {
90  ::EndShaderMode();
91  return *this;
92  }
93 
99  inline int GetLocation(const std::string& uniformName) const {
100  return ::GetShaderLocation(*this, uniformName.c_str());
101  }
102 
108  inline int GetLocationAttrib(const std::string& attribName) const {
109  return ::GetShaderLocationAttrib(*this, attribName.c_str());
110  }
111 
117  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
118  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
119  return *this;
120  }
121 
127  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
128  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
129  return *this;
130  }
131 
137  inline Shader& SetValue(int uniformLoc, const ::Matrix& mat) {
138  ::SetShaderValueMatrix(*this, uniformLoc, mat);
139  return *this;
140  }
141 
147  inline Shader& SetValue(int uniformLoc, const ::Texture2D& texture) {
148  ::SetShaderValueTexture(*this, uniformLoc, texture);
149  return *this;
150  }
151 
152  private:
153  inline void set(const ::Shader& shader) {
154  id = shader.id;
155  locs = shader.locs;
156  }
157 };
158 } // namespace raylib
159 
160 #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:117
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Definition: Shader.hpp:137
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:99
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType, int count)
Set shader uniform value vector.
Definition: Shader.hpp:127
raylib::Shader::EndMode
Shader & EndMode()
End custom shader drawing (use default shader).
Definition: Shader.hpp:89
raylib::Shader
Shader type (generic)
Definition: Shader.hpp:14
raylib::Shader::BeginMode
Shader & BeginMode()
Begin custom shader drawing.
Definition: Shader.hpp:81
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Get shader attribute location.
Definition: Shader.hpp:108
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:147