📄 xm_api.c
字号:
struct xmesa_renderbuffer *front_xrb, *back_xrb;#ifndef XFree86Server XGCValues gcvalues;#endif if (b) { assert(b->xm_visual == v); } if (b) { front_xrb = b->frontxrb; back_xrb = b->backxrb; } else { front_xrb = back_xrb = NULL; } /* Save true bits/pixel */ v->BitsPerPixel = bits_per_pixel(v); assert(v->BitsPerPixel > 0); if (rgb_flag==GL_FALSE) { /* COLOR-INDEXED WINDOW: * Even if the visual is TrueColor or DirectColor we treat it as * being color indexed. This is weird but might be useful to someone. */ v->dithered_pf = v->undithered_pf = PF_Index; v->mesa_visual.indexBits = GET_VISUAL_DEPTH(v); } else { /* RGB WINDOW: * We support RGB rendering into almost any kind of visual. */ const int xclass = v->mesa_visual.visualType; if (xclass==GLX_TRUE_COLOR || xclass==GLX_DIRECT_COLOR) { setup_truecolor( v, b, cmap ); } else if (xclass==GLX_STATIC_GRAY && GET_VISUAL_DEPTH(v)==1) { setup_monochrome( v, b ); } else if (xclass==GLX_GRAY_SCALE || xclass==GLX_STATIC_GRAY) { if (!setup_grayscale( client, v, b, cmap )) { return GL_FALSE; } } else if ((xclass==GLX_PSEUDO_COLOR || xclass==GLX_STATIC_COLOR) && GET_VISUAL_DEPTH(v)>=4 && GET_VISUAL_DEPTH(v)<=16) { if (!setup_dithered_color( client, v, b, cmap )) { return GL_FALSE; } } else { _mesa_warning(NULL, "XMesa: RGB mode rendering not supported in given visual.\n"); return GL_FALSE; } v->mesa_visual.indexBits = 0; if (_mesa_getenv("MESA_NO_DITHER")) { v->dithered_pf = v->undithered_pf; } } /* * If MESA_INFO env var is set print out some debugging info * which can help Brian figure out what's going on when a user * reports bugs. */ if (_mesa_getenv("MESA_INFO")) { _mesa_printf("X/Mesa visual = %p\n", (void *) v); _mesa_printf("X/Mesa dithered pf = %u\n", v->dithered_pf); _mesa_printf("X/Mesa undithered pf = %u\n", v->undithered_pf); _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level); _mesa_printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v)); _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); } if (b && window) { /* Do window-specific initializations */ b->frontxrb->drawable = window; b->frontxrb->pixmap = (XMesaPixmap) window; /* Setup for single/double buffering */ if (v->mesa_visual.doubleBufferMode) { /* Double buffered */ b->shm = check_for_xshm( v->display ); xmesa_alloc_back_buffer(b, b->mesa_buffer.Width, b->mesa_buffer.Height); } /* X11 graphics contexts */#ifdef XFree86Server b->gc = CreateScratchGC(v->display, window->depth);#else b->gc = XCreateGC( v->display, window, 0, NULL );#endif XMesaSetFunction( v->display, b->gc, GXcopy ); /* cleargc - for glClear() */#ifdef XFree86Server b->cleargc = CreateScratchGC(v->display, window->depth);#else b->cleargc = XCreateGC( v->display, window, 0, NULL );#endif XMesaSetFunction( v->display, b->cleargc, GXcopy ); /* * Don't generate Graphics Expose/NoExpose events in swapbuffers(). * Patch contributed by Michael Pichler May 15, 1995. */#ifdef XFree86Server b->swapgc = CreateScratchGC(v->display, window->depth); { CARD32 v[1]; v[0] = FALSE; dixChangeGC(NullClient, b->swapgc, GCGraphicsExposures, v, NULL); }#else gcvalues.graphics_exposures = False; b->swapgc = XCreateGC( v->display, window, GCGraphicsExposures, &gcvalues);#endif XMesaSetFunction( v->display, b->swapgc, GXcopy ); /* * Set fill style and tile pixmap once for all for HPCR stuff * (instead of doing it each time in clear_color_HPCR_pixmap()) * Initialize whole stuff * Patch contributed by Jacques Leroy March 8, 1998. */ if (v->hpcr_clear_flag && back_xrb->pixmap) { int i; for (i=0; i<16; i++) { XMesaPutPixel(v->hpcr_clear_ximage, i, 0, 0); XMesaPutPixel(v->hpcr_clear_ximage, i, 1, 0); } XMesaPutImage(b->display, (XMesaDrawable) v->hpcr_clear_pixmap, b->cleargc, v->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2); XMesaSetFillStyle( v->display, b->cleargc, FillTiled); XMesaSetTile( v->display, b->cleargc, v->hpcr_clear_pixmap ); } /* Initialize the row buffer XImage for use in write_color_span() */#ifdef XFree86Server b->rowimage = XMesaCreateImage(GET_VISUAL_DEPTH(v), MAX_WIDTH, 1, (char *)MALLOC(MAX_WIDTH*4));#else b->rowimage = XCreateImage( v->display, v->visinfo->visual, v->visinfo->depth, ZPixmap, 0, /*format, offset*/ (char*) MALLOC(MAX_WIDTH*4), /*data*/ MAX_WIDTH, 1, /*width, height*/ 32, /*bitmap_pad*/ 0 /*bytes_per_line*/ );#endif if (!b->rowimage) return GL_FALSE; } return GL_TRUE;}/* * Convert an RGBA color to a pixel value. */unsigned longxmesa_color_to_pixel(GLcontext *ctx, GLubyte r, GLubyte g, GLubyte b, GLubyte a, GLuint pixelFormat){ XMesaContext xmesa = XMESA_CONTEXT(ctx); switch (pixelFormat) { case PF_Index: return 0; case PF_Truecolor: { unsigned long p; PACK_TRUECOLOR( p, r, g, b ); return p; } case PF_8A8B8G8R: return PACK_8A8B8G8R( r, g, b, a ); case PF_8A8R8G8B: return PACK_8A8R8G8B( r, g, b, a ); case PF_8R8G8B: /* fall through */ case PF_8R8G8B24: return PACK_8R8G8B( r, g, b ); case PF_5R6G5B: return PACK_5R6G5B( r, g, b ); case PF_Dither: { DITHER_SETUP; return DITHER( 1, 0, r, g, b ); } case PF_1Bit: /* 382 = (3*255)/2 */ return ((r+g+b) > 382) ^ xmesa->xm_visual->bitFlip; case PF_HPCR: return DITHER_HPCR(1, 1, r, g, b); case PF_Lookup: { LOOKUP_SETUP; return LOOKUP( r, g, b ); } case PF_Grayscale: return GRAY_RGB( r, g, b ); case PF_Dither_True: /* fall through */ case PF_Dither_5R6G5B: { unsigned long p; PACK_TRUEDITHER(p, 1, 0, r, g, b); return p; } default: _mesa_problem(ctx, "Bad pixel format in xmesa_color_to_pixel"); } return 0;}#define NUM_VISUAL_TYPES 6/** * Convert an X visual type to a GLX visual type. * * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) * to be converted. * \return If \c visualType is a valid X visual type, a GLX visual type will * be returned. Otherwise \c GLX_NONE will be returned. * * \note * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the * DRI CVS tree. */static GLintxmesa_convert_from_x_visual_type( int visualType ){ static const int glx_visual_types[ NUM_VISUAL_TYPES ] = { GLX_STATIC_GRAY, GLX_GRAY_SCALE, GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, GLX_TRUE_COLOR, GLX_DIRECT_COLOR }; return ( (unsigned) visualType < NUM_VISUAL_TYPES ) ? glx_visual_types[ visualType ] : GLX_NONE;}/**********************************************************************//***** Public Functions *****//**********************************************************************//* * Create a new X/Mesa visual. * Input: display - X11 display * visinfo - an XVisualInfo pointer * rgb_flag - GL_TRUE = RGB mode, * GL_FALSE = color index mode * alpha_flag - alpha buffer requested? * db_flag - GL_TRUE = double-buffered, * GL_FALSE = single buffered * stereo_flag - stereo visual? * ximage_flag - GL_TRUE = use an XImage for back buffer, * GL_FALSE = use an off-screen pixmap for back buffer * depth_size - requested bits/depth values, or zero * stencil_size - requested bits/stencil values, or zero * accum_red_size - requested bits/red accum values, or zero * accum_green_size - requested bits/green accum values, or zero * accum_blue_size - requested bits/blue accum values, or zero * accum_alpha_size - requested bits/alpha accum values, or zero * num_samples - number of samples/pixel if multisampling, or zero * level - visual level, usually 0 * visualCaveat - ala the GLX extension, usually GLX_NONE * Return; a new XMesaVisual or 0 if error. */XMesaVisual XMesaCreateVisual( XMesaDisplay *display, XMesaVisualInfo visinfo, GLboolean rgb_flag, GLboolean alpha_flag, GLboolean db_flag, GLboolean stereo_flag, GLboolean ximage_flag, GLint depth_size, GLint stencil_size, GLint accum_red_size, GLint accum_green_size, GLint accum_blue_size, GLint accum_alpha_size, GLint num_samples, GLint level, GLint visualCaveat ){ char *gamma; XMesaVisual v; GLint red_bits, green_bits, blue_bits, alpha_bits; /* For debugging only */ if (_mesa_getenv("MESA_XSYNC")) { /* This makes debugging X easier. * In your debugger, set a breakpoint on _XError to stop when an * X protocol error is generated. */#ifdef XFree86Server /* NOT_NEEDED */#else XSynchronize( display, 1 );#endif } v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual); if (!v) { return NULL; } /* * In the X server, NULL is passed in for the display. It will have * to be set before using this visual. See XMesaSetVisualDisplay() * below. */ v->display = display; /* Save a copy of the XVisualInfo struct because the user may X_mesa_free() * the struct but we may need some of the information contained in it * at a later time. */#ifndef XFree86Server v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo)); if(!v->visinfo) { _mesa_free(v); return NULL; } MEMCPY(v->visinfo, visinfo, sizeof(*visinfo));#endif /* check for MESA_GAMMA environment variable */ gamma = _mesa_getenv("MESA_GAMMA"); if (gamma) { v->RedGamma = v->GreenGamma = v->BlueGamma = 0.0; sscanf( gamma, "%f %f %f", &v->RedGamma, &v->GreenGamma, &v->BlueGamma ); if (v->RedGamma<=0.0) v->RedGamma = 1.0; if (v->GreenGamma<=0.0) v->GreenGamma = v->RedGamma; if (v->BlueGamma<=0.0) v->BlueGamma = v->RedGamma; } else { v->RedGamma = v->GreenGamma = v->BlueGamma = 1.0; } v->ximage_flag = ximage_flag;#ifdef XFree86Server /* We could calculate these values by ourselves. nplanes is either the sum * of the red, green, and blue bits or the number index bits. * ColormapEntries is either (1U << index_bits) or * (1U << max(redBits, greenBits, blueBits)). */ assert(visinfo->nplanes > 0); v->nplanes = visinfo->nplanes; v->ColormapEntries = visinfo->ColormapEntries; v->mesa_visual.redMask = visinfo->redMask; v->mesa_visual.greenMask = visinfo->greenMask; v->mesa_visual.blueMask = visinfo->blueMask; v->mesa_visual.visualID = visinfo->vid; v->mesa_visual.screen = 0; /* FIXME: What should be done here? */#else v->mesa_visual.redMask = visinfo->red_mask; v->mesa_visual.greenMask = visinfo->green_mask; v->mesa_visual.blueMask = visinfo->blue_mask; v->mesa_visual.visualID = visinfo->visualid; v->mesa_visual.screen = visinfo->screen;#endif#if defined(XFree86Server) || !(defined(__cplusplus) || defined(c_plusplus)) v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->class);#else v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->c_class);#endif v->mesa_visual.visualRating = visualCaveat; (void) initialize_visual_and_buffer( 0, v, NULL, rgb_flag, 0, 0 ); { const int xclass = v->mesa_visual.visualType; if (xclass==GLX_TRUE_COLOR || xclass==GLX_DIRECT_COLOR) { red_bits = _mesa_bitcount(GET_REDMASK(v)); green_bits = _mesa_bitcount(GET_GREENMASK(v)); blue_bits = _mesa_bitcount(GET_BLUEMASK(v)); alpha_bits = 0; } else { /* this is an approximation */ int depth; depth = GET_VISUAL_DEPTH(v);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -