glxcmds.c

来自「mesa-6.5-minigui源码」· C语言 代码 · 共 2,495 行 · 第 1/5 页

C
2,495
字号
    }}PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc){    DestroyContext(dpy, gc);}/*** Return the major and minor version #s for the GLX extension*/PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor){    __GLXdisplayPrivate *priv;    /* Init the extension.  This fetches the major and minor version. */    priv = __glXInitialize(dpy);    if (!priv) return GL_FALSE;    if (major) *major = priv->majorVersion;    if (minor) *minor = priv->minorVersion;    return GL_TRUE;}/*** Query the existance of the GLX extension*/PUBLIC Bool 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;}/*** Put a barrier in the token stream that forces the GL to finish its** work before X can proceed.*/PUBLIC void glXWaitGL(void){    xGLXWaitGLReq *req;    GLXContext gc = __glXGetCurrentContext();    Display *dpy = gc->currentDpy;    if (!dpy) return;    /* Flush any pending commands out */    __glXFlushRenderBuffer(gc, gc->pc);#ifdef GLX_DIRECT_RENDERING    if (gc->isDirect) {/* This bit of ugliness unwraps the glFinish function */#ifdef glFinish#undef glFinish#endif	glFinish();	return;    }#endif    /* Send the glXWaitGL request */    LockDisplay(dpy);    GetReq(GLXWaitGL,req);    req->reqType = gc->majorOpcode;    req->glxCode = X_GLXWaitGL;    req->contextTag = gc->currentContextTag;    UnlockDisplay(dpy);    SyncHandle();}/*** Put a barrier in the token stream that forces X to finish its** work before GL can proceed.*/PUBLIC void glXWaitX(void){    xGLXWaitXReq *req;    GLXContext gc = __glXGetCurrentContext();    Display *dpy = gc->currentDpy;    if (!dpy) return;    /* Flush any pending commands out */    __glXFlushRenderBuffer(gc, gc->pc);#ifdef GLX_DIRECT_RENDERING    if (gc->isDirect) {	XSync(dpy, False);	return;    }#endif    /*    ** Send the glXWaitX request.    */    LockDisplay(dpy);    GetReq(GLXWaitX,req);    req->reqType = gc->majorOpcode;    req->glxCode = X_GLXWaitX;    req->contextTag = gc->currentContextTag;    UnlockDisplay(dpy);    SyncHandle();}PUBLIC void glXUseXFont(Font font, int first, int count, int listBase){    xGLXUseXFontReq *req;    GLXContext gc = __glXGetCurrentContext();    Display *dpy = gc->currentDpy;    if (!dpy) return;    /* Flush any pending commands out */    (void) __glXFlushRenderBuffer(gc, gc->pc);#ifdef GLX_DIRECT_RENDERING    if (gc->isDirect) {      DRI_glXUseXFont(font, first, count, listBase);      return;    }#endif    /* Send the glXUseFont request */    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();}/************************************************************************//*** Copy the source context to the destination context using the** attribute "mask".*/PUBLIC void 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) {	/* NOT_DONE: This does not work yet */    }#endif    /*    ** If the source is the current context, send its tag so that the context    ** can be flushed before the copy.    */    if (source == gc && dpy == gc->currentDpy) {	tag = gc->currentContextTag;    } else {	tag = 0;    }    /* Send the glXCopyContext request */    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();}/** * Determine if a context uses direct rendering. * * \param dpy        Display where the context was created. * \param contextID  ID of the context to be tested. * * \returns \c GL_TRUE if the context is direct rendering or not. */static Bool __glXIsDirect(Display *dpy, GLXContextID contextID){    xGLXIsDirectReq *req;    xGLXIsDirectReply reply;    CARD8 opcode;    opcode = __glXSetupForCommand(dpy);    if (!opcode) {	return GL_FALSE;    }    /* Send the glXIsDirect request */    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;}/** * \todo * Shouldn't this function \b always return \c GL_FALSE when * \c GLX_DIRECT_RENDERING is not defined?  Do we really need to bother with * the GLX protocol here at all? */PUBLIC Bool 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);}PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis, 				    Pixmap pixmap){    xGLXCreateGLXPixmapReq *req;    GLXPixmap xid;    CARD8 opcode;    opcode = __glXSetupForCommand(dpy);    if (!opcode) {	return None;    }    /* Send the glXCreateGLXPixmap request */    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;}/*** Destroy the named pixmap*/PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap){    xGLXDestroyGLXPixmapReq *req;    CARD8 opcode;    opcode = __glXSetupForCommand(dpy);    if (!opcode) {	return;    }        /* Send the glXDestroyGLXPixmap request */    LockDisplay(dpy);    GetReq(GLXDestroyGLXPixmap,req);    req->reqType = opcode;    req->glxCode = X_GLXDestroyGLXPixmap;    req->glxpixmap = glxpixmap;    UnlockDisplay(dpy);    SyncHandle();}PUBLIC void 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;    }    /*    ** The calling thread may or may not have a current context.  If it    ** does, send the context tag so the server can do a flush.    */    gc = __glXGetCurrentContext();    if ((gc != NULL) && (dpy == gc->currentDpy) &&  	((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {	tag = gc->currentContextTag;    } else {	tag = 0;    }    /* Send the glXSwapBuffers request */    LockDisplay(dpy);    GetReq(GLXSwapBuffers,req);    req->reqType = opcode;    req->glxCode = X_GLXSwapBuffers;    req->drawable = drawable;    req->contextTag = tag;    UnlockDisplay(dpy);    SyncHandle();    XFlush(dpy);}/*** Return configuration information for the given display, screen and** visual combination.*/PUBLIC int 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 ) {	const __GLcontextModes * const modes = _gl_context_modes_find_visual(					     psc->configs, vis->visualid );	/* Lookup attribute after first finding a match on the visual */	if ( modes != NULL ) {	    return _gl_get_context_mode_data( modes, attribute, value_return );	}		status = GLX_BAD_VISUAL;    }    /*    ** If we can't find the config for this visual, this visual is not    ** supported by the OpenGL implementation on the server.    */    if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {	*value_return = GL_FALSE;	status = Success;    }    return status;}/************************************************************************/static voidinit_fbconfig_for_chooser( __GLcontextModes * config,			   GLboolean fbconfig_style_tags ){    memset( config, 0, sizeof( __GLcontextModes ) );    config->visualID = (XID) GLX_DONT_CARE;    config->visualType = GLX_DONT_CARE;    /* glXChooseFBConfig specifies different defaults for these two than     * glXChooseVisual.     */    if ( fbconfig_style_tags ) {	config->rgbMode = GL_TRUE;	config->doubleBufferMode = GLX_DONT_CARE;    }    config->visualRating = GLX_DONT_CARE;    config->transparentPixel = GLX_NONE;    config->transparentRed = GLX_DONT_CARE;    config->transparentGreen = GLX_DONT_CARE;    config->transparentBlue = GLX_DONT_CARE;    config->transparentAlpha = GLX_DONT_CARE;    config->transparentIndex = GLX_DONT_CARE;    config->drawableType = GLX_WINDOW_BIT;    config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;    config->xRenderable = GLX_DONT_CARE;    config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE);    config->swapMethod = GLX_DONT_CARE;}#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 )/** * Determine if two GLXFBConfigs are compatible. * * \param a  Application specified config to test. * \param b  Server specified config to test against \c a. */static Boolfbconfigs_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;    }    /* There is a bug in a few of the XFree86 DDX drivers.  They contain     * visuals with a "transparent type" of 0 when they really mean GLX_NONE.     * Technically speaking, it is a bug in the DDX driver, but there is     * enough of an installed base to work around the problem here.  In any     * case, 0 is not a valid value of the transparent type, so we'll treat 0      * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and     * 0 from the server to be a match to maintain backward compatibility with     * the (broken) drivers.     */    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;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?