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) {
21  id = Id;
22  locs = Locs;
23  }
24 
25  Shader(const std::string& vsFileName, const std::string& fsFileName) {
26  set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
27  }
28 
32  static ::Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
33  return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
34  }
35 
36  static ::Shader LoadFromMemory(const std::string& vsCode, const std::string& fsCode) {
37  return ::LoadShaderFromMemory(vsCode.c_str(), fsCode.c_str());
38  }
39 
40  GETTERSETTER(unsigned int, Id, id)
41  GETTERSETTER(int*, Locs, locs)
42 
43  Shader& operator=(const ::Shader& shader) {
44  set(shader);
45  return *this;
46  }
47 
48  ~Shader() {
49  Unload();
50  }
51 
52  void Unload() {
53  if (locs != NULL) {
54  ::UnloadShader(*this);
55  }
56  }
57 
61  inline Shader& BeginMode() {
62  ::BeginShaderMode(*this);
63  return *this;
64  }
65 
69  inline Shader& EndMode() {
70  ::EndShaderMode();
71  return *this;
72  }
73 
79  inline int GetLocation(const std::string& uniformName) const {
80  return ::GetShaderLocation(*this, uniformName.c_str());
81  }
82 
88  inline int GetLocationAttrib(const std::string& attribName) const {
89  return ::GetShaderLocationAttrib(*this, attribName.c_str());
90  }
91 
97  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
98  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
99  return *this;
100  }
101 
107  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
108  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
109  return *this;
110  }
111 
117  inline Shader& SetValue(int uniformLoc, const ::Matrix& mat) {
118  ::SetShaderValueMatrix(*this, uniformLoc, mat);
119  return *this;
120  }
121 
127  inline Shader& SetValue(int uniformLoc, const ::Texture2D& texture) {
128  ::SetShaderValueTexture(*this, uniformLoc, texture);
129  return *this;
130  }
131 
132  private:
133  inline void set(const ::Shader& shader) {
134  id = shader.id;
135  locs = shader.locs;
136  }
137 };
138 } // namespace raylib
139 
140 #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:97
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Definition: Shader.hpp:117
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:79
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType, int count)
Set shader uniform value vector.
Definition: Shader.hpp:107
raylib::Shader::EndMode
Shader & EndMode()
End custom shader drawing (use default shader).
Definition: Shader.hpp:69
raylib::Shader
Shader type (generic)
Definition: Shader.hpp:14
raylib::Shader::BeginMode
Shader & BeginMode()
Begin custom shader drawing.
Definition: Shader.hpp:61
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Get shader attribute location.
Definition: Shader.hpp:88
raylib::Shader::Load
::Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Load shader from files and bind default locations.
Definition: Shader.hpp:32
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Texture2D &texture)
Set shader uniform value for texture.
Definition: Shader.hpp:127