void ShaderCompiler::compileAll(bool wait) { if (m_is_compiling) { if(wait) this->wait(); return; } m_is_compiling = true; m_app.getAssetBrowser()->enableUpdate(!m_is_compiling); PlatformInterface::FileInfo info; auto* iter = PlatformInterface::createFileIterator("shaders", m_editor.getAllocator()); auto& fs = m_editor.getEngine().getFileSystem(); while (PlatformInterface::getNextFile(iter, &info)) { if (!Lumix::PathUtils::hasExtension(info.filename, "shd")) continue; const char* shd_path = StringBuilder<Lumix::MAX_PATH_LENGTH>("shaders/", info.filename); auto* file = fs.open(fs.getDiskDevice(), Lumix::Path(shd_path), Lumix::FS::Mode::READ | Lumix::FS::Mode::OPEN); if (file) { int size = (int)file->size(); Lumix::Array<char> data(m_editor.getAllocator()); data.resize(size + 1); file->read(&data[0], size); data[size] = '\0'; Lumix::ShaderCombinations combinations; Lumix::Shader::getShaderCombinations(getRenderer(), &data[0], &combinations); compileAllPasses(shd_path, false, combinations.m_fs_local_mask, combinations); compileAllPasses(shd_path, true, combinations.m_vs_local_mask, combinations); fs.close(*file); } else { Lumix::g_log_error.log("Editor") << "Could not open " << shd_path; } } PlatformInterface::destroyFileIterator(iter); if(wait) { this->wait(); } }
void ShaderCompiler::compileAll() { if (m_is_compiling) return; m_is_compiling = true; Lumix::FS::FileInfo info; auto* iter = Lumix::FS::createFileIterator("shaders", m_editor.getAllocator()); auto& fs = m_editor.getEngine().getFileSystem(); while(Lumix::FS::getNextFile(iter, &info)) { if (!Lumix::PathUtils::hasExtension(info.filename, "shd")) return; const char* shd_path = StringBuilder<Lumix::MAX_PATH_LENGTH>( "shaders/", info.filename); auto* file = fs.open(fs.getDiskDevice(), shd_path, Lumix::FS::Mode::READ | Lumix::FS::Mode::OPEN); if (file) { int size = (int)file->size(); Lumix::Array<char> data(m_editor.getAllocator()); data.resize(size + 1); file->read(&data[0], size); data[size] = '\0'; Lumix::ShaderCombinations combinations; Lumix::Shader::getShaderCombinations( getRenderer(), &data[0], &combinations); compileAllPasses( shd_path, false, combinations.m_fs_combinations, combinations); compileAllPasses( shd_path, true, combinations.m_vs_combinations, combinations); fs.close(*file); } else { Lumix::g_log_error.log("shader compiler") << "Could not open " << shd_path; } } Lumix::FS::destroyFileIterator(iter); }
void ShaderCompiler::compile(const char* path) { StringBuilder<Lumix::MAX_PATH_LENGTH> compiled_dir(m_editor.getBasePath(), "/shaders/compiled"); if (!Lumix::makePath(compiled_dir)) { if (!Lumix::dirExists(compiled_dir)) { Lumix::messageBox("Could not create directory shaders/compiled. Please create it and " "restart the editor"); } } m_to_reload.emplace(path, m_editor.getAllocator()); auto& fs = m_editor.getEngine().getFileSystem(); auto* file = fs.open(fs.getDiskDevice(), path, Lumix::FS::Mode::OPEN_AND_READ); if (file) { int size = (int)file->size(); Lumix::Array<char> data(m_editor.getAllocator()); data.resize(size + 1); file->read(&data[0], size); data[size] = 0; fs.close(*file); Lumix::ShaderCombinations combinations; Lumix::Shader::getShaderCombinations( getRenderer(), &data[0], &combinations); compileAllPasses( path, false, combinations.m_fs_combinations, combinations); compileAllPasses( path, true, combinations.m_vs_combinations, combinations); } else { Lumix::g_log_error.log("shader compiler") << "Could not open " << path; } }