| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Library/BsEditorShaderIncludeHandler.h"
- #include "Library/BsProjectLibrary.h"
- #include "Resources/BsResources.h"
- #include "Library/BsProjectResourceMeta.h"
- #include "Resources/BsBuiltinResources.h"
- #include "Utility/BsBuiltinEditorResources.h"
- namespace bs
- {
- HShaderInclude EditorShaderIncludeHandler::findInclude(const String& name) const
- {
- Path path = toResourcePath(name);
- if (path.isEmpty())
- return HShaderInclude();
- ResourceLoadFlags loadFlags = ResourceLoadFlag::Default | ResourceLoadFlag::KeepSourceData;
- if (name.size() >= 8)
- {
- if (name.substr(0, 8) == "$ENGINE$" || name.substr(0, 8) == "$EDITOR$")
- return static_resource_cast<ShaderInclude>(Resources::instance().load(path, loadFlags));
- }
- ProjectLibrary::LibraryEntry* entry = gProjectLibrary().findEntry(path).get();
- if (entry != nullptr && entry->type == ProjectLibrary::LibraryEntryType::File)
- {
- ProjectLibrary::FileEntry* fileEntry = static_cast<ProjectLibrary::FileEntry*>(entry);
- if (fileEntry->meta != nullptr)
- {
- auto& resourceMetas = fileEntry->meta->getResourceMetaData();
- for(auto& resMeta : resourceMetas)
- {
- if(resMeta->getTypeID() == TID_ShaderInclude)
- return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resMeta->getUUID(), false, loadFlags));
- }
- }
- }
- return HShaderInclude();
- }
- Path EditorShaderIncludeHandler::toResourcePath(const String& name)
- {
- if (name.substr(0, 8) == "$ENGINE$")
- {
- if (name.size() > 8)
- {
- Path fullPath = BuiltinResources::getShaderIncludeFolder();
- Path includePath = name.substr(9, name.size() - 9);
- fullPath.append(includePath);
- fullPath.setFilename(includePath.getFilename() + ".asset");
- return fullPath;
- }
- }
- else if (name.substr(0, 8) == "$EDITOR$")
- {
- if (name.size() > 8)
- {
- Path fullPath = BuiltinResources::getEditorShaderIncludeFolder();
- Path includePath = name.substr(9, name.size() - 9);
- fullPath.append(includePath);
- fullPath.setFilename(includePath.getFilename() + ".asset");
- return fullPath;
- }
- }
- else
- {
- return name;
- }
- return Path::BLANK;
- }
- }
|