BsGLSupport.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "BsGLSupport.h"
  2. #include "BsGLTexture.h"
  3. #include "GL/glew.h"
  4. GLenum GLEWAPIENTRY glewContextInit(BansheeEngine::GLSupport *glSupport);
  5. namespace BansheeEngine
  6. {
  7. void GLSupport::initializeExtensions()
  8. {
  9. glewContextInit(this);
  10. // Set version string
  11. const GLubyte* pcVer = glGetString(GL_VERSION);
  12. assert(pcVer && "Problems getting GL version string using glGetString");
  13. String tmpStr = (const char*)pcVer;
  14. mVersion = tmpStr.substr(0, tmpStr.find(" "));
  15. // Get vendor
  16. const GLubyte* pcVendor = glGetString(GL_VENDOR);
  17. tmpStr = (const char*)pcVendor;
  18. mVendor = tmpStr.substr(0, tmpStr.find(" "));
  19. // Set extension list
  20. int numExtensions = 0;
  21. glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions);
  22. for (int i = 0; i < numExtensions; i++)
  23. {
  24. extensionList.insert(String((char*)glGetStringi(GL_EXTENSIONS, i)));
  25. }
  26. }
  27. bool GLSupport::checkMinGLVersion(const String& v) const
  28. {
  29. unsigned int first, second, third;
  30. unsigned int cardFirst, cardSecond, cardThird;
  31. if(v == mVersion)
  32. return true;
  33. String::size_type pos = v.find(".");
  34. if(pos == String::npos)
  35. return false;
  36. String::size_type pos1 = v.rfind(".");
  37. if(pos1 == String::npos)
  38. return false;
  39. first = ::atoi(v.substr(0, pos).c_str());
  40. second = ::atoi(v.substr(pos + 1, pos1 - (pos + 1)).c_str());
  41. third = ::atoi(v.substr(pos1 + 1, v.length()).c_str());
  42. pos = mVersion.find(".");
  43. if(pos == String::npos)
  44. return false;
  45. pos1 = mVersion.rfind(".");
  46. if(pos1 == String::npos)
  47. return false;
  48. cardFirst = ::atoi(mVersion.substr(0, pos).c_str());
  49. cardSecond = ::atoi(mVersion.substr(pos + 1, pos1 - (pos + 1)).c_str());
  50. cardThird = ::atoi(mVersion.substr(pos1 + 1, mVersion.length()).c_str());
  51. if(first <= cardFirst && second <= cardSecond && third <= cardThird)
  52. return true;
  53. return false;
  54. }
  55. bool GLSupport::checkExtension(const String& ext) const
  56. {
  57. if(extensionList.find(ext) == extensionList.end())
  58. return false;
  59. return true;
  60. }
  61. }