Bumped up shader version to 150 (work on shaders not compiling for #115 and #117)

Improved jsonFindDefault to not crash when the value types do not match (should partially fix #116)

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2022-07-15 12:20:12 +02:00
parent d6561268d6
commit 8955ba791c
3 changed files with 38 additions and 5 deletions

View File

@ -104,6 +104,25 @@ template <typename T> T Core::jsonFindDefault (nlohmann::json& data, const char
if (value == data.end () || value->type () == nlohmann::detail::value_t::null)
return defaultValue;
// type checks
if ((std::is_same <T, float>::value || std::is_same <T, double>::value) && value->type () != nlohmann::detail::value_t::number_float)
{
fprintf(stderr, "%s is not of type double, returning default value\n", key);
return defaultValue;
}
else if (std::is_same <T, std::string>::value && value->type () != nlohmann::detail::value_t::string)
{
fprintf (stderr, "%s is not of type string, returning default value\n", key);
return defaultValue;
}
else if (std::is_same <T, bool>::value && value->type () != nlohmann::detail::value_t::boolean)
{
fprintf (stderr, "%s is not of type boolean, returning default value\n", key);
return defaultValue;
}
// TODO: SUPPORT INTEGERS AND OTHER TYPES
return *value;
}

View File

@ -36,18 +36,18 @@ CEffect* CEffect::fromJSON (json data, Core::CObject* object, CContainer* contai
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile ((*file_it).get <std::string> (), container));
auto name_it = jsonFindRequired (content, "name", "Effect must have a name");
auto description_it = jsonFindRequired (content, "description", "Effect must have a description");
auto description = jsonFindDefault <std::string> (content, "description", "");
auto group_it = jsonFindRequired (content, "group", "Effect must have a group");
auto preview_it = jsonFindRequired (content, "preview", "Effect must have a preview");
auto preview = jsonFindDefault <std::string> (content, "preview", "");
auto passes_it = jsonFindRequired (content, "passes", "Effect must have a pass list");
auto dependencies_it = jsonFindRequired (content, "dependencies", "");
auto fbos_it = content.find ("fbos");
CEffect* effect = new CEffect (
*name_it,
*description_it,
description,
*group_it,
*preview_it,
preview,
object
);

View File

@ -478,7 +478,7 @@ namespace WallpaperEngine::Render::Shaders
if (this->m_recursive == false)
{
// add the opengl compatibility at the top
finalCode = "#version 130\n"
finalCode = "#version 150\n"
"#define highp\n"
"#define mediump\n"
"#define lowp\n"
@ -503,6 +503,20 @@ namespace WallpaperEngine::Render::Shaders
"#define float3 vec3\n"
"#define float4 vec4\n";
if (this->m_type == Type_Vertex)
{
finalCode +=
"#define varying out\n"
"#define attribute in\n";
}
else
{
finalCode +=
"#define varying in\n"
"#define gl_FragColor glOutColor\n"
"out vec4 glOutColor;\n";
}
// add combo values
auto cur = this->m_combos->begin ();
auto end = this->m_combos->end ();