📄 glxext.c
字号:
memset(psc, 0, screens * sizeof(__GLXscreenConfigs)); priv->screenConfigs = psc; priv->serverGLXversion = __glXGetStringFromServer(dpy, priv->majorOpcode, X_GLXQueryServerString, 0, GLX_VERSION); if ( priv->serverGLXversion == NULL ) { FreeScreenConfigs(priv); return GL_FALSE; } if ( atof( priv->serverGLXversion ) >= 1.3 ) { supported_request = 1; } /* ** Now fetch each screens configs structures. If a screen supports ** GL (by returning a numVisuals > 0) then allocate memory for our ** config structure and then fill it in. */ for (i = 0; i < screens; i++, psc++) { if ( supported_request != 1 ) { psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode, X_GLXQueryServerString, i, GLX_EXTENSIONS); if ( strstr( psc->serverGLXexts, "GLX_SGIX_fbconfig" ) != NULL ) { supported_request = 2; } else { supported_request = 3; } } LockDisplay(dpy); switch( supported_request ) { case 1: GetReq(GLXGetFBConfigs,fb_req); fb_req->reqType = priv->majorOpcode; fb_req->glxCode = X_GLXGetFBConfigs; fb_req->screen = i; break; case 2: GetReqExtra(GLXVendorPrivateWithReply, sz_xGLXGetFBConfigsSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq); sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; sgi_req->reqType = priv->majorOpcode; sgi_req->glxCode = X_GLXVendorPrivateWithReply; sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; sgi_req->screen = i; break; case 3: GetReq(GLXGetVisualConfigs,req); req->reqType = priv->majorOpcode; req->glxCode = X_GLXGetVisualConfigs; req->screen = i; break; } if (!_XReply(dpy, (xReply*) &reply, 0, False)) { /* Something is busted. Punt. */ UnlockDisplay(dpy); FreeScreenConfigs(priv); return GL_FALSE; } UnlockDisplay(dpy); if (!reply.numVisuals) { /* This screen does not support GL rendering */ UnlockDisplay(dpy); continue; } /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for * FIXME: FBconfigs? */ /* Check number of properties */ nprops = reply.numProps; if ((nprops < __GLX_MIN_CONFIG_PROPS) || (nprops > __GLX_MAX_CONFIG_PROPS)) { /* Huh? Not in protocol defined limits. Punt */ UnlockDisplay(dpy); SyncHandle(); FreeScreenConfigs(priv); return GL_FALSE; } /* Allocate memory for our config structure */ psc->configs = _gl_context_modes_create(reply.numVisuals, sizeof(__GLcontextModes)); if (!psc->configs) { UnlockDisplay(dpy); SyncHandle(); FreeScreenConfigs(priv); return GL_FALSE; } /* Allocate memory for the properties, if needed */ if ( supported_request != 3 ) { nprops *= 2; } prop_size = nprops * __GLX_SIZE_INT32; if (prop_size <= sizeof(buf)) { props = buf; } else { props = (INT32 *) Xmalloc(prop_size); } /* Read each config structure and convert it into our format */ config = psc->configs; for (j = 0; j < reply.numVisuals; j++) { assert( config != NULL ); _XRead(dpy, (char *)props, prop_size); if ( supported_request != 3 ) { config->rgbMode = GL_TRUE; config->drawableType = GLX_WINDOW_BIT; } else { config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT; } __glXInitializeVisualConfigFromTags( config, nprops, props, (supported_request != 3), GL_TRUE ); if ( config->fbconfigID == GLX_DONT_CARE ) { config->fbconfigID = config->visualID; } config->screen = i; config = config->next; } if (props != buf) { Xfree((char *)props); } UnlockDisplay(dpy);#ifdef GLX_DIRECT_RENDERING /* Initialize per screen dynamic client GLX extensions */ psc->ext_list_first_time = GL_TRUE; /* Initialize the direct rendering per screen data and functions */ if (priv->driDisplay.private != NULL) { /* FIXME: Should it be some sort of an error if createNewScreen[i] * FIXME: is NULL? */ if (priv->driDisplay.createNewScreen && priv->driDisplay.createNewScreen[i]) { psc->driScreen.screenConfigs = (void *)psc; psc->driScreen.private = CallCreateNewScreen(dpy, i, & psc->driScreen, & priv->driDisplay, priv->driDisplay.createNewScreen[i] ); } }#endif } SyncHandle(); return GL_TRUE;}/*** Initialize the client side extension code.*/__GLXdisplayPrivate *__glXInitialize(Display* dpy){ XExtDisplayInfo *info = __glXFindDisplay(dpy); XExtData **privList, *private, *found; __GLXdisplayPrivate *dpyPriv; XEDataObject dataObj; int major, minor;#if defined(USE_XTHREADS) { static int firstCall = 1; if (firstCall) { /* initialize the GLX mutexes */ xmutex_init(&__glXmutex); firstCall = 0; } }#endif INIT_MESA_SPARC /* The one and only long long lock */ __glXLock(); if (!XextHasExtension(info)) { /* No GLX extension supported by this server. Oh well. */ __glXUnlock(); XMissingExtension(dpy, __glXExtensionName); return 0; } /* See if a display private already exists. If so, return it */ dataObj.display = dpy; privList = XEHeadOfExtensionList(dataObj); found = XFindOnExtensionList(privList, info->codes->extension); if (found) { __glXUnlock(); return (__GLXdisplayPrivate *) found->private_data; } /* See if the versions are compatible */ if (!QueryVersion(dpy, info->codes->major_opcode, &major, &minor)) { /* The client and server do not agree on versions. Punt. */ __glXUnlock(); return 0; } /* ** Allocate memory for all the pieces needed for this buffer. */ private = (XExtData *) Xmalloc(sizeof(XExtData)); if (!private) { __glXUnlock(); return 0; } dpyPriv = (__GLXdisplayPrivate *) Xmalloc(sizeof(__GLXdisplayPrivate)); if (!dpyPriv) { __glXUnlock(); Xfree((char*) private); return 0; } /* ** Init the display private and then read in the screen config ** structures from the server. */ dpyPriv->majorOpcode = info->codes->major_opcode; dpyPriv->majorVersion = major; dpyPriv->minorVersion = minor; dpyPriv->dpy = dpy; dpyPriv->serverGLXvendor = 0x0; dpyPriv->serverGLXversion = 0x0;#ifdef GLX_DIRECT_RENDERING /* ** Initialize the direct rendering per display data and functions. ** Note: This _must_ be done before calling any other DRI routines ** (e.g., those called in AllocAndFetchScreenConfigs). */ if (getenv("LIBGL_ALWAYS_INDIRECT")) { /* Assinging zero here assures we'll never go direct */ dpyPriv->driDisplay.private = 0; dpyPriv->driDisplay.destroyDisplay = 0; } else { dpyPriv->driDisplay.private = driCreateDisplay(dpy, &dpyPriv->driDisplay); }#endif if (!AllocAndFetchScreenConfigs(dpy, dpyPriv)) { __glXUnlock(); Xfree((char*) dpyPriv); Xfree((char*) private); return 0; } /* ** Fill in the private structure. This is the actual structure that ** hangs off of the Display structure. Our private structure is ** referred to by this structure. Got that? */ private->number = info->codes->extension; private->next = 0; private->free_private = __glXFreeDisplayPrivate; private->private_data = (char *) dpyPriv; XAddToExtensionList(privList, private); if (dpyPriv->majorVersion == 1 && dpyPriv->minorVersion >= 1) { __glXClientInfo(dpy, dpyPriv->majorOpcode); } __glXUnlock(); return dpyPriv;}/*** Setup for sending a GLX command on dpy. Make sure the extension is** initialized. Try to avoid calling __glXInitialize as its kinda slow.*/CARD8 __glXSetupForCommand(Display *dpy){ GLXContext gc; __GLXdisplayPrivate *priv; /* If this thread has a current context, flush its rendering commands */ gc = __glXGetCurrentContext(); if (gc->currentDpy) { /* Flush rendering buffer of the current context, if any */ (void) __glXFlushRenderBuffer(gc, gc->pc); if (gc->currentDpy == dpy) { /* Use opcode from gc because its right */ INIT_MESA_SPARC return gc->majorOpcode; } else { /* ** Have to get info about argument dpy because it might be to ** a different server */ } } /* Forced to lookup extension via the slow initialize route */ priv = __glXInitialize(dpy); if (!priv) { return 0; } return priv->majorOpcode;}/** * Flush the drawing command transport buffer. * * \param ctx Context whose transport buffer is to be flushed. * \param pc Pointer to first unused buffer location. * * \todo * Modify this function to use \c ctx->pc instead of the explicit * \c pc parameter. */GLubyte *__glXFlushRenderBuffer(__GLXcontext *ctx, GLubyte *pc){ Display * const dpy = ctx->currentDpy;#ifdef USE_XCB XCBConnection *c = XCBConnectionOfDisplay(dpy);#else xGLXRenderReq *req;#endif /* USE_XCB */ const GLint size = pc - ctx->buf; if ( (dpy != NULL) && (size > 0) ) {#ifdef USE_XCB XCBGlxRender(c, ctx->currentContextTag, size, (char *)ctx->buf);#else /* Send the entire buffer as an X request */ LockDisplay(dpy); GetReq(GLXRender,req); req->reqType = ctx->majorOpcode; req->glxCode = X_GLXRender; req->contextTag = ctx->currentContextTag; req->length += (size + 3) >> 2; _XSend(dpy, (char *)ctx->buf, size); UnlockDisplay(dpy); SyncHandle();#endif } /* Reset pointer and return it */ ctx->pc = ctx->buf; return ctx->pc;}/** * Send a portion of a GLXRenderLarge command to the server. The advantage of * this function over \c __glXSendLargeCommand is that callers can use the * data buffer in the GLX context and may be able to avoid allocating an * extra buffer. The disadvantage is the clients will have to do more * GLX protocol work (i.e., calculating \c totalRequests, etc.). * * \sa __glXSendLargeCommand * * \param gc GLX context * \param requestNumber Which part of the whole command is this? The first * request is 1. * \param totalRequests How many requests will there be? * \param data Command data. * \param dataLen Size, in bytes, of the command data. */void __glXSendLargeChunk(__GLXcontext *gc, GLint requestNumber, GLint totalRequests, const GLvoid * data, GLint dataLen){ Display *dpy = gc->currentDpy;#ifdef USE_XCB XCBConnection *c = XCBConnectionOfDisplay(dpy); XCBGlxRenderLarge(c, gc->currentContextTag, requestNumber, totalRequests, dataLen, data);#else xGLXRenderLargeReq *req; if ( requestNumber == 1 ) { LockDisplay(dpy); } GetReq(GLXRenderLarge,req); req->reqType = gc->majorOpcode; req->glxCode = X_GLXRenderLarge; req->contextTag = gc->currentContextTag; req->length += (dataLen + 3) >> 2; req->requestNumber = requestNumber; req->requestTotal = totalRequests; req->dataBytes = dataLen; Data(dpy, data, dataLen); if ( requestNumber == totalRequests ) { UnlockDisplay(dpy); SyncHandle(); }#endif /* USE_XCB */}/** * Send a command that is too large for the GLXRender protocol request. * * Send a large command, one that is too large for some reason to * send using the GLXRender protocol request. One reason to send * a large command is to avoid copying the data. * * \param ctx GLX context * \param header Header data. * \param headerLen Size, in bytes, of the header data. It is assumed that * the header data will always be small enough to fit in * a single X protocol packet. * \param data Command data. * \param dataLen Size, in bytes, of the command data. */void __glXSendLargeCommand(__GLXcontext *ctx, const GLvoid *header, GLint headerLen, const GLvoid *data, GLint dataLen){ GLint maxSize; GLint totalRequests, requestNumber; /* ** Calculate the maximum amount of data can be stuffed into a single ** packet. sz_xGLXRenderReq is added because bufSize is the maximum ** packet size minus sz_xGLXRenderReq. */ maxSize = (ctx->bufSize + sz_xGLXRenderReq) - sz_xGLXRenderLargeReq; totalRequests = 1 + (dataLen / maxSize); if (dataLen % maxSize) totalRequests++; /* ** Send all of the command, except the large array, as one request. */ assert( headerLen <= maxSize ); __glXSendLargeChunk(ctx, 1, totalRequests, header, headerLen); /* ** Send enough requests until the whole array is sent. */ for ( requestNumber = 2 ; requestNumber <= (totalRequests - 1) ; requestNumber++ ) { __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, maxSize); data = (const GLvoid *) (((const GLubyte *) data) + maxSize); dataLen -= maxSize; assert( dataLen > 0 ); } assert( dataLen <= maxSize ); __glXSendLargeChunk(ctx, requestNumber, totalRequests, data, dataLen);}/************************************************************************/GLXContext glXGetCurrentContext(void){ GLXContext cx = __glXGetCurrentContext();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -