1#ifndef OE_RENDER_SHADER_BASE_H
2#define OE_RENDER_SHADER_BASE_H
8#include <unordered_map>
9#include <glm/mat4x4.hpp>
12#include "../scene/material.h"
45 _program_handle(other._program_handle),
47 _defines(other._defines),
48 _locations(other._locations),
49 _pass_locations(other._pass_locations),
50 _pass_programs(other._pass_programs)
52 other._program_handle = 0;
53 other._pass_programs = {};
69 void define(
const std::string& name,
const T& value)
71 _defines[name] = std::to_string(value);
79 void define(
const std::string& name,
const char* value)
81 _defines[name] = std::string(value);
89 void define(
const std::string& name,
const std::string& value)
91 _defines[name] = value;
150 void fillTextures(
const std::map<std::string, std::pair<uint32_t, Texture*>>& textures);
155 void fillCubemaps(
const std::map<std::string, std::pair<uint32_t, Cubemap*>>& cubemaps);
188 void setInt(
const std::string& name,
const int32_t value);
196 void setUInt(
const std::string& name,
const uint32_t value);
204 void setFloat(
const std::string& name,
const float value);
212 void setDouble(
const std::string& name,
const double value);
220 void setMat3(
const std::string& name,
const glm::mat3& value);
228 void setMat4(
const std::string& name,
const glm::mat4& value);
236 void setVec2i(
const std::string& name,
const glm::ivec2& value);
244 void setVec2(
const std::string& name,
const glm::vec2& value);
252 void setVec3(
const std::string& name,
const glm::vec3& value);
260 void setVec4(
const std::string& name,
const glm::vec4& value);
268 void setIntArray(
const std::string& name,
const std::vector<int32_t>& values);
276 void setUIntArray(
const std::string& name,
const std::vector<uint32_t>& values);
284 void setFloatArray(
const std::string& name,
const std::vector<float>& values);
300 void setVec2iArray(
const std::string& name,
const std::vector<glm::ivec2>& values);
308 void setVec2Array(
const std::string& name,
const std::vector<glm::vec2>& values);
316 void setVec3Array(
const std::string& name,
const std::vector<glm::vec3>& values);
324 void setVec4Array(
const std::string& name,
const std::vector<glm::vec4>& values);
332 void setMat4Array(
const std::string& name,
const std::vector<glm::mat4>& values);
335 std::unordered_map<GeometryPass, std::string> _vertex_shader_sources;
336 std::unordered_map<RenderingPass, std::string> _fragment_shader_sources;
344 std::size_t operator ()(
const std::pair<GeometryPass, RenderingPass> &p)
const
346 auto h1 = std::hash<GeometryPass>{}(p.first);
347 auto h2 = std::hash<RenderingPass>{}(p.second);
353 std::string _generate_header() const noexcept;
355 uint32_t _program_handle = 0;
359 std::unordered_map<std::
string, std::
string> _defines;
361 std::unordered_map<std::
string, int32_t> _locations;
363 std::unordered_map<std::pair<
GeometryPass,
RenderingPass>, std::unordered_map<std::
string, int32_t>, PassPairHash> _pass_locations;
366 static uint32_t _last_bound_shader;
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 uint32_t uniforms to the shader.
void setFloatArray(const std::string &name, const std::vector< float > &values)
Send an array of float uniforms to the shader.
void fillCubemaps(const std::map< std::string, std::pair< uint32_t, Cubemap * > > &cubemaps)
Fill cubemaps uniforms + bind cubemaps.
const std::string & getName() const
Get shader name.
Definition shader_base.h:110
void fillTextures(std::span< const scene::TextureProperty > textures)
Fill textures uniforms + bind textures.
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:79
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 fillTextures(const std::map< std::string, std::pair< uint32_t, Texture * > > &textures)
Fill textures uniforms + bind textures.
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:69
void define(const std::string &name)
Define a shader constant without value.
Definition shader_base.h:101
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 uint32_t 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 setVec3(const std::string &name, const glm::vec3 &value)
Send a vec3 uniform to the shader.
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:89
The "eye of the scene".
Definition camera.h:31
Render agnostic material.
Definition material.h:90
Scene node.
Definition node.h:30
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures).
Definition opengl.h:12
RenderingPass
Pipeline rendering passes.
Definition passes.h:24
GeometryPass
Vertex rendering passes.
Definition passes.h:12
Scene related management (Render-agnostic Geometry, Manger, etc...).
Definition debug.h:19