compiler.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __BASIC_SHADER_LOADER_H__
  2. #define __BASIC_SHADER_LOADER_H__
  3. #include <irrlicht/irrlicht.h>
  4. #include <iostream>
  5. #include <vector>
  6. #include <map>
  7. #include <wallpaperengine/fs/fileResolver.h>
  8. namespace wp
  9. {
  10. namespace shaders
  11. {
  12. /**
  13. * A basic shader loader that adds basic function definitions to every loaded shader
  14. */
  15. class compiler
  16. {
  17. public:
  18. struct VariableReplacement
  19. {
  20. const char* original;
  21. const char* replacement;
  22. };
  23. struct TypeName
  24. {
  25. const char* name;
  26. int size;
  27. };
  28. enum Type
  29. {
  30. Type_Vertex = 0,
  31. Type_Pixel = 1,
  32. };
  33. static std::map<std::string, std::string> sVariableReplacement;
  34. static std::vector<std::string> sTypes;
  35. compiler (irr::io::path file, Type type, bool recursive = false);
  36. std::string precompile();
  37. private:
  38. bool peekString (std::string str, std::string::const_iterator& it);
  39. bool expectSemicolon (std::string::const_iterator& it);
  40. void ignoreSpaces (std::string::const_iterator& it);
  41. void ignoreUpToNextLineFeed (std::string::const_iterator& it);
  42. void ignoreUpToBlockCommentEnd (std::string::const_iterator& it);
  43. std::string extractType (std::string::const_iterator& it);
  44. std::string extractName (std::string::const_iterator& it);
  45. std::string extractQuotedValue (std::string::const_iterator& it);
  46. std::string lookupShaderFile (std::string filename);
  47. std::string lookupReplaceSymbol (std::string symbol);
  48. bool isChar (std::string::const_iterator& it);
  49. bool isNumeric (std::string::const_iterator& it);
  50. irr::io::path m_file;
  51. std::string m_content;
  52. std::string m_compiledContent;
  53. bool m_error;
  54. std::string m_errorInfo;
  55. Type m_type;
  56. wp::fs::fileResolver m_resolver;
  57. };
  58. }
  59. }
  60. #endif /* !__BASIC_SHADER_LOADER_H__ */