Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
OpenglShaderProgram.h
Go to the documentation of this file.
1#pragma once
2
4
5#include "ThirdParty/glad2.h"
6
7#include <Common/Container/TStdUnorderedStringMap.h>
8#include <Utility/utility.h>
9
10#include <memory>
11#include <string>
12
13namespace ph::editor::ghi
14{
15
16class Shader;
17
19{
20public:
22 std::string name,
23 const std::shared_ptr<Shader>& vertexShader,
24 const std::shared_ptr<Shader>& fragmentShader);
25
26 ~OpenglShaderProgram() override;
27
28 void bind() override;
29
30 void setInt32(std::string_view name, int32 value) override;
31 void setFloat32(std::string_view name, float32 value) override;
32 void setVector3F(std::string_view name, const math::Vector3F& value) override;
33 void setVector4F(std::string_view name, const math::Vector4F& value) override;
34 void setMatrix4F(std::string_view name, const math::Matrix4F& value) override;
35
36private:
37 struct Uniform final
38 {
39 GLint location = -1;
40 GLsizei arraySize = 0;
41 GLenum type = GL_NONE;
42 };
43
44 static GLuint getOpenglHandle(Shader& shader);
45 void checkLinkStatus(const Shader& vertexShader, const Shader& fragmentShader) const;
46 void validateProgram(const Shader& vertexShader, const Shader& fragmentShader) const;
47 void collectProgramUniforms();
48 const Uniform* getUniform(GLenum type, std::string_view name) const;
49 void warnUniformNotFound(const Uniform* uniform, GLenum intendedType, std::string_view intendedName) const;
50 std::string getInfoLog() const;
51
52 GLuint m_programID;
53 TStdUnorderedStringMap<Uniform> m_nameToUniform;
54};
55
56inline auto OpenglShaderProgram::getUniform(const GLenum type, std::string_view name) const
57-> const Uniform*
58{
59 const auto& iter = m_nameToUniform.find(name);
60 const Uniform* uniform = nullptr;
61 if(iter != m_nameToUniform.cend() && iter->second.type == type)
62 {
63 uniform = &(iter->second);
64 }
65 else
66 {
67 uniform = nullptr;
68 warnUniformNotFound(uniform, type, name);
69 }
70
71 return uniform;
72}
73
74}// end namespace ph::editor::ghi
Definition OpenglShaderProgram.h:19
OpenglShaderProgram(std::string name, const std::shared_ptr< Shader > &vertexShader, const std::shared_ptr< Shader > &fragmentShader)
Definition OpenglShaderProgram.cpp:17
void setInt32(std::string_view name, int32 value) override
Definition OpenglShaderProgram.cpp:55
void bind() override
Definition OpenglShaderProgram.cpp:50
void setVector3F(std::string_view name, const math::Vector3F &value) override
Definition OpenglShaderProgram.cpp:73
void setFloat32(std::string_view name, float32 value) override
Definition OpenglShaderProgram.cpp:64
void setMatrix4F(std::string_view name, const math::Matrix4F &value) override
Definition OpenglShaderProgram.cpp:100
void setVector4F(std::string_view name, const math::Vector4F &value) override
Definition OpenglShaderProgram.cpp:86
~OpenglShaderProgram() override
Definition OpenglShaderProgram.cpp:45
Definition Shader.h:16
Definition ShaderProgram.h:15
Definition PlatformDisplay.h:13