+ // GL init. Must come after resource processing.
+
+ rh->egl_ctx = eglGetCurrentContext();
+ Assert(rh->egl_ctx != EGL_NO_CONTEXT, "doinit: EGL_NO_CONTEXT");
+
+ get_egl_surface (rh);
+
+ rh->egl_display = eglGetCurrentDisplay();
+ Assert(rh->egl_display != EGL_NO_DISPLAY, "doinit: EGL_NO_DISPLAY");
+
+ unsigned egl_major, egl_minor;
+ if (sscanf ((const char *)eglQueryString(rh->egl_display, EGL_VERSION),
+ "%u.%u", &egl_major, &egl_minor) < 2)
+ {
+ egl_major = 1;
+ egl_minor = 0;
+ }
+
+ EGLint config_attribs[3];
+ config_attribs[0] = EGL_CONFIG_ID;
+ eglQueryContext(rh->egl_display, rh->egl_ctx, EGL_CONFIG_ID,
+ &config_attribs[1]);
+ config_attribs[2] = EGL_NONE;
+
+ EGLint num_config;
+ eglChooseConfig(rh->egl_display, config_attribs,
+ &rh->egl_config, 1, &num_config);
+ Assert(num_config == 1, "no EGL config chosen");
+
+ const GLubyte *extensions = glGetString (GL_EXTENSIONS);
+ rh->gl_fbo_p = jwzgles_gluCheckExtension (
+ (const GLubyte *)"GL_OES_framebuffer_object", extensions);
+
+ if (rh->gl_fbo_p) {
+ PFNGLGENFRAMEBUFFERSOESPROC glGenFramebuffersOES =
+ (PFNGLGENFRAMEBUFFERSOESPROC)
+ eglGetProcAddress ("glGenFramebuffersOES");
+
+ rh->glBindFramebufferOES = (PFNGLBINDFRAMEBUFFEROESPROC)
+ eglGetProcAddress ("glBindFramebufferOES");
+ rh->glFramebufferTexture2DOES = (PFNGLFRAMEBUFFERTEXTURE2DOESPROC)
+ eglGetProcAddress ("glFramebufferTexture2DOES");
+
+ glGetIntegerv (GL_FRAMEBUFFER_BINDING_OES, &rh->fb_default);
+ Assert (!rh->fb_default, "default framebuffer not current framebuffer");
+ glGenFramebuffersOES (1, &rh->fb_pixmap);
+ wnd->texture = 0;
+ } else {
+ wnd->egl_surface = rh->egl_surface;
+ }
+
+ /* TODO: Maybe ask for EGL_SWAP_BEHAVIOR_PRESERVED_BIT on the Java side of
+ things via EGLConfigChooser. I (Dave) seem to automatically get
+ this (n = 1), but maybe other devices won't.
+ */
+ rh->frontbuffer_p = False;
+
+ if (rh->api == API_XLIB ||
+ (rh->api == API_GL &&
+ strcmp("True", get_string_resource_window(wnd, "doubleBuffer")))) {
+
+ rh->frontbuffer_p = True;
+
+# if 0 /* Might need to be 0 for Adreno...? */
+ if (egl_major > 1 || (egl_major == 1 && egl_minor >= 2)) {
+ EGLint surface_type;
+ eglGetConfigAttrib(rh->egl_display, rh->egl_config, EGL_SURFACE_TYPE,
+ &surface_type);
+ if(surface_type & EGL_SWAP_BEHAVIOR_PRESERVED_BIT) {
+ eglSurfaceAttrib(rh->egl_display, rh->egl_surface, EGL_SWAP_BEHAVIOR,
+ EGL_BUFFER_PRESERVED);
+ rh->frontbuffer_p = False;
+ }
+ }
+# endif
+
+ if (rh->frontbuffer_p) {
+ /* create_pixmap needs rh->gl_fbo_p and wnd->frame. */
+ create_pixmap (wnd, wnd);
+
+ /* No preserving backbuffers, so manual blit from back to "front". */
+ rh->frontbuffer.type = PIXMAP;
+ rh->frontbuffer.frame = wnd->frame;
+ rh->frontbuffer.pixmap.depth = visual_depth (NULL, NULL);
+
+ if(rh->gl_fbo_p) {
+ rh->frontbuffer.texture = 0;
+ } else {
+ Assert (wnd->egl_surface != rh->egl_surface,
+ "oops: wnd->egl_surface == rh->egl_surface");
+ rh->frontbuffer.egl_surface = rh->egl_surface;
+ }
+ }
+ }
+
+ rh->dpy = jwxyz_make_display(wnd);
+ Assert(wnd == XRootWindow(rh->dpy, 0), "Wrong root window.");
+ // TODO: Zero looks right, but double-check that is the right number
+
+ /* Requires valid rh->dpy. */
+ rh->copy_gc = XCreateGC (rh->dpy, &rh->frontbuffer, 0, NULL);
+
+ rh->gles_state = jwzgles_make_state();
+ restore_surface(rh);