1#ifndef OE_RENDER_SHADER_BASE_H 
    2#define OE_RENDER_SHADER_BASE_H 
    9#include <unordered_map> 
   10#include <glm/mat4x4.hpp> 
   12#include "../scene/material.h" 
   13#include "../util/non_copyable.h" 
   55            void define(
const std::string& name, 
const T& value)
 
   57                _defines[name] = std::to_string(value);
 
 
   65            void define(
const std::string& name, 
const char* value)
 
   67                _defines[name] = std::string(value);
 
 
   75            void define(
const std::string& name, 
const std::string& value)
 
   77                _defines[name] = value;
 
 
  129            void fillTextures(
const std::map<std::string, std::pair<uint32_t, std::shared_ptr<oe::render::Texture>>>& textures);
 
  134            void fillCubemaps(
const std::map<std::string, std::pair<uint32_t, std::shared_ptr<oe::render::Cubemap>>>& cubemaps);
 
  167            void setInt(
const std::string& name, 
const int32_t value);
 
  175            void setUInt(
const std::string& name, 
const uint32_t value);
 
  183            void setFloat(
const std::string& name, 
const float value);
 
  191            void setDouble(
const std::string& name, 
const double value);
 
  199            void setMat3(
const std::string& name, 
const glm::mat3& value);
 
  207            void setMat4(
const std::string& name, 
const glm::mat4& value);
 
  215            void setVec2i(
const std::string& name, 
const glm::ivec2& value);
 
  223            void setVec2(
const std::string& name, 
const glm::vec2& value);
 
  231            void setVec3(
const std::string& name, 
const glm::vec3& value);
 
  239            void setVec4(
const std::string& name, 
const glm::vec4& value);
 
  247            void setIntArray(
const std::string& name, 
const std::vector<int32_t>& values);
 
  255            void setUIntArray(
const std::string& name, 
const std::vector<uint32_t>& values);
 
  263            void setFloatArray(
const std::string& name, 
const std::vector<float>& values);
 
  279            void setVec2iArray(
const std::string& name, 
const std::vector<glm::ivec2>& values);
 
  287            void setVec2Array(
const std::string& name, 
const std::vector<glm::vec2>& values);
 
  295            void setVec3Array(
const std::string& name, 
const std::vector<glm::vec3>& values);
 
  303            void setVec4Array(
const std::string& name, 
const std::vector<glm::vec4>& values);
 
  311            void setMat4Array(
const std::string& name, 
const std::vector<glm::mat4>& values);
 
  314            std::unordered_map<GeometryPass, std::string> _vertex_shader_sources;
 
  315            std::unordered_map<RenderingPass, std::string> _fragment_shader_sources;
 
  323                std::size_t operator ()(
const std::pair<GeometryPass, RenderingPass> &p)
 const 
  325                    auto h1 = std::hash<GeometryPass>{}(p.first);
 
  326                    auto h2 = std::hash<RenderingPass>{}(p.second);
 
  332            std::string _generate_header() const noexcept;
 
  334            uint32_t _program_handle = 0;
 
  338            std::unordered_map<std::
string, std::
string> _defines;
 
  340            std::unordered_map<std::
string, int32_t> _locations;
 
  342            std::unordered_map<std::pair<
GeometryPass, 
RenderingPass>, std::unordered_map<std::
string, int32_t>, PassPairHash> _pass_locations;
 
  345            static uint32_t _last_bound_shader;
 
 
Shader class.
Definition shader_base.h:33
 
void setVec4(const std::string &name, const glm::vec4 &value)
Send a vec4 uniform to the shader.
 
void compile(const GeometryPass vertex_pass, const RenderingPass fragment_pass)
Compile / link the shader using the graphic API.
 
void setUIntArray(const std::string &name, const std::vector< uint32_t > &values)
Send a array of unsigned int uniforms to the shader.
 
void setFloatArray(const std::string &name, const std::vector< float > &values)
Send an array of float uniforms to the shader.
 
const std::string & getName() const
Get shader name.
Definition shader_base.h:96
 
void bind(const GeometryPass vertex_pass, const RenderingPass fragment_pass)
Use the shader in graphic API.
 
void fillFromCamera(const scene::Camera &camera) noexcept
Fill uniforms from camera (mainly position + transform matrices)
 
void setFloat(const std::string &name, const float value)
Send a float uniform to the shader.
 
void setMat3(const std::string &name, const glm::mat3 &value)
Send a 3x3 matrix uniform to the shader.
 
void setVec2(const std::string &name, const glm::vec2 &value)
Send a vec2 uniform to the shader.
 
void setMat4(const std::string &name, const glm::mat4 &value)
Send a 4x4 matrix uniform to the shader.
 
void define(const std::string &name, const char *value)
Define a shader constant.
Definition shader_base.h:65
 
void fillFromMaterial(const scene::Material *material)
Fill uniforms from material.
 
void setMat4Array(const std::string &name, const std::vector< glm::mat4 > &values)
Send an array of matrix uniforms to the shader.
 
void unbind()
Tell the graphic API to release this shader.
 
void setVec2iArray(const std::string &name, const std::vector< glm::ivec2 > &values)
Send an array of ivec2 uniforms to the shader.
 
ShaderBase(const std::string &name="")
Create a new shader instance.
 
void setVec3Array(const std::string &name, const std::vector< glm::vec3 > &values)
Send an array of vec3 uniforms to the shader.
 
void setDouble(const std::string &name, const double value)
Send a double uniform to the shader.
 
void define(const std::string &name, const T &value)
Define a shader constant.
Definition shader_base.h:55
 
void define(const std::string &name)
Define a shader constant without value.
Definition shader_base.h:87
 
void setVec4Array(const std::string &name, const std::vector< glm::vec4 > &values)
Send an array of vec4 uniforms to the shader.
 
void setUInt(const std::string &name, const uint32_t value)
Send an unsigned int uniform to the shader.
 
void setInt(const std::string &name, const int32_t value)
Send an int uniform to the shader.
 
void setVec2Array(const std::string &name, const std::vector< glm::vec2 > &values)
Send an array of vec2 uniforms to the shader.
 
void fillTextures(const std::map< std::string, std::pair< uint32_t, std::shared_ptr< oe::render::Texture > > > &textures)
Fill textures uniforms + bind textures.
 
void setVec3(const std::string &name, const glm::vec3 &value)
Send a vec3 uniform to the shader.
 
void fillCubemaps(const std::map< std::string, std::pair< uint32_t, std::shared_ptr< oe::render::Cubemap > > > &cubemaps)
Fill cubemaps uniforms + bind cubemaps.
 
void setDoubleArray(const std::string &name, const std::vector< double > &values)
Send an array of double uniforms to the shader.
 
void setVec2i(const std::string &name, const glm::ivec2 &value)
Send an ivec2 uniform to the shader.
 
void setIntArray(const std::string &name, const std::vector< int32_t > &values)
Send an array of int uniforms to the shader.
 
void define(const std::string &name, const std::string &value)
Define a shader constant.
Definition shader_base.h:75
 
The "eye of the scene".
Definition camera.h:33
 
Render agnostic material.
Definition material.h:26
 
Prevent class to be copied.
Definition non_copyable.h:12
 
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10
 
RenderingPass
Pipeline rendering passes.
Definition common.h:26
 
GeometryPass
Vertex rendering passes.
Definition common.h:14
 
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19