From f67b7c9b80f77435d273047121c805722cb75084 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 23 Nov 2010 17:24:08 +0000 Subject: [PATCH] Hack to make the GLES2 tri demo use two windows https://bugs.freedesktop.org/show_bug.cgi?id=31868 --- src/egl/opengles2/tri.c | 55 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/egl/opengles2/tri.c b/src/egl/opengles2/tri.c index 8981d8a..e8419ef 100644 --- a/src/egl/opengles2/tri.c +++ b/src/egl/opengles2/tri.c @@ -315,11 +315,16 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, eglBindAPI(EGL_OPENGL_ES_API); #endif - ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); - if (!ctx) { - printf("Error: eglCreateContext failed\n"); - exit(1); - } + if (*ctxRet) + ctx = *ctxRet; + else + { + ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs ); + if (!ctx) { + printf("Error: eglCreateContext failed\n"); + exit(1); + } + } /* test eglQueryContext() */ { @@ -353,8 +358,8 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, static void -event_loop(Display *dpy, Window win, - EGLDisplay egl_dpy, EGLSurface egl_surf) +event_loop(Display *dpy, Window *win, + EGLContext egl_ctx, EGLDisplay egl_dpy, EGLSurface *egl_surf) { while (1) { int redraw = 0; @@ -403,7 +408,19 @@ event_loop(Display *dpy, Window win, if (redraw) { draw(); - eglSwapBuffers(egl_dpy, egl_surf); + eglSwapBuffers(egl_dpy, egl_surf[0]); + + /* Temporarily switch to the other surface and draw to that too */ + if (!eglMakeCurrent(egl_dpy, egl_surf[1], egl_surf[1], egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + } + draw(); + eglSwapBuffers(egl_dpy, egl_surf[1]); + + /* Switch back to the original surface for the next redraw */ + if (!eglMakeCurrent(egl_dpy, egl_surf[0], egl_surf[0], egl_ctx)) { + printf("Error: eglMakeCurrent() failed\n"); + } } } } @@ -423,9 +440,9 @@ main(int argc, char *argv[]) { const int winWidth = 300, winHeight = 300; Display *x_dpy; - Window win; - EGLSurface egl_surf; - EGLContext egl_ctx; + Window win[2]; + EGLSurface egl_surf[2]; + EGLContext egl_ctx = 0; EGLDisplay egl_dpy; char *dpyName = NULL; GLboolean printInfo = GL_FALSE; @@ -479,10 +496,14 @@ main(int argc, char *argv[]) make_x_window(x_dpy, egl_dpy, "OpenGL ES 2.x tri", 0, 0, winWidth, winHeight, - &win, &egl_ctx, &egl_surf); + win, &egl_ctx, egl_surf); + make_x_window(x_dpy, egl_dpy, + "OpenGL ES 2.x tri - win2", 0, 0, winWidth, winHeight, + win + 1, &egl_ctx, egl_surf + 1); - XMapWindow(x_dpy, win); - if (!eglMakeCurrent(egl_dpy, egl_surf, egl_surf, egl_ctx)) { + XMapWindow(x_dpy, win[0]); + XMapWindow(x_dpy, win[1]); + if (!eglMakeCurrent(egl_dpy, egl_surf[0], egl_surf[0], egl_ctx)) { printf("Error: eglMakeCurrent() failed\n"); return -1; } @@ -502,14 +523,14 @@ main(int argc, char *argv[]) */ reshape(winWidth, winHeight); - event_loop(x_dpy, win, egl_dpy, egl_surf); + event_loop(x_dpy, win, egl_ctx, egl_dpy, egl_surf); eglDestroyContext(egl_dpy, egl_ctx); - eglDestroySurface(egl_dpy, egl_surf); + eglDestroySurface(egl_dpy, egl_surf[0]); eglTerminate(egl_dpy); - XDestroyWindow(x_dpy, win); + XDestroyWindow(x_dpy, win[0]); XCloseDisplay(x_dpy); return 0; -- 1.7.3.16.g9464b