1#include <Core/CoreMacros.hpp>
2#include <Core/Resources/Resources.hpp>
3#include <Engine/Data/ShaderConfiguration.hpp>
5#include <glbinding/Version.h>
6#include <glbinding/Version.inl>
21 "[[Default resources path not found]]" ) +
22 "Shaders/Materials/Plain/Plain.vert.glsl" };
25 "[[Default resources path not found]]" ) +
26 "Shaders/Materials/Plain/Plain.frag.glsl" };
34 stream <<
" -- shader configuration [" << config.m_name <<
"]\n";
36 for (
const auto& s : config.m_shaders ) {
37 stream <<
" shaders [" << s.first <<
" " << s.second <<
" ]\n";
40 for (
const auto& s : config.m_properties ) {
41 stream <<
"props [" << s <<
"]\n";
44 for (
const auto& s : config.m_includes ) {
45 stream <<
"inc [" << s.first <<
"]\n";
47 for (
const auto& s : config.m_named_strings ) {
48 stream <<
"props [" << s.first <<
"]\n";
53ShaderConfiguration ShaderConfiguration::m_defaultShaderConfig(
"Default Program",
55 defaultFragmentShader );
57ShaderConfiguration::ShaderConfiguration(
const std::string& name ) :
58 m_name { name }, m_version {
"#version " + s_glslVersion } {}
57ShaderConfiguration::ShaderConfiguration(
const std::string& name ) : {
…}
60ShaderConfiguration::ShaderConfiguration(
const std::string& name,
63 m_name { name }, m_version {
"#version " + s_glslVersion } {
64 m_shaders[ShaderType_VERTEX] = { vertexShader,
true };
65 m_shaders[ShaderType_FRAGMENT] = { fragmentShader,
true };
60ShaderConfiguration::ShaderConfiguration(
const std::string& name, {
…}
69 m_shaders[type] = { name,
true };
73 m_shaders[type] = { source,
false };
77 m_properties.
insert(
"#define " + prop );
81 for (
const auto& prop : props ) {
82 m_properties.
insert(
"#define " + prop );
86void ShaderConfiguration::removeProperty(
const std::string& prop ) {
87 m_properties.
erase(
"#define " + prop );
95 for (
const auto& incl : incls ) {
100void ShaderConfiguration::removeInclude(
const std::string& incl, ShaderType type ) {
102 m_properties.
erase(
"#include " + incl );
111 return ( ( !m_shaders[ShaderType_VERTEX].first.
empty() ) &&
112 ( !m_shaders[ShaderType_FRAGMENT].first.
empty() ) ) ||
113 !m_shaders[ShaderType_COMPUTE].first.
empty();
119 for (
size_t i = 0; i < ShaderType_COUNT; ++i ) {
120 if ( m_shaders[i] != o.m_shaders[i] ) {
return m_shaders[i] < o.m_shaders[i]; }
123 if ( m_properties.
size() == o.m_properties.
size() ) {
124 if ( m_properties.
empty() ) {
125 if ( m_includes.
size() == o.m_includes.
size() ) {
126 if ( m_includes.
empty() ) { res =
false; }
128 auto lit = m_includes.
begin();
129 auto rit = o.m_includes.
begin();
131 for ( ; ( lit != m_includes.
end() ) && ( *lit == *rit ); ++lit, ++rit )
134 if ( lit == m_includes.
end() ) { res =
false; }
135 else { res = *lit < *rit; }
140 auto lit = m_properties.
begin();
141 auto rit = o.m_properties.
begin();
143 for ( ; ( lit != m_properties.
end() ) && ( *lit == *rit ); ++lit, ++rit )
146 if ( lit == m_properties.
end() ) { res =
false; }
147 else { res = *lit < *rit; }
150 else { res = m_properties.
size() < o.m_properties.
size(); }
164ShaderConfiguration::getNamedStrings()
const {
165 return m_named_strings;
168std::string ShaderConfiguration::s_glslVersion {
"410" };
184 auto it = openGLToGLSL.
find( version.toString() );
185 if ( it != openGLToGLSL.end() ) { s_glslVersion = it->second; }
186 else { s_glslVersion =
"410"; }
189 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