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(::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 
54  static Shader Load(const std::string& vsFileName, const std::string& fsFileName) {
55  return ::LoadShader(vsFileName.c_str(), fsFileName.c_str());
56  }
57 
58  static Shader LoadCode(const std::string& vsCode, const std::string& fsCode) {
59  return ::LoadShaderCode(vsCode.c_str(), fsCode.c_str());
60  }
61 
62  GETTERSETTER(unsigned int, Id, id)
63  GETTERSETTER(int*, Locs, locs)
64 
65  Shader& operator=(const ::Shader& shader) {
66  set(shader);
67  return *this;
68  }
69 
70  Shader& operator=(const Shader& shader) {
71  set(shader);
72  return *this;
73  }
74 
75  ~Shader() {
76  Unload();
77  }
78 
79  void Unload() {
80  ::UnloadShader(*this);
81  }
82 
83  inline Shader& BeginShaderMode() {
84  ::BeginShaderMode(*this);
85  return *this;
86  }
87 
88  inline Shader& EndShaderMode() {
90  return *this;
91  }
92 
96  inline int GetLocation(const std::string& uniformName) const {
97  return ::GetShaderLocation(*this, uniformName.c_str());
98  }
99 
103  inline int GetLocationAttrib(const std::string& attribName) const {
104  return ::GetShaderLocationAttrib(*this, attribName.c_str());
105  }
106 
110  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
111  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
112  return *this;
113  }
114 
118  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
119  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
120  return *this;
121  }
122 
126  inline Shader& SetValue(int uniformLoc, Matrix mat) {
127  ::SetShaderValueMatrix(*this, uniformLoc, mat);
128  return *this;
129  }
130 
134  inline Shader& SetValue(int uniformLoc, ::Texture2D texture) {
135  ::SetShaderValueTexture(*this, uniformLoc, texture);
136  return *this;
137  }
138 
139  ::TextureCubemap GenTextureCubemap(::Texture2D panorama, int size, int format) const {
140  return ::GenTextureCubemap(*this, panorama, size, format);
141  }
142 
143  ::TextureCubemap GenTextureIrradiance(::Texture2D panorama, int size) const {
144  return ::GenTextureIrradiance(*this, panorama, size);
145  }
146 
147  ::TextureCubemap GenTexturePrefilter(::Texture2D panorama, int size) const {
148  return ::GenTexturePrefilter(*this, panorama, size);
149  }
150 
151  ::Texture2D GenTextureBRDF(int size) const {
152  return ::GenTextureBRDF(*this, size);
153  }
154 
155  protected:
156  inline void set(::Shader shader) {
157  id = shader.id;
158  locs = shader.locs;
159  }
160 };
161 } // namespace raylib
162 
163 #endif // RAYLIB_CPP_INCLUDE_SHADER_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Shader::GenTextureCubemap
::TextureCubemap GenTextureCubemap(::Texture2D panorama, int size, int format) const
Definition: Shader.hpp:139
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType)
Set shader uniform value.
Definition: Shader.hpp:110
raylib::Matrix
Definition: Matrix.hpp:46
raylib::Shader::LoadCode
static Shader LoadCode(const std::string &vsCode, const std::string &fsCode)
Definition: Shader.hpp:58
raylib::Shader::BeginShaderMode
Shader & BeginShaderMode()
Definition: Shader.hpp:83
raylib::Shader::GenTextureIrradiance
::TextureCubemap GenTextureIrradiance(::Texture2D panorama, int size) const
Definition: Shader.hpp:143
raylib::Shader::~Shader
~Shader()
Definition: Shader.hpp:75
raylib::Shader::EndShaderMode
Shader & EndShaderMode()
Definition: Shader.hpp:88
raylib::Shader::Shader
Shader(::Shader shader)
Definition: Shader.hpp:37
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:96
raylib::Shader::Load
static Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Definition: Shader.hpp:54
raylib::Shader::Shader
Shader()
Definition: Shader.hpp:46
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, ::Texture2D texture)
Set shader uniform value for texture.
Definition: Shader.hpp:134
raylib::Shader::operator=
Shader & operator=(const Shader &shader)
Definition: Shader.hpp:70
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const std::string &value, int uniformType, int count)
Definition: Shader.hpp:118
raylib::Shader
Definition: Shader.hpp:35
raylib::Shader::Shader
Shader(unsigned int Id, int *Locs)
Definition: Shader.hpp:41
raylib::Shader::Shader
Shader(const std::string &vsFileName, const std::string &fsFileName)
Definition: Shader.hpp:50
raylib::Shader::Unload
void Unload()
Definition: Shader.hpp:79
raylib::Shader::GetLocationAttrib
int GetLocationAttrib(const std::string &attribName) const
Get shader attribute location.
Definition: Shader.hpp:103
raylib::Texture
Definition: Texture.hpp:36
raylib::Shader::GenTextureBRDF
::Texture2D GenTextureBRDF(int size) const
Definition: Shader.hpp:151
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, Matrix mat)
Definition: Shader.hpp:126
raylib::Shader::GenTexturePrefilter
::TextureCubemap GenTexturePrefilter(::Texture2D panorama, int size) const
Definition: Shader.hpp:147
raylib::Shader::set
void set(::Shader shader)
Definition: Shader.hpp:156