#include "packsingle.h"
#include "glxclient.h"
#include <extensions/extutil.h>
#include <extensions/Xext.h>
#include <assert.h>
#include <string.h>
#include "glapi.h"
#ifdef GLX_DIRECT_RENDERING
#include "indirect_init.h"
#include <extensions/xf86vmode.h>
#endif
#include "glxextensions.h"
#include "glcontextmodes.h"
#include <sys/time.h>
const char __glXGLClientExtensions[] =
"GL_ARB_depth_texture "
"GL_ARB_imaging "
"GL_ARB_multisample "
"GL_ARB_multitexture "
"GL_ARB_point_parameters "
"GL_ARB_point_sprite "
"GL_ARB_shadow "
"GL_ARB_shadow_ambient "
"GL_ARB_texture_border_clamp "
"GL_ARB_texture_cube_map "
"GL_ARB_texture_env_add "
"GL_ARB_texture_env_combine "
"GL_ARB_texture_env_crossbar "
"GL_ARB_texture_env_dot3 "
"GL_ARB_texture_mirrored_repeat "
"GL_ARB_texture_non_power_of_two "
"GL_ARB_transpose_matrix "
"GL_ARB_window_pos "
"GL_EXT_abgr "
"GL_EXT_bgra "
"GL_EXT_blend_color "
"GL_EXT_blend_func_separate "
"GL_EXT_blend_logic_op "
"GL_EXT_blend_minmax "
"GL_EXT_blend_subtract "
"GL_EXT_clip_volume_hint "
"GL_EXT_copy_texture "
"GL_EXT_draw_range_elements "
"GL_EXT_fog_coord "
"GL_EXT_multi_draw_arrays "
"GL_EXT_packed_pixels "
"GL_EXT_polygon_offset "
"GL_EXT_rescale_normal "
"GL_EXT_secondary_color "
"GL_EXT_separate_specular_color "
"GL_EXT_shadow_funcs "
"GL_EXT_stencil_two_side "
"GL_EXT_stencil_wrap "
"GL_EXT_subtexture "
"GL_EXT_texture "
"GL_EXT_texture3D "
"GL_EXT_texture_edge_clamp "
"GL_EXT_texture_env_add "
"GL_EXT_texture_env_combine "
"GL_EXT_texture_env_dot3 "
"GL_EXT_texture_filter_anisotropic "
"GL_EXT_texture_lod "
"GL_EXT_texture_lod_bias "
"GL_EXT_texture_object "
"GL_EXT_texture_rectangle "
"GL_EXT_vertex_array "
"GL_APPLE_packed_pixels "
"GL_APPLE_ycbcr_422 "
"GL_ATI_texture_env_combine3 "
"GL_ATI_texture_float "
"GL_ATI_texture_mirror_once "
"GL_ATIX_texture_env_combine3 "
"GL_HP_convolution_border_modes "
#if 0
"GL_HP_occlusion_test "
#endif
"GL_IBM_cull_vertex "
"GL_IBM_pixel_filter_hint "
"GL_IBM_rasterpos_clip "
"GL_IBM_texture_clamp_nodraw "
"GL_IBM_texture_mirrored_repeat "
"GL_INGR_interlace_read "
"GL_MESA_pack_invert "
"GL_MESA_ycbcr_texture "
"GL_NV_blend_square "
"GL_NV_copy_depth_to_color "
"GL_NV_depth_clamp "
"GL_NV_fog_distance "
"GL_NV_light_max_exponent "
"GL_NV_multisample_filter_hint "
"GL_NV_point_sprite "
"GL_NV_texgen_reflection "
"GL_NV_texture_rectangle "
"GL_SGIS_generate_mipmap "
"GL_SGIS_multisample "
"GL_SGIS_texture_border_clamp "
"GL_SGIS_texture_edge_clamp "
"GL_SGIS_texture_lod "
"GL_SGIX_blend_alpha_minmax "
"GL_SGIX_clipmap "
"GL_SGIX_depth_texture "
"GL_SGIX_fog_offset "
"GL_SGIX_shadow "
"GL_SGIX_shadow_ambient "
"GL_SGIX_texture_coordinate_clamp "
"GL_SGIX_texture_lod_bias "
"GL_SGIX_texture_range "
"GL_SGIX_texture_scale_bias "
"GL_SGIX_vertex_preclip "
"GL_SGIX_vertex_preclip_hint "
"GL_SGIX_ycrcb "
"GL_SUN_convolution_border_modes "
"GL_SUN_slice_accum "
;
static const char __glXGLXClientVendorName[] = "SGI";
static const char __glXGLXClientVersion[] = "1.2";
const char __glXGLClientVersion[] = "1.2";
#ifdef GLX_DIRECT_RENDERING
static void * DriverCreateContextWrapper( __GLXscreenConfigs *psc,
Display *dpy, XVisualInfo *vis, void *shared, __DRIcontext *ctx,
__GLcontextModes *fbconfig );
static Bool dummyBindContext2( Display *dpy, int scrn,
GLXDrawable draw, GLXDrawable read, GLXContext gc );
static Bool dummyUnbindContext2( Display *dpy, int scrn,
GLXDrawable draw, GLXDrawable read, GLXContext gc );
static Bool dummyBindContext2( Display *dpy, int scrn,
GLXDrawable draw, GLXDrawable read,
GLXContext gc )
{
assert( draw == read );
return (*gc->driContext.bindContext)( dpy, scrn, draw, gc );
}
static Bool dummyUnbindContext2( Display *dpy, int scrn,
GLXDrawable draw, GLXDrawable read,
GLXContext gc )
{
assert( draw == read );
return (*gc->driContext.unbindContext)( dpy, scrn, draw, gc, GL_FALSE );
}
static void * DriverCreateContextWrapper( __GLXscreenConfigs *psc,
Display *dpy, XVisualInfo *vis,
void *shared,
__DRIcontext *ctx,
__GLcontextModes *fbconfig )
{
void * ctx_priv;
(void) fbconfig;
ctx_priv = (*psc->driScreen.createContext)(dpy, vis, shared, ctx);
if ( ctx_priv != NULL ) {
if ( ctx->unbindContext2 == NULL ) {
ctx->unbindContext2 = dummyUnbindContext2;
}
if ( ctx->bindContext2 == NULL ) {
ctx->bindContext2 = dummyBindContext2;
}
}
return ctx_priv;
}
#endif
#ifdef GLX_DIRECT_RENDERING
static __DRIdrawable *
GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num )
{
__GLXdisplayPrivate * const priv = __glXInitialize(dpy);
if ( (priv != NULL) && (priv->driDisplay.private != NULL) ) {
const unsigned screen_count = ScreenCount(dpy);
unsigned i;
for ( i = 0 ; i < screen_count ; i++ ) {
__DRIscreen * const psc = &priv->screenConfigs[i].driScreen;
__DRIdrawable * const pdraw = (psc->private != NULL)
? (*psc->getDrawable)(dpy, drawable, psc->private) : NULL;
if ( pdraw != NULL ) {
if ( scrn_num != NULL ) {
*scrn_num = i;
}
return pdraw;
}
}
}
return NULL;
}
#endif
static __GLXscreenConfigs *
GetGLXScreenConfigs(Display *dpy, int scrn)
{
__GLXdisplayPrivate * const priv = __glXInitialize(dpy);
return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL;
}
static int
GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv,
__GLXscreenConfigs ** ppsc )
{
if ( dpy == NULL ) {
return GLX_NO_EXTENSION;
}
*ppriv = __glXInitialize(dpy);
if ( *ppriv == NULL ) {
return GLX_NO_EXTENSION;
}
if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
return GLX_BAD_SCREEN;
}
*ppsc = &((*ppriv)->screenConfigs[scrn]);
if ( ((*ppsc)->configs == NULL) || ((*ppsc)->numConfigs <= 0) ) {
return GLX_BAD_VISUAL;
}
return Success;
}
static
GLXContext AllocateGLXContext( Display *dpy )
{
GLXContext gc;
int bufSize;
CARD8 opcode;
__GLXattribute *state;
if (!dpy)
return NULL;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return NULL;
}
gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
if (!gc) {
return NULL;
}
memset(gc, 0, sizeof(struct __GLXcontextRec));
state = Xmalloc(sizeof(struct __GLXattributeRec));
if (state == NULL) {
Xfree(gc);
return NULL;
}
gc->client_state_private = state;
memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
gc->buf = (GLubyte *) Xmalloc(bufSize);
if (!gc->buf) {
Xfree(gc->client_state_private);
Xfree(gc);
return NULL;
}
gc->bufSize = bufSize;
gc->renderMode = GL_RENDER;
state->storePack.alignment = 4;
state->storeUnpack.alignment = 4;
__glXInitVertexArrayState(gc);
gc->attributes.stackPointer = &gc->attributes.stack[0];
gc->fastImageUnpack = GL_FALSE;
gc->fillImage = __glFillImage;
gc->isDirect = GL_FALSE;
gc->pc = gc->buf;
gc->bufEnd = gc->buf + bufSize;
if (__glXDebug) {
gc->limit = gc->buf;
} else {
gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
}
gc->createDpy = dpy;
gc->majorOpcode = opcode;
if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
}
if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
bufSize = __GLX_MAX_RENDER_CMD_SIZE;
}
gc->maxSmallRenderCommandSize = bufSize;
return gc;
}
static
GLXContext CreateContext(Display *dpy, XVisualInfo *vis,
__GLcontextModes * fbconfig, GLXContext shareList,
Bool allowDirect, GLXContextID contextID,
Bool use_glx_1_3, int renderType)
{
GLXContext gc;
if ( dpy == NULL )
return NULL;
gc = AllocateGLXContext(dpy);
if (!gc)
return NULL;
if (None == contextID) {
if ( (vis == NULL) && (fbconfig == NULL) )
return NULL;
#ifdef GLX_DIRECT_RENDERING
if (allowDirect) {
int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
__GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
if (psc && psc->driScreen.private) {
void * const shared = (shareList != NULL)
? shareList->driContext.private : NULL;
gc->driContext.private =
DriverCreateContextWrapper( psc, dpy, vis, shared,
&gc->driContext, fbconfig );
if (gc->driContext.private) {
gc->isDirect = GL_TRUE;
gc->screen = screen;
if ( fbconfig == NULL ) {
gc->vid = vis->visualid;
gc->fbconfigID = None;
}
else {
gc->vid = fbconfig->visualID;
gc->fbconfigID = fbconfig->fbconfigID;
}
}
}
}
#endif
LockDisplay(dpy);
if ( fbconfig == NULL ) {
xGLXCreateContextReq *req;
GetReq(GLXCreateContext,req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXCreateContext;
req->context = gc->xid = XAllocID(dpy);
req->visual = vis->visualid;
req->screen = vis->screen;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
}
else if ( use_glx_1_3 ) {
xGLXCreateNewContextReq *req;
GetReq(GLXCreateNewContext,req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXCreateNewContext;
req->context = gc->xid = XAllocID(dpy);
req->fbconfig = fbconfig->fbconfigID;
req->screen = fbconfig->screen;
req->renderType = renderType;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
}
else {
xGLXVendorPrivateReq *vpreq;
xGLXCreateContextWithConfigSGIXReq *req;
GetReqExtra(GLXVendorPrivate,
sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateReq,vpreq);
req = (xGLXCreateContextWithConfigSGIXReq *)vpreq;
req->reqType = gc->majorOpcode;
req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
req->context = gc->xid = XAllocID(dpy);
req->fbconfig = fbconfig->fbconfigID;
req->screen = fbconfig->screen;
req->renderType = renderType;
req->shareList = shareList ? shareList->xid : None;
req->isDirect = gc->isDirect;
}
UnlockDisplay(dpy);
SyncHandle();
gc->imported = GL_FALSE;
}
else {
gc->xid = contextID;
gc->imported = GL_TRUE;
}
return gc;
}
GLXContext GLX_PREFIX(glXCreateContext)(Display *dpy, XVisualInfo *vis,
GLXContext shareList, Bool allowDirect)
{
return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
False, 0);
}
void __glXFreeContext(__GLXcontext *gc)
{
if (gc->vendor) XFree((char *) gc->vendor);
if (gc->renderer) XFree((char *) gc->renderer);
if (gc->version) XFree((char *) gc->version);
if (gc->extensions) XFree((char *) gc->extensions);
__glFreeAttributeState(gc);
XFree((char *) gc->buf);
XFree((char *) gc->client_state_private);
XFree((char *) gc);
}
static void
DestroyContext(Display *dpy, GLXContext gc)
{
xGLXDestroyContextReq *req;
GLXContextID xid;
CARD8 opcode;
GLboolean imported;
opcode = __glXSetupForCommand(dpy);
if (!opcode || !gc) {
return;
}
__glXLock();
xid = gc->xid;
imported = gc->imported;
gc->xid = None;
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
if (gc->driContext.private) {
(*gc->driContext.destroyContext)(dpy, gc->screen,
gc->driContext.private);
gc->driContext.private = NULL;
}
}
#endif
if (gc->currentDpy) {
__glXUnlock();
} else {
__glXUnlock();
__glXFreeContext(gc);
}
if (!imported) {
LockDisplay(dpy);
GetReq(GLXDestroyContext,req);
req->reqType = opcode;
req->glxCode = X_GLXDestroyContext;
req->context = xid;
UnlockDisplay(dpy);
SyncHandle();
}
}
void GLX_PREFIX(glXDestroyContext)(Display *dpy, GLXContext gc)
{
DestroyContext(dpy, gc);
}
Bool GLX_PREFIX(glXQueryVersion)(Display *dpy, int *major, int *minor)
{
__GLXdisplayPrivate *priv;
priv = __glXInitialize(dpy);
if (!priv) return GL_FALSE;
if (major) *major = priv->majorVersion;
if (minor) *minor = priv->minorVersion;
return GL_TRUE;
}
Bool GLX_PREFIX(glXQueryExtension)(Display *dpy, int *errorBase, int *eventBase)
{
int major_op, erb, evb;
Bool rv;
rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
if (rv) {
if (errorBase) *errorBase = erb;
if (eventBase) *eventBase = evb;
}
return rv;
}
void GLX_PREFIX(glXWaitGL)(void)
{
xGLXWaitGLReq *req;
GLXContext gc = __glXGetCurrentContext();
Display *dpy = gc->currentDpy;
if (!dpy) return;
__glXFlushRenderBuffer(gc, gc->pc);
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
#ifdef glFinish
#undef glFinish
#endif
glFinish();
return;
}
#endif
LockDisplay(dpy);
GetReq(GLXWaitGL,req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXWaitGL;
req->contextTag = gc->currentContextTag;
UnlockDisplay(dpy);
SyncHandle();
}
void GLX_PREFIX(glXWaitX)(void)
{
xGLXWaitXReq *req;
GLXContext gc = __glXGetCurrentContext();
Display *dpy = gc->currentDpy;
if (!dpy) return;
__glXFlushRenderBuffer(gc, gc->pc);
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
XSync(dpy, False);
return;
}
#endif
LockDisplay(dpy);
GetReq(GLXWaitX,req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXWaitX;
req->contextTag = gc->currentContextTag;
UnlockDisplay(dpy);
SyncHandle();
}
void GLX_PREFIX(glXUseXFont)(Font font, int first, int count, int listBase)
{
xGLXUseXFontReq *req;
GLXContext gc = __glXGetCurrentContext();
Display *dpy = gc->currentDpy;
if (!dpy) return;
(void) __glXFlushRenderBuffer(gc, gc->pc);
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
DRI_glXUseXFont(font, first, count, listBase);
return;
}
#endif
LockDisplay(dpy);
GetReq(GLXUseXFont,req);
req->reqType = gc->majorOpcode;
req->glxCode = X_GLXUseXFont;
req->contextTag = gc->currentContextTag;
req->font = font;
req->first = first;
req->count = count;
req->listBase = listBase;
UnlockDisplay(dpy);
SyncHandle();
}
void GLX_PREFIX(glXCopyContext)(Display *dpy, GLXContext source, GLXContext dest,
unsigned long mask)
{
xGLXCopyContextReq *req;
GLXContext gc = __glXGetCurrentContext();
GLXContextTag tag;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
#ifdef GLX_DIRECT_RENDERING
if (gc->isDirect) {
}
#endif
if (source == gc && dpy == gc->currentDpy) {
tag = gc->currentContextTag;
} else {
tag = 0;
}
LockDisplay(dpy);
GetReq(GLXCopyContext,req);
req->reqType = opcode;
req->glxCode = X_GLXCopyContext;
req->source = source ? source->xid : None;
req->dest = dest ? dest->xid : None;
req->mask = mask;
req->contextTag = tag;
UnlockDisplay(dpy);
SyncHandle();
}
static Bool __glXIsDirect(Display *dpy, GLXContextID contextID)
{
xGLXIsDirectReq *req;
xGLXIsDirectReply reply;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return GL_FALSE;
}
LockDisplay(dpy);
GetReq(GLXIsDirect,req);
req->reqType = opcode;
req->glxCode = X_GLXIsDirect;
req->context = contextID;
_XReply(dpy, (xReply*) &reply, 0, False);
UnlockDisplay(dpy);
SyncHandle();
return reply.isDirect;
}
Bool GLX_PREFIX(glXIsDirect)(Display *dpy, GLXContext gc)
{
if (!gc) {
return GL_FALSE;
#ifdef GLX_DIRECT_RENDERING
} else if (gc->isDirect) {
return GL_TRUE;
#endif
}
return __glXIsDirect(dpy, gc->xid);
}
GLXPixmap GLX_PREFIX(glXCreateGLXPixmap)(Display *dpy, XVisualInfo *vis, Pixmap pixmap)
{
xGLXCreateGLXPixmapReq *req;
GLXPixmap xid;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return None;
}
LockDisplay(dpy);
GetReq(GLXCreateGLXPixmap,req);
req->reqType = opcode;
req->glxCode = X_GLXCreateGLXPixmap;
req->screen = vis->screen;
req->visual = vis->visualid;
req->pixmap = pixmap;
req->glxpixmap = xid = XAllocID(dpy);
UnlockDisplay(dpy);
SyncHandle();
return xid;
}
void GLX_PREFIX(glXDestroyGLXPixmap)(Display *dpy, GLXPixmap glxpixmap)
{
xGLXDestroyGLXPixmapReq *req;
CARD8 opcode;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
LockDisplay(dpy);
GetReq(GLXDestroyGLXPixmap,req);
req->reqType = opcode;
req->glxCode = X_GLXDestroyGLXPixmap;
req->glxpixmap = glxpixmap;
UnlockDisplay(dpy);
SyncHandle();
}
void GLX_PREFIX(glXSwapBuffers)(Display *dpy, GLXDrawable drawable)
{
xGLXSwapBuffersReq *req;
GLXContext gc;
GLXContextTag tag;
CARD8 opcode;
#ifdef GLX_DIRECT_RENDERING
__DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL );
if ( pdraw != NULL ) {
(*pdraw->swapBuffers)(dpy, pdraw->private);
return;
}
#endif
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return;
}
gc = __glXGetCurrentContext();
if ((gc != NULL) && (dpy == gc->currentDpy) &&
((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {
tag = gc->currentContextTag;
} else {
tag = 0;
}
LockDisplay(dpy);
GetReq(GLXSwapBuffers,req);
req->reqType = opcode;
req->glxCode = X_GLXSwapBuffers;
req->drawable = drawable;
req->contextTag = tag;
UnlockDisplay(dpy);
SyncHandle();
XFlush(dpy);
}
int GLX_PREFIX(glXGetConfig)(Display *dpy, XVisualInfo *vis, int attribute,
int *value_return)
{
__GLXdisplayPrivate *priv;
__GLXscreenConfigs *psc;
int status;
status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc );
if ( status == Success ) {
unsigned i;
for ( i = 0 ; i < psc->numConfigs ; i++ ) {
if (psc->configs[i].visualID == vis->visualid) {
return _gl_get_context_mode_data( & psc->configs[i],
attribute,
value_return );
}
}
status = GLX_BAD_VISUAL;
}
if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {
*value_return = GL_FALSE;
status = Success;
}
return status;
}
#define MATCH_DONT_CARE( param ) \
do { \
if ( (a-> param != GLX_DONT_CARE) \
&& (a-> param != b-> param) ) { \
return False; \
} \
} while ( 0 )
#define MATCH_MINIMUM( param ) \
do { \
if ( (a-> param != GLX_DONT_CARE) \
&& (a-> param > b-> param) ) { \
return False; \
} \
} while ( 0 )
#define MATCH_EXACT( param ) \
do { \
if ( a-> param != b-> param) { \
return False; \
} \
} while ( 0 )
static Bool
fbconfigs_compatible( const __GLcontextModes * const a,
const __GLcontextModes * const b )
{
MATCH_DONT_CARE( doubleBufferMode );
MATCH_DONT_CARE( visualType );
MATCH_DONT_CARE( visualRating );
MATCH_DONT_CARE( xRenderable );
MATCH_DONT_CARE( fbconfigID );
MATCH_DONT_CARE( swapMethod );
MATCH_MINIMUM( rgbBits );
MATCH_MINIMUM( numAuxBuffers );
MATCH_MINIMUM( redBits );
MATCH_MINIMUM( greenBits );
MATCH_MINIMUM( blueBits );
MATCH_MINIMUM( alphaBits );
MATCH_MINIMUM( depthBits );
MATCH_MINIMUM( stencilBits );
MATCH_MINIMUM( accumRedBits );
MATCH_MINIMUM( accumGreenBits );
MATCH_MINIMUM( accumBlueBits );
MATCH_MINIMUM( accumAlphaBits );
MATCH_MINIMUM( sampleBuffers );
MATCH_MINIMUM( maxPbufferWidth );
MATCH_MINIMUM( maxPbufferHeight );
MATCH_MINIMUM( maxPbufferPixels );
MATCH_MINIMUM( samples );
MATCH_DONT_CARE( stereoMode );
MATCH_EXACT( level );
if ( ((a->drawableType & b->drawableType) == 0)
|| ((a->renderType & b->renderType) == 0) ) {
return False;
}
if ( a->transparentPixel != GLX_DONT_CARE
&& a->transparentPixel != 0 ) {
if ( a->transparentPixel == GLX_NONE ) {
if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 )
return False;
} else {
MATCH_EXACT( transparentPixel );
}
switch ( a->transparentPixel ) {
case GLX_TRANSPARENT_RGB:
MATCH_DONT_CARE( transparentRed );
MATCH_DONT_CARE( transparentGreen );
MATCH_DONT_CARE( transparentBlue );
MATCH_DONT_CARE( transparentAlpha );
break;
case GLX_TRANSPARENT_INDEX:
MATCH_DONT_CARE( transparentIndex );
break;
default:
break;
}
}
return True;
}
#define PREFER_LARGER(comp) \
do { \
if ( ((*a)-> comp) != ((*b)-> comp) ) { \
return ((*b)-> comp) - ((*a)-> comp) ; \
} \
} while( 0 )
#define PREFER_SMALLER(comp) \
do { \
if ( ((*a)-> comp) != ((*b)-> comp) ) { \
return ((*a)-> comp) - ((*b)-> comp) ; \
} \
} while( 0 )
static int
fbconfig_compare( const __GLcontextModes * const * const a,
const __GLcontextModes * const * const b )
{
PREFER_SMALLER( visualSelectGroup );
PREFER_SMALLER( visualRating );
PREFER_SMALLER( rgbBits );
if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) {
return ( !(*a)->doubleBufferMode ) ? -1 : 1;
}
PREFER_SMALLER( numAuxBuffers );
PREFER_LARGER( redBits );
PREFER_LARGER( greenBits );
PREFER_LARGER( blueBits );
PREFER_LARGER( alphaBits );
PREFER_LARGER( stencilBits );
PREFER_LARGER( accumRedBits );
PREFER_LARGER( accumGreenBits );
PREFER_LARGER( accumBlueBits );
PREFER_LARGER( accumAlphaBits );
PREFER_SMALLER( sampleBuffers );
PREFER_SMALLER( samples );
PREFER_LARGER( maxPbufferWidth );
PREFER_LARGER( maxPbufferHeight );
PREFER_LARGER( maxPbufferPixels );
PREFER_LARGER( drawableType );
PREFER_LARGER( renderType );
return 0;
}
static int
choose_visual( __GLcontextModes ** configs, int num_configs,
const int *attribList, GLboolean fbconfig_style_tags )
{
__GLcontextModes test_config;
int base;
int i;
__glXInitializeVisualConfigFromTags( & test_config, 512,
(const INT32 *) attribList,
GL_TRUE, fbconfig_style_tags );
base = 0;
for ( i = 0 ; i < num_configs ; i++ ) {
if ( fbconfigs_compatible( & test_config, configs[i] ) ) {
configs[ base ] = configs[ i ];
base++;
}
}
if ( base == 0 ) {
return 0;
}
if ( base < num_configs ) {
(void) memset( & configs[ base ], 0,
sizeof( void * ) * (num_configs - base) );
}
qsort( configs, base, sizeof( __GLcontextModes * ),
(int (*)(const void*, const void*)) fbconfig_compare );
return base;
}
XVisualInfo *GLX_PREFIX(glXChooseVisual)(Display *dpy, int screen, int *attribList)
{
XVisualInfo visualTemplate;
XVisualInfo *visualList;
__GLXdisplayPrivate *priv;
__GLXscreenConfigs *psc;
__GLcontextModes test_config;
const __GLcontextModes *best_config = NULL;
int i;
if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
return None;
}
__glXInitializeVisualConfigFromTags( & test_config, 512,
(const INT32 *) attribList,
GL_TRUE, GL_FALSE );
for (i = 0; i < psc->numConfigs; i++) {
if ( fbconfigs_compatible( & test_config, &psc->configs[i] ) ) {
const __GLcontextModes * const temp = &psc->configs[i];
if ( (best_config == None)
|| (fbconfig_compare( &temp, &best_config ) > 0) ) {
best_config = &psc->configs[i];
}
}
}
visualList = NULL;
if (best_config != NULL) {
visualTemplate.screen = screen;
visualTemplate.visualid = best_config->visualID;
visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask,
&visualTemplate, &i );
}
return visualList;
}
char *__glXInternalQueryServerString( Display *dpy, int opcode,
int screen, int name )
{
xGLXQueryServerStringReq *req;
xGLXQueryServerStringReply reply;
int length, numbytes, slop;
char *buf;
LockDisplay(dpy);
GetReq(GLXQueryServerString,req);
req->reqType = opcode;
req->glxCode = X_GLXQueryServerString;
req->screen = screen;
req->name = name;
_XReply(dpy, (xReply*) &reply, 0, False);
length = reply.length;
numbytes = reply.n;
slop = numbytes * __GLX_SIZE_INT8 & 3;
buf = (char *)Xmalloc(numbytes);
if (!buf) {
_XEatData(dpy, length);
} else {
_XRead(dpy, (char *)buf, numbytes);
if (slop) _XEatData(dpy,4-slop);
}
UnlockDisplay(dpy);
SyncHandle();
return buf;
}
#define SEPARATOR " "
char *__glXCombineExtensionStrings( const char *cext_string, const char *sext_string )
{
int clen, slen;
char *combo_string, *token, *s1;
const char *s2, *end;
if ( (clen = strlen( cext_string)) > (slen = strlen( sext_string)) ) {
combo_string = (char *) Xmalloc( slen + 2 );
s1 = (char *) Xmalloc( slen + 2 ); strcpy( s1, sext_string );
s2 = cext_string;
} else {
combo_string = (char *) Xmalloc( clen + 2 );
s1 = (char *) Xmalloc( clen + 2 ); strcpy( s1, cext_string);
s2 = sext_string;
}
if (!combo_string || !s1) {
if (combo_string) Xfree(combo_string);
if (s1) Xfree(s1);
return NULL;
}
combo_string[0] = '\0';
token = strtok( s1, SEPARATOR);
while ( token != NULL ) {
const char *p = s2;
end = p + strlen(p);
while (p < end) {
int n = strcspn(p, SEPARATOR);
if ((strlen(token) == n) && (strncmp(token, p, n) == 0)) {
combo_string = strcat( combo_string, token);
combo_string = strcat( combo_string, SEPARATOR);
}
p += (n + 1);
}
token = strtok( NULL, SEPARATOR);
}
Xfree(s1);
return combo_string;
}
const char *GLX_PREFIX(glXQueryExtensionsString)( Display *dpy, int screen )
{
__GLXscreenConfigs *psc;
__GLXdisplayPrivate *priv;
if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
return NULL;
}
if (!psc->effectiveGLXexts) {
if (!psc->serverGLXexts) {
psc->serverGLXexts = __glXInternalQueryServerString(dpy, priv->majorOpcode,
screen, GLX_EXTENSIONS);
}
__glXCalculateUsableExtensions(psc,
#ifdef GLX_DIRECT_RENDERING
(priv->driDisplay.private != NULL),
#else
GL_FALSE,
#endif
priv->minorVersion);
}
return psc->effectiveGLXexts;
}
const char *GLX_PREFIX(glXGetClientString)( Display *dpy, int name )
{
switch(name) {
case GLX_VENDOR:
return (__glXGLXClientVendorName);
case GLX_VERSION:
return (__glXGLXClientVersion);
case GLX_EXTENSIONS:
return (__glXGetClientExtensions());
default:
return NULL;
}
}
const char *GLX_PREFIX(glXQueryServerString)( Display *dpy, int screen, int name )
{
__GLXscreenConfigs *psc;
__GLXdisplayPrivate *priv;
if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
return NULL;
}
switch(name) {
case GLX_VENDOR:
if (!priv->serverGLXvendor) {
priv->serverGLXvendor =
__glXInternalQueryServerString(dpy, priv->majorOpcode,
screen, GLX_VENDOR);
}
return(priv->serverGLXvendor);
case GLX_VERSION:
if (!priv->serverGLXversion) {
priv->serverGLXversion =
__glXInternalQueryServerString(dpy, priv->majorOpcode,
screen, GLX_VERSION);
}
return(priv->serverGLXversion);
case GLX_EXTENSIONS:
if (!psc->serverGLXexts) {
psc->serverGLXexts =
__glXInternalQueryServerString(dpy, priv->majorOpcode,
screen, GLX_EXTENSIONS);
}
return(psc->serverGLXexts);
default:
return NULL;
}
}
void __glXClientInfo ( Display *dpy, int opcode )
{
xGLXClientInfoReq *req;
int size;
LockDisplay(dpy);
GetReq(GLXClientInfo,req);
req->reqType = opcode;
req->glxCode = X_GLXClientInfo;
req->major = GLX_MAJOR_VERSION;
req->minor = GLX_MINOR_VERSION;
size = strlen(__glXGLClientExtensions) + 1;
req->length += (size + 3) >> 2;
req->numbytes = size;
Data(dpy, __glXGLClientExtensions, size);
UnlockDisplay(dpy);
SyncHandle();
}
Display *glXGetCurrentDisplay(void)
{
GLXContext gc = __glXGetCurrentContext();
if (NULL == gc) return NULL;
return gc->currentDpy;
}
GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
glXGetCurrentDisplay)
static int __glXQueryContextInfo(Display *dpy, GLXContext ctx)
{
xGLXVendorPrivateReq *vpreq;
xGLXQueryContextInfoEXTReq *req;
xGLXQueryContextInfoEXTReply reply;
CARD8 opcode;
GLuint numValues;
int retval;
if (ctx == NULL) {
return GLX_BAD_CONTEXT;
}
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return 0;
}
LockDisplay(dpy);
GetReqExtra(GLXVendorPrivate,
sz_xGLXQueryContextInfoEXTReq-sz_xGLXVendorPrivateReq,vpreq);
req = (xGLXQueryContextInfoEXTReq *)vpreq;
req->reqType = opcode;
req->glxCode = X_GLXVendorPrivateWithReply;
req->vendorCode = X_GLXvop_QueryContextInfoEXT;
req->context = (unsigned int)(ctx->xid);
_XReply(dpy, (xReply*) &reply, 0, False);
numValues = reply.n;
if (numValues == 0)
retval = Success;
else if (numValues > __GLX_MAX_CONTEXT_PROPS)
retval = 0;
else
{
int *propList, *pProp;
int nPropListBytes;
int i;
nPropListBytes = numValues << 3;
propList = (int *) Xmalloc(nPropListBytes);
if (NULL == propList) {
retval = 0;
} else {
_XRead(dpy, (char *)propList, nPropListBytes);
pProp = propList;
for (i=0; i < numValues; i++) {
switch (*pProp++) {
case GLX_SHARE_CONTEXT_EXT:
ctx->share_xid = *pProp++;
break;
case GLX_VISUAL_ID_EXT:
ctx->vid = *pProp++;
break;
case GLX_SCREEN_EXT:
ctx->screen = *pProp++;
break;
case GLX_FBCONFIG_ID_SGIX:
ctx->fbconfigID = *pProp++;
break;
default:
pProp++;
continue;
}
}
Xfree((char *)propList);
retval = Success;
}
}
UnlockDisplay(dpy);
SyncHandle();
return retval;
}
int GLX_PREFIX(glXQueryContextInfoEXT)(Display *dpy, GLXContext ctx,
int attribute, int *value)
{
int retVal;
if (!ctx->isDirect && (ctx->vid == None)) {
retVal = __glXQueryContextInfo(dpy, ctx);
if (Success != retVal) return retVal;
}
switch (attribute) {
case GLX_SHARE_CONTEXT_EXT:
*value = (int)(ctx->share_xid);
break;
case GLX_VISUAL_ID_EXT:
*value = (int)(ctx->vid);
break;
case GLX_SCREEN_EXT:
*value = (int)(ctx->screen);
break;
case GLX_FBCONFIG_ID_SGIX:
*value = (int)(ctx->fbconfigID);
break;
default:
return GLX_BAD_ATTRIBUTE;
}
return Success;
}
GLXContextID glXGetContextIDEXT(const GLXContext ctx)
{
return ctx->xid;
}
GLXContext GLX_PREFIX(glXImportContextEXT)(Display *dpy, GLXContextID contextID)
{
GLXContext ctx;
if (contextID == None) {
return NULL;
}
if (__glXIsDirect(dpy, contextID)) {
return NULL;
}
ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
if (NULL != ctx) {
if (Success != __glXQueryContextInfo(dpy, ctx)) {
return NULL;
}
}
return ctx;
}
void GLX_PREFIX(glXFreeContextEXT)(Display *dpy, GLXContext ctx)
{
DestroyContext(dpy, ctx);
}
GLXFBConfig *GLX_PREFIX(glXChooseFBConfig)(Display *dpy, int screen, const int *attribList, int *nitems)
{
__GLcontextModes ** config_list;
int list_size;
config_list = (__GLcontextModes **)
GLX_PREFIX(glXGetFBConfigs)( dpy, screen, & list_size );
if ( (config_list != NULL) && (list_size > 0) ) {
list_size = choose_visual( config_list, list_size, attribList,
GL_TRUE );
if ( list_size == 0 ) {
XFree( config_list );
config_list = NULL;
}
}
*nitems = list_size;
return (GLXFBConfig *) config_list;
}
GLXContext GLX_PREFIX(glXCreateNewContext)(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool allowDirect)
{
return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
allowDirect, None, True, renderType );
}
GLXPbuffer GLX_PREFIX(glXCreatePbuffer)(Display *dpy, GLXFBConfig config, const int *attribList)
{
(void) dpy;
(void) config;
(void) attribList;
return 0;
}
GLXPixmap GLX_PREFIX(glXCreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList)
{
(void) dpy;
(void) config;
(void) pixmap;
(void) attribList;
return 0;
}
GLXWindow GLX_PREFIX(glXCreateWindow)(Display *dpy, GLXFBConfig config, Window win, const int *attribList)
{
(void) dpy;
(void) config;
(void) win;
(void) attribList;
return 0;
}
void GLX_PREFIX(glXDestroyPbuffer)(Display *dpy, GLXPbuffer pbuf)
{
(void) dpy;
(void) pbuf;
}
void GLX_PREFIX(glXDestroyPixmap)(Display *dpy, GLXPixmap pixmap)
{
(void) dpy;
(void) pixmap;
}
void GLX_PREFIX(glXDestroyWindow)(Display *dpy, GLXWindow window)
{
(void) dpy;
(void) window;
}
GLXDrawable GLX_PREFIX(glXGetCurrentReadDrawable)(void)
{
GLXContext gc = __glXGetCurrentContext();
return gc->currentReadable;
}
GLXFBConfig *GLX_PREFIX(glXGetFBConfigs)(Display *dpy, int screen, int *nelements)
{
__GLXdisplayPrivate *priv = __glXInitialize(dpy);
__GLcontextModes ** config = NULL;
int i;
if ( (priv->screenConfigs != NULL)
&& (screen >= 0) && (screen <= ScreenCount(dpy))
&& (priv->screenConfigs[screen].numConfigs > 0)
&& (priv->screenConfigs[screen].configs->fbconfigID != ((XID)-1)) ) {
config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *)
* priv->screenConfigs[screen].numConfigs );
if ( config != NULL ) {
*nelements = priv->screenConfigs[screen].numConfigs;
for ( i = 0 ; i < *nelements ; i++ ) {
config[i] = & priv->screenConfigs[screen].configs[i];
}
}
}
return (GLXFBConfig *) config;
}
int GLX_PREFIX(glXGetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value)
{
__GLXdisplayPrivate *priv = __glXInitialize(dpy);
__GLcontextModes * fbconfig = (__GLcontextModes *) config;
const int screen_count = ScreenCount(dpy);
int i;
if ( priv->screenConfigs != NULL ) {
for ( i = 0 ; i < screen_count ; i++ ) {
const int numConfigs = priv->screenConfigs[i].numConfigs;
if ( ( numConfigs > 0)
&& (priv->screenConfigs[i].configs->fbconfigID != ((XID)-1))
&& (fbconfig >= & priv->screenConfigs[i].configs[0])
&& (fbconfig < & priv->screenConfigs[i].configs[numConfigs]) ) {
return _gl_get_context_mode_data(fbconfig, attribute, value);
}
}
}
return GLXBadFBConfig;
}
void GLX_PREFIX(glXGetSelectedEvent)(Display *dpy, GLXDrawable drawable, unsigned long *mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
XVisualInfo *GLX_PREFIX(glXGetVisualFromFBConfig)(Display *dpy, GLXFBConfig config)
{
XVisualInfo visualTemplate;
__GLcontextModes * fbconfig = (__GLcontextModes *) config;
int count;
visualTemplate.visualid = fbconfig->visualID;
return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count);
}
int GLX_PREFIX(glXQueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value)
{
(void) dpy;
(void) ctx;
(void) attribute;
(void) value;
return 0;
}
void GLX_PREFIX(glXQueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
{
(void) dpy;
(void) draw;
(void) attribute;
(void) value;
}
void GLX_PREFIX(glXSelectEvent)(Display *dpy, GLXDrawable drawable, unsigned long mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
GLX_ALIAS(GLXDrawable, glXGetCurrentReadDrawableSGI, (void), (),
glXGetCurrentReadDrawable)
int GLX_PREFIX(glXSwapIntervalSGI)(int interval)
{
xGLXVendorPrivateReq *req;
GLXContext gc = __glXGetCurrentContext();
Display * dpy;
CARD32 * interval_ptr;
CARD8 opcode;
if ( gc == NULL ) {
return GLX_BAD_CONTEXT;
}
if ( interval <= 0 ) {
return GLX_BAD_VALUE;
}
#ifdef GLX_DIRECT_RENDERING
if ( gc->isDirect ) {
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
gc->screen );
__DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy,
gc->currentDrawable,
NULL );
if ( __glXExtensionBitIsEnabled( psc, SGI_swap_control_bit )
&& (pdraw != NULL) ) {
pdraw->swap_interval = interval;
return 0;
}
else {
return GLX_BAD_CONTEXT;
}
}
#endif
dpy = gc->currentDpy;
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return 0;
}
LockDisplay(dpy);
GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req);
req->reqType = opcode;
req->glxCode = X_GLXVendorPrivate;
req->vendorCode = X_GLXvop_SwapIntervalSGI;
req->contextTag = gc->currentContextTag;
interval_ptr = (CARD32 *) req + 1;
*interval_ptr = interval;
UnlockDisplay(dpy);
SyncHandle();
XFlush(dpy);
return 0;
}
GLint GLX_PREFIX(glXSwapIntervalMESA)(unsigned interval)
{
#ifdef GLX_DIRECT_RENDERING
GLXContext gc = __glXGetCurrentContext();
if ( interval < 0 ) {
return GLX_BAD_VALUE;
}
if ( (gc != NULL) && gc->isDirect ) {
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
gc->screen );
if ( (psc != NULL) && (psc->driScreen.private != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_control_bit ) ) {
__DRIdrawable * const pdraw =
(*psc->driScreen.getDrawable)(gc->currentDpy,
gc->currentDrawable,
psc->driScreen.private);
if ( pdraw != NULL ) {
pdraw->swap_interval = interval;
return 0;
}
}
}
#else
(void) interval;
#endif
return GLX_BAD_CONTEXT;
}
GLint GLX_PREFIX(glXGetSwapIntervalMESA)( void )
{
#ifdef GLX_DIRECT_RENDERING
GLXContext gc = __glXGetCurrentContext();
if ( (gc != NULL) && gc->isDirect ) {
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
gc->screen );
if ( (psc != NULL) && (psc->driScreen.private != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_control_bit ) ) {
__DRIdrawable * const pdraw =
(*psc->driScreen.getDrawable)(gc->currentDpy,
gc->currentDrawable,
psc->driScreen.private);
if ( pdraw != NULL ) {
return pdraw->swap_interval;
}
}
}
#endif
return 0;
}
GLint GLX_PREFIX(glXBeginFrameTrackingMESA)(Display *dpy, GLXDrawable drawable)
{
int status = GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
__GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
status = pdraw->frameTracking( dpy, pdraw->private, GL_TRUE );
}
#else
(void) dpy;
(void) drawable;
#endif
return status;
}
GLint GLX_PREFIX(glXEndFrameTrackingMESA)(Display *dpy, GLXDrawable drawable)
{
int status = GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
__GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
if ( (pdraw != NULL) && (pdraw->frameTracking != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
status = pdraw->frameTracking( dpy, pdraw->private, GL_FALSE );
}
#else
(void) dpy;
(void) drawable;
#endif
return status;
}
GLint GLX_PREFIX(glXGetFrameUsageMESA)(Display *dpy, GLXDrawable drawable,
GLfloat *usage)
{
int status = GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
__GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
int64_t sbc, missedFrames;
float lastMissedUsage;
status = pdraw->queryFrameTracking( dpy, pdraw->private, &sbc,
&missedFrames, &lastMissedUsage,
usage );
}
#else
(void) dpy;
(void) drawable;
(void) usage;
#endif
return status;
}
GLint GLX_PREFIX(glXQueryFrameTrackingMESA)(Display *dpy, GLXDrawable drawable,
int64_t *sbc, int64_t *missedFrames,
GLfloat *lastMissedUsage)
{
int status = GLX_BAD_CONTEXT;
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
__GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
if ( (pdraw != NULL ) && (pdraw->queryFrameTracking != NULL)
&& __glXExtensionBitIsEnabled( psc, MESA_swap_frame_usage_bit ) ) {
float usage;
status = pdraw->queryFrameTracking( dpy, pdraw->private, sbc,
missedFrames, lastMissedUsage,
& usage );
}
#else
(void) dpy;
(void) drawable;
(void) sbc;
(void) missedFrames;
(void) lastMissedUsage;
#endif
return status;
}
int GLX_PREFIX(glXGetVideoSyncSGI)(unsigned int *count)
{
#ifdef GLX_DIRECT_RENDERING
GLXContext gc = __glXGetCurrentContext();
if ( (gc != NULL) && gc->isDirect ) {
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
gc->screen );
if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
&& psc->driScreen.private && psc->driScreen.getMSC) {
int ret;
int64_t temp;
ret = psc->driScreen.getMSC( psc->driScreen.private, & temp );
*count = (unsigned) temp;
return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
}
}
#else
(void) count;
#endif
return GLX_BAD_CONTEXT;
}
int GLX_PREFIX(glXWaitVideoSyncSGI)(int divisor, int remainder, unsigned int *count)
{
#ifdef GLX_DIRECT_RENDERING
GLXContext gc = __glXGetCurrentContext();
if ( divisor <= 0 || remainder < 0 )
return GLX_BAD_VALUE;
if ( (gc != NULL) && gc->isDirect ) {
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
gc->screen );
if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
&& psc->driScreen.private ) {
__DRIdrawable * const pdraw =
(*psc->driScreen.getDrawable)(gc->currentDpy,
gc->currentDrawable,
psc->driScreen.private);
if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL) ) {
int ret;
int64_t msc;
int64_t sbc;
ret = (*pdraw->waitForMSC)( gc->currentDpy, pdraw->private,
0, divisor, remainder,
& msc, & sbc );
*count = (unsigned) msc;
return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
}
}
}
#else
(void) count;
#endif
return GLX_BAD_CONTEXT;
}
#if defined(_VL_H)
GLXVideoSourceSGIX GLX_PREFIX(glXCreateGLXVideoSourceSGIX)(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
{
(void) dpy;
(void) screen;
(void) server;
(void) path;
(void) nodeClass;
(void) drainNode;
return 0;
}
void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX)(Display *dpy, GLXVideoSourceSGIX src)
{
(void) dpy;
(void) src;
}
#endif
GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
(dpy, config, attribute, value),
glXGetFBConfigAttrib)
GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
(Display *dpy, int screen, int *attrib_list, int *nelements),
(dpy, screen, attrib_list, nelements),
glXChooseFBConfig)
GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
(Display * dpy, GLXFBConfigSGIX config),
(dpy, config),
glXGetVisualFromFBConfig)
GLXPixmap GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX)(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
{
xGLXVendorPrivateReq *vpreq;
xGLXCreateGLXPixmapWithConfigSGIXReq *req;
GLXPixmap xid = None;
CARD8 opcode;
const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
__GLXscreenConfigs * psc;
if ( (dpy == NULL) || (config == NULL) ) {
return None;
}
psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
if ( (psc != NULL)
&& __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
opcode = __glXSetupForCommand(dpy);
if (!opcode) {
return None;
}
LockDisplay(dpy);
GetReqExtra(GLXVendorPrivate,
sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateReq,vpreq);
req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
req->reqType = opcode;
req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
req->screen = fbconfig->screen;
req->fbconfig = fbconfig->fbconfigID;
req->pixmap = pixmap;
req->glxpixmap = xid = XAllocID(dpy);
UnlockDisplay(dpy);
SyncHandle();
}
return xid;
}
GLXContext GLX_PREFIX(glXCreateContextWithConfigSGIX)(Display *dpy, GLXFBConfigSGIX config, int renderType, GLXContext shareList, Bool allowDirect)
{
GLXContext gc = NULL;
const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
__GLXscreenConfigs * psc;
if ( (dpy == NULL) || (config == NULL) ) {
return None;
}
psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
if ( (psc != NULL)
&& __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
allowDirect, None, False, renderType );
}
return gc;
}
GLXFBConfigSGIX GLX_PREFIX(glXGetFBConfigFromVisualSGIX)(Display *dpy, XVisualInfo *vis)
{
__GLXdisplayPrivate *priv;
__GLXscreenConfigs *psc;
int i;
if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
&& __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
&& (psc->configs[0].fbconfigID != ((XID)-1)) ) {
for ( i = 0 ; i < psc->numConfigs ; i++ ) {
if ( psc->configs[i].visualID == vis->visualid ) {
return (GLXFBConfigSGIX) & (psc->configs[i]);
}
}
}
return NULL;
}
GLXPbufferSGIX GLX_PREFIX(glXCreateGLXPbufferSGIX)(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list)
{
(void) dpy;
(void) config;
(void) width;
(void) height;
(void) attrib_list;
return 0;
}
void GLX_PREFIX(glXDestroyGLXPbufferSGIX)(Display *dpy, GLXPbufferSGIX pbuf)
{
(void) dpy;
(void) pbuf;
}
int GLX_PREFIX(glXQueryGLXPbufferSGIX)(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
{
(void) dpy;
(void) pbuf;
(void) attribute;
(void) value;
return 0;
}
void GLX_PREFIX(glXSelectEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
void GLX_PREFIX(glXGetSelectedEventSGIX)(Display *dpy, GLXDrawable drawable, unsigned long *mask)
{
(void) dpy;
(void) drawable;
(void) mask;
}
void GLX_PREFIX(glXCushionSGI)(Display *dpy, Window win, float cushion)
{
(void) dpy;
(void) win;
(void) cushion;
}
int GLX_PREFIX(glXBindChannelToWindowSGIX)(Display *dpy, int screen, int channel , Window window)
{
(void) dpy;
(void) screen;
(void) channel;
(void) window;
return 0;
}
int GLX_PREFIX(glXChannelRectSGIX)(Display *dpy, int screen, int channel, int x, int y, int w, int h)
{
(void) dpy;
(void) screen;
(void) channel;
(void) x;
(void) y;
(void) w;
(void) h;
return 0;
}
int GLX_PREFIX(glXQueryChannelRectSGIX)(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
{
(void) dpy;
(void) screen;
(void) channel;
(void) x;
(void) y;
(void) w;
(void) h;
return 0;
}
int GLX_PREFIX(glXQueryChannelDeltasSGIX)(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
{
(void) dpy;
(void) screen;
(void) channel;
(void) dx;
(void) dy;
(void) dw;
(void) dh;
return 0;
}
int GLX_PREFIX(glXChannelRectSyncSGIX)(Display *dpy, int screen, int channel, GLenum synctype)
{
(void) dpy;
(void) screen;
(void) channel;
(void) synctype;
return 0;
}
#if defined(_DM_BUFFER_H_)
Bool GLX_PREFIX(glXAssociateDMPbufferSGIX)(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
{
(void) dpy;
(void) pbuffer;
(void) params;
(void) dmbuffer;
return False;
}
#endif
void GLX_PREFIX(glXJoinSwapGroupSGIX)(Display *dpy, GLXDrawable drawable, GLXDrawable member)
{
(void) dpy;
(void) drawable;
(void) member;
}
void GLX_PREFIX(glXBindSwapBarrierSGIX)(Display *dpy, GLXDrawable drawable, int barrier)
{
(void) dpy;
(void) drawable;
(void) barrier;
}
Bool GLX_PREFIX(glXQueryMaxSwapBarriersSGIX)(Display *dpy, int screen, int *max)
{
(void) dpy;
(void) screen;
(void) max;
return False;
}
Status GLX_PREFIX(glXGetTransparentIndexSUN)(Display *dpy, Window overlay, Window underlay, long *pTransparent)
{
(void) dpy;
(void) overlay;
(void) underlay;
(void) pTransparent;
return 0;
}
Bool GLX_PREFIX(glXGetSyncValuesOML)(Display *dpy, GLXDrawable drawable,
int64_t *ust, int64_t *msc, int64_t *sbc)
{
#ifdef GLX_DIRECT_RENDERING
__GLXdisplayPrivate * const priv = __glXInitialize(dpy);
if ( priv != NULL ) {
int i;
__DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i );
__GLXscreenConfigs * const psc = &priv->screenConfigs[i];
assert( (pdraw == NULL) || (i != -1) );
return ( (pdraw && pdraw->getSBC && psc->driScreen.getMSC)
&& __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )
&& ((*psc->driScreen.getMSC)( psc->driScreen.private, msc ) == 0)
&& ((*pdraw->getSBC)( dpy, psc->driScreen.private, sbc ) == 0)
&& (__glXGetUST( ust ) == 0) );
}
#else
(void) dpy;
(void) drawable;
(void) ust;
(void) msc;
(void) sbc;
#endif
return False;
}
Bool GLX_PREFIX(glXGetMscRateOML)(Display * dpy, GLXDrawable drawable,
int32_t * numerator, int32_t * denominator)
{
#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
__GLXdisplayPrivate * const priv = __glXInitialize(dpy);
if ( priv != NULL ) {
XF86VidModeModeLine mode_line;
int dot_clock;
int screen_num;
int i;
GetDRIDrawable( dpy, drawable, & screen_num );
if ( (screen_num != -1)
&& XF86VidModeQueryVersion( dpy, & i, & i )
&& XF86VidModeGetModeLine( dpy, screen_num, & dot_clock,
& mode_line ) ) {
unsigned n = dot_clock * 1000;
unsigned d = mode_line.vtotal * mode_line.htotal;
# define V_INTERLACE 0x010
# define V_DBLSCAN 0x020
if ( (mode_line.flags & V_INTERLACE) ) {
n *= 2;
}
else if ( (mode_line.flags & V_DBLSCAN) ) {
d *= 2;
}
if ( (n % d) == 0 ) {
n /= d;
d = 1;
}
else {
static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
for ( i = 0 ; f[i] != 0 ; i++ ) {
while ( ((n % f[i]) == 0) && ((d % f[i]) == 0) ) {
d /= f[i];
n /= f[i];
}
}
}
*numerator = n;
*denominator = d;
(void) drawable;
return True;
}
}
#else
(void) dpy;
(void) drawable;
(void) numerator;
(void) denominator;
#endif
return False;
}
int64_t GLX_PREFIX(glXSwapBuffersMscOML)(Display *dpy, GLXDrawable drawable,
int64_t target_msc,
int64_t divisor, int64_t remainder)
{
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
if ( divisor < 0 || remainder < 0 || target_msc < 0 )
return -1;
if ( divisor > 0 && remainder >= divisor )
return -1;
if ( (pdraw != NULL) && (pdraw->swapBuffersMSC != NULL)
&& __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
return (*pdraw->swapBuffersMSC)(dpy, pdraw->private, target_msc,
divisor, remainder);
}
#else
(void) dpy;
(void) drawable;
(void) target_msc;
(void) divisor;
(void) remainder;
#endif
return 0;
}
Bool GLX_PREFIX(glXWaitForMscOML)(Display * dpy, GLXDrawable drawable,
int64_t target_msc,
int64_t divisor, int64_t remainder,
int64_t *ust, int64_t *msc, int64_t *sbc)
{
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
int ret;
if ( divisor < 0 || remainder < 0 || target_msc < 0 )
return False;
if ( divisor > 0 && remainder >= divisor )
return False;
if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL)
&& __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
ret = (*pdraw->waitForMSC)( dpy, pdraw->private, target_msc,
divisor, remainder, msc, sbc );
return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
}
#else
(void) dpy;
(void) drawable;
(void) target_msc;
(void) divisor;
(void) remainder;
(void) ust;
(void) msc;
(void) sbc;
#endif
return False;
}
Bool GLX_PREFIX(glXWaitForSbcOML)(Display * dpy, GLXDrawable drawable,
int64_t target_sbc,
int64_t *ust, int64_t *msc, int64_t *sbc )
{
#ifdef GLX_DIRECT_RENDERING
int screen;
__DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
int ret;
if ( target_sbc < 0 )
return False;
if ( (pdraw != NULL) && (pdraw->waitForSBC != NULL)
&& __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )) {
ret = (*pdraw->waitForSBC)( dpy, pdraw->private, target_sbc, msc, sbc );
return( (ret == 0) && (__glXGetUST( ust ) == 0) );
}
#else
(void) dpy;
(void) drawable;
(void) target_sbc;
(void) ust;
(void) msc;
(void) sbc;
#endif
return False;
}
void *GLX_PREFIX(glXAllocateMemoryMESA)(Display *dpy, int scrn,
size_t size,
float readFreq,
float writeFreq,
float priority)
{
#ifdef GLX_DIRECT_RENDERING
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
if (psc && psc->driScreen.private && psc->driScreen.allocateMemory) {
return (*psc->driScreen.allocateMemory)( dpy, scrn, size,
readFreq, writeFreq,
priority );
}
}
#else
(void) dpy;
(void) scrn;
(void) size;
(void) readFreq;
(void) writeFreq;
(void) priority;
#endif
return NULL;
}
void GLX_PREFIX(glXFreeMemoryMESA)(Display *dpy, int scrn, void *pointer)
{
#ifdef GLX_DIRECT_RENDERING
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
if (psc && psc->driScreen.private && psc->driScreen.freeMemory) {
(*psc->driScreen.freeMemory)( dpy, scrn, pointer );
}
}
#else
(void) dpy;
(void) scrn;
(void) pointer;
#endif
}
GLuint GLX_PREFIX(glXGetMemoryOffsetMESA)( Display *dpy, int scrn,
const void *pointer )
{
#ifdef GLX_DIRECT_RENDERING
__GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
if ( __glXExtensionBitIsEnabled( psc, MESA_allocate_memory_bit ) ) {
if (psc && psc->driScreen.private && psc->driScreen.memoryOffset) {
return (*psc->driScreen.memoryOffset)( dpy, scrn, pointer );
}
}
#else
(void) dpy;
(void) scrn;
(void) pointer;
#endif
return ~0L;
}
Bool GLX_PREFIX(glXReleaseBuffersMESA)( Display *dpy, GLXDrawable d )
{
(void) dpy;
(void) d;
return False;
}
GLXPixmap GLX_PREFIX(glXCreateGLXPixmapMESA)( Display *dpy,
XVisualInfo *visual,
Pixmap pixmap, Colormap cmap )
{
(void) dpy;
(void) visual;
(void) pixmap;
(void) cmap;
return 0;
}
void GLX_PREFIX(glXCopySubBufferMESA)( Display *dpy, GLXDrawable drawable,
int x, int y, int width, int height )
{
(void) dpy;
(void) drawable;
(void) x;
(void) y;
(void) width;
(void) height;
}
Bool GLX_PREFIX(glXSet3DfxModeMESA)( int mode )
{
(void) mode;
return GL_FALSE;
}
char *
__glXstrdup(const char *str)
{
char *copy;
copy = (char *) Xmalloc(strlen(str) + 1);
if (!copy)
return NULL;
strcpy(copy, str);
return copy;
}
struct name_address_pair {
const char *Name;
GLvoid *Address;
};
#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
static const struct name_address_pair GLX_functions[] = {
GLX_FUNCTION( glXChooseVisual ),
GLX_FUNCTION( glXCopyContext ),
GLX_FUNCTION( glXCreateContext ),
GLX_FUNCTION( glXCreateGLXPixmap ),
GLX_FUNCTION( glXDestroyContext ),
GLX_FUNCTION( glXDestroyGLXPixmap ),
GLX_FUNCTION( glXGetConfig ),
GLX_FUNCTION( glXGetCurrentContext ),
GLX_FUNCTION( glXGetCurrentDrawable ),
GLX_FUNCTION( glXIsDirect ),
GLX_FUNCTION( glXMakeCurrent ),
GLX_FUNCTION( glXQueryExtension ),
GLX_FUNCTION( glXQueryVersion ),
GLX_FUNCTION( glXSwapBuffers ),
GLX_FUNCTION( glXUseXFont ),
GLX_FUNCTION( glXWaitGL ),
GLX_FUNCTION( glXWaitX ),
GLX_FUNCTION( glXGetClientString ),
GLX_FUNCTION( glXQueryExtensionsString ),
GLX_FUNCTION( glXQueryServerString ),
GLX_FUNCTION( glXGetCurrentDisplay ),
GLX_FUNCTION( glXChooseFBConfig ),
GLX_FUNCTION( glXCreateNewContext ),
GLX_FUNCTION( glXCreatePbuffer ),
GLX_FUNCTION( glXCreatePixmap ),
GLX_FUNCTION( glXCreateWindow ),
GLX_FUNCTION( glXDestroyPbuffer ),
GLX_FUNCTION( glXDestroyPixmap ),
GLX_FUNCTION( glXDestroyWindow ),
GLX_FUNCTION( glXGetCurrentReadDrawable ),
GLX_FUNCTION( glXGetFBConfigAttrib ),
GLX_FUNCTION( glXGetFBConfigs ),
GLX_FUNCTION( glXGetSelectedEvent ),
GLX_FUNCTION( glXGetVisualFromFBConfig ),
GLX_FUNCTION( glXMakeContextCurrent ),
GLX_FUNCTION( glXQueryContext ),
GLX_FUNCTION( glXQueryDrawable ),
GLX_FUNCTION( glXSelectEvent ),
GLX_FUNCTION( glXSwapIntervalSGI ),
GLX_FUNCTION( glXGetVideoSyncSGI ),
GLX_FUNCTION( glXWaitVideoSyncSGI ),
GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
#if defined(_VL_H)
GLX_FUNCTION( glXCreateGLXVideoSourceSGIX ),
GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX ),
#endif
GLX_FUNCTION( glXFreeContextEXT ),
GLX_FUNCTION( glXGetContextIDEXT ),
GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
GLX_FUNCTION( glXImportContextEXT ),
GLX_FUNCTION( glXQueryContextInfoEXT ),
GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
GLX_FUNCTION( glXSelectEventSGIX ),
GLX_FUNCTION( glXGetSelectedEventSGIX ),
GLX_FUNCTION( glXCushionSGI ),
GLX_FUNCTION( glXBindChannelToWindowSGIX ),
GLX_FUNCTION( glXChannelRectSGIX ),
GLX_FUNCTION( glXQueryChannelRectSGIX ),
GLX_FUNCTION( glXQueryChannelDeltasSGIX ),
GLX_FUNCTION( glXChannelRectSyncSGIX ),
#if defined(_DM_BUFFER_H_)
GLX_FUNCTION( glXAssociateDMPbufferSGIX ),
#endif
GLX_FUNCTION( glXJoinSwapGroupSGIX ),
GLX_FUNCTION( glXBindSwapBarrierSGIX ),
GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX ),
GLX_FUNCTION( glXGetTransparentIndexSUN ),
GLX_FUNCTION( glXAllocateMemoryMESA ),
GLX_FUNCTION( glXFreeMemoryMESA ),
GLX_FUNCTION( glXGetMemoryOffsetMESA ),
GLX_FUNCTION( glXCopySubBufferMESA ),
GLX_FUNCTION( glXCreateGLXPixmapMESA ),
GLX_FUNCTION( glXReleaseBuffersMESA ),
GLX_FUNCTION( glXSet3DfxModeMESA ),
GLX_FUNCTION( glXSwapIntervalMESA ),
GLX_FUNCTION( glXGetSwapIntervalMESA ),
GLX_FUNCTION( glXBeginFrameTrackingMESA ),
GLX_FUNCTION( glXEndFrameTrackingMESA ),
GLX_FUNCTION( glXGetFrameUsageMESA ),
GLX_FUNCTION( glXQueryFrameTrackingMESA ),
GLX_FUNCTION( glXGetProcAddressARB ),
GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
GLX_FUNCTION( glXWaitForSbcOML ),
GLX_FUNCTION( glXWaitForMscOML ),
GLX_FUNCTION( glXSwapBuffersMscOML ),
GLX_FUNCTION( glXGetMscRateOML ),
GLX_FUNCTION( glXGetSyncValuesOML ),
#ifdef GLX_DIRECT_RENDERING
GLX_FUNCTION( __glXInitialize ),
GLX_FUNCTION( __glXFindDRIScreen ),
GLX_FUNCTION( __glXGetInternalVersion ),
GLX_FUNCTION( __glXWindowExists ),
#endif
GLX_FUNCTION( __glXScrEnableExtension ),
GLX_FUNCTION( __glXGetUST ),
{ NULL, NULL }
};
static const GLvoid *
get_glx_proc_address(const char *funcName)
{
GLuint i;
for (i = 0; GLX_functions[i].Name; i++) {
if (strcmp(GLX_functions[i].Name, funcName) == 0)
return GLX_functions[i].Address;
}
return NULL;
}
#ifndef GLX_BUILT_IN_XMESA
void (*glXGetProcAddressARB(const GLubyte *procName))( void )
{
typedef void (*gl_function)( void );
gl_function f;
f = (gl_function) get_glx_proc_address((const char *) procName);
if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
&& (procName[2] != 'X') ) {
f = (gl_function) _glapi_get_proc_address((const char *) procName);
}
return f;
}
void (*glXGetProcAddress(const GLubyte *procName))( void )
#if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
__attribute__ ((alias ("glXGetProcAddressARB")));
#else
{
return glXGetProcAddressARB(procName);
}
#endif
#endif
int __glXGetInternalVersion(void)
{
return 20030818;
}
static Bool windowExistsFlag;
static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
{
if (xerr->error_code == BadWindow) {
windowExistsFlag = GL_FALSE;
}
return 0;
}
Bool __glXWindowExists(Display *dpy, GLXDrawable draw)
{
XWindowAttributes xwa;
int (*oldXErrorHandler)(Display *, XErrorEvent *);
XSync(dpy, GL_FALSE);
windowExistsFlag = GL_TRUE;
oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
XGetWindowAttributes(dpy, draw, &xwa);
XSetErrorHandler(oldXErrorHandler);
return windowExistsFlag;
}
int __glXGetUST( int64_t * ust )
{
struct timeval tv;
if ( ust == NULL ) {
return -EFAULT;
}
if ( gettimeofday( & tv, NULL ) == 0 ) {
ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
return 0;
} else {
return -errno;
}
}