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

📄 xm_api.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
   XMesaColormap cmap;   int depth;   assert(v);   assert(w);   /* Check that window depth matches visual depth */#ifdef XFree86Server   depth = ((XMesaDrawable)w)->depth;#else   XGetWindowAttributes( v->display, w, &attr );   depth = attr.depth;#endif   if (GET_VISUAL_DEPTH(v) != depth) {      _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n",                    GET_VISUAL_DEPTH(v), depth);      return NULL;   }   /* 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 = create_xmesa_buffer((XMesaDrawable) w, WINDOW, v, cmap);   if (!b)      return NULL;   if (!initialize_visual_and_buffer( v, b, v->mesa_visual.rgbMode,                                      (XMesaDrawable) w, cmap )) {      xmesa_free_buffer(b);      return NULL;   }   return b;}/** * 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 */PUBLIC XMesaBufferXMesaCreatePixmapBuffer(XMesaVisual v, XMesaPixmap p, XMesaColormap cmap){   XMesaBuffer b;   assert(v);   b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap);   if (!b)      return NULL;   if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,				     (XMesaDrawable) p, cmap)) {      xmesa_free_buffer(b);      return NULL;   }   return b;}/** * For GLX_EXT_texture_from_pixmap */XMesaBufferXMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p,                               XMesaColormap cmap,                               int format, int target, int mipmap){   GET_CURRENT_CONTEXT(ctx);   XMesaBuffer b;   GLuint width, height;   assert(v);   b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap);   if (!b)      return NULL;   /* get pixmap size, update framebuffer/renderbuffer dims */   xmesa_get_window_size(v->display, b, &width, &height);   _mesa_resize_framebuffer(NULL, &(b->mesa_buffer), width, height);   if (target == 0) {      /* examine dims */      if (ctx->Extensions.ARB_texture_non_power_of_two) {         target = GLX_TEXTURE_2D_EXT;      }      else if (   _mesa_bitcount(width)  == 1               && _mesa_bitcount(height) == 1) {         /* power of two size */         if (height == 1) {            target = GLX_TEXTURE_1D_EXT;         }         else {            target = GLX_TEXTURE_2D_EXT;         }      }      else if (ctx->Extensions.NV_texture_rectangle) {         target = GLX_TEXTURE_RECTANGLE_EXT;      }      else {         /* non power of two textures not supported */         XMesaDestroyBuffer(b);         return 0;      }   }   b->TextureTarget = target;   b->TextureFormat = format;   b->TextureMipmap = mipmap;   if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,				     (XMesaDrawable) p, cmap)) {      xmesa_free_buffer(b);      return NULL;   }   return b;}XMesaBufferXMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap,                   unsigned int width, unsigned int height){#ifndef XFree86Server   XMesaWindow root;   XMesaDrawable drawable;  /* X Pixmap Drawable */   XMesaBuffer b;   /* allocate pixmap for front buffer */   root = RootWindow( v->display, v->visinfo->screen );   drawable = XCreatePixmap(v->display, root, width, height,                            v->visinfo->depth);   if (!drawable)      return NULL;   b = create_xmesa_buffer(drawable, PBUFFER, v, cmap);   if (!b)      return NULL;   if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,				     drawable, cmap)) {      xmesa_free_buffer(b);      return NULL;   }   return b;#else   return 0;#endif}/* * Deallocate an XMesaBuffer structure and all related info. */PUBLIC voidXMesaDestroyBuffer(XMesaBuffer b){   xmesa_free_buffer(b);}/** * Query the current window size and update the corresponding GLframebuffer * and all attached renderbuffers. * Called when: *  1. the first time a buffer is bound to a context. *  2. from glViewport to poll for window size changes *  3. from the XMesaResizeBuffers() API function. * Note: it's possible (and legal) for xmctx to be NULL.  That can happen * when resizing a buffer when no rendering context is bound. */voidxmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer){   GLuint width, height;   xmesa_get_window_size(drawBuffer->display, drawBuffer, &width, &height);   if (drawBuffer->mesa_buffer.Width != width ||       drawBuffer->mesa_buffer.Height != height) {      GLcontext *ctx = xmctx ? &xmctx->mesa : NULL;      _mesa_resize_framebuffer(ctx, &(drawBuffer->mesa_buffer), width, height);   }   drawBuffer->mesa_buffer.Initialized = GL_TRUE; /* XXX TEMPORARY? */}/* * Bind buffer b to context c and make c the current rendering context. */GLboolean XMesaMakeCurrent( XMesaContext c, XMesaBuffer b ){   return XMesaMakeCurrent2( c, b, b );}/* * Bind buffer b to context c and make c the current rendering context. */PUBLICGLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,                             XMesaBuffer readBuffer ){   if (c) {      if (!drawBuffer || !readBuffer)         return GL_FALSE;  /* must specify buffers! */      if (&(c->mesa) == _mesa_get_current_context()          && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer          && c->mesa.ReadBuffer == &readBuffer->mesa_buffer          && XMESA_BUFFER(c->mesa.DrawBuffer)->wasCurrent) {         /* same context and buffer, do nothing */         return GL_TRUE;      }      c->xm_buffer = drawBuffer;#ifdef FX      if (FXmakeCurrent( drawBuffer ))         return GL_TRUE;#endif      /* Call this periodically to detect when the user has begun using       * GL rendering from multiple threads.       */      _glapi_check_multithread();      xmesa_check_and_update_buffer_size(c, drawBuffer);      if (readBuffer != drawBuffer)         xmesa_check_and_update_buffer_size(c, readBuffer);      _mesa_make_current(&(c->mesa),                         &drawBuffer->mesa_buffer,                         &readBuffer->mesa_buffer);      if (c->xm_visual->mesa_visual.rgbMode) {         /*          * Must recompute and set these pixel values because colormap          * can be different for different windows.          */         c->clearpixel = xmesa_color_to_pixel( &c->mesa,                                               c->clearcolor[0],                                               c->clearcolor[1],                                               c->clearcolor[2],                                               c->clearcolor[3],                                               c->xm_visual->undithered_pf);         XMesaSetForeground(c->display, drawBuffer->cleargc, c->clearpixel);      }      /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */      drawBuffer->wasCurrent = GL_TRUE;   }   else {      /* Detach */      _mesa_make_current( NULL, NULL, NULL );   }   return GL_TRUE;}/* * Unbind the context c from its buffer. */GLboolean XMesaUnbindContext( XMesaContext c ){   /* A no-op for XFree86 integration purposes */   return GL_TRUE;}XMesaContext XMesaGetCurrentContext( void ){   GET_CURRENT_CONTEXT(ctx);   if (ctx) {      XMesaContext xmesa = XMESA_CONTEXT(ctx);      return xmesa;   }   else {      return 0;   }}XMesaBuffer XMesaGetCurrentBuffer( void ){   GET_CURRENT_CONTEXT(ctx);   if (ctx) {      XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer);      return xmbuf;   }   else {      return 0;   }}/* New in Mesa 3.1 */XMesaBuffer XMesaGetCurrentReadBuffer( void ){   GET_CURRENT_CONTEXT(ctx);   if (ctx) {      return XMESA_BUFFER(ctx->ReadBuffer);   }   else {      return 0;   }}#ifdef XFree86ServerPUBLICGLboolean XMesaForceCurrent(XMesaContext c){   if (c) {      _glapi_set_dispatch(c->mesa.CurrentDispatch);      if (&(c->mesa) != _mesa_get_current_context()) {	 _mesa_make_current(&c->mesa, c->mesa.DrawBuffer, c->mesa.ReadBuffer);      }   }   else {      _mesa_make_current(NULL, NULL, NULL);   }   return GL_TRUE;}PUBLICGLboolean XMesaLoseCurrent(XMesaContext c){   (void) c;   _mesa_make_current(NULL, NULL, NULL);   return GL_TRUE;}PUBLICGLboolean XMesaCopyContext( XMesaContext xm_src, XMesaContext xm_dst, GLuint mask ){   _mesa_copy_context(&xm_src->mesa, &xm_dst->mesa, mask);   return GL_TRUE;}#endif /* XFree86Server */#ifndef FXGLboolean XMesaSetFXmode( GLint mode ){   (void) mode;   return GL_FALSE;}#endif/* * Copy the back buffer to the front buffer.  If there's no back buffer * this is a no-op. */PUBLICvoid XMesaSwapBuffers( XMesaBuffer b ){   GET_CURRENT_CONTEXT(ctx);   if (!b->backxrb) {      /* single buffered */      return;   }   /* If we're swapping the buffer associated with the current context    * we have to flush any pending rendering commands first.    */   if (ctx && ctx->DrawBuffer == &(b->mesa_buffer))      _mesa_notifySwapBuffers(ctx);   if (b->db_mode) {#ifdef FX      if (FXswapBuffers(b))         return;#endif      if (b->backxrb->ximage) {	 /* Copy Ximage (back buf) from client memory to server window */#if defined(USE_XSHM) && !defined(XFree86Server)	 if (b->shm) {            /*_glthread_LOCK_MUTEX(_xmesa_lock);*/	    XShmPutImage( b->xm_visual->display, b->frontxrb->drawable,			  b->swapgc,			  b->backxrb->ximage, 0, 0,			  0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height,                          False );            /*_glthread_UNLOCK_MUTEX(_xmesa_lock);*/	 }	 else#endif         {            /*_glthread_LOCK_MUTEX(_xmesa_lock);*/            XMesaPutImage( b->xm_visual->display, b

⌨️ 快捷键说明

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