BsSLPlugin.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "BsSLPrerequisites.h"
  2. #include "BsPath.h"
  3. #include "BsFileSystem.h"
  4. #include "BsDataStream.h"
  5. extern "C" {
  6. #include "BsASTFX.h"
  7. #include "BsParserFX.h"
  8. #include "BsLexerFX.h"
  9. }
  10. namespace BansheeEngine
  11. {
  12. ASTFXNode* parseFX(const char* source)
  13. {
  14. yyscan_t scanner;
  15. YY_BUFFER_STATE state;
  16. if (yylex_init(&scanner)) {
  17. // couldn't initialize
  18. return nullptr;
  19. }
  20. state = yy_scan_string(source, scanner);
  21. ASTFXNode* output = nodeCreate(NT_Shader);
  22. if (yyparse(output, scanner)) {
  23. // error parsing
  24. return nullptr;
  25. }
  26. yy_delete_buffer(state, scanner);
  27. yylex_destroy(scanner);
  28. return output;
  29. }
  30. /**
  31. * @brief Returns a name of the plugin.
  32. */
  33. extern "C" BS_SL_EXPORT const String& getPluginName()
  34. {
  35. return SystemName;
  36. }
  37. /**
  38. * @brief Entry point to the plugin. Called by the engine when the plugin is loaded.
  39. */
  40. extern "C" BS_SL_EXPORT void* loadPlugin()
  41. {
  42. // TODO - Register importer
  43. // DEBUG
  44. yydebug = 1;
  45. Path exampleFX = "D:\\testFX.txt";
  46. DataStreamPtr file = FileSystem::openFile(exampleFX);
  47. String contents = file->getAsString();
  48. ASTFXNode* node = parseFX(contents.c_str());
  49. int bp = 0;
  50. nodeDelete(node);
  51. return nullptr;
  52. }
  53. }