Radium Engine  1.5.20
Loading...
Searching...
No Matches
ShaderProgram.hpp
1#pragma once
2
3#include <Engine/RaEngine.hpp>
4
5#include <Core/Types.hpp>
6
7#include <Core/CoreMacros.hpp>
8#include <Engine/Data/ShaderConfiguration.hpp>
9
10#include <globjects/Program.h>
11
12#include <array>
13#include <memory>
14#include <string>
15#include <type_traits>
16
17namespace globjects {
18class Shader;
19class NamedString;
20class StaticStringSource;
21} // namespace globjects
22
23namespace Ra {
24namespace Engine {
25namespace Data {
26
27class Texture;
28
34class RA_ENGINE_API ShaderProgram final
35{
36 public:
38 explicit ShaderProgram( const Data::ShaderConfiguration& shaderConfig );
40
41 void load( const Data::ShaderConfiguration& shaderConfig );
42 void reload();
43
44 Data::ShaderConfiguration getBasicConfiguration() const;
45
46 void bind() const;
47 void validate() const;
48 void unbind() const;
49
51 template <typename T>
52 void setUniform( const char* name, const T& value ) const;
53 void setUniform( const char* name, Texture* tex, int texUnit ) const;
54
55 template <typename T>
56 void setUniform( gl::GLint location, const T& value ) const {
57 m_program->setUniform( location, value );
58 }
59
64 void setUniformTexture( const char* name, Texture* tex ) const;
65
66 globjects::Program* getProgramObject() const;
67
69 void addShaderFromSource( Data::ShaderType type,
71 const std::string& name = "",
72 bool fromFile = true );
73
74 void link();
75
76 private:
77 struct TextureBinding {
78 int m_texUnit { -1 };
79 int m_location { -1 };
80 TextureBinding( int unit, int location ) : m_texUnit { unit }, m_location { location } {}
81 TextureBinding() = default;
82 };
84 TextureUnits textureUnits;
85
86 void loadShader( Data::ShaderType type,
87 const std::string& name,
88 const std::set<std::string>& props,
90 bool fromFile = true,
91 const std::string& version = "#version " +
92 ShaderConfiguration::getGLSLVersion() );
93
94 std::string preprocessIncludes( const std::string& name,
95 const std::string& shader,
96 int level,
97 int line = 0 );
98
99 private:
100 Data::ShaderConfiguration m_configuration;
101
103 m_shaderObjects;
105 m_shaderSources;
106
108};
109
110// declare specialization, definied in .cpp
111template <>
112RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Vector2d& value ) const;
113
114template <>
115RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Vector3d& value ) const;
116
117template <>
118RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Vector4d& value ) const;
119
120template <>
121RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Matrix2d& value ) const;
122
123template <>
124RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Matrix3d& value ) const;
125
126template <>
127RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Core::Matrix4d& value ) const;
128
129template <>
130RA_ENGINE_API void ShaderProgram::setUniform( const char* name, const Scalar& value ) const;
131
132template <>
133RA_ENGINE_API void ShaderProgram::setUniform( const char* name,
134 const std::vector<Scalar>& value ) const;
135
136// Uniform setters
137template <typename T>
138inline void ShaderProgram::setUniform( const char* name, const T& value ) const {
139 m_program->setUniform<T>( name, value );
140}
141
142} // namespace Data
143} // namespace Engine
144} // namespace Ra
void setUniform(const char *name, const T &value) const
Uniform setters.
Represent a Texture of the engine.
Definition Texture.hpp:120
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3