2 #include "caffe2/core/logging.h" 10 #include <unordered_map> 11 #include <unordered_set> 14 #include "sys/utsname.h" 18 void getOpenGLESVersion(
int& major,
int& minor) {
19 glGetIntegerv(GL_MAJOR_VERSION, &major);
20 glGetIntegerv(GL_MINOR_VERSION, &minor);
23 bool checkOpenGLExtensions(std::string gl_ext_str) {
24 static std::unordered_set<std::string> extensions;
25 if (extensions.empty()) {
26 const caffe2::string extension_str((
const char*)glGetString(GL_EXTENSIONS));
27 LOG(INFO) <<
"GL_EXTENSIONS: " << extension_str;
29 std::stringstream ss(extension_str);
31 std::string extension;
33 extensions.insert(extension);
37 return extensions.count(gl_ext_str) > 0;
40 bool GLContext::GL_EXT_texture_border_clamp_defined() {
41 static int major = 0, minor = 0;
43 getOpenGLESVersion(major, minor);
46 if (major == 3 && minor == 2) {
50 return checkOpenGLExtensions(
"GL_EXT_texture_border_clamp") ||
51 checkOpenGLExtensions(
"GL_OES_texture_border_clamp");
54 bool supportOpenGLES3(
bool* half_float_supported) {
55 int major = 0, minor = 0;
56 getOpenGLESVersion(major, minor);
58 LOG(INFO) <<
"GL_VERSION: OpenGL ES " << major <<
"." << minor;
61 LOG(ERROR) <<
"OpenGL ES 3.0 not supported";
65 if (!checkOpenGLExtensions(
"GL_EXT_color_buffer_half_float")) {
66 LOG(ERROR) <<
"GL_EXT_color_buffer_half_float is not available";
67 if (half_float_supported) {
68 *half_float_supported =
false;
76 static int version = 0;
77 static std::once_flag once;
78 std::call_once(once, [&]() {
79 struct utsname systemInfo;
81 std::string iphone_ver_str = systemInfo.machine;
82 LOG(INFO) << systemInfo.machine;
84 if (iphone_ver_str.find(
"iPhone") != std::string::npos) {
85 std::regex regStr(
"([0-9]+)");
87 if (std::regex_search(iphone_ver_str, matchs, regStr)) {
88 version = stoi(matchs[0]);
98 bool isSupportedRenderer() {
99 static std::unordered_set<std::string> supported_renderers = {
108 std::string rendererStr((
const char*)glGetString(GL_RENDERER));
109 LOG(INFO) <<
"GL_RENDERER: " << rendererStr;
111 int start = rendererStr.find_first_not_of(
" ");
112 int end = rendererStr.find_last_not_of(
" ");
113 rendererStr = rendererStr.substr(start, end - start + 1);
114 return supported_renderers.count(rendererStr) > 0;
118 bool isSupportedDevice() {
120 return iPhoneVersion() >= 7;
122 return isSupportedRenderer();