58 EGLNativeWindowType win)
60 if (itsDisplay) {
LERROR(
"Display already initialized -- IGNORED");
return; }
63 itsDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
64 if (itsDisplay == EGL_NO_DISPLAY)
LFATAL(
"Could not get an OpenGL display");
69 LINFO(
"Initialized EGL v" << major <<
'.' << minor);
72 EGLenum
const api = eglQueryAPI();
75 case EGL_OPENGL_API:
LFATAL(
"EGL API is unsupported EGL_OPENGL_API");
break;
76 case EGL_OPENGL_ES_API:
LINFO(
"EGL API is EGL_OPENGL_ES_API");
break;
77 case EGL_OPENVG_API:
LFATAL(
"EGL API is unsupported EGL_OPENVG_API");
break;
78 case EGL_NONE:
LFATAL(
"EGL API is unsupported EGL_NONE");
break;
79 default:
LFATAL(
"EGL API is unknown");
83 static EGLint
const cfg_attr[] =
85 EGL_SAMPLES, EGL_DONT_CARE,
92 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
93 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
95 EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
100 GL_CHECK_BOOL(eglChooseConfig(itsDisplay, cfg_attr,
nullptr, 0, &num_config));
101 LINFO(
"OpenGL configs available: " << num_config);
102 if (num_config < 1)
LFATAL(
"Could not find a suitable OpenGL config");
104 EGLConfig * configs =
new EGLConfig[num_config];
105 GL_CHECK_BOOL(eglChooseConfig(itsDisplay, cfg_attr, configs, num_config, &num_config));
107 for (
int i = 0; i < num_config; ++i)
112 #define JEVOIS_EGL_INFO(x) GL_CHECK(eglGetConfigAttrib(itsDisplay, configs[i], x, &val)); \
113 info += std::string(#x) + '=' + std::to_string(val) + ", ";
141 LINFO(
"EGL config " << i <<
": " << info);
143 #undef JEVOIS_EGL_INFO
145 GL_CHECK(eglGetConfigAttrib(itsDisplay, configs[i], EGL_RED_SIZE, &val));
146 if (val != 8)
continue;
147 GL_CHECK(eglGetConfigAttrib(itsDisplay, configs[i], EGL_GREEN_SIZE, &val));
148 if (val != 8)
continue;
149 GL_CHECK(eglGetConfigAttrib(itsDisplay, configs[i], EGL_BLUE_SIZE, &val));
150 if (val != 8)
continue;
153 LINFO(
"Using config " << i <<
" with 8-bit R,G,B.");
154 itsConfig = configs[i];
161 if (gotit ==
false)
LFATAL(
"Could not find a suitable OpenGL config");
164 static EGLint
const win_attr[] =
169 GL_CHECK(itsSurface = eglCreateWindowSurface(itsDisplay, itsConfig, win, win_attr));
170 LINFO(
"OpenGL surface created ok.");
175 LINFO(
"OpenGL-ES API bound ok.");
178 static EGLint
const ctx_attr[] =
180 EGL_CONTEXT_CLIENT_VERSION, 3,
181 EGL_CONTEXT_MAJOR_VERSION_KHR, 3,
182 EGL_CONTEXT_MINOR_VERSION_KHR, 2,
186 GL_CHECK(itsContext = eglCreateContext(itsDisplay, itsConfig, EGL_NO_CONTEXT, ctx_attr));
187 if (itsContext == EGL_NO_CONTEXT)
LFATAL(
"Failed to create OpenGL context");
188 LINFO(
"OpenGL context ok");
191 GL_CHECK(eglMakeCurrent(itsDisplay, itsSurface, itsSurface, itsContext));
194 glGetIntegerv(GL_MAJOR_VERSION, &major);
195 glGetIntegerv(GL_MINOR_VERSION, &minor);
196 LINFO(glGetString(GL_VERSION) <<
' '<< glGetString(GL_VENDOR) <<
" (" << glGetString(GL_RENDERER) <<
197 ") GL_VER=" << major <<
'.' << minor);
198 LINFO(
"OpenGL extensions: " << glGetString(GL_EXTENSIONS));
205 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
211 if (itsDisplay != EGL_NO_DISPLAY)
213 eglBindAPI(EGL_OPENGL_ES_API);
214 eglMakeCurrent(itsDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, itsContext);
215 eglMakeCurrent(itsDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
216 if (itsSurface) { eglDestroySurface(itsDisplay, itsSurface); itsSurface = 0; }
217 eglDestroyContext(itsDisplay, itsContext); itsContext = EGL_NO_CONTEXT;
218 eglTerminate(itsDisplay); itsDisplay = EGL_NO_DISPLAY;
227 unsigned short w,
h; getWindowSize(w,
h);
229 if (w == 0)
LFATAL(
"Need to call init() first");
232 glViewport(0, 0, w,
h);
233 glClear(GL_COLOR_BUFFER_BIT);
249 GL_CHECK(eglQuerySurface(itsDisplay, itsSurface, EGL_WIDTH, &ww));
250 GL_CHECK(eglQuerySurface(itsDisplay, itsSurface, EGL_HEIGHT, &hh));
261 {
return itsDisplay; }