📄 fakeglx.c
字号:
xmvis = choose_visual(dpy, screen, list, GL_FALSE); if (xmvis) {#if 0 return xmvis->vishandle;#else /* create a new vishandle - the cached one may be stale */ xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo)); if (xmvis->vishandle) { _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); } return xmvis->vishandle;#endif } else return NULL;}static GLXContextFake_glXCreateContext( Display *dpy, XVisualInfo *visinfo, GLXContext share_list, Bool direct ){ XMesaVisual xmvis; struct fake_glx_context *glxCtx; struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list; if (!dpy || !visinfo) return 0; glxCtx = CALLOC_STRUCT(fake_glx_context); if (!glxCtx) return 0; /* deallocate unused windows/buffers */#if 0 XMesaGarbageCollect();#endif xmvis = find_glx_visual( dpy, visinfo ); if (!xmvis) { /* This visual wasn't found with glXChooseVisual() */ xmvis = create_glx_visual( dpy, visinfo ); if (!xmvis) { /* unusable visual */ _mesa_free(glxCtx); return NULL; } } glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx ? shareCtx->xmesaContext : NULL); if (!glxCtx->xmesaContext) { _mesa_free(glxCtx); return NULL; } glxCtx->xmesaContext->direct = GL_FALSE; glxCtx->glxContext.isDirect = GL_FALSE; glxCtx->glxContext.currentDpy = dpy; glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */ assert((void *) glxCtx == (void *) &(glxCtx->glxContext)); return (GLXContext) glxCtx;}/* XXX these may have to be removed due to thread-safety issues. */static GLXContext MakeCurrent_PrevContext = 0;static GLXDrawable MakeCurrent_PrevDrawable = 0;static GLXDrawable MakeCurrent_PrevReadable = 0;static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;/* GLX 1.3 and later */static BoolFake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx ){ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; if (ctx && draw && read) { XMesaBuffer drawBuffer, readBuffer; XMesaContext xmctx = glxCtx->xmesaContext; /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */ if (ctx == MakeCurrent_PrevContext && draw == MakeCurrent_PrevDrawable) { drawBuffer = MakeCurrent_PrevDrawBuffer; } else { drawBuffer = XMesaFindBuffer( dpy, draw ); } if (!drawBuffer) { /* drawable must be a new window! */ drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw ); if (!drawBuffer) { /* Out of memory, or context/drawable depth mismatch */ return False; }#ifdef FX FXcreateContext( xmctx->xm_visual, draw, xmctx, drawBuffer );#endif } /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */ if (ctx == MakeCurrent_PrevContext && read == MakeCurrent_PrevReadable) { readBuffer = MakeCurrent_PrevReadBuffer; } else { readBuffer = XMesaFindBuffer( dpy, read ); } if (!readBuffer) { /* drawable must be a new window! */ readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read ); if (!readBuffer) { /* Out of memory, or context/drawable depth mismatch */ return False; }#ifdef FX FXcreateContext( xmctx->xm_visual, read, xmctx, readBuffer );#endif } MakeCurrent_PrevContext = ctx; MakeCurrent_PrevDrawable = draw; MakeCurrent_PrevReadable = read; MakeCurrent_PrevDrawBuffer = drawBuffer; MakeCurrent_PrevReadBuffer = readBuffer; /* Now make current! */ if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) { ((__GLXcontext *) ctx)->currentDpy = dpy; ((__GLXcontext *) ctx)->currentDrawable = draw; ((__GLXcontext *) ctx)->currentReadable = read; return True; } else { return False; } } else if (!ctx && !draw && !read) { /* release current context w/out assigning new one. */ XMesaMakeCurrent( NULL, NULL ); MakeCurrent_PrevContext = 0; MakeCurrent_PrevDrawable = 0; MakeCurrent_PrevReadable = 0; MakeCurrent_PrevDrawBuffer = 0; MakeCurrent_PrevReadBuffer = 0; return True; } else { /* The args must either all be non-zero or all zero. * This is an error. */ return False; }}static BoolFake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx ){ return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );}static GLXPixmapFake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap ){ XMesaVisual v; XMesaBuffer b; v = find_glx_visual( dpy, visinfo ); if (!v) { v = create_glx_visual( dpy, visinfo ); if (!v) { /* unusable visual */ return 0; } } b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); if (!b) { return 0; } return b->frontxrb->pixmap;}/*** GLX_MESA_pixmap_colormap ***/static GLXPixmapFake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap, Colormap cmap ){ XMesaVisual v; XMesaBuffer b; v = find_glx_visual( dpy, visinfo ); if (!v) { v = create_glx_visual( dpy, visinfo ); if (!v) { /* unusable visual */ return 0; } } b = XMesaCreatePixmapBuffer( v, pixmap, cmap ); if (!b) { return 0; } return b->frontxrb->pixmap;}static voidFake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ){ XMesaBuffer b = XMesaFindBuffer(dpy, pixmap); if (b) { XMesaDestroyBuffer(b); } else if (_mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n"); }}static voidFake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, unsigned long mask ){ struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src; struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst; XMesaContext xm_src = fakeSrc->xmesaContext; XMesaContext xm_dst = fakeDst->xmesaContext; (void) dpy; if (MakeCurrent_PrevContext == src) { _mesa_Flush(); } _mesa_copy_context( &(xm_src->mesa), &(xm_dst->mesa), (GLuint) mask );}static BoolFake_glXQueryExtension( Display *dpy, int *errorb, int *event ){ /* Mesa's GLX isn't really an X extension but we try to act like one. */ (void) dpy; (void) errorb; (void) event; return True;}extern void _kw_ungrab_all( Display *dpy );void _kw_ungrab_all( Display *dpy ){ XUngrabPointer( dpy, CurrentTime ); XUngrabKeyboard( dpy, CurrentTime );}static voidFake_glXDestroyContext( Display *dpy, GLXContext ctx ){ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; (void) dpy; MakeCurrent_PrevContext = 0; MakeCurrent_PrevDrawable = 0; MakeCurrent_PrevReadable = 0; MakeCurrent_PrevDrawBuffer = 0; MakeCurrent_PrevReadBuffer = 0; XMesaDestroyContext( glxCtx->xmesaContext ); XMesaGarbageCollect(); _mesa_free(glxCtx);}static BoolFake_glXIsDirect( Display *dpy, GLXContext ctx ){ struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx; (void) dpy; return glxCtx->xmesaContext->direct;}static voidFake_glXSwapBuffers( Display *dpy, GLXDrawable drawable ){ XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); if (buffer) { XMesaSwapBuffers(buffer); } else if (_mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n", (int) drawable); }}/*** GLX_MESA_copy_sub_buffer ***/static voidFake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, int x, int y, int width, int height ){ XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); if (buffer) { XMesaCopySubBuffer(buffer, x, y, width, height); } else if (_mesa_getenv("MESA_DEBUG")) { _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n"); }}static BoolFake_glXQueryVersion( Display *dpy, int *maj, int *min ){ (void) dpy; /* Return GLX version, not Mesa version */ assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION); *maj = CLIENT_MAJOR_VERSION; *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION ); return True;}/* * Query the GLX attributes of the given XVisualInfo. */static intget_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ){ ASSERT(xmvis); switch(attrib) { case GLX_USE_GL: if (fbconfig) return GLX_BAD_ATTRIBUTE; *value = (int) True; return 0; case GLX_BUFFER_SIZE: *value = xmvis->visinfo->depth; return 0; case GLX_LEVEL: *value = xmvis->mesa_visual.level; return 0; case GLX_RGBA: if (fbconfig) return GLX_BAD_ATTRIBUTE; if (xmvis->mesa_visual.rgbMode) { *value = True; } else { *value = False; } return 0; case GLX_DOUBLEBUFFER: *value = (int) xmvis->mesa_visual.doubleBufferMode; return 0; case GLX_STEREO: *value = (int) xmvis->mesa_visual.stereoMode; return 0; case GLX_AUX_BUFFERS: *value = xmvis->mesa_visual.numAuxBuffers; return 0; case GLX_RED_SIZE: *value = xmvis->mesa_visual.redBits; return 0; case GLX_GREEN_SIZE: *value = xmvis->mesa_visual.greenBits; return 0; case GLX_BLUE_SIZE: *value = xmvis->mesa_visual.blueBits; return 0; case GLX_ALPHA_SIZE: *value = xmvis->mesa_visual.alphaBits; return 0; case GLX_DEPTH_SIZE: *value = xmvis->mesa_visual.depthBits; return 0; case GLX_STENCIL_SIZE: *value = xmvis->mesa_visual.stencilBits; return 0; case GLX_ACCUM_RED_SIZE: *value = xmvis->mesa_visual.accumRedBits; return 0; case GLX_ACCUM_GREEN_SIZE: *value = xmvis->mesa_visual.accumGreenBits; return 0; case GLX_ACCUM_BLUE_SIZE: *value = xmvis->mesa_visual.accumBlueBits; return 0; case GLX_ACCUM_ALPHA_SIZE: *value = xmvis->mesa_visual.accumAlphaBits; return 0; /* * GLX_EXT_visual_info extension */ case GLX_X_VISUAL_TYPE_EXT: switch (xmvis->visinfo->CLASS) { case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0; case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0; case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0; case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0; case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0; case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0; } return 0; case GLX_TRANSPARENT_TYPE_EXT: if (xmvis->mesa_visual.level==0) { /* normal planes */ *value = GLX_NONE_EXT; } else if (xmvis->mesa_visual.level>0) { /* overlay */ if (xmvis->mesa_visual.rgbMode) { *value = GLX_TRANSPARENT_RGB_EXT; } else { *value = GLX_TRANSPARENT_INDEX_EXT; } } else if (xmvis->mesa_visual.level<0) { /* underlay */ *value = GLX_NONE_EXT; } return 0; case GLX_TRANSPARENT_INDEX_VALUE_EXT: { int pixel = transparent_pixel( xmvis ); if (pixel>=0) { *value = pixel; } /* else undefined */ } return 0; case GLX_TRANSPARENT_RED_VALUE_EXT: /* undefined */ return 0; case GLX_TRANSPARENT_GREEN_VALUE_EXT: /* undefined */ return 0; case GLX_TRANSPARENT_BLUE_VALUE_EXT: /* undefined */ return 0; case GLX_TRANSPARENT_ALPHA_VALUE_EXT: /* undefined */ return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -