BsShaderIncludeHandler.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "BsShaderIncludeHandler.h"
  2. #include "BsProjectLibrary.h"
  3. #include "BsResources.h"
  4. #include "BsProjectResourceMeta.h"
  5. #include "BsBuiltinResources.h"
  6. #include "BsBuiltinEditorResources.h"
  7. namespace BansheeEngine
  8. {
  9. HShaderInclude EditorShaderIncludeHandler::findInclude(const String& name) const
  10. {
  11. if (name.substr(0, 8) == "$ENGINE$")
  12. {
  13. if (name.size() > 8)
  14. {
  15. Path fullPath = BuiltinResources::DefaultShaderFolder;
  16. Path includePath = name.substr(9, name.size() - 9);
  17. fullPath.append(includePath);
  18. fullPath.setFilename(includePath.getFilename() + ".asset");
  19. return static_resource_cast<ShaderInclude>(Resources::instance().load(fullPath));
  20. }
  21. }
  22. else if (name.substr(0, 8) == "$EDITOR$")
  23. {
  24. if (name.size() > 8)
  25. {
  26. Path fullPath = BuiltinEditorResources::DefaultShaderFolder;
  27. Path includePath = name.substr(9, name.size() - 9);
  28. fullPath.append(includePath);
  29. fullPath.setFilename(includePath.getFilename() + ".asset");
  30. return static_resource_cast<ShaderInclude>(Resources::instance().load(fullPath));
  31. }
  32. }
  33. else
  34. {
  35. Path path = name;
  36. ProjectLibrary::LibraryEntry* entry = ProjectLibrary::instance().findEntry(path);
  37. if (entry != nullptr && entry->type == ProjectLibrary::LibraryEntryType::File)
  38. {
  39. ProjectLibrary::ResourceEntry* resEntry = static_cast<ProjectLibrary::ResourceEntry*>(entry);
  40. return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resEntry->meta->getUUID()));
  41. }
  42. }
  43. return HShaderInclude();
  44. }
  45. }