⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xm_api.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 5 页
字号:
         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) );      }   }   if (alpha_flag && alpha_bits == 0)      alpha_bits = 8;   _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;}void XMesaSetVisualDisplay( XMesaDisplay *dpy, XMesaVisual v ){    v->display = dpy;}void 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. */XMesaContext 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);#if ENABLE_EXT_texure_compression_s3tc    if (c->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   /* 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 ) ||       !_ac_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;}void XMesaDestroyContext( XMesaContext c ){   GLcontext *mesaCtx = &c->mesa;#ifdef FX   XMesaBuffer xmbuf = XMESA_BUFFER(mesaCtx->DrawBuffer);   if (xmbuf && xmbuf->FXctx)      fxMesaDestroyContext(xmbuf->FXctx);#endif   _swsetup_DestroyContext( mesaCtx );   _swrast_DestroyContext( mesaCtx );   _tnl_DestroyContext( mesaCtx );   _ac_DestroyContext( mesaCtx );   _mesa_free_context_data( mesaCtx );   _mesa_free( c );}/* * XXX this isn't a public function!  It's a hack for the 3Dfx driver. * Create a new XMesaBuffer from an X window. * Input:  v - the XMesaVisual *         w - the window *         c - the context * Return:  new XMesaBuffer or NULL if error */XMesaBufferXMesaCreateWindowBuffer2(XMesaVisual v, XMesaWindow w, XMesaContext c){#ifndef XFree86Server   XWindowAttributes attr;#endif#ifdef FX   char *fxEnvVar;#endif   int client = 0;   XMesaBuffer b;   XMesaColormap cmap;   assert(v);   (void) c;   /* Check that window depth matches visual depth */#ifdef XFree86Server   client = CLIENT_ID(((XMesaDrawable)w)->id);   if (GET_VISUAL_DEPTH(v) != ((XMesaDrawable)w)->depth) {      _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n",                    GET_VISUAL_DEPTH(v), ((XMesaDrawable) w)->depth);      return NULL;   }#else   XGetWindowAttributes( v->display, w, &attr );   if (GET_VISUAL_DEPTH(v) != attr.depth) {      _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n",                    GET_VISUAL_DEPTH(v), attr.depth);      return NULL;   }#endif   /* Find colormap */#ifdef XFree86Server   cmap = (ColormapPtr)LookupIDByType(wColormap(w), RT_COLORMAP);#else   if (attr.colormap) {      cmap = attr.colormap;   }   else {      _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w);      /* this is weird, a window w/out a colormap!? */      /* OK, let's just allocate a new one and hope for the best */      cmap = XCreateColormap(v->display, w, attr.visual, AllocNone);   }#endif   b = alloc_xmesa_buffer(v, WINDOW, cmap);   if (!b) {      return NULL;   }   if (!initialize_visual_and_buffer( client, v, b, v->mesa_visual.rgbMode,                                      (XMesaDrawable) w, cmap )) {      free_xmesa_buffer(client, b);      return NULL;   }#ifdef FX   fxEnvVar = _mesa_getenv("MESA_GLX_FX");   if (fxEnvVar) {     if (fxEnvVar[0]!='d') {       int attribs[100];       int numAttribs = 0;       int hw;       if (v->mesa_visual.depthBits > 0) {	 attribs[numAttribs++] = FXMESA_DEPTH_SIZE;	 attribs[numAttribs++] = v->mesa_visual.depthBits;       }       if (v->mesa_visual.doubleBufferMode) {	 attribs[numAttribs++] = FXMESA_DOUBLEBUFFER;       }       if (v->mesa_visual.accumRedBits > 0) {	 attribs[numAttribs++] = FXMESA_ACCUM_SIZE;	 attribs[numAttribs++] = v->mesa_visual.accumRedBits;       }       if (v->mesa_visual.stencilBits > 0) {         attribs[numAttribs++] = FXMESA_STENCIL_SIZE;         attribs[numAttribs++] = v->mesa_visual.stencilBits;       }       if (v->mesa_visual.alphaBits > 0) {         attribs[numAttribs++] = FXMESA_ALPHA_SIZE;         attribs[numAttribs++] = v->mesa_visual.alphaBits;       }       if (1) {         attribs[numAttribs++] = FXMESA_SHARE_CONTEXT;         attribs[numAttribs++] = (int) &(c->mesa);       }       attribs[numAttribs++] = FXMESA_NONE;       /* [dBorca] we should take an envvar for `fxMesaSelectCurrentBoard'!!! */       hw = fxMesaSelectCurrentBoard(0);       /* if these fail, there's a new bug somewhere */       ASSERT(b->mesa_buffer.Width > 0);       ASSERT(b->mesa_buffer.Height > 0);       if ((hw == GR_SSTTYPE_VOODOO) || (hw == GR_SSTTYPE_Voodoo2)) {         b->FXctx = fxMesaCreateBestContext(0, b->mesa_buffer.Width,                                            b->mesa_buffer.Height, attribs);         if ((v->undithered_pf!=PF_Index) && (b->backxrb->ximage)) {	   b->FXisHackUsable = b->FXctx ? GL_TRUE : GL_FALSE;	   if (b->FXctx && (fxEnvVar[0]=='w' || fxEnvVar[0]=='W')) {	     b->FXwindowHack = GL_TRUE;	     FX_grSstControl(GR_CONTROL_DEACTIVATE);	   }           else {	     b->FXwindowHack = GL_FALSE;	   }         }       }       else {         if (fxEnvVar[0]=='w' || fxEnvVar[0]=='W')	   b->FXctx = fxMesaCreateContext(w, GR_RESOLUTION_NONE,					  GR_REFRESH_75Hz, attribs);         else	   b->FXctx = fxMesaCreateBestContext(0, b->mesa_buffer.Width,                                              b->mesa_buffer.Height, attribs);         b->FXisHackUsable = GL_FALSE;         b->FXwindowHack = GL_FALSE;       }       /*       fprintf(stderr,               "voodoo %d, wid %d height %d hack: usable %d active %d\n",               hw, b->mesa_buffer.Width, b->mesa_buffer.Height,	       b->FXisHackUsable, b->FXwindowHack);       */     }   }   else {      _mesa_warning(NULL, "WARNING: This Mesa Library includes the Glide driver but\n");      _mesa_warning(NULL, "         you have not defined the MESA_GLX_FX env. var.\n");      _mesa_warning(NULL, "         (check the README.3DFX file for more information).\n\n");      _mesa_warning(NULL, "         you can disable this message with a 'export MESA_GLX_FX=disable'.\n");   }#endif   return b;}XMesaBufferXMesaCreateWindowBuffer(XMesaVisual v, XMesaWindow w){   return XMesaCreateWindowBuffer2( v, w, NULL );}/** * Create a new XMesaBuffer from an X pixmap. * * \param v    the XMesaVisual * \param p    the pixmap * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or *             \c GLX_DIRECT_COLOR visual for the pixmap * \returns new XMesaBuffer or NULL if error */XMesaBufferXMesaCreatePixmapBuffer(XMesaVisual v, XMesaPixmap p, XMesaColormap cmap){   int client = 0;   XMesaBuffer b;   assert(v);   b = alloc_xmesa_buffer(v, PIXMAP, cmap);   if (!b) {      return NULL;   }#ifdef XFree86Server   client = CLIENT_ID(((XMesaDrawable)p)->id);#endif   if (!initialize_visual_and_buffer(client, v, b, v->mesa_visual.rgbMode,				     (XMesaDrawable) p, cmap)) {      free_xmesa_buffer(client, b);      return NULL;   }   return b;}XMesaBufferXMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap,                   unsigned int width, unsigned int height){#ifdef XFree86Server   return 0;#else   int client = 0;   XMesaWindow root;   XMesaDrawable drawable;  /* X Pixmap Drawable */   XMesaBuffer b;   b = alloc_xmesa_buffer(v, PBUFFER, cmap);   if (!b) {      return NULL;   }   /* allocate pixmap for front buffer */   root = RootWindow( v->display, v->visinfo->screen );   drawable = XCreatePixmap( v->display, root, width, height, v->visinfo->depth );   if (!initialize_visual_and_buffer(client, v, b, v->mesa_visual.rgbMode,				     drawable, cmap)) {      free_xmesa_buffer(client, b);      return NULL;   }   return b;#endif}/* * Deallocate an XMesaBuffer structure and all related info. */void XMesaDestroyBuffer( XMesaBuffer b ){   int client = 0;#ifdef XFree86Server   if (b->frontxrb->drawable)       client = CLIENT_ID(b->frontxrb->drawable->id);#endif   if (b->gc)  XMesaFreeGC( b->xm_visual->display, b->gc );   if (b->cleargc)  XMesaFreeGC( b->xm_visual->display, b->cleargc );   if (b->swapgc)  XMesaFreeGC( b->xm_visual->display, b->swapgc );   if (b->xm_visual->mesa_visual.doubleBufferMode)   {      if (b->backxrb->ximage) {#if defined(USE_XSHM) && !defined(XFree86Server)         if (b->shm) {            XShmDetach( b->xm_visual->display, &b->shminfo );            XDestroyImage( b->backxrb->ximage );   

⌨️ 快捷键说明

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