BsD3D9EmulatedParamBlocks.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #include "BsD3D9EmulatedParamBlocks.h"
  5. #include <regex>
  6. namespace BansheeEngine
  7. {
  8. String D3D9EmulatedParamBlockParser::parse(const String& gpuProgSource, Vector<D3D9EmulatedParamBlock>& paramBlocks)
  9. {
  10. static std::regex paramBlockRegex("BS_PARAM_BLOCK\\s*(.*\\})");
  11. static std::regex blockNameRegex("([^\\s\\{]*)");
  12. static std::regex paramNameRegex("(?:\\{ *([^\\, ]*))|(?:\\, *([^\\, \\}]*))");
  13. static std::regex replaceRegex("BS_PARAM_BLOCK\\s*(.*\\}\\n?)");
  14. std::sregex_iterator paramBlockIter(gpuProgSource.begin(), gpuProgSource.end(), paramBlockRegex);
  15. std::sregex_iterator iterEnd;
  16. while (paramBlockIter != iterEnd)
  17. {
  18. std::string stdString = (*paramBlockIter)[1];
  19. String paramBlockString = String(stdString.begin(), stdString.end());
  20. paramBlocks.push_back(D3D9EmulatedParamBlock());
  21. D3D9EmulatedParamBlock& block = paramBlocks.back();
  22. std::smatch nameMatch;
  23. if (std::regex_search(paramBlockString, nameMatch, blockNameRegex))
  24. {
  25. stdString = nameMatch[1];
  26. block.blockName = String(stdString.begin(), stdString.end());
  27. }
  28. std::sregex_iterator paramNameIter(paramBlockString.begin(), paramBlockString.end(), paramNameRegex);
  29. while (paramNameIter != iterEnd)
  30. {
  31. stdString = (*paramNameIter)[1];
  32. block.paramNames.push_back(String(stdString.begin(), stdString.end()));
  33. paramNameIter++;
  34. }
  35. paramBlockIter++;
  36. }
  37. // Return string without param block definitions
  38. return std::regex_replace(gpuProgSource, replaceRegex, "");
  39. }
  40. }