1#ifndef RAYLIB_CPP_INCLUDE_SHADER_HPP_
2#define RAYLIB_CPP_INCLUDE_SHADER_HPP_
8#include "ShaderUnmanaged.hpp"
10#include "./raylib-cpp-utils.hpp"
11#include "./raylib.hpp"
19 using ShaderUnmanaged::ShaderUnmanaged;
21 Shader(
const std::string_view vsFileName,
const std::string_view fsFileName) {
22 set(::LoadShader(vsFileName.data(), fsFileName.data()));
25 Shader(
const char* vsFileName,
const char* fsFileName) {
26 set(::LoadShader(vsFileName, fsFileName));
43 static ::Shader
Load(
const std::string_view vsFileName,
const std::string_view fsFileName) {
44 return ::LoadShader(vsFileName.data(), fsFileName.data());
47 static ::Shader
Load(
const char* vsFileName,
const char* fsFileName) {
48 return ::LoadShader(vsFileName, fsFileName);
56 static ::Shader
LoadFromMemory(
const std::string_view vsCode,
const std::string_view fsCode) {
57 return ::LoadShaderFromMemory(vsCode.data(), fsCode.data());
60 static ::Shader
LoadFromMemory(
const char* vsCode,
const char* fsCode) {
61 return ::LoadShaderFromMemory(vsCode, fsCode);
64 GETTER(
unsigned int, Id,
id)
65 GETTER(
int*, Locs, locs)
97 if (locs !=
nullptr) {
98 ::UnloadShader(*
this);
106 ::BeginShaderMode(*
this);
124 return ::GetShaderLocation(*
this, uniformName.data());
133 return ::GetShaderLocationAttrib(*
this, attribName.data());
142 ::SetShaderValue(*
this, uniformLoc, value, uniformType);
152 inline Shader&
SetValue(std::string_view uniformName,
const void* value,
int uniformType) {
153 ::SetShaderValue(*
this,
GetLocation(uniformName), value, uniformType);
164 ::SetShaderValue(*
this, uniformLoc, &value, uniformType);
175 inline Shader&
SetValue(std::string_view uniformName,
const T& value,
int uniformType) {
176 ::SetShaderValue(*
this,
GetLocation(uniformName), &value, uniformType);
185 Shader&
SetValue(
int uniformLoc,
const void* value,
int uniformType,
int count) {
186 ::SetShaderValueV(*
this, uniformLoc, value, uniformType, count);
196 inline Shader&
SetValue(std::string_view uniformName,
const void* value,
int uniformType,
int count) {
197 ::SetShaderValueV(*
this,
GetLocation(uniformName), value, uniformType, count);
208 ::SetShaderValueV(*
this, uniformLoc, data.value(), uniformType, data.count());
219 inline Shader&
SetValue(std::string_view uniformName, std::span<T> data,
int uniformType) {
220 ::SetShaderValueV(*
this,
GetLocation(uniformName), data.value(), uniformType, data.count());
230 ::SetShaderValueMatrix(*
this, uniformLoc, mat);
241 ::SetShaderValueMatrix(*
this,
GetLocation(uniformName), mat);
251 ::SetShaderValueTexture(*
this, uniformLoc, texture);
261 inline Shader&
SetValue(std::string_view uniformName, const ::Texture2D& texture) {
262 ::SetShaderValueTexture(*
this,
GetLocation(uniformName), texture);
270 return id != 0 && locs !=
nullptr;
274 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.
bool IsValid() const
Retrieves whether or not the shader is ready.
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.
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.
Shader type (generic), not managed by C++ RAII.
All raylib-cpp classes and functions appear in the raylib namespace.