diff --git a/wallpaperengine/effect.cpp b/wallpaperengine/effect.cpp index 6dd06c9..708849b 100644 --- a/wallpaperengine/effect.cpp +++ b/wallpaperengine/effect.cpp @@ -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 (name, (*cur).get ())); + } + else + { + wp::irrlicht::device->getLogger ()->log ("Unknown type for combo value", name.c_str (), irr::ELL_ERROR); + } + } + } + std::vector& effect::getTextureList () { return this->m_textures; diff --git a/wallpaperengine/effect.h b/wallpaperengine/effect.h index e99cb46..84f4f2d 100644 --- a/wallpaperengine/effect.h +++ b/wallpaperengine/effect.h @@ -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 m_vertexVariables; std::map m_pixelVariables; + std::map m_combos; std::map m_constants; std::vector m_textures; diff --git a/wallpaperengine/irr/CImageLoaderTEX.cpp b/wallpaperengine/irr/CImageLoaderTEX.cpp index 7112db1..95a27a4 100644 --- a/wallpaperengine/irr/CImageLoaderTEX.cpp +++ b/wallpaperengine/irr/CImageLoaderTEX.cpp @@ -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: diff --git a/wallpaperengine/shaders/compiler.cpp b/wallpaperengine/shaders/compiler.cpp index a2a6e7f..19d841f 100644 --- a/wallpaperengine/shaders/compiler.cpp +++ b/wallpaperengine/shaders/compiler.cpp @@ -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* 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::const_iterator entry = this->m_combos->find ((*combo).get ()); + + if (entry == this->m_combos->end ()) { - this->m_compiledContent += "#define " + (*combo).get () + " " + std::to_string ((*defvalue).get ()) + "\n"; - } - else if ((*defvalue).is_number_integer ()) - { - this->m_compiledContent += "#define " + (*combo).get () + " " + std::to_string ((*defvalue).get ()) + "\n"; - } - else if ((*defvalue).is_string ()) - { - this->m_compiledContent += "#define " + (*combo).get () + " " + (*defvalue).get () + "\n"; + // if no combo is defined just load the default settings + if ((*defvalue).is_number_float ()) + { + this->m_compiledContent += "#define " + (*combo).get () + " " + std::to_string ((*defvalue).get ()) + "\n"; + } + else if ((*defvalue).is_number_integer ()) + { + this->m_compiledContent += "#define " + (*combo).get () + " " + std::to_string ((*defvalue).get ()) + "\n"; + } + else if ((*defvalue).is_string ()) + { + this->m_compiledContent += "#define " + (*combo).get () + " " + (*defvalue).get () + "\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::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 { diff --git a/wallpaperengine/shaders/compiler.h b/wallpaperengine/shaders/compiler.h index 294916d..27cf9c5 100644 --- a/wallpaperengine/shaders/compiler.h +++ b/wallpaperengine/shaders/compiler.h @@ -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* 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 m_parameters; + /** + * The combos the shader should be generated with + */ + std::map * m_combos; + /** + * Whether this compilation is a recursive one or not + */ + bool m_recursive; }; } }