BsSLPlugin.cpp 1.4 KB

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