+enum {
+ GEARS_WINDOW,
+ GEARS_PIXMAP,
+ GEARS_PIXMAP_TEXTURE,
+ GEARS_PBUFFER,
+ GEARS_PBUFFER_TEXTURE,
+ GEARS_RENDERBUFFER
+};
+
+static void
+texture_gears(struct egl_manager *eman, int surface_type)
+{
+ static const GLint verts[12] =
+ { -5, -6, -10, 5, -6, -10, -5, 4, 10, 5, 4, 10 };
+ static const GLint tex_coords[8] = { 0, 0, 1, 0, 0, 1, 1, 1 };
+
+ eglMakeCurrent(eman->dpy, eman->win, eman->win, eman->ctx);
+
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glVertexPointer(3, GL_INT, 0, verts);
+ glTexCoordPointer(2, GL_INT, 0, tex_coords);
+
+ if (surface_type == GEARS_PBUFFER_TEXTURE)
+ eglBindTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisable(GL_TEXTURE_2D);
+
+ if (surface_type == GEARS_PBUFFER_TEXTURE)
+ eglReleaseTexImage(eman->dpy, eman->pbuf, EGL_BACK_BUFFER);
+
+ 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);
+ }
+ }
+}
+