ggl.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "core/strings/stringFunctions.h"
  23. #include "platform/platformDlibrary.h"
  24. #include "console/console.h"
  25. namespace GL
  26. {
  27. //-----------------------------------------------------------------------------
  28. // Current active extensions
  29. struct GLExtensionPtrs;
  30. GLExtensionPtrs* _GGLptr;
  31. struct GLExtensionFlags;
  32. GLExtensionFlags* _GGLflag;
  33. //-----------------------------------------------------------------------------
  34. static inline int versionCombine( int major, int minor )
  35. {
  36. return major * 100 + minor;
  37. }
  38. bool bindFunction( DLibrary *dll, void *&fnAddress, const char *name )
  39. {
  40. fnAddress = dll->bind( name );
  41. if (!fnAddress)
  42. Con::warnf( "GLExtensions: DLL bind failed for %s", name );
  43. return fnAddress != 0;
  44. }
  45. bool hasExtension( const char *name, const char *extensions )
  46. {
  47. // Extensions are compared against the extension strings
  48. if (extensions && *extensions) {
  49. const char* ptr = dStrstr(extensions,name);
  50. if (ptr) {
  51. char end = ptr[dStrlen(name)];
  52. if (end == ' ' || end == 0)
  53. return true;
  54. }
  55. }
  56. return false;
  57. }
  58. bool hasVersion( const char *name, const char* prefix, int major, int minor )
  59. {
  60. // Extension group names are compared against the version number. The prefix
  61. // string should be "GL_VERSION" or "GLX_VERSION".. group names are
  62. // "GL_VERSION_1_1", "GL_VERSION_1_2", "GLX_VERSION_1_2", etc.
  63. while (*name && *prefix && *name == *prefix)
  64. name++, prefix++;
  65. if (*name == '_' && *prefix == '\0') {
  66. int maj = dAtoi(++name);
  67. while (dIsdigit(*name))
  68. *name++;
  69. int min = dAtoi(++name);
  70. return versionCombine(maj,min) <= versionCombine(major,minor);
  71. }
  72. return false;
  73. }
  74. } // Namespace