You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 line
1.8 KiB

  1. #include <fstream>
  2. #include <iostream>
  3. #include "../../libShaderFile.hpp"
  4. #if _WIN64
  5. static const char* LibName = "..\\..\\..\\libShaderFile-x86_64-win64.dll";
  6. #elif _WIN32
  7. static const char* LibName = "..\\..\\..\\libShaderFile-i386-win32.dll";
  8. #elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__)
  9. static const char* LibName = "../../../libShaderFile-x86_64-linux.so";
  10. #elif __linux__ && (__i386 || _X86_)
  11. static const char* LibName = "../../../libShaderFile-i386-linux.so";
  12. #else
  13. # error 'unknown operation system'
  14. #endif
  15. class FileReader : public lsf::IFileReader
  16. {
  17. public:
  18. virtual bool loadStream(const std::string& filename, std::ostream& os)
  19. {
  20. std::ifstream fs(filename.c_str());
  21. if (!fs)
  22. return false;
  23. os << fs.rdbuf();
  24. return true;
  25. }
  26. };
  27. int main(int argc, char **argv)
  28. {
  29. try
  30. {
  31. if (argc < 3)
  32. {
  33. std::cout << "error: expected input file and generator/class name as parameter" << std::endl;
  34. return 1;
  35. }
  36. // initialize library
  37. lsf::Library lib(LibName);
  38. // create and load shader file
  39. lsf::ShaderFile shaderFile(lib);
  40. FileReader reader;
  41. shaderFile.loadFromFunc(argv[1], reader);
  42. const lsf::Library& l = shaderFile.getLibrary();
  43. // get generator
  44. lsf::Generator generator(shaderFile, argv[2]);
  45. int i = 3;
  46. while (i < argc-1)
  47. {
  48. generator.setProperty(argv[i], argv[i+1]);
  49. i += 2;
  50. }
  51. std::cout << generator.generateCode() << std::endl;
  52. return 0;
  53. }
  54. catch(const std::exception& ex)
  55. {
  56. std::cout << "error: " << ex.what() << std::endl;
  57. return 2;
  58. }
  59. }