BsEditorShaderIncludeHandler.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsEditorShaderIncludeHandler.h"
  4. #include "BsProjectLibrary.h"
  5. #include "BsResources.h"
  6. #include "BsProjectResourceMeta.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsBuiltinEditorResources.h"
  9. namespace BansheeEngine
  10. {
  11. HShaderInclude EditorShaderIncludeHandler::findInclude(const String& name) const
  12. {
  13. Path path = toResourcePath(name);
  14. if (path.isEmpty())
  15. return HShaderInclude();
  16. if (name.size() >= 8)
  17. {
  18. if (name.substr(0, 8) == "$ENGINE$" || name.substr(0, 8) == "$EDITOR$")
  19. return static_resource_cast<ShaderInclude>(Resources::instance().load(path));
  20. }
  21. ProjectLibrary::LibraryEntry* entry = gProjectLibrary().findEntry(path);
  22. if (entry != nullptr && entry->type == ProjectLibrary::LibraryEntryType::File)
  23. {
  24. ProjectLibrary::ResourceEntry* resEntry = static_cast<ProjectLibrary::ResourceEntry*>(entry);
  25. if (resEntry->meta != nullptr)
  26. return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resEntry->meta->getUUID()));
  27. }
  28. return HShaderInclude();
  29. }
  30. Path EditorShaderIncludeHandler::toResourcePath(const String& name)
  31. {
  32. if (name.substr(0, 8) == "$ENGINE$")
  33. {
  34. if (name.size() > 8)
  35. {
  36. Path fullPath = BuiltinResources::getShaderIncludeFolder();
  37. Path includePath = name.substr(9, name.size() - 9);
  38. fullPath.append(includePath);
  39. fullPath.setFilename(includePath.getFilename() + ".asset");
  40. return fullPath;
  41. }
  42. }
  43. else if (name.substr(0, 8) == "$EDITOR$")
  44. {
  45. if (name.size() > 8)
  46. {
  47. Path fullPath = BuiltinEditorResources::getShaderIncludeFolder();
  48. Path includePath = name.substr(9, name.size() - 9);
  49. fullPath.append(includePath);
  50. fullPath.setFilename(includePath.getFilename() + ".asset");
  51. return fullPath;
  52. }
  53. }
  54. else
  55. {
  56. return name;
  57. }
  58. return Path::BLANK;
  59. }
  60. }