Bomberman
Shaders.hpp
Go to the documentation of this file.
1 //
2 // Created by cbihan on 04/06/2021.
3 //
4 
5 #pragma once
6 
7 #include <string>
8 #include <memory>
9 #include <map>
10 #include <raylib.h>
11 #include "Utils/Cache.hpp"
12 #include "Vector/Vector3.hpp"
13 
14 namespace RAY
15 {
16  class Shader
17  {
18  private:
20  std::string _vertexFile;
22  std::string _fragmentFile;
23 
25  std::shared_ptr<::Shader> _rayLibShader;
26 
28  std::map<std::string, int> _shaderIndexVars = {};
29 
31  public:
32  //INTERNAL:
33  const std::shared_ptr<::Shader> &getShaderPtr() const;
34 
35  public:
36 
38  static void BeginUsingCustomShader(RAY::Shader &shader);
40  static void EndUsingCustomShader();
41 
44  void setShaderUniformVar(const std::string &varName, float value);
45 
48  void setShaderUniformVar(const std::string &varName, int value);
49 
50  void setShaderUniformVar(const std::string &varName, const RAY::Vector3 &vector);
51 
52  void setLocation(::ShaderLocationIndex, const std::string &name);
53 
55  Shader(const std::string &vertexFile, const std::string &fragmentFile, bool lonely = false);
57  Shader(const Shader &) = default;
59  ~Shader() = default;
61  Shader &operator=(const Shader &) = default;
62  };
63 
64 }
Vector3.hpp
RAY::Vector3
A Three-dimensionnal Vector data type.
Definition: Vector3.hpp:15
Cache.hpp
RAY::Shader::_fragmentFile
std::string _fragmentFile
The fragment file of the shader.
Definition: Shaders.hpp:22
RAY::Shader::getShaderPtr
const std::shared_ptr<::Shader > & getShaderPtr() const
Definition: Shaders.cpp:24
RAY::Shader::_vertexFile
std::string _vertexFile
The vertex file of the shader.
Definition: Shaders.hpp:20
RAY::Shader::_shaderIndexVars
std::map< std::string, int > _shaderIndexVars
Fetch and cache the index of the shader variable on the first set of the var.
Definition: Shaders.hpp:28
RAY
Definition: IAudio.hpp:12
RAY::Shader::Shader
Shader(const std::string &vertexFile, const std::string &fragmentFile, bool lonely=false)
ctor if no vertexfile in needed set it to nullptr
Definition: Shaders.cpp:16
RAY::Shader::BeginUsingCustomShader
static void BeginUsingCustomShader(RAY::Shader &shader)
start using a custom shader when drawing
Definition: Shaders.cpp:56
RAY::Shader::EndUsingCustomShader
static void EndUsingCustomShader()
stop using the custom shader
Definition: Shaders.cpp:61
RAY::Cache<::Shader >
Definition: Cache.hpp:112
RAY::Shader::~Shader
~Shader()=default
dtor
RAY::Shader::setShaderUniformVar
void setShaderUniformVar(const std::string &varName, float value)
The set var for float values.
Definition: Shaders.cpp:29
RAY::Shader::_shadersCache
static Cache<::Shader > _shadersCache
Definition: Shaders.hpp:30
RAY::Shader
Definition: Shaders.hpp:16
RAY::Shader::operator=
Shader & operator=(const Shader &)=default
Assignment operator.
RAY::Shader::setLocation
void setLocation(::ShaderLocationIndex, const std::string &name)
RAY::Shader::_rayLibShader
std::shared_ptr<::Shader > _rayLibShader
Raylib shader struct.
Definition: Shaders.hpp:25