ge_gl_utils.hpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef HEADER_GE_GL_UTILS_HPP
  2. #define HEADER_GE_GL_UTILS_HPP
  3. #include <glad/gl.h>
  4. #include <set>
  5. #include <sstream>
  6. #include <string>
  7. namespace GE
  8. {
  9. inline bool hasGLExtension(const std::string& extension)
  10. {
  11. if (glGetStringi)
  12. {
  13. int num = 0;
  14. glGetIntegerv(GL_NUM_EXTENSIONS, &num);
  15. for (int i = 0; i < num; i++)
  16. {
  17. char* ext = (char*)glGetStringi(GL_EXTENSIONS, i);
  18. if (ext && extension == ext)
  19. return true;
  20. }
  21. return false;
  22. }
  23. static std::set<std::string> extensions;
  24. if (extensions.empty())
  25. {
  26. char* all_ext = (char*)glGetString(GL_EXTENSIONS);
  27. if (all_ext)
  28. {
  29. std::stringstream ss(all_ext);
  30. while (true)
  31. {
  32. std::string ext;
  33. if (ss >> ext)
  34. extensions.insert(ext);
  35. else
  36. break;
  37. }
  38. }
  39. }
  40. return extensions.find(extension) != extensions.end();
  41. } // hasGLExtension
  42. }
  43. #endif