raylib-cpp
C++ object-oriented wrapper library for raylib.
Shader.hpp
1 #ifndef RAYLIB_CPP_SHADER_HPP_
2 #define RAYLIB_CPP_SHADER_HPP_
3 
4 #ifdef __cplusplus
5 extern "C"{
6 #endif
7 #include "raylib.h"
8 #ifdef __cplusplus
9 }
10 #endif
11 
12 #include "./raylib-cpp-utils.hpp"
13 #include "Texture.hpp"
14 
15 namespace raylib {
16  class Shader : public ::Shader {
17  public:
18  Shader(::Shader shader) {
19  set(shader);
20  };
21 
22  Shader(unsigned int Id, int* Locs) {
23  id = Id;
24  locs = Locs;
25  };
26 
27  Shader() {
28  set(GetShaderDefault());
29  }
30 
31  GETTERSETTER(unsigned int,Id,id)
32  GETTERSETTER(int*,Locs,locs)
33 
34  Shader& operator=(const ::Shader& shader) {
35  set(shader);
36  return *this;
37  }
38 
39  Shader& operator=(const Shader& shader) {
40  set(shader);
41  return *this;
42  }
43 
44  ~Shader() {
45  Unload();
46  }
47 
48  void Unload() {
49  ::UnloadShader(*this);
50  }
51 
52  static Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
53  return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
54  }
55  static Shader LoadCode(const std::string& vsCode, const std::string& fsCode) {
56  char* param1 = (char*)vsCode.c_str();
57  char* param2 = (char*)fsCode.c_str();
58  return ::LoadShaderCode(param1, param2);
59  }
60 
61  inline Shader& BeginShaderMode() {
62  ::BeginShaderMode(*this);
63  return *this;
64  }
65 
66  inline Shader& EndShaderMode() {
68  return *this;
69  }
70 
71  inline int GetLocation(const std::string& uniformName) const {
72  return ::GetShaderLocation(*this, uniformName.c_str());
73  }
74 
75  inline int GetLocationAttrib(const std::string& attribName) const {
76  return ::GetShaderLocationAttrib(*this, attribName.c_str());
77  }
78 
79  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
80  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
81  return *this;
82  }
83 
87  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
88  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
89  return *this;
90  }
91 
95  inline Shader& SetValue(int uniformLoc, Matrix mat) {
96  ::SetShaderValueMatrix(*this, uniformLoc, mat);
97  return *this;
98  }
99 
103  inline Shader& SetValue(int uniformLoc, Texture2D texture) {
104  ::SetShaderValueTexture(*this, uniformLoc, texture);
105  return *this;
106  }
107 
108  ::TextureCubemap GenTextureCubemap(Texture2D panorama, int size, int format) {
109  return ::GenTextureCubemap(*this, panorama, size, format);
110  }
111 
113  return ::GenTextureIrradiance(*this, panorama, size);
114  }
115 
117  return ::GenTexturePrefilter(*this, panorama, size);
118  }
119 
121  return ::GenTextureBRDF(*this, size);
122  }
123 
124  protected:
125  inline void set(::Shader shader) {
126  id = shader.id;
127  locs = shader.locs;
128  }
129  };
130 }
131 
132 #endif
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType)
Definition: Shader.hpp:79
raylib::Matrix
Definition: Matrix.hpp:21
raylib::Shader::LoadCode
static Shader LoadCode(const std::string &vsCode, const std::string &fsCode)
Definition: Shader.hpp:55
raylib::Shader::BeginShaderMode
Shader & BeginShaderMode()
Definition: Shader.hpp:61
raylib::Shader::GenTextureBRDF
::Texture2D GenTextureBRDF(int size)
Definition: Shader.hpp:120
raylib::Shader::~Shader
~Shader()
Definition: Shader.hpp:44
raylib::Shader::EndShaderMode
Shader & EndShaderMode()
Definition: Shader.hpp:66
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, Texture2D texture)
Definition: Shader.hpp:103
raylib::Shader::GenTextureCubemap
::TextureCubemap GenTextureCubemap(Texture2D panorama, int size, int format)
Definition: Shader.hpp:108
raylib::Shader::Shader
Shader(::Shader shader)
Definition: Shader.hpp:18
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Definition: Shader.hpp:71
raylib::Shader::Load
static Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Definition: Shader.hpp:52
raylib::Shader::Shader
Shader()
Definition: Shader.hpp:27
raylib::Shader::operator=
Shader & operator=(const Shader &shader)
Definition: Shader.hpp:39
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType, int count)
Definition: Shader.hpp:87
raylib::Shader
Definition: Shader.hpp:16
raylib::Shader::Shader
Shader(unsigned int Id, int *Locs)
Definition: Shader.hpp:22
raylib::Shader::Unload
void Unload()
Definition: Shader.hpp:48
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Definition: Shader.hpp:75
raylib::Texture
Definition: Texture.hpp:19
raylib::Shader::GenTextureIrradiance
::TextureCubemap GenTextureIrradiance(Texture2D panorama, int size)
Definition: Shader.hpp:112
raylib::Shader::GenTexturePrefilter
::TextureCubemap GenTexturePrefilter(Texture2D panorama, int size)
Definition: Shader.hpp:116
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, Matrix mat)
Definition: Shader.hpp:95
raylib::Shader::set
void set(::Shader shader)
Definition: Shader.hpp:125