BsShaderIncludeHandler.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resEntry->meta->getUUID()));
  24. }
  25. return HShaderInclude();
  26. }
  27. Path EditorShaderIncludeHandler::toResourcePath(const String& name)
  28. {
  29. if (name.substr(0, 8) == "$ENGINE$")
  30. {
  31. if (name.size() > 8)
  32. {
  33. Path fullPath = BuiltinResources::EngineShaderIncludeFolder;
  34. Path includePath = name.substr(9, name.size() - 9);
  35. fullPath.append(includePath);
  36. fullPath.setFilename(includePath.getFilename() + ".asset");
  37. return fullPath;
  38. }
  39. }
  40. else if (name.substr(0, 8) == "$EDITOR$")
  41. {
  42. if (name.size() > 8)
  43. {
  44. Path fullPath = BuiltinEditorResources::EditorShaderIncludeFolder;
  45. Path includePath = name.substr(9, name.size() - 9);
  46. fullPath.append(includePath);
  47. fullPath.setFilename(includePath.getFilename() + ".asset");
  48. return fullPath;
  49. }
  50. }
  51. else
  52. {
  53. return name;
  54. }
  55. return Path::BLANK;
  56. }
  57. }