4 #include <entity/component/LightComponents.h>
5 #include <math/Types.h>
6 #include <render/backend/RenderBackend.h>
7 #include <resource/Resource.h>
8 #include <utility/Serial.h>
12 constexpr std::string_view SHADER_PREPROCESSOR_DEFAULT_PREFIX =
"#";
13 constexpr std::string_view SHADER_PREPROCESSOR_DEFAULT_SUFFIX =
"#";
17 explicit Shader(std::string identifier_);
18 void compile(
const byte buffer[], std::size_t bufferLength)
override;
22 inline void setUniform(std::string_view name,
bool value) {
23 Renderer::setShaderUniform1b(this->handle, name, value);
25 inline void setUniform(std::string_view name,
unsigned int value) {
26 Renderer::setShaderUniform1u(this->handle, name, value);
28 inline void setUniform(std::string_view name,
int value) {
29 Renderer::setShaderUniform1i(this->handle, name, value);
31 inline void setUniform(std::string_view name,
float value) {
32 Renderer::setShaderUniform1f(this->handle, name, value);
34 inline void setUniform(std::string_view name, glm::vec2b value) {
35 Renderer::setShaderUniform2b(this->handle, name, value);
37 inline void setUniform(std::string_view name, glm::vec2u value) {
38 Renderer::setShaderUniform2u(this->handle, name, value);
40 inline void setUniform(std::string_view name, glm::vec2i value) {
41 Renderer::setShaderUniform2i(this->handle, name, value);
43 inline void setUniform(std::string_view name, glm::vec2f value) {
44 Renderer::setShaderUniform2f(this->handle, name, value);
46 inline void setUniform(std::string_view name, glm::vec3b value) {
47 Renderer::setShaderUniform3b(this->handle, name, value);
49 inline void setUniform(std::string_view name, glm::vec3u value) {
50 Renderer::setShaderUniform3u(this->handle, name, value);
52 inline void setUniform(std::string_view name, glm::vec3i value) {
53 Renderer::setShaderUniform3i(this->handle, name, value);
55 inline void setUniform(std::string_view name, glm::vec3f value) {
56 Renderer::setShaderUniform3f(this->handle, name, value);
58 inline void setUniform(std::string_view name, glm::vec4b value) {
59 Renderer::setShaderUniform4b(this->handle, name, value);
61 inline void setUniform(std::string_view name, glm::vec4u value) {
62 Renderer::setShaderUniform4u(this->handle, name, value);
64 inline void setUniform(std::string_view name, glm::vec4i value) {
65 Renderer::setShaderUniform4i(this->handle, name, value);
67 inline void setUniform(std::string_view name, glm::vec4f value) {
68 Renderer::setShaderUniform4f(this->handle, name, value);
70 inline void setUniform(std::string_view name, glm::mat4 value) {
71 Renderer::setShaderUniform4m(this->handle, name, value);
74 [[nodiscard]]
inline bool usesPVMatrices()
const {
77 [[nodiscard]]
inline bool usesModelMatrix()
const {
80 [[nodiscard]]
inline bool isLit()
const {
84 static void addPreprocessorSymbol(
const std::string& name,
const std::string& value);
85 static void setPreprocessorPrefix(
const std::string& prefix);
86 static void setPreprocessorSuffix(
const std::string& suffix);
89 static inline std::unordered_map<std::string, std::string> preprocessorSymbols{
90 {
"DIRECTIONAL_LIGHT_MAX", std::to_string(DIRECTIONAL_LIGHT_MAX)},
91 {
"POINT_LIGHT_MAX", std::to_string(POINT_LIGHT_MAX)},
92 {
"SPOT_LIGHT_MAX", std::to_string(SPOT_LIGHT_MAX)},
94 static inline std::string preprocessorPrefix = std::string{SHADER_PREPROCESSOR_DEFAULT_PREFIX};
95 static inline std::string preprocessorSuffix = std::string{SHADER_PREPROCESSOR_DEFAULT_SUFFIX};
97 static std::string replaceMacros(
const std::string&,
const std::string&);
103 std::string vertexPath{
"file://shaders/unlitTextured.vsh"};
104 std::string fragmentPath{
"file://shaders/unlitTextured.fsh"};
107 template<
typename Archive>
108 void serialize(Archive& ar) {
110 cereal::make_nvp(
"usesPV", this->usesPV),
111 cereal::make_nvp(
"usesM", this->usesM),
112 cereal::make_nvp(
"lit", this->lit),
113 cereal::make_nvp(
"vertex", this->vertexPath),
114 cereal::make_nvp(
"fragment", this->fragmentPath)
A chunk of data, usually a file. Is typically cached and shared.