+int fghChooseConfig(EGLConfig* config) {
+ EGLint num_config;
+ EGLint attributes[32];
+ int where = 0;
+ ATTRIB_VAL(EGL_SURFACE_TYPE, EGL_WINDOW_BIT);
+#ifdef EGL_OPENGL_ES3_BIT
+ if (fgDisplay.pDisplay.egl.MinorVersion >= 5 && fgState.MajorVersion >= 3) {
+ ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT);
+ } else
+#endif
+ if (fgState.MajorVersion >= 2) {
+ /*
+ * Khronos does not specify a EGL_OPENGL_ES3_BIT outside of the OpenGL extension "EGL_KHR_create_context" and EGL 1.5. There are numerous references on the internet
+ * that say to use EGL_OPENGL_ES3_BIT (pre-EGL 1.5), followed by many saying they can't find it in any headers. In fact, the official updated specification for EGL
+ * does not have any references to OpenGL ES 3.x. Tests have shown that EGL_OPENGL_ES2_BIT will work with ES 3.x.
+ */
+ ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT);
+ } else {
+ ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT);
+ }
+ /* Technically it's possible to request a standard OpenGL (non-ES)
+ context, but currently our build system assumes EGL => GLES */
+ /* attribs[i++] = EGL_RENDERABLE_TYPE; */
+ /* attribs[i++] = EGL_OPENGL_BIT; */
+#ifdef TARGET_HOST_BLACKBERRY
+ /* Only 888 and 565 seem to work. Based on
+ http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and
+ https://twitter.com/BlackBerryDev/status/380720927475912706 */
+ ATTRIB_VAL(EGL_BLUE_SIZE, 8);
+ ATTRIB_VAL(EGL_GREEN_SIZE, 8);
+ ATTRIB_VAL(EGL_RED_SIZE, 8);
+#else
+ ATTRIB_VAL(EGL_BLUE_SIZE, 1);
+ ATTRIB_VAL(EGL_GREEN_SIZE, 1);
+ ATTRIB_VAL(EGL_RED_SIZE, 1);
+#endif
+ ATTRIB_VAL(EGL_ALPHA_SIZE, (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0);
+ ATTRIB_VAL(EGL_DEPTH_SIZE, (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0);
+ ATTRIB_VAL(EGL_STENCIL_SIZE, (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0);
+ ATTRIB_VAL(EGL_SAMPLE_BUFFERS, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? 1 : 0);
+ ATTRIB_VAL(EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0);
+ ATTRIB(EGL_NONE);
+
+ if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display,
+ attributes, config, 1, &num_config)) {
+ fgWarning("eglChooseConfig: error %x\n", eglGetError());
+ return 0;
+ }
+
+ return 1;
+}
+