BsSLImporter.cpp 1.1 KB

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