EGLBoolean verbose;
EGLint major, minor;
+
+ GC gc;
};
static struct egl_manager *
}
}
+ eman->gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL);
+
XMapWindow(eman->xdpy, eman->xwin);
return EGL_TRUE;
if (eman->xpix != None)
XFreePixmap(eman->xdpy, eman->xpix);
+ XFreeGC(eman->xdpy, eman->gc);
+
free(eman);
}
eglSwapBuffers(eman->dpy, eman->win);
}
+static void
+copy_gears(struct egl_manager *eman,
+ EGLint tile_w, EGLint tile_h, EGLint w, EGLint h)
+{
+ int x, y;
+
+ eglWaitClient();
+
+ for (x = 0; x < w; x += tile_w) {
+ for (y = 0; y < h; y += tile_h) {
+
+ XCopyArea(eman->xdpy, eman->xpix, eman->xwin, eman->gc,
+ 0, 0, tile_w, tile_h, x, y);
+ }
+ }
+}
+
static void
event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h)
{
- GC gc = XCreateGC(eman->xdpy, eman->xwin, 0, NULL);
- EGLint orig_w = w, orig_h = h;
+ int window_w = w, window_h = h;
if (surface_type == EGL_PBUFFER_BIT)
printf("there will be no screen update if "
/* we'll redraw below */
break;
case ConfigureNotify:
- w = event.xconfigure.width;
- h = event.xconfigure.height;
+ window_w = event.xconfigure.width;
+ window_h = event.xconfigure.height;
if (surface_type == EGL_WINDOW_BIT)
- reshape(w, h);
+ reshape(window_w, window_h);
break;
case KeyPress:
{
static int frames = 0;
static double tRot0 = -1.0, tRate0 = -1.0;
double dt, t = current_time();
- int x, y;
if (tRot0 < 0.0)
tRot0 = t;
dt = t - tRot0;
angle -= 3600.0;
switch (surface_type) {
+ case GEARS_WINDOW:
+ draw();
+ eglSwapBuffers(eman->dpy, eman->win);
+ break;
+
case GEARS_PBUFFER:
+ draw();
+ if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix))
+ break;
+ copy_gears(eman, w, h, window_w, window_h);
+ break;
+
case GEARS_PBUFFER_TEXTURE:
eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx);
+ draw();
+ texture_gears(eman, surface_type);
break;
case GEARS_PIXMAP:
- case GEARS_PIXMAP_TEXTURE:
- eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx);
+ draw();
+ copy_gears(eman, w, h, window_w, window_h);
break;
- }
- draw();
- switch (surface_type) {
- case GEARS_WINDOW:
- eglSwapBuffers(eman->dpy, eman->win);
- break;
- case GEARS_PBUFFER_TEXTURE:
case GEARS_PIXMAP_TEXTURE:
+ eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx);
+ draw();
texture_gears(eman, surface_type);
break;
- case GEARS_PBUFFER:
- if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix))
- break;
- eglWaitClient();
- /* fall through */
- case GEARS_PIXMAP:
- eglWaitClient();
- for (x = 0; x < w; x += orig_w) {
- for (y = 0; y < h; y += orig_h) {
- XCopyArea(eman->xdpy, eman->xpix, eman->xwin, gc,
- 0, 0, orig_w, orig_h, x, y);
- }
- }
- break;
- }
+ }
frames++;
}
}
}
-
- XFreeGC(eman->xdpy, gc);
}