Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ShaderProgram.h
Go to the documentation of this file.
1#pragma once
2
3#include <Common/primitive_type.h>
4#include <Common/assertion.h>
5#include <Math/math_fwd.h>
6
7#include <string>
8#include <string_view>
9#include <type_traits>
10
11namespace ph::editor::ghi
12{
13
15{
16public:
17 explicit ShaderProgram(std::string name);
18 virtual ~ShaderProgram();
19
20 virtual void bind() = 0;
21
22 virtual void setInt32(std::string_view name, int32 value) = 0;
23 virtual void setFloat32(std::string_view name, float32 value) = 0;
24 virtual void setVector3F(std::string_view name, const math::Vector3F& value) = 0;
25 virtual void setVector4F(std::string_view name, const math::Vector4F& value) = 0;
26 virtual void setMatrix4F(std::string_view name, const math::Matrix4F& value) = 0;
27
28 std::string_view getName() const;
29
30 template<typename T>
31 void setUniform(std::string_view name, const T& value);
32
33private:
34 std::string m_name;
35};
36
37inline std::string_view ShaderProgram::getName() const
38{
39 return m_name;
40}
41
42template<typename T>
43inline void ShaderProgram::setUniform(std::string_view name, const T& value)
44{
45 if constexpr(std::is_same_v<T, int32>)
46 {
47 setInt32(name, value);
48 }
49 else if constexpr(std::is_same_v<T, float32>)
50 {
51 setFloat32(name, value);
52 }
53 else if constexpr(std::is_same_v<T, math::Vector3F>)
54 {
55 setVector3F(name, value);
56 }
57 else if constexpr(std::is_same_v<T, math::Vector4F>)
58 {
59 setVector4F(name, value);
60 }
61 else if constexpr(std::is_same_v<T, math::Matrix4F>)
62 {
63 setMatrix4F(name, value);
64 }
65 else
66 {
67 PH_ASSERT_UNREACHABLE_SECTION();
68 }
69}
70
71}// end namespace ph::editor::ghi
Definition ShaderProgram.h:15
ShaderProgram(std::string name)
Definition ShaderProgram.cpp:8
virtual void setFloat32(std::string_view name, float32 value)=0
virtual void setVector3F(std::string_view name, const math::Vector3F &value)=0
virtual void setVector4F(std::string_view name, const math::Vector4F &value)=0
void setUniform(std::string_view name, const T &value)
Definition ShaderProgram.h:43
virtual void setMatrix4F(std::string_view name, const math::Matrix4F &value)=0
virtual void setInt32(std::string_view name, int32 value)=0
std::string_view getName() const
Definition ShaderProgram.h:37
Definition PlatformDisplay.h:13