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 
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& BeginMode() {
84  ::BeginShaderMode(*this);
85  return *this;
86  }
87 
88  inline Shader& EndMode() {
89  ::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 
112  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType) {
113  ::SetShaderValue(*this, uniformLoc, value.c_str(), uniformType);
114  return *this;
115  }
116 
122  inline Shader& SetValue(int uniformLoc, const std::string& value, int uniformType, int count) {
123  ::SetShaderValueV(*this, uniformLoc, value.c_str(), uniformType, count);
124  return *this;
125  }
126 
132  inline Shader& SetValue(int uniformLoc, const ::Matrix& mat) {
133  ::SetShaderValueMatrix(*this, uniformLoc, mat);
134  return *this;
135  }
136 
140  inline Shader& SetValue(int uniformLoc, const ::Texture2D& texture) {
141  ::SetShaderValueTexture(*this, uniformLoc, texture);
142  return *this;
143  }
144 
145  ::TextureCubemap GenTextureCubemap(const ::Texture2D& panorama, int size, int format) const {
146  return ::GenTextureCubemap(*this, panorama, size, format);
147  }
148 
149  ::TextureCubemap GenTextureIrradiance(const ::Texture2D& panorama, int size) const {
150  return ::GenTextureIrradiance(*this, panorama, size);
151  }
152 
153  ::TextureCubemap GenTexturePrefilter(const ::Texture2D& panorama, int size) const {
154  return ::GenTexturePrefilter(*this, panorama, size);
155  }
156 
157  ::Texture2D GenTextureBRDF(int size) const {
158  return ::GenTextureBRDF(*this, size);
159  }
160 
161  protected:
162  inline void set(const ::Shader& shader) {
163  id = shader.id;
164  locs = shader.locs;
165  }
166 };
167 } // namespace raylib
168 
169 #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:112
raylib::Shader::GenTextureCubemap
::TextureCubemap GenTextureCubemap(const ::Texture2D &panorama, int size, int format) const
Definition: Shader.hpp:145
raylib::Shader::~Shader
~Shader()
Definition: Shader.hpp:75
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Definition: Shader.hpp:132
raylib::Shader::GenTexturePrefilter
::TextureCubemap GenTexturePrefilter(const ::Texture2D &panorama, int size) const
Definition: Shader.hpp:153
raylib::Shader::GetLocation
int GetLocation(const std::string &uniformName) const
Get shader uniform location.
Definition: Shader.hpp:96
raylib::Shader::Shader
Shader()
Definition: Shader.hpp:46
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)
Set shader uniform value vector.
Definition: Shader.hpp:122
raylib::Shader::GenTextureIrradiance
::TextureCubemap GenTextureIrradiance(const ::Texture2D &panorama, int size) const
Definition: Shader.hpp:149
raylib::Shader::EndMode
Shader & EndMode()
Definition: Shader.hpp:88
raylib::Shader
Definition: Shader.hpp:35
raylib::Shader::BeginMode
Shader & BeginMode()
Definition: Shader.hpp:83
raylib::Shader::Shader
Shader(unsigned int Id, int *Locs)
Definition: Shader.hpp:41
raylib::Shader::set
void set(const ::Shader &shader)
Definition: Shader.hpp:162
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::Shader::LoadCode
::Shader LoadCode(const std::string &vsCode, const std::string &fsCode)
Definition: Shader.hpp:58
raylib::Texture
Definition: Texture.hpp:36
raylib::Shader::GenTextureBRDF
::Texture2D GenTextureBRDF(int size) const
Definition: Shader.hpp:157
raylib::Shader::Shader
Shader(const ::Shader &shader)
Definition: Shader.hpp:37
raylib::Shader::Load
::Shader Load(const std::string &vsFileName, const std::string &fsFileName)
Definition: Shader.hpp:54
raylib::Shader::SetValue
Shader & SetValue(int uniformLoc, const ::Texture2D &texture)
Set shader uniform value for texture.
Definition: Shader.hpp:140