1#ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
2#define RAYLIB_CPP_INCLUDE_SHADER_HPP_
9#include "./raylib-cpp-utils.hpp"
18 Shader(const ::Shader& shader) {
22 Shader(
unsigned int id,
int* locs =
nullptr) : ::Shader{id, locs} {}
23 Shader(
unsigned int id, std::span<int> locs) : ::Shader{id, locs.data()} {}
25 Shader(
const std::string_view vsFileName,
const std::string_view fsFileName) {
26 set(::LoadShader(vsFileName.data(), fsFileName.data()));
29 Shader(
const char* vsFileName,
const char* fsFileName) {
30 set(::LoadShader(vsFileName, fsFileName));
47 static ::Shader
Load(
const std::string_view vsFileName,
const std::string_view fsFileName) {
48 return ::LoadShader(vsFileName.data(), fsFileName.data());
51 static ::Shader
Load(
const char* vsFileName,
const char* fsFileName) {
52 return ::LoadShader(vsFileName, fsFileName);
60 static ::Shader
LoadFromMemory(
const std::string_view vsCode,
const std::string_view fsCode) {
61 return ::LoadShaderFromMemory(vsCode.data(), fsCode.data());
64 static ::Shader
LoadFromMemory(
const char* vsCode,
const char* fsCode) {
65 return ::LoadShaderFromMemory(vsCode, fsCode);
68 GETTER(
unsigned int, Id,
id)
69 GETTER(
int*, Locs, locs)
103 if (locs !=
nullptr) {
104 ::UnloadShader(*
this);
112 ::BeginShaderMode(*
this);
130 return ::GetShaderLocation(*
this, uniformName.data());
139 return ::GetShaderLocationAttrib(*
this, attribName.data());
148 ::SetShaderValue(*
this, uniformLoc, value, uniformType);
158 inline Shader&
SetValue(std::string_view uniformName,
const void* value,
int uniformType) {
159 ::SetShaderValue(*
this,
GetLocation(uniformName), value, uniformType);
170 ::SetShaderValue(*
this, uniformLoc, &value, uniformType);
181 inline Shader&
SetValue(std::string_view uniformName,
const T& value,
int uniformType) {
182 ::SetShaderValue(*
this,
GetLocation(uniformName), &value, uniformType);
191 Shader&
SetValue(
int uniformLoc,
const void* value,
int uniformType,
int count) {
192 ::SetShaderValueV(*
this, uniformLoc, value, uniformType, count);
202 inline Shader&
SetValue(std::string_view uniformName,
const void* value,
int uniformType,
int count) {
203 ::SetShaderValueV(*
this,
GetLocation(uniformName), value, uniformType, count);
214 ::SetShaderValueV(*
this, uniformLoc, data.value(), uniformType, data.count());
225 inline Shader&
SetValue(std::string_view uniformName, std::span<T> data,
int uniformType) {
226 ::SetShaderValueV(*
this,
GetLocation(uniformName), data.value(), uniformType, data.count());
236 ::SetShaderValueMatrix(*
this, uniformLoc, mat);
247 ::SetShaderValueMatrix(*
this,
GetLocation(uniformName), mat);
257 ::SetShaderValueTexture(*
this, uniformLoc, texture);
267 inline Shader&
SetValue(std::string_view uniformName, const ::Texture2D& texture) {
268 ::SetShaderValueTexture(*
this,
GetLocation(uniformName), texture);
276 return id != 0 && locs !=
nullptr;
280 void set(const ::Shader& shader) {
Shader & SetValue(std::string_view uniformName, const T &value, int uniformType)
Set shader uniform value Automatically finds the location of the uniform given its name.
Shader & SetValue(int uniformLoc, const ::Texture2D &texture)
Set shader uniform value for texture.
Shader & SetValue(std::string_view uniformName, const void *value, int uniformType)
Set shader uniform value Automatically finds the location of the uniform given its name.
int GetLocationAttrib(const std::string_view attribName) const
Get shader attribute location.
Shader & SetValue(int uniformLoc, std::span< T > data, int uniformType)
Set shader uniform value vector (represented as a std::span)
Shader & SetValue(std::string_view uniformName, const ::Texture2D &texture)
Set shader uniform value for texture Automatically finds the location of the uniform given its name.
Shader & SetValue(std::string_view uniformName, const ::Matrix &mat)
Set shader uniform value (matrix 4x4) Automatically finds the location of the uniform given its name.
void Unload()
Unload shader from GPU memory (VRAM)
~Shader()
Unload shader from GPU memory (VRAM)
Shader & BeginMode()
Begin custom shader drawing.
Shader & SetValue(int uniformLoc, const void *value, int uniformType)
Set shader uniform value.
Shader & SetValue(std::string_view uniformName, std::span< T > data, int uniformType)
Set shader uniform value vector (represented as a std::span) Automatically finds the location of the ...
Shader & EndMode()
End custom shader drawing (use default shader).
Shader & SetValue(int uniformLoc, const ::Matrix &mat)
Set shader uniform value (matrix 4x4)
Shader & SetValue(std::string_view uniformName, const void *value, int uniformType, int count)
Set shader uniform value vector Automatically finds the location of the uniform given its name.
::Shader Load(const std::string_view vsFileName, const std::string_view fsFileName)
Load shader from files and bind default locations.
bool IsReady() const
Retrieves whether or not the shader is ready.
int GetLocation(const std::string_view uniformName) const
Get shader uniform location.
Shader & SetValue(int uniformLoc, const void *value, int uniformType, int count)
Set shader uniform value vector.
::Shader LoadFromMemory(const std::string_view vsCode, const std::string_view fsCode)
Load a shader from memory.
Shader & SetValue(int uniformLoc, const T &value, int uniformType)
Set shader uniform value.