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

📄 glxapi.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Mesa 3-D graphics library * Version:  7.1 *  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved. *  * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: *  * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//* * This is the GLX API dispatcher.  Calls to the glX* functions are * either routed to the real GLX encoders or to Mesa's pseudo-GLX functions. * See the glxapi.h file for more details. */#include <assert.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include "main/glheader.h"#include "glapi/glapi.h"#include "glxapi.h"extern struct _glxapi_table *_real_GetGLXDispatchTable(void);extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);struct display_dispatch {   Display *Dpy;   struct _glxapi_table *Table;   struct display_dispatch *Next;};static struct display_dispatch *DispatchList = NULL;/* Display -> Dispatch caching */static Display *prevDisplay = NULL;static struct _glxapi_table *prevTable = NULL;static struct _glxapi_table *get_dispatch(Display *dpy){   if (!dpy)      return NULL;   /* search list of display/dispatch pairs for this display */   {      const struct display_dispatch *d = DispatchList;      while (d) {         if (d->Dpy == dpy) {            prevDisplay = dpy;            prevTable = d->Table;            return d->Table;  /* done! */         }         d = d->Next;      }   }   /* A new display, determine if we should use real GLX    * or Mesa's pseudo-GLX.    */   {      struct _glxapi_table *t = _mesa_GetGLXDispatchTable();      if (t) {         struct display_dispatch *d;         d = (struct display_dispatch *) malloc(sizeof(struct display_dispatch));         if (d) {            d->Dpy = dpy;            d->Table = t;            /* insert at head of list */            d->Next = DispatchList;            DispatchList = d;            /* update cache */            prevDisplay = dpy;            prevTable = t;            return t;         }      }   }   /* If we get here that means we can't use real GLX on this display    * and the Mesa pseudo-GLX software renderer wasn't compiled in.    * Or, we ran out of memory!    */   return NULL;}/* Don't use the GET_DISPATCH defined in glthread.h */#undef GET_DISPATCH#define GET_DISPATCH(DPY, TABLE)	\   if (DPY == prevDisplay) {		\      TABLE = prevTable;		\   }					\   else if (!DPY) {			\      TABLE = NULL;			\   }					\   else {				\      TABLE = get_dispatch(DPY);	\   }   /** * GLX API current context. */#if defined(GLX_USE_TLS)PUBLIC __thread void * CurrentContext    __attribute__((tls_model("initial-exec")));#elif defined(THREADS)static _glthread_TSD ContextTSD;         /**< Per-thread context pointer */#elsestatic GLXContext CurrentContext = 0;#endifstatic voidSetCurrentContext(GLXContext c){#if defined(GLX_USE_TLS)   CurrentContext = c;#elif defined(THREADS)   _glthread_SetTSD(&ContextTSD, c);#else   CurrentContext = c;#endif}/* * GLX API entrypoints *//*** GLX_VERSION_1_0 ***/XVisualInfo PUBLIC *glXChooseVisual(Display *dpy, int screen, int *list){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return NULL;   return (t->ChooseVisual)(dpy, screen, list);}void PUBLICglXCopyContext(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->CopyContext)(dpy, src, dst, mask);}GLXContext PUBLICglXCreateContext(Display *dpy, XVisualInfo *visinfo, GLXContext shareList, Bool direct){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreateContext)(dpy, visinfo, shareList, direct);}GLXPixmap PUBLICglXCreateGLXPixmap(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreateGLXPixmap)(dpy, visinfo, pixmap);}void PUBLICglXDestroyContext(Display *dpy, GLXContext ctx){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return;   if (glXGetCurrentContext() == ctx)      SetCurrentContext(NULL);   (t->DestroyContext)(dpy, ctx);}void PUBLICglXDestroyGLXPixmap(Display *dpy, GLXPixmap pixmap){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->DestroyGLXPixmap)(dpy, pixmap);}int PUBLICglXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return GLX_NO_EXTENSION;   return (t->GetConfig)(dpy, visinfo, attrib, value);}GLXContext PUBLICglXGetCurrentContext(void){#if defined(GLX_USE_TLS)   return CurrentContext;#elif defined(THREADS)   return (GLXContext) _glthread_GetTSD(&ContextTSD);#else   return CurrentContext;#endif}GLXDrawable PUBLICglXGetCurrentDrawable(void){   __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();   return gc ? gc->currentDrawable : 0;}Bool PUBLICglXIsDirect(Display *dpy, GLXContext ctx){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return False;   return (t->IsDirect)(dpy, ctx);}Bool PUBLICglXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx){   Bool b;   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t) {      return False;   }   b = (*t->MakeCurrent)(dpy, drawable, ctx);   if (b) {      SetCurrentContext(ctx);   }   return b;}Bool PUBLICglXQueryExtension(Display *dpy, int *errorb, int *event){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return False;   return (t->QueryExtension)(dpy, errorb, event);}Bool PUBLICglXQueryVersion(Display *dpy, int *maj, int *min){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return False;   return (t->QueryVersion)(dpy, maj, min);}void PUBLICglXSwapBuffers(Display *dpy, GLXDrawable drawable){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->SwapBuffers)(dpy, drawable);}void PUBLICglXUseXFont(Font font, int first, int count, int listBase){   struct _glxapi_table *t;   Display *dpy = glXGetCurrentDisplay();   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->UseXFont)(font, first, count, listBase);}void PUBLICglXWaitGL(void){   struct _glxapi_table *t;   Display *dpy = glXGetCurrentDisplay();   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->WaitGL)();}void PUBLICglXWaitX(void){   struct _glxapi_table *t;   Display *dpy = glXGetCurrentDisplay();   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->WaitX)();}/*** GLX_VERSION_1_1 ***/const char PUBLIC *glXGetClientString(Display *dpy, int name){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return NULL;   return (t->GetClientString)(dpy, name);}const char PUBLIC *glXQueryExtensionsString(Display *dpy, int screen){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return NULL;   return (t->QueryExtensionsString)(dpy, screen);}const char PUBLIC *glXQueryServerString(Display *dpy, int screen, int name){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return NULL;   return (t->QueryServerString)(dpy, screen, name);}/*** GLX_VERSION_1_2 ***/Display PUBLIC *glXGetCurrentDisplay(void){   /* Same code as in libGL's glxext.c */   __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();   if (NULL == gc) return NULL;   return gc->currentDpy;}/*** GLX_VERSION_1_3 ***/GLXFBConfig PUBLIC *glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->ChooseFBConfig)(dpy, screen, attribList, nitems);}GLXContext PUBLICglXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreateNewContext)(dpy, config, renderType, shareList, direct);}GLXPbuffer PUBLICglXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreatePbuffer)(dpy, config, attribList);}GLXPixmap PUBLICglXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreatePixmap)(dpy, config, pixmap, attribList);}GLXWindow PUBLICglXCreateWindow(Display *dpy, GLXFBConfig config, Window win, const int *attribList){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return 0;   return (t->CreateWindow)(dpy, config, win, attribList);}void PUBLICglXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf){   struct _glxapi_table *t;   GET_DISPATCH(dpy, t);   if (!t)      return;   (t->DestroyPbuffer)(dpy, pbuf);}

⌨️ 快捷键说明

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