BsEditorShaderIncludeHandler.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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::FileEntry* fileEntry = static_cast<ProjectLibrary::FileEntry*>(entry);
  25. if (fileEntry->meta != nullptr)
  26. {
  27. auto& resourceMetas = fileEntry->meta->getResourceMetaData();
  28. for(auto& resMeta : resourceMetas)
  29. {
  30. if(resMeta->getTypeID() == TID_ShaderInclude)
  31. return static_resource_cast<ShaderInclude>(Resources::instance().loadFromUUID(resMeta->getUUID()));
  32. }
  33. }
  34. }
  35. return HShaderInclude();
  36. }
  37. Path EditorShaderIncludeHandler::toResourcePath(const String& name)
  38. {
  39. if (name.substr(0, 8) == "$ENGINE$")
  40. {
  41. if (name.size() > 8)
  42. {
  43. Path fullPath = BuiltinResources::getShaderIncludeFolder();
  44. Path includePath = name.substr(9, name.size() - 9);
  45. fullPath.append(includePath);
  46. fullPath.setFilename(includePath.getFilename() + ".asset");
  47. return fullPath;
  48. }
  49. }
  50. else if (name.substr(0, 8) == "$EDITOR$")
  51. {
  52. if (name.size() > 8)
  53. {
  54. Path fullPath = BuiltinEditorResources::getShaderIncludeFolder();
  55. Path includePath = name.substr(9, name.size() - 9);
  56. fullPath.append(includePath);
  57. fullPath.setFilename(includePath.getFilename() + ".asset");
  58. return fullPath;
  59. }
  60. }
  61. else
  62. {
  63. return name;
  64. }
  65. return Path::BLANK;
  66. }
  67. }