コード例 #1
0
void ShaderCompiler::parseDependencies()
{
	m_dependencies.clear();
	bool is_opengl = getRenderer().isOpenGL();
	Lumix::StaticString<30> compiled_dir("shaders/compiled", is_opengl ? "_gl" : "");
	auto* iter = PlatformInterface::createFileIterator(compiled_dir, m_editor.getAllocator());

	auto& fs = m_editor.getEngine().getFileSystem();
	PlatformInterface::FileInfo info;
	while (PlatformInterface::getNextFile(iter, &info))
	{
		if (!Lumix::PathUtils::hasExtension(info.filename, "d")) continue;

		auto* file = fs.open(fs.getDiskDevice(),
			Lumix::Path(Lumix::StaticString<Lumix::MAX_PATH_LENGTH>(compiled_dir, "/", info.filename)),
			Lumix::FS::Mode::READ | Lumix::FS::Mode::OPEN);
		if (!file)
		{
			Lumix::g_log_error.log("Editor") << "Could not open " << info.filename;
			continue;
		}

		char first_line[100];
		readLine(file, first_line, sizeof(first_line));
		for (int i = 0; i < sizeof(first_line); ++i)
		{
			if (first_line[i] == '\0' || first_line[i] == ' ')
			{
				first_line[i] = '\0';
				break;
			}
		}

		char line[100];
		while (readLine(file, line, sizeof(line)))
		{
			char* trimmed_line = Lumix::trimmed(line);
			char* c = trimmed_line;
			while (*c)
			{
				if (*c == ' ') break;
				++c;
			}
			*c = '\0';

			addDependency(trimmed_line, first_line);
		}

		char basename[Lumix::MAX_PATH_LENGTH];
		char src[Lumix::MAX_PATH_LENGTH];
		Lumix::PathUtils::getBasename(basename, sizeof(basename), first_line);
		getSourceFromBinaryBasename(src, sizeof(src), basename);

		addDependency(src, first_line);

		fs.close(*file);
	}

	PlatformInterface::destroyFileIterator(iter);
}
コード例 #2
0
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;
	}
}
コード例 #3
0
void ShaderCompiler::compileAll(bool wait)
{
	if (m_is_compiling)
	{
		if(wait) this->wait();
		return;
	}

	Lumix::StaticString<Lumix::MAX_PATH_LENGTH> compiled_dir(
		m_editor.getEngine().getDiskFileDevice()->getBasePath(), "/shaders/compiled");
	if (getRenderer().isOpenGL()) compiled_dir << "_gl";
	if (!PlatformInterface::makePath(compiled_dir))
	{
		if (!PlatformInterface::dirExists(compiled_dir))
		{
			Lumix::messageBox("Could not create directory shaders/compiled. Please create it and "
				"restart the editor");
		}
		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 = Lumix::StaticString<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.fs_local_mask, combinations);
			compileAllPasses(shd_path, true, combinations.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();
}