-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontext_egl.cpp
101 lines (75 loc) · 2.8 KB
/
context_egl.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "context_egl.h"
/*---------------------------------------------------------------------------*/
void contextInitAndGetAPI(Params& params, Context& ctx) {
EGLDisplay& display = ctx.display;
EGLConfig& config = ctx.config;
EGLContext& context = ctx.context;
EGLSurface& surface = ctx.surface;
const EGLint config_attribute_list[] =
{
//EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RED_SIZE, 4,
EGL_GREEN_SIZE, 4,
EGL_BLUE_SIZE, 4,
EGL_ALPHA_SIZE, 4,
EGL_CONFORMANT, EGL_OPENGL_ES3_BIT,
EGL_DEPTH_SIZE, 16,
EGL_NONE
};
const EGLint context_attrib_list[] =
{
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE
};
const EGLint pbuffer_attrib_list[] =
{
EGL_WIDTH, params.width,
EGL_HEIGHT, params.height,
EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE,
EGL_TEXTURE_TARGET, EGL_NO_TEXTURE,
EGL_LARGEST_PBUFFER, EGL_TRUE,
EGL_NONE
};
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint major;
EGLint minor;
if(eglInitialize(display, &major, &minor) == EGL_FALSE) {
crash("%s", "eglInitialize failed.");
}
params.APIVersion = ((int)major * 100) + ((int) minor * 10);
params.API = API_OPENGL_ES;
EGLint num_config;
if(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config) == EGL_FALSE) {
crash("%s", "eglChooseConfig failed.");
}
if(num_config != 1) {
crash("%s", "eglChooseConfig did not return 1 config.");
}
context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attrib_list);
if(context == EGL_NO_CONTEXT) {
crash("eglCreateContext failed: %x", eglGetError());
}
surface = eglCreatePbufferSurface(display, config, pbuffer_attrib_list);
if(surface == EGL_NO_SURFACE) {
crash("eglCreatePbufferSurface failed: %x", eglGetError());
}
eglMakeCurrent(display, surface, surface, context);
}
/*---------------------------------------------------------------------------*/
bool contextKeepLooping(Context &ctx) {
return true;
}
/*---------------------------------------------------------------------------*/
void contextSwap(Context& ctx) {
eglSwapBuffers(ctx.display, ctx.surface);
}
/*---------------------------------------------------------------------------*/
void contextSetKeyCallback(Context& ctx) {
printf("Warning: no key callback support with EGL!\n");
}
/*---------------------------------------------------------------------------*/
void contextTerminate(Context& ctx) {
eglTerminate(ctx.display);
}
/*---------------------------------------------------------------------------*/