#include "glproc.hpp"
#include "glws.hpp"
+#include <cairo/cairo-xlib.h>
+
namespace glws {
glXWaitX();
}
+ GlxDrawable(const unsigned pixmap_id, int width, int height) :
+ Drawable(NULL, width, height, false)
+ {
+ window = pixmap_id;
+ }
+
void processKeys(void) {
XEvent event;
while (XCheckWindowEvent(display, window, StructureNotifyMask | KeyPressMask, &event)) {
}
};
-
class GlxContext : public Context
{
public:
return true;
}
+void
+createWindow(Drawable *drawable, const Visual *_visual)
+{
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+ const GlxVisual *visual = static_cast<const GlxVisual *>(_visual);
+
+ glXCreateWindow(display, visual->fbconfig, glxDrawable->window, NULL);
+}
+
+Drawable *
+createPixmap(unsigned width, unsigned height, unsigned depth)
+{
+ Pixmap pixmap;
+
+ pixmap = XCreatePixmap(display, DefaultRootWindow(display),
+ width, height, depth);
+
+ printf ("Replayed XCreatePixmap to create pixmap %ld\n", pixmap);
+
+ return new GlxDrawable(pixmap, width, height);
+}
+
+Drawable *
+createGLPixmap(GLXFBConfig fbconfig, Drawable *_pixmap,
+ unsigned width, unsigned height, int *attrib_list)
+{
+ GlxDrawable *pixmap = static_cast<GlxDrawable *>(_pixmap);
+ Pixmap gl_pixmap;
+
+ gl_pixmap = glXCreatePixmap(display, fbconfig, pixmap->window, attrib_list);
+
+ printf ("And replayed glXCreatePixmap to create pixmap %ld\n", gl_pixmap);
+
+ return new GlxDrawable(gl_pixmap, width, height);
+}
+
+void
+destroyWindow(Drawable *drawable)
+{
+/*
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+ glXDestroyWindow(display, glxDrawable->window);
+*/
+}
+
+void
+bindTexImage(Drawable *drawable, int buffer)
+{
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+ glXBindTexImageEXT(display, glxDrawable->window, buffer, NULL);
+}
+
+void
+releaseTexImage(Drawable *drawable, int buffer)
+{
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+ glXReleaseTexImageEXT(display, glxDrawable->window, buffer);
+}
+
+void
+copySubBuffer(Drawable *drawable, int x, int y, int width, int height)
+{
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+
+ glXCopySubBufferMESA(display, glxDrawable->window, x, y, width, height);
+}
+
+void
+putImageData(glws::Drawable *drawable, char *data,
+ int width, int height, int depth,
+ int bits_per_pixel, int bytes_per_line, int byte_order)
+{
+ GlxDrawable *glxDrawable = static_cast<GlxDrawable *>(drawable);
+ GC gc;
+ XImage image;
+
+ printf ("Calling XPutImage to pixmap %ld\n", glxDrawable->window);
+
+ image.width = width;
+ image.height = height;
+ image.format = ZPixmap;
+ image.data = data;
+ image.byte_order = byte_order;
+ image.bitmap_unit = 32;
+ image.bitmap_bit_order = byte_order;
+ image.bitmap_pad = 32;
+ image.depth = depth,
+ image.bytes_per_line = bytes_per_line;
+ image.bits_per_pixel = bits_per_pixel;
+ image.red_mask = 0;
+ image.green_mask = 0;
+ image.blue_mask = 0;
+ image.obdata = 0;
+
+ XInitImage(&image);
+
+ {
+ Window root;
+ int x_ignore, y_ignore;
+ unsigned width, height, depth, border_width_ignore;
+ XGetGeometry(display, glxDrawable->window, &root, &x_ignore, &y_ignore,
+ &width, &height, &border_width_ignore, &depth);
+ }
+
+ gc = XCreateGC(display, glxDrawable->window, 0, NULL);
+ XPutImage(display, glxDrawable->window, gc, &image, 0, 0, 0, 0, width, height);
+
+ {
+ static int count = 0;
+ char filename[] = "put-image-data-X.png";
+ cairo_surface_t *surface;
+
+ surface = cairo_xlib_surface_create(display, glxDrawable->window, DefaultVisual(display, DefaultScreen(display)), width, height);
+
+ filename[15] = '0' + count;
+ cairo_surface_write_to_png(surface, filename);
+
+ cairo_surface_destroy(surface);
+ count++;
+ }
+
+}
+
+GLXFBConfig
+chooseConfig(int *attrib_list)
+{
+ GLXFBConfig *configs;
+ int nelements;
+ configs = glXChooseFBConfig(display, DefaultScreen(display), attrib_list, &nelements);
+ if (nelements)
+ return configs[nelements - 1];
+ else
+ return NULL;
+}
-} /* namespace glws */
+} /* drawable glws */