📄 xm_api.c
字号:
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 *****//**********************************************************************/#ifdef IN_DRI_DRIVER#define need_GL_VERSION_1_3#define need_GL_VERSION_1_4#define need_GL_VERSION_1_5#define need_GL_VERSION_2_0/* sw extensions for imaging */#define need_GL_EXT_blend_color#define need_GL_EXT_blend_minmax#define need_GL_EXT_convolution#define need_GL_EXT_histogram#define need_GL_SGI_color_table/* sw extensions not associated with some GL version */#define need_GL_ARB_shader_objects#define need_GL_ARB_vertex_program#define need_GL_APPLE_vertex_array_object#define need_GL_ATI_fragment_shader#define need_GL_EXT_depth_bounds_test#define need_GL_EXT_framebuffer_object#define need_GL_EXT_framebuffer_blit#define need_GL_EXT_gpu_program_parameters#define need_GL_EXT_paletted_texture#define need_GL_IBM_multimode_draw_arrays#define need_GL_MESA_resize_buffers#define need_GL_NV_vertex_program#define need_GL_NV_fragment_program#include "extension_helper.h"#include "utils.h"const struct dri_extension card_extensions[] ={ { "GL_VERSION_1_3", GL_VERSION_1_3_functions }, { "GL_VERSION_1_4", GL_VERSION_1_4_functions }, { "GL_VERSION_1_5", GL_VERSION_1_5_functions }, { "GL_VERSION_2_0", GL_VERSION_2_0_functions }, { "GL_EXT_blend_color", GL_EXT_blend_color_functions }, { "GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions }, { "GL_EXT_convolution", GL_EXT_convolution_functions }, { "GL_EXT_histogram", GL_EXT_histogram_functions }, { "GL_SGI_color_table", GL_SGI_color_table_functions }, { "GL_ARB_shader_objects", GL_ARB_shader_objects_functions }, { "GL_ARB_vertex_program", GL_ARB_vertex_program_functions }, { "GL_APPLE_vertex_array_object", GL_APPLE_vertex_array_object_functions }, { "GL_ATI_fragment_shader", GL_ATI_fragment_shader_functions }, { "GL_EXT_depth_bounds_test", GL_EXT_depth_bounds_test_functions }, { "GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions }, { "GL_EXT_framebuffer_blit", GL_EXT_framebuffer_blit_functions }, { "GL_EXT_gpu_program_parameters", GL_EXT_gpu_program_parameters_functions }, { "GL_EXT_paletted_texture", GL_EXT_paletted_texture_functions }, { "GL_IBM_multimode_draw_arrays", GL_IBM_multimode_draw_arrays_functions }, { "GL_MESA_resize_buffers", GL_MESA_resize_buffers_functions }, { "GL_NV_vertex_program", GL_NV_vertex_program_functions }, { "GL_NV_fragment_program", GL_NV_fragment_program_functions }, { NULL, NULL }};#endif/* * 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. */PUBLICXMesaVisual 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;#ifdef IN_DRI_DRIVER /* driInitExtensions() should be called once per screen to setup extension * indices. There is no need to call it when the context is created since * XMesa enables mesa sw extensions on its own. */ driInitExtensions( NULL, card_extensions, GL_FALSE );#endif#ifndef XFree86Server /* 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. */ XSynchronize( display, 1 ); }#endif v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual); if (!v) { return NULL; } 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; if (alpha_flag) v->mesa_visual.alphaBits = 8; (void) initialize_visual_and_buffer( 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)); } else { /* this is an approximation */ int depth; depth = GET_VISUAL_DEPTH(v); red_bits = depth / 3; depth -= red_bits; green_bits = depth / 2; depth -= green_bits; blue_bits = depth; alpha_bits = 0; assert( red_bits + green_bits + blue_bits == GET_VISUAL_DEPTH(v) ); } alpha_bits = v->mesa_visual.alphaBits; } _mesa_initialize_visual( &v->mesa_visual, rgb_flag, db_flag, stereo_flag, red_bits, green_bits, blue_bits, alpha_bits, v->mesa_visual.indexBits, depth_size, stencil_size, accum_red_size, accum_green_size, accum_blue_size, accum_alpha_size, 0 ); /* XXX minor hack */ v->mesa_visual.level = level; return v;}PUBLICvoid XMesaDestroyVisual( XMesaVisual v ){#ifndef XFree86Server _mesa_free(v->visinfo);#endif _mesa_free(v);}/** * Create a new XMesaContext. * \param v the XMesaVisual * \param share_list another XMesaContext with which to share display * lists or NULL if no sharing is wanted. * \return an XMesaContext or NULL if error. */PUBLICXMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ){ static GLboolean firstTime = GL_TRUE; XMesaContext c; GLcontext *mesaCtx; struct dd_function_table functions; TNLcontext *tnl; if (firstTime) { _glthread_INIT_MUTEX(_xmesa_lock); firstTime = GL_FALSE; } /* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */ c = (XMesaContext) CALLOC_STRUCT(xmesa_context); if (!c) return NULL; mesaCtx = &(c->mesa); /* initialize with default driver functions, then plug in XMesa funcs */ _mesa_init_driver_functions(&functions); xmesa_init_driver_functions(v, &functions); if (!_mesa_initialize_context(mesaCtx, &v->mesa_visual, share_list ? &(share_list->mesa) : (GLcontext *) NULL, &functions, (void *) c)) { _mesa_free(c); return NULL; } _mesa_enable_sw_extensions(mesaCtx); _mesa_enable_1_3_extensions(mesaCtx); _mesa_enable_1_4_extensions(mesaCtx); _mesa_enable_1_5_extensions(mesaCtx); _mesa_enable_2_0_extensions(mesaCtx); _mesa_enable_2_1_extensions(mesaCtx);#if ENABLE_EXT_texure_compression_s3tc if (mesaCtx->Mesa_DXTn) { _mesa_enable_extension(mesaCtx, "GL_EXT_texture_compression_s3tc"); _mesa_enable_extension(mesaCtx, "GL_S3_s3tc"); } _mesa_enable_extension(mesaCtx, "GL_3DFX_texture_compression_FXT1");#endif#if ENABLE_EXT_timer_query _mesa_enable_extension(mesaCtx, "GL_EXT_timer_query");#endif#ifdef XFree86Server /* If we're running in the X server, do bounds checking to prevent * segfaults and server crashes! */ mesaCtx->Const.CheckArrayBounds = GL_TRUE;#endif /* finish up xmesa context initializations */ c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE; c->xm_visual = v; c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ c->display = v->display; c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ /* Initialize the software rasterizer and helper modules. */ if (!_swrast_CreateContext( mesaCtx ) || !_vbo_CreateContext( mesaCtx ) || !_tnl_CreateContext( mesaCtx ) || !_swsetup_CreateContext( mesaCtx )) { _mesa_free_context_data(&c->mesa); _mesa_free(c); return NULL; } /* tnl setup */ tnl = TNL_CONTEXT(mesaCtx); tnl->Driver.RunPipeline = _tnl_run_pipeline; /* swrast setup */ xmesa_register_swrast_functions( mesaCtx ); _swsetup_Wakeup(mesaCtx); return c;}PUBLICvoid XMesaDestroyContext( XMesaContext c ){ GLcontext *mesaCtx = &c->mesa;#ifdef FX FXdestroyContext( XMESA_BUFFER(mesaCtx->DrawBuffer) );#endif _swsetup_DestroyContext( mesaCtx ); _swrast_DestroyContext( mesaCtx ); _tnl_DestroyContext( mesaCtx ); _vbo_DestroyContext( mesaCtx ); _mesa_free_context_data( mesaCtx ); _mesa_free( c );}/** * Private function for creating an XMesaBuffer which corresponds to an * X window or pixmap. * \param v the window's XMesaVisual * \param w the window we're wrapping * \return new XMesaBuffer or NULL if error */PUBLIC XMesaBufferXMesaCreateWindowBuffer(XMesaVisual v, XMesaWindow w){#ifndef XFree86Server XWindowAttributes attr;#endif XMesaBuffer b;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -