BsShaderIncludeHandler.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. Path path = toResourcePath(name);
  12. if (path.isEmpty())
  13. return HShaderInclude();
  14. if (name.size() >= 8)
  15. {
  16. if (name.substr(0, 8) == "$ENGINE$" || name.substr(0, 8) == "$EDITOR$")
  17. return static_resource_cast<ShaderInclude>(Resources::instance().load(path));
  18. }
  19. ProjectLibrary::LibraryEntry* entry = gProjectLibrary().findEntry(path);
  20. if (entry != nullptr && entry->type == ProjectLibrary::LibraryEntryType::File)
  21. {
  22. ProjectLibrary::ResourceEntry* resEntry = static_cast<ProjectLibrary::ResourceEntry*>(entry);
  23. if (resEntry->meta != nullptr)
  24. return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resEntry->meta->getUUID()));
  25. }
  26. return HShaderInclude();
  27. }
  28. Path EditorShaderIncludeHandler::toResourcePath(const String& name)
  29. {
  30. if (name.substr(0, 8) == "$ENGINE$")
  31. {
  32. if (name.size() > 8)
  33. {
  34. Path fullPath = BuiltinResources::EngineShaderIncludeFolder;
  35. Path includePath = name.substr(9, name.size() - 9);
  36. fullPath.append(includePath);
  37. fullPath.setFilename(includePath.getFilename() + ".asset");
  38. return fullPath;
  39. }
  40. }
  41. else if (name.substr(0, 8) == "$EDITOR$")
  42. {
  43. if (name.size() > 8)
  44. {
  45. Path fullPath = BuiltinEditorResources::EditorShaderIncludeFolder;
  46. Path includePath = name.substr(9, name.size() - 9);
  47. fullPath.append(includePath);
  48. fullPath.setFilename(includePath.getFilename() + ".asset");
  49. return fullPath;
  50. }
  51. }
  52. else
  53. {
  54. return name;
  55. }
  56. return Path::BLANK;
  57. }
  58. }