mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
+ Support for loading combos settings directly from the JSON
~ Fixed loading of uncompressed textures Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
d05e751839
commit
43263b6a72
@ -30,10 +30,14 @@ namespace wp
|
||||
return;
|
||||
|
||||
json::const_iterator textures = (*curpass).find ("textures");
|
||||
json::const_iterator combos = (*curpass).find ("combos");
|
||||
|
||||
if (textures == (*curpass).end () || (*textures).is_array () == false)
|
||||
return;
|
||||
|
||||
if (combos != (*curpass).end ())
|
||||
this->parseCombos (*combos);
|
||||
|
||||
json::const_iterator curtex = (*textures).begin ();
|
||||
json::const_iterator endtex = (*textures).end ();
|
||||
|
||||
@ -88,8 +92,8 @@ namespace wp
|
||||
irr::io::path fragpath = shaderpath + ".frag";
|
||||
irr::io::path vertpath = shaderpath + ".vert";
|
||||
|
||||
this->m_fragShader = new wp::shaders::compiler (fragpath, wp::shaders::compiler::Type::Type_Pixel, false);
|
||||
this->m_vertShader = new wp::shaders::compiler (vertpath, wp::shaders::compiler::Type::Type_Vertex, false);
|
||||
this->m_fragShader = new wp::shaders::compiler (fragpath, wp::shaders::compiler::Type::Type_Pixel, &this->m_combos, false);
|
||||
this->m_vertShader = new wp::shaders::compiler (vertpath, wp::shaders::compiler::Type::Type_Vertex, &this->m_combos, false);
|
||||
|
||||
this->m_materialType = wp::irrlicht::driver->getGPUProgrammingServices ()
|
||||
->addHighLevelShaderMaterial (
|
||||
@ -315,6 +319,26 @@ namespace wp
|
||||
}
|
||||
}
|
||||
|
||||
void effect::parseCombos (json data)
|
||||
{
|
||||
json::const_iterator cur = data.begin ();
|
||||
json::const_iterator end = data.end ();
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
{
|
||||
std::string name = cur.key ();
|
||||
|
||||
if ((*cur).is_number_integer () == true)
|
||||
{
|
||||
this->m_combos.insert (std::pair <std::string, int> (name, (*cur).get <int> ()));
|
||||
}
|
||||
else
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Unknown type for combo value", name.c_str (), irr::ELL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<wp::texture*>& effect::getTextureList ()
|
||||
{
|
||||
return this->m_textures;
|
||||
|
@ -37,12 +37,14 @@ namespace wp
|
||||
};
|
||||
|
||||
void parseConstantValues (json data);
|
||||
void parseCombos (json data);
|
||||
|
||||
wp::shaders::compiler* m_fragShader;
|
||||
wp::shaders::compiler* m_vertShader;
|
||||
|
||||
std::map <std::string, ShaderParameter*> m_vertexVariables;
|
||||
std::map <std::string, ShaderParameter*> m_pixelVariables;
|
||||
std::map <std::string, int> m_combos;
|
||||
|
||||
std::map <std::string, void*> m_constants;
|
||||
std::vector <wp::texture*> m_textures;
|
||||
|
@ -131,6 +131,14 @@ namespace irr {
|
||||
|
||||
input->read (&mipmap_compressed_size, 4);
|
||||
|
||||
// TODO: BETTER POSITION FOR THIS
|
||||
if (mipmap_compression == 0)
|
||||
{
|
||||
// this might be better named as mipmap_bytes_size instead of compressed_size
|
||||
// as in uncompressed files this variable actually holds the file length
|
||||
mipmap_uncompressed_size = mipmap_compressed_size;
|
||||
}
|
||||
|
||||
char *decompressedBuffer = new char [mipmap_uncompressed_size];
|
||||
|
||||
if (mipmap_compression == 1)
|
||||
@ -216,6 +224,11 @@ namespace irr {
|
||||
case FREE_IMAGE_FORMAT::FIF_JPEG:
|
||||
// add extension to the file
|
||||
filename += ".jpg";
|
||||
wp::irrlicht::device->getFileSystem ()->createAndWriteFile ("/tmp/test.jpg", false)->write (filebuffer, mipmap_uncompressed_size);
|
||||
file = wp::irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
|
||||
break;
|
||||
case FREE_IMAGE_FORMAT::FIF_GIF:
|
||||
filename += ".gif";
|
||||
file = wp::irrlicht::device->getFileSystem ()->createMemoryReadFile (filebuffer, mipmap_uncompressed_size, filename.c_str (), true);
|
||||
break;
|
||||
default:
|
||||
|
@ -17,8 +17,11 @@ namespace wp
|
||||
{
|
||||
namespace shaders
|
||||
{
|
||||
compiler::compiler (irr::io::path& file, Type type, bool recursive)
|
||||
compiler::compiler (irr::io::path& file, Type type, std::map<std::string, int>* combos, bool recursive)
|
||||
{
|
||||
this->m_recursive = recursive;
|
||||
this->m_combos = combos;
|
||||
|
||||
// begin with an space so it gets ignored properly on parse
|
||||
if (recursive == false)
|
||||
{
|
||||
@ -208,7 +211,7 @@ namespace wp
|
||||
|
||||
// now compile the new shader
|
||||
// do not include the default header (as it's already included in the parent)
|
||||
compiler loader (shader, this->m_type, true);
|
||||
compiler loader (shader, this->m_type, this->m_combos, true);
|
||||
|
||||
return loader.precompile ();
|
||||
}
|
||||
@ -372,6 +375,19 @@ namespace wp
|
||||
|
||||
this->parseComboConfiguration (configuration); BREAK_IF_ERROR;
|
||||
}
|
||||
else if (this->peekString ("[COMBO_OFF]", it) == true)
|
||||
{
|
||||
// parse combo json data to define the proper variables
|
||||
this->ignoreSpaces (it);
|
||||
begin = it;
|
||||
this->ignoreUpToNextLineFeed (it);
|
||||
|
||||
std::string configuration; configuration.append (begin, it);
|
||||
|
||||
this->m_compiledContent += "// [COMBO_OFF] " + configuration;
|
||||
|
||||
this->parseComboConfiguration (configuration); BREAK_IF_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ignoreUpToNextLineFeed (it);
|
||||
@ -420,8 +436,11 @@ namespace wp
|
||||
}
|
||||
}
|
||||
|
||||
wp::irrlicht::device->getLogger ()->log ("Compiled shader output for", this->m_file.c_str ());
|
||||
wp::irrlicht::device->getLogger ()->log (this->m_compiledContent.c_str ());
|
||||
if (this->m_recursive == false)
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Compiled shader output for", this->m_file.c_str ());
|
||||
wp::irrlicht::device->getLogger ()->log (this->m_compiledContent.c_str ());
|
||||
}
|
||||
|
||||
return this->m_compiledContent;
|
||||
#undef BREAK_IF_ERROR
|
||||
@ -436,29 +455,38 @@ namespace wp
|
||||
// add line feed just in case
|
||||
this->m_compiledContent += "\n";
|
||||
|
||||
// {"material":"ui_editor_properties_perspective","combo":"PERSPECTIVE","type":"options","default":0}
|
||||
|
||||
if (combo == data.end () || defvalue == data.end ())
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Cannot parse combo information", irr::ELL_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((*defvalue).is_number_float ())
|
||||
// check the combos
|
||||
std::map<std::string, int>::const_iterator entry = this->m_combos->find ((*combo).get <std::string> ());
|
||||
|
||||
if (entry == this->m_combos->end ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::f32> ()) + "\n";
|
||||
}
|
||||
else if ((*defvalue).is_number_integer ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::s32> ()) + "\n";
|
||||
}
|
||||
else if ((*defvalue).is_string ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + (*defvalue).get <std::string> () + "\n";
|
||||
// if no combo is defined just load the default settings
|
||||
if ((*defvalue).is_number_float ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::f32> ()) + "\n";
|
||||
}
|
||||
else if ((*defvalue).is_number_integer ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*defvalue).get <irr::s32> ()) + "\n";
|
||||
}
|
||||
else if ((*defvalue).is_string ())
|
||||
{
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + (*defvalue).get <std::string> () + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Cannot parse combo information, unknown type", irr::ELL_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Cannot parse combo information, unknown type", irr::ELL_ERROR);
|
||||
this->m_compiledContent += "#define " + (*combo).get <std::string> () + " " + std::to_string ((*entry).second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,7 +500,9 @@ namespace wp
|
||||
// this is not a real parameter
|
||||
if (material == data.end () || defvalue == data.end ())
|
||||
{
|
||||
wp::irrlicht::device->getLogger ()->log ("Cannot parse parameter info for ", name.c_str (), irr::ELL_ERROR);
|
||||
if (type != "sampler2D")
|
||||
wp::irrlicht::device->getLogger ()->log ("Cannot parse parameter info for ", name.c_str (), irr::ELL_ERROR);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -550,7 +580,9 @@ namespace wp
|
||||
}
|
||||
else if (type == "sampler2D")
|
||||
{
|
||||
param->defaultValue = nullptr;
|
||||
// samplers are not saved, we can ignore them for now
|
||||
delete param;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ namespace wp
|
||||
* @param type The type of shader
|
||||
* @param recursive Whether the compiler should add base definitions or not
|
||||
*/
|
||||
compiler (irr::io::path& file, Type type, bool recursive = false);
|
||||
compiler (irr::io::path& file, Type type, std::map<std::string, int>* combos, bool recursive = false);
|
||||
/**
|
||||
* Performs the actual pre-compilation/pre-processing over the shader files
|
||||
* This step is kinda big, replaces variables names on sVariableReplacement,
|
||||
@ -225,9 +225,17 @@ namespace wp
|
||||
*/
|
||||
Type m_type;
|
||||
/**
|
||||
* Tha parameters the shader needs
|
||||
* The parameters the shader needs
|
||||
*/
|
||||
std::vector <ShaderParameter*> m_parameters;
|
||||
/**
|
||||
* The combos the shader should be generated with
|
||||
*/
|
||||
std::map <std::string, int>* m_combos;
|
||||
/**
|
||||
* Whether this compilation is a recursive one or not
|
||||
*/
|
||||
bool m_recursive;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user