raylib-cpp
C++ object-oriented wrapper library for raylib.
Shader.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
26 #define RAYLIB_CPP_INCLUDE_SHADER_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
32 #include "Texture.hpp"
33 
34 namespace raylib {
35 class Shader : public ::Shader {
36  public:
37  Shader(const ::Shader& shader) {
38  set(shader);
39  }
40 
41  Shader(unsigned int Id, int* Locs) {
42  id = Id;
43  locs = Locs;
44  }
45 
46  Shader() {
47  set(GetShaderDefault());
48  }
49 
50  Shader(const std::string& vsFileName, const std::string& fsFileName) {
51  set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
52  }
53 
57  static ::Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
58  return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
59  }
60 
64  static ::Shader LoadCode(const std::string& vsCode, const std::string& fsCode) {
65  return ::LoadShaderCode(vsCode.c_str(), fsCode.c_str());
66  }
67 
68  GETTERSETTER(unsigned int, Id, id)
69  GETTERSETTER(int*, Locs, locs)
70 
71  Shader& operator=(const ::Shader& shader) {
72  set(shader);
73  return *this;
74  }
75 
76  ~Shader() {
77  Unload();
78  }
79 
80  void Unload() {
81  ::UnloadShader(*this);
82  }
83 
87  inline Shader& BeginMode() {
88  ::BeginShaderMode(*this);
89  return *this;
90  }
91 
95  inline Shader& EndMode() {
96  ::EndShaderMode();
97  return *this;
98  }
99 
103  inline int GetLocation(const std::string& uniformName) const {
104  return ::GetShaderLocation(*this, uniformName.c_str());
105  }
106 
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  ::TextureCubemap GenTextureCubemap(const ::Texture2D& panorama, int size, int format) const {
155  return ::GenTextureCubemap(*this, panorama, size, format);
156  }
157 
158  ::TextureCubemap GenTextureIrradiance(const ::Texture2D& panorama, int size) const {
159  return ::GenTextureIrradiance(*this, panorama, size);
160  }
161 
162  ::TextureCubemap GenTexturePrefilter(const ::Texture2D& panorama, int size) const {
163  return ::GenTexturePrefilter(*this, panorama, size);
164  }
165 
166  ::Texture2D GenTextureBRDF(int size) const {
167  return ::GenTextureBRDF(*this, size);
168  }
169 
170  protected:
171  inline void set(const ::Shader& shader) {
172  id = shader.id;
173  locs = shader.locs;
174  }
175 };
176 } // namespace raylib
177 
178 #endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType)
Set shader uniform value.
Definition: Shader.hpp:119
raylib::Shader::GenTextureCubemap
::TextureCubemap GenTextureCubemap(const ::Texture2D &panorama, int size, int format) const
Definition: Shader.hpp:154
raylib::Shader::~Shader
~Shader()
Definition: Shader.hpp:76
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Definition: Shader.hpp:139
raylib::Shader::GenTexturePrefilter
::TextureCubemap GenTexturePrefilter(const ::Texture2D &panorama, int size) const
Definition: Shader.hpp:162
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:103
raylib::Shader::Shader
Shader()
Definition: Shader.hpp:46
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::GenTextureIrradiance
::TextureCubemap GenTextureIrradiance(const ::Texture2D &panorama, int size) const
Definition: Shader.hpp:158
raylib::Shader::EndMode
Shader & EndMode()
End custom shader drawing (use default shader).
Definition: Shader.hpp:95
raylib::Shader
Definition: Shader.hpp:35
raylib::Shader::BeginMode
Shader & BeginMode()
Begin custom shader drawing.
Definition: Shader.hpp:87
raylib::Shader::Shader
Shader(unsigned int Id, int *Locs)
Definition: Shader.hpp:41
raylib::Shader::set
void set(const ::Shader &shader)
Definition: Shader.hpp:171
raylib::Shader::Shader
Shader(const std::string &vsFileName, const std::string &fsFileName)
Definition: Shader.hpp:50
raylib::Shader::Unload
void Unload()
Definition: Shader.hpp:80
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Get shader attribute location.
Definition: Shader.hpp:110
raylib::Shader::LoadCode
::Shader LoadCode(const std::string &vsCode, const std::string &fsCode)
Load shader from code strings and bind default locations.
Definition: Shader.hpp:64
raylib::Texture
Definition: Texture.hpp:36
raylib::Shader::GenTextureBRDF
::Texture2D GenTextureBRDF(int size) const
Definition: Shader.hpp:166
raylib::Shader::Shader
Shader(const ::Shader &shader)
Definition: Shader.hpp:37
raylib::Shader::Load
::Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Load shader from files and bind default locations.
Definition: Shader.hpp:57
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Texture2D &texture)
Set shader uniform value for texture.
Definition: Shader.hpp:149