Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 1 | #import <OpenGLES/EAGL.h> |
| 2 | #import <OpenGLES/ES2/gl.h> |
| 3 | |
| 4 | #import <cpuinfo.h> |
| 5 | #import <log.h> |
| 6 | #import <gpu/api.h> |
| 7 | |
| 8 | |
Marat Dukhan | 0252701 | 2017-10-23 16:03:05 -0700 | [diff] [blame] | 9 | #if ! __has_feature(objc_arc) |
| 10 | #error "This file must be built with Automatic Reference Counting (-fobjc-arc option)" |
| 11 | #endif |
| 12 | |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 13 | void cpuinfo_gpu_ios_query_gles2(char gpu_name[restrict static CPUINFO_GPU_NAME_MAX]) { |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 14 | EAGLContext *const existing_context = [EAGLContext currentContext]; |
| 15 | EAGLContext *new_context = nil; |
| 16 | if (!existing_context) { |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 17 | /* No existing context: create new context */ |
| 18 | |
| 19 | /* OpenGL ES 2.0 is supported by iPhone 3GS and up */ |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 20 | new_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
| 21 | if (!new_context) { |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 22 | cpuinfo_log_warning("failed to initialize OpenGLES context"); |
| 23 | } |
| 24 | |
| 25 | /* Set context */ |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 26 | if (![EAGLContext setCurrentContext:new_context]) { |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 27 | cpuinfo_log_warning("failed to set current OpenGLES context"); |
| 28 | } |
| 29 | } |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 30 | |
Marat Dukhan | 03f5c0b | 2017-10-25 16:09:39 -0700 | [diff] [blame^] | 31 | const char* renderer_str = (const char*) glGetString(GL_RENDERER); |
| 32 | if (renderer_str != NULL) { |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 33 | strncpy(gpu_name, renderer_str, CPUINFO_GPU_NAME_MAX - 1); |
| 34 | gpu_name[CPUINFO_GPU_NAME_MAX - 1] = '\0'; |
| 35 | cpuinfo_log_debug("GL_RENDERER: %s", renderer_str); |
| 36 | } else { |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 37 | cpuinfo_log_warning("failed to get GL_RENDERER for OpenGLES context"); |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Marat Dukhan | 41a7e35 | 2017-10-23 16:11:31 -0700 | [diff] [blame] | 40 | if (new_context) { |
| 41 | /* Reset context back to the original one */ |
| 42 | if (![EAGLContext setCurrentContext:nil]) { |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 43 | cpuinfo_log_warning("failed to reset OpenGLES context"); |
| 44 | } |
Hao Lu | 3617d5b | 2017-10-23 15:16:50 -0700 | [diff] [blame] | 45 | } |
| 46 | } |