aboutsummaryrefslogtreecommitdiff
path: root/src/gpu/gles-ios.m
blob: 1dc8e6fe9520845ccc023fdbae20dac9403e8f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES2/gl.h>

#import <cpuinfo.h>
#import <log.h>
#import <gpu/api.h>


#if ! __has_feature(objc_arc)
	#error "This file must be built with Automatic Reference Counting (-fobjc-arc option)"
#endif

void cpuinfo_gpu_ios_query_gles2(char gpu_name[restrict static CPUINFO_GPU_NAME_MAX]) {
	EAGLContext *const existing_context = [EAGLContext currentContext];
	EAGLContext *new_context = nil;
	if (!existing_context) {
		/* No existing context: create new context */

		/* OpenGL ES 2.0 is supported by iPhone 3GS and up */
		new_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
		if (!new_context) {
			cpuinfo_log_warning("failed to initialize OpenGLES context");
		}

		/* Set context */
		if (![EAGLContext setCurrentContext:new_context]) {
			cpuinfo_log_warning("failed to set current OpenGLES context");
		}
	}

	const char* renderer_str = (const char*) glGetString(GL_RENDERER);
	if (renderer_str != NULL) {
		strncpy(gpu_name, renderer_str, CPUINFO_GPU_NAME_MAX - 1);
		gpu_name[CPUINFO_GPU_NAME_MAX - 1] = '\0';
		cpuinfo_log_debug("GL_RENDERER: %s", renderer_str);
	} else {
		cpuinfo_log_warning("failed to get GL_RENDERER for OpenGLES context");
	}

	if (new_context) {
		/* Reset context back to the original one */
		if (![EAGLContext setCurrentContext:nil]) {
			cpuinfo_log_warning("failed to reset OpenGLES context");
		}
	}
}