Browse Source

ShaderTools: fix the input callback snippet to be less wrong.

First of all, it's quite unusual to have an array of const chars. Then,
it was not really handling file opening errors, which is actually a VERY
BAD THING when you are wondering why your include isn't parsed.
pull/481/head
Vladimír Vondruš 6 years ago
parent
commit
6b93a2d364
  1. 18
      doc/snippets/MagnumShaderTools.cpp

18
doc/snippets/MagnumShaderTools.cpp

@ -97,11 +97,10 @@ Containers::Array<char> spirv = converter->convertDataToData(
{
Containers::Pointer<ShaderTools::AbstractConverter> converter;
Containers::Array<const char> extract(const std::string&, const std::string&);
Containers::Array<char> extract(const std::string&, const std::string&);
/* [AbstractConverter-usage-callbacks] */
struct Data {
std::unordered_map<std::string,
Containers::Array<const char>> files;
std::unordered_map<std::string, Containers::Array<char>> files;
} data;
converter->setInputFileCallback([](const std::string& filename,
@ -116,11 +115,16 @@ converter->setInputFileCallback([](const std::string& filename,
return {};
}
/* Extract from an archive if not there yet */
if(found == data.files.end()) found = data.files.emplace(
filename, extract("shaders.zip", filename)).first;
/* Extract from an archive if not there yet; fail if not extraction
failed */
if(found == data.files.end()) {
Containers::Array<char> file = extract("shaders.zip", filename);
if(!file) return {};
return Containers::arrayView(found->second);
found = data.files.emplace(filename, std::move(file)).first;
}
return Containers::ArrayView<const char>{found->second};
}, data);
/* extracted from a ZIP */

Loading…
Cancel
Save