BsSLImporter.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsSLImporter.h"
  4. #include "BsDataStream.h"
  5. #include "BsFileSystem.h"
  6. #include "BsSLFXCompiler.h"
  7. namespace BansheeEngine
  8. {
  9. SLImporter::SLImporter()
  10. :SpecificImporter()
  11. {
  12. }
  13. SLImporter::~SLImporter()
  14. {
  15. }
  16. bool SLImporter::isExtensionSupported(const WString& ext) const
  17. {
  18. WString lowerCaseExt = ext;
  19. StringUtil::toLowerCase(lowerCaseExt);
  20. return lowerCaseExt == L"bsl";
  21. }
  22. bool SLImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const
  23. {
  24. return true; // Plain-text so I don't even check for magic number
  25. }
  26. ResourcePtr SLImporter::import(const Path& filePath, ConstImportOptionsPtr importOptions)
  27. {
  28. DataStreamPtr stream = FileSystem::openFile(filePath);
  29. String source = stream->getAsString();
  30. BSLFXCompileResult result = BSLFXCompiler::compile(source);
  31. if (result.shader != nullptr)
  32. result.shader->setName(filePath.getWFilename(false));
  33. else
  34. {
  35. String file;
  36. if (result.errorFile.empty())
  37. file = filePath.toString();
  38. else
  39. file = result.errorFile;
  40. LOGERR("Error while parsing shader FX code \"" + file + "\":\n" + result.errorMessage + ". Location: " +
  41. toString(result.errorLine) + " (" + toString(result.errorColumn) + ")");
  42. }
  43. return result.shader;
  44. }
  45. }