BsSLImporter.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "BsShaderImportOptions.h"
  8. namespace BansheeEngine
  9. {
  10. SLImporter::SLImporter()
  11. :SpecificImporter()
  12. {
  13. }
  14. SLImporter::~SLImporter()
  15. {
  16. }
  17. bool SLImporter::isExtensionSupported(const WString& ext) const
  18. {
  19. WString lowerCaseExt = ext;
  20. StringUtil::toLowerCase(lowerCaseExt);
  21. return lowerCaseExt == L"bsl";
  22. }
  23. bool SLImporter::isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const
  24. {
  25. return true; // Plain-text so I don't even check for magic number
  26. }
  27. SPtr<Resource> SLImporter::import(const Path& filePath, SPtr<const ImportOptions> importOptions)
  28. {
  29. SPtr<DataStream> stream = FileSystem::openFile(filePath);
  30. String source = stream->getAsString();
  31. SPtr<const ShaderImportOptions> io = std::static_pointer_cast<const ShaderImportOptions>(importOptions);
  32. BSLFXCompileResult result = BSLFXCompiler::compile(source, io->getDefines());
  33. if (result.shader != nullptr)
  34. result.shader->setName(filePath.getWFilename(false));
  35. else
  36. {
  37. String file;
  38. if (result.errorFile.empty())
  39. file = filePath.toString();
  40. else
  41. file = result.errorFile;
  42. LOGERR("Error while parsing shader FX code \"" + file + "\":\n" + result.errorMessage + ". Location: " +
  43. toString(result.errorLine) + " (" + toString(result.errorColumn) + ")");
  44. }
  45. return result.shader;
  46. }
  47. SPtr<ImportOptions> SLImporter::createImportOptions() const
  48. {
  49. return bs_shared_ptr_new<ShaderImportOptions>();
  50. }
  51. }