From: Stephen Seo Date: Wed, 20 Mar 2024 02:11:22 +0000 (+0900) Subject: Refactor glslc usage X-Git-Url: https://git.seodisparate.com/stephenseo/css/base.css?a=commitdiff_plain;h=8c1190d923b369668e0cb0980bd517c42b6f7ef1;p=blue_noise_generation Refactor glslc usage --- diff --git a/src/blue_noise.cpp b/src/blue_noise.cpp index fec8bcd..001ed09 100644 --- a/src/blue_noise.cpp +++ b/src/blue_noise.cpp @@ -320,26 +320,28 @@ image::Bl dither::blue_noise(int width, int height, int threads, // Check and compile compute shader. { - std::ifstream ifs("src/blue_noise.glsl"); - if (ifs.good()) { - ifs.close(); - if (std::system("glslc -fshader-stage=compute -o compute.spv src/blue_noise.glsl") != 0) { - std::clog << "WARNING: Failed to compile src/blue_noise.glsl!\n"; - goto ENDOF_VULKAN; - } - } else { - ifs = std::ifstream("../src/blue_noise.glsl"); + std::array filenames{ + "blue_noise.glsl", "src/blue_noise.glsl", "../src/blue_noise.glsl"}; + bool success = false; + for (const auto filename : filenames) { + std::ifstream ifs(filename); if (ifs.good()) { ifs.close(); - if (std::system("glslc -fshader-stage=compute -o compute.spv ../src/blue_noise.glsl") != 0) { - std::clog << "WARNING: Failed to compile ../src/blue_noise.glsl!\n"; + std::string command("glslc -fshader-stage=compute -o compute.spv "); + command.append(filename); + if (std::system(command.c_str()) != 0) { + std::clog << "WARNING: Failed to compile " << filename << "!\n"; goto ENDOF_VULKAN; + } else { + success = true; + break; } - } else { - std::clog << "WARNING: Unable to find blue_noise.glsl!\n"; - goto ENDOF_VULKAN; } } + if (!success) { + std::clog << "WARNING: Could not find blue_noise.glsl!\n"; + goto ENDOF_VULKAN; + } } } ENDOF_VULKAN: