#include <inttypes.h>
#include <pthread.h>
#include "glxclient.h"
#include <X11/extensions/extutil.h>
#include <X11/extensions/Xext.h>
#include <assert.h>
#include <string.h>
#include "glxextensions.h"
#include "glcontextmodes.h"
#include "apple_glx_drawable.h"
#include "glx_error.h"
PUBLIC GLXPbuffer
glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attrib_list) {
int i, width, height;
GLXPbuffer result;
int errorcode;
width = 0;
height = 0;
for(i = 0; attrib_list[i]; ++i) {
switch(attrib_list[i]) {
case GLX_PBUFFER_WIDTH:
width = attrib_list[i + 1];
++i;
break;
case GLX_PBUFFER_HEIGHT:
height = attrib_list[i + 1];
++i;
break;
case GLX_LARGEST_PBUFFER:
++i;
break;
case GLX_PRESERVED_CONTENTS:
++i;
break;
default:
return None;
}
}
if(apple_glx_pbuffer_create(dpy, config, width, height, &errorcode,
&result)) {
__glXSendError(dpy, errorcode, 0, X_GLXCreatePbuffer, true);
return None;
}
return result;
}
PUBLIC void
glXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf)
{
if(apple_glx_pbuffer_destroy(dpy, pbuf)) {
__glXSendError(dpy, GLXBadPbuffer, pbuf, X_GLXDestroyPbuffer, false);
}
}
PUBLIC void
glXQueryDrawable(Display *dpy, GLXDrawable drawable,
int attribute, unsigned int *value) {
Window root;
int x, y;
unsigned int width, height, bd, depth;
if(apple_glx_pixmap_query(drawable, attribute, value))
return;
if(apple_glx_pbuffer_query(drawable, attribute, value))
return;
if(XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &bd, &depth)) {
switch(attribute) {
case GLX_WIDTH:
*value = width;
break;
case GLX_HEIGHT:
*value = height;
break;
}
}
}
PUBLIC void
glXSelectEvent(Display *dpy, GLXDrawable drawable, unsigned long mask)
{
XWindowAttributes xwattr;
if(apple_glx_pbuffer_set_event_mask(drawable, mask))
return;
if(XGetWindowAttributes(dpy, drawable, &xwattr))
return;
__glXSendError(dpy, GLXBadDrawable, drawable,
X_GLXChangeDrawableAttributes, false);
}
PUBLIC void
glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask)
{
XWindowAttributes xwattr;
if(apple_glx_pbuffer_get_event_mask(drawable, mask))
return;
if(XGetWindowAttributes(dpy, drawable, &xwattr)) {
*mask = 0;
return;
}
__glXSendError(dpy, GLXBadDrawable, drawable, X_GLXGetDrawableAttributes,
true);
}
PUBLIC GLXPixmap
glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
const int *attrib_list )
{
const __GLcontextModes *modes = (const __GLcontextModes *)config;
if(apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
return None;
return pixmap;
}
PUBLIC GLXWindow
glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
const int *attrib_list )
{
XWindowAttributes xwattr;
XVisualInfo *visinfo;
(void)attrib_list;
XGetWindowAttributes(dpy, win, &xwattr);
visinfo = glXGetVisualFromFBConfig(dpy, config);
if(NULL == visinfo) {
__glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateWindow, false);
return None;
}
if(visinfo->visualid != XVisualIDFromVisual(xwattr.visual)) {
__glXSendError(dpy, BadMatch, 0, X_GLXCreateWindow, true);
return None;
}
XFree(visinfo);
return win;
}
PUBLIC void
glXDestroyPixmap(Display *dpy, GLXPixmap pixmap)
{
if(apple_glx_pixmap_destroy(dpy, pixmap))
__glXSendError(dpy, GLXBadPixmap, pixmap, X_GLXDestroyPixmap, false);
}
PUBLIC void
glXDestroyWindow(Display *dpy, GLXWindow win)
{
}