Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
isextensionsupported.cc
Go to the documentation of this file.
1 
19 
20 #include <cctype>
21 #include <cstring>
22 
23 #include "ion/base/logging.h"
24 #include "ion/portgfx/glheaders.h"
25 #include "ion/portgfx/visual.h"
26 
27 namespace ion {
28 namespace portgfx {
29 
30 ION_API bool IsExtensionSupported(const std::string& unprefixed_extension,
31  const std::string& extensions_string) {
32  if (unprefixed_extension.empty())
33  return false;
34  if (IsExtensionIncomplete(unprefixed_extension.c_str()))
35  return false;
36 
38  size_t found = 0;
39  while ((found = extensions_string.find(unprefixed_extension, found + 1)) !=
40  std::string::npos) {
43  size_t found_begin = extensions_string.rfind(' ', found);
44  if (found_begin != std::string::npos) {
45  ++found_begin;
46  } else {
47  found_begin = 0;
48  }
49 
51  for (size_t c = found_begin; c < found; ++c) {
52  if (!isupper(extensions_string[c]) && extensions_string[c] != '_')
53  goto next;
54  }
55 
58  if (extensions_string.size() > found + unprefixed_extension.size() &&
59  extensions_string[found + unprefixed_extension.size()] != ' ')
60  goto next;
61 
63  return true;
64 
65  next:
66  continue;
67  }
68 
69  return false;
70 }
71 
72 ION_API bool IsExtensionSupported(const char* unprefixed_extension) {
73  if (!Visual::GetCurrent()) {
76  LOG(WARNING) << "IsExtensionSupported(" << unprefixed_extension
77  << ") returning false because there is no OpenGL context.";
78  return false;
79  }
80  const char* extensions =
81  reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
82  if (!extensions) return false;
83  const std::string unprefixed(unprefixed_extension);
84  return IsExtensionSupported(std::string(unprefixed_extension),
85  std::string(extensions));
86 }
87 
88 ION_API bool IsExtensionIncomplete(const char* unprefixed_extension) {
89 #if defined(ION_PLATFORM_ANDROID) || defined(ION_PLATFORM_GENERIC_ARM)
90  if (!strcmp(unprefixed_extension, "vertex_array_object"))
93  return true;
94 #endif
95  return false;
96 }
97 
98 } // namespace portgfx
99 } // namespace ion
ION_API bool IsExtensionIncomplete(const char *unprefixed_extension)
Returns whether the passed extension is known to be incomplete for the current platform.
static const Visual * GetCurrent()
Returns the Visual that is current for the calling thread.
Definition: visual.cc:213
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
Definition: logging.h:216
ION_API bool IsExtensionSupported(const std::string &unprefixed_extension, const std::string &extensions_string)
Returns whether the currently bound OpenGL implementation supports the named extension.
Copyright 2016 Google Inc.