1#include <Core/Resources/Resources.hpp>
2#include <Engine/Data/ShaderConfiguration.hpp>
3#include <Engine/Data/ShaderProgramManager.hpp>
4#include <glbinding/Version.h>
11 "[[Default resources path not found]]" ) +
12 "Shaders/Materials/Plain/Plain.vert.glsl" };
15 "[[Default resources path not found]]" ) +
16 "Shaders/Materials/Plain/Plain.frag.glsl" };
24 stream <<
" -- shader configuration [" << config.m_name <<
"]\n";
26 for (
const auto& s : config.m_shaders ) {
27 stream <<
" shaders [" << s.first <<
" " << s.second <<
" ]\n";
30 for (
const auto& s : config.m_properties ) {
31 stream <<
"props [" << s <<
"]\n";
34 for (
const auto& s : config.m_includes ) {
35 stream <<
"inc [" << s.first <<
"]\n";
37 for (
const auto& s : config.m_named_strings ) {
38 stream <<
"props [" << s.first <<
"]\n";
43ShaderConfiguration ShaderConfiguration::m_defaultShaderConfig(
"Default Program",
45 defaultFragmentShader );
47ShaderConfiguration::ShaderConfiguration(
const std::string& name ) :
48 m_name { name }, m_version {
"#version " + s_glslVersion } {}
50ShaderConfiguration::ShaderConfiguration(
const std::string& name,
53 m_name { name }, m_version {
"#version " + s_glslVersion } {
54 m_shaders[ShaderType_VERTEX] = { vertexShader,
true };
55 m_shaders[ShaderType_FRAGMENT] = { fragmentShader,
true };
59 m_shaders[type] = { name,
true };
63 m_shaders[type] = { source,
false };
67 m_properties.
insert(
"#define " + prop );
71 for (
const auto& prop : props ) {
72 m_properties.
insert(
"#define " + prop );
76void ShaderConfiguration::removeProperty(
const std::string& prop ) {
77 m_properties.
erase(
"#define " + prop );
85 for (
const auto& incl : incls ) {
90void ShaderConfiguration::removeInclude(
const std::string& incl, ShaderType type ) {
92 m_properties.
erase(
"#include " + incl );
101 return ( ( !m_shaders[ShaderType_VERTEX].first.
empty() ) &&
102 ( !m_shaders[ShaderType_FRAGMENT].first.
empty() ) ) ||
103 !m_shaders[ShaderType_COMPUTE].first.
empty();
109 for (
size_t i = 0; i < ShaderType_COUNT; ++i ) {
110 if ( m_shaders[i] != o.m_shaders[i] ) {
return m_shaders[i] < o.m_shaders[i]; }
113 if ( m_properties.
size() == o.m_properties.
size() ) {
114 if ( m_properties.
empty() ) {
115 if ( m_includes.
size() == o.m_includes.
size() ) {
116 if ( m_includes.
empty() ) { res =
false; }
118 auto lit = m_includes.
begin();
119 auto rit = o.m_includes.
begin();
121 for ( ; ( lit != m_includes.
end() ) && ( *lit == *rit ); ++lit, ++rit )
124 if ( lit == m_includes.
end() ) { res =
false; }
125 else { res = *lit < *rit; }
130 auto lit = m_properties.
begin();
131 auto rit = o.m_properties.
begin();
133 for ( ; ( lit != m_properties.
end() ) && ( *lit == *rit ); ++lit, ++rit )
136 if ( lit == m_properties.
end() ) { res =
false; }
137 else { res = *lit < *rit; }
140 else { res = m_properties.
size() < o.m_properties.
size(); }
154ShaderConfiguration::getNamedStrings()
const {
155 return m_named_strings;
158std::string ShaderConfiguration::s_glslVersion {
"410" };
174 auto it = openGLToGLSL.
find( version.toString() );
175 if ( it != openGLToGLSL.end() ) { s_glslVersion = it->second; }
176 else { s_glslVersion =
"410"; }
179 return s_glslVersion;
static void setOpenGLVersion(const glbinding::Version &version)
set the OpenGL version to use in the generated header for shaders.
void addShader(ShaderType type, const std::string &name)
void addInclude(const std::string &incl, ShaderType type=ShaderType_FRAGMENT)
void addNamedString(const std::string &includepath, const std::string &realfile)
Manage named strings (see ShaderProgramManager::addNamedString)
void addShaderSource(ShaderType type, const std::string &source)
void addProperty(const std::string &prop)
static std::string getGLSLVersion()
get the OpenGL version used in the generated header for shaders.
T emplace_back(T... args)
optional< std::string > getRadiumResourcesPath()
Get the path of Radium internal resources.
hepler function to manage enum as underlying types in VariableSet