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

📄 fakeglx.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * 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 an emulation of the GLX API which allows Mesa/GLX-based programs * to run on X servers which do not have the real GLX extension. * * Thanks to the contributors: * * Initial version:  Philip Brown (phil@bolthole.com) * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu) * Further visual-handling refinements: Wolfram Gloger *    (wmglo@Dent.MED.Uni-Muenchen.DE). * * Notes: *   Don't be fooled, stereo isn't supported yet. */#include "glxheader.h"#include "glxapi.h"#include "GL/xmesa.h"#include "context.h"#include "config.h"#include "macros.h"#include "imports.h"#include "mtypes.h"#include "version.h"#include "xfonts.h"#include "xmesaP.h"#ifdef __VMS#define _mesa_sprintf sprintf#endif/* This indicates the client-side GLX API and GLX encoder version. */#define CLIENT_MAJOR_VERSION 1#define CLIENT_MINOR_VERSION 4  /* but don't have 1.3's pbuffers, etc yet *//* This indicates the server-side GLX decoder version. * GLX 1.4 indicates OpenGL 1.3 support */#define SERVER_MAJOR_VERSION 1#define SERVER_MINOR_VERSION 4/* This is appended onto the glXGetClient/ServerString version strings. */#define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING/* Who implemented this GLX? */#define VENDOR "Brian Paul"#define EXTENSIONS \   "GLX_MESA_set_3dfx_mode " \   "GLX_MESA_copy_sub_buffer " \   "GLX_MESA_pixmap_colormap " \   "GLX_MESA_release_buffers " \   "GLX_ARB_get_proc_address " \   "GLX_EXT_texture_from_pixmap " \   "GLX_EXT_visual_info " \   "GLX_EXT_visual_rating " \   /*"GLX_SGI_video_sync "*/ \   "GLX_SGIX_fbconfig " \   "GLX_SGIX_pbuffer "/* * Our fake GLX context will contain a "real" GLX context and an XMesa context. * * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context, * and vice versa. * * We really just need this structure in order to make the libGL functions * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay() * work correctly. */struct fake_glx_context {   __GLXcontext glxContext;   /* this MUST be first! */   XMesaContext xmesaContext;};/**********************************************************************//***                       GLX Visual Code                          ***//**********************************************************************/#define DONT_CARE -1static XMesaVisual *VisualTable = NULL;static int NumVisuals = 0;/* * This struct and some code fragments borrowed * from Mark Kilgard's GLUT library. */typedef struct _OverlayInfo {  /* Avoid 64-bit portability problems by being careful to use     longs due to the way XGetWindowProperty is specified. Note     that these parameters are passed as CARD32s over X     protocol. */  unsigned long overlay_visual;  long transparent_type;  long value;  long layer;} OverlayInfo;/* Macro to handle c_class vs class field name in XVisualInfo struct */#if defined(__cplusplus) || defined(c_plusplus)#define CLASS c_class#else#define CLASS class#endif/* * Test if the given XVisualInfo is usable for Mesa rendering. */static GLbooleanis_usable_visual( XVisualInfo *vinfo ){   switch (vinfo->CLASS) {      case StaticGray:      case GrayScale:         /* Any StaticGray/GrayScale visual works in RGB or CI mode */         return GL_TRUE;      case StaticColor:      case PseudoColor:	 /* Any StaticColor/PseudoColor visual of at least 4 bits */	 if (vinfo->depth>=4) {	    return GL_TRUE;	 }	 else {	    return GL_FALSE;	 }      case TrueColor:      case DirectColor:	 /* Any depth of TrueColor or DirectColor works in RGB mode */	 return GL_TRUE;      default:	 /* This should never happen */	 return GL_FALSE;   }}/** * Get an array OverlayInfo records for specified screen. * \param dpy  the display * \param screen  screen number * \param numOverlays  returns numver of OverlayInfo records * \return  pointer to OverlayInfo array, free with XFree() */static OverlayInfo *GetOverlayInfo(Display *dpy, int screen, int *numOverlays){   Atom overlayVisualsAtom;   Atom actualType;   Status status;   unsigned char *ovInfo;   unsigned long sizeData, bytesLeft;   int actualFormat;   /*    * The SERVER_OVERLAY_VISUALS property on the root window contains    * a list of overlay visuals.  Get that list now.    */   overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);   if (overlayVisualsAtom == None) {      return 0;   }   status = XGetWindowProperty(dpy, RootWindow(dpy, screen),                               overlayVisualsAtom, 0L, (long) 10000, False,                               overlayVisualsAtom, &actualType, &actualFormat,                               &sizeData, &bytesLeft,                               &ovInfo);   if (status != Success || actualType != overlayVisualsAtom ||       actualFormat != 32 || sizeData < 4) {      /* something went wrong */      XFree((void *) ovInfo);      *numOverlays = 0;      return NULL;   }   *numOverlays = sizeData / 4;   return (OverlayInfo *) ovInfo;}/** * Return the level (overlay, normal, underlay) of a given XVisualInfo. * Input:  dpy - the X display *         vinfo - the XVisualInfo to test * Return:  level of the visual: *             0 = normal planes *            >0 = overlay planes *            <0 = underlay planes */static intlevel_of_visual( Display *dpy, XVisualInfo *vinfo ){   OverlayInfo *overlay_info;   int numOverlaysPerScreen, i;   overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);   if (!overlay_info) {      return 0;   }   /* search the overlay visual list for the visual ID of interest */   for (i = 0; i < numOverlaysPerScreen; i++) {      const OverlayInfo *ov = overlay_info + i;      if (ov->overlay_visual == vinfo->visualid) {         /* found the visual */         if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {            int level = ov->layer;            XFree((void *) overlay_info);            return level;         }         else {            XFree((void *) overlay_info);            return 0;         }      }   }   /* The visual ID was not found in the overlay list. */   XFree((void *) overlay_info);   return 0;}/* * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the * configuration in our list of GLX visuals. */static XMesaVisualsave_glx_visual( Display *dpy, XVisualInfo *vinfo,                 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,                 GLboolean stereoFlag,                 GLint depth_size, GLint stencil_size,                 GLint accumRedSize, GLint accumGreenSize,                 GLint accumBlueSize, GLint accumAlphaSize,                 GLint level, GLint numAuxBuffers ){   GLboolean ximageFlag = GL_TRUE;   XMesaVisual xmvis;   GLint i;   GLboolean comparePointers;   if (dbFlag) {      /* Check if the MESA_BACK_BUFFER env var is set */      char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");      if (backbuffer) {         if (backbuffer[0]=='p' || backbuffer[0]=='P') {            ximageFlag = GL_FALSE;         }         else if (backbuffer[0]=='x' || backbuffer[0]=='X') {            ximageFlag = GL_TRUE;         }         else {            _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");         }      }   }   if (stereoFlag) {      /* stereo not supported */      return NULL;   }   /* Comparing IDs uses less memory but sometimes fails. */   /* XXX revisit this after 3.0 is finished. */   if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))      comparePointers = GL_TRUE;   else      comparePointers = GL_FALSE;   /* Force the visual to have an alpha channel */   if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))      alphaFlag = GL_TRUE;   /* First check if a matching visual is already in the list */   for (i=0; i<NumVisuals; i++) {      XMesaVisual v = VisualTable[i];      if (v->display == dpy          && v->mesa_visual.level == level          && v->mesa_visual.numAuxBuffers == numAuxBuffers          && v->ximage_flag == ximageFlag          && v->mesa_visual.rgbMode == rgbFlag          && v->mesa_visual.doubleBufferMode == dbFlag          && v->mesa_visual.stereoMode == stereoFlag          && (v->mesa_visual.alphaBits > 0) == alphaFlag          && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)          && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)          && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)          && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)          && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)          && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {         /* now either compare XVisualInfo pointers or visual IDs */         if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)             || (comparePointers && v->vishandle == vinfo)) {            return v;         }      }   }   /* Create a new visual and add it to the list. */   xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,                              stereoFlag, ximageFlag,                              depth_size, stencil_size,                              accumRedSize, accumBlueSize,                              accumBlueSize, accumAlphaSize, 0, level,                              GLX_NONE_EXT );   if (xmvis) {      /* Save a copy of the pointer now so we can find this visual again       * if we need to search for it in find_glx_visual().       */      xmvis->vishandle = vinfo;      /* Allocate more space for additional visual */      VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable,                                    sizeof(XMesaVisual) * NumVisuals,                                    sizeof(XMesaVisual) * (NumVisuals + 1));      /* add xmvis to the list */      VisualTable[NumVisuals] = xmvis;      NumVisuals++;      /* XXX minor hack, because XMesaCreateVisual doesn't support an       * aux buffers parameter.       */      xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;   }   return xmvis;}/** * Return the default number of bits for the Z buffer. * If defined, use the MESA_GLX_DEPTH_BITS env var value. * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant. * XXX probably do the same thing for stencil, accum, etc. */static GLintdefault_depth_bits(void){   int zBits;   const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");   if (zEnv)      zBits = _mesa_atoi(zEnv);   else      zBits = DEFAULT_SOFTWARE_DEPTH_BITS;   return zBits;}static GLintdefault_alpha_bits(void){   int aBits;   const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");   if (aEnv)      aBits = _mesa_atoi(aEnv);   else      aBits = 0;   return aBits;}static GLintdefault_accum_bits(void){   return 16;}/* * Create a GLX visual from a regular XVisualInfo. * This is called when Fake GLX is given an XVisualInfo which wasn't * returned by glXChooseVisual.  Since this is the first time we're * considering this visual we'll take a guess at reasonable values * for depth buffer size, stencil size, accum size, etc. * This is the best we can do with a client-side emulation of GLX. */static XMesaVisualcreate_glx_visual( Display *dpy, XVisualInfo *visinfo ){   int vislevel;   GLint zBits = default_depth_bits();   GLint accBits = default_accum_bits();   GLboolean alphaFlag = default_alpha_bits() > 0;   vislevel = level_of_visual( dpy, visinfo );   if (vislevel) {      /* Configure this visual as a CI, single-buffered overlay */      return save_glx_visual( dpy, visinfo,                              GL_FALSE,  /* rgb */                              GL_FALSE,  /* alpha */                              GL_FALSE,  /* double */                              GL_FALSE,  /* stereo */                              0,         /* depth bits */                              0,         /* stencil bits */                              0,0,0,0,   /* accum bits */                              vislevel,  /* level */                              0          /* numAux */                            );   }   else if (is_usable_visual( visinfo )) {      if (_mesa_getenv("MESA_GLX_FORCE_CI")) {         /* Configure this visual as a COLOR INDEX visual. */         return save_glx_visual( dpy, visinfo,                                 GL_FALSE,   /* rgb */                                 GL_FALSE,  /* alpha */                                 GL_TRUE,   /* double */                                 GL_FALSE,  /* stereo */                                 zBits,                                 STENCIL_BITS,                                 0, 0, 0, 0, /* accum bits */                                 0,         /* level */                                 0          /* numAux */                               );      }      else {         /* Configure this visual as RGB, double-buffered, depth-buffered. */         /* This is surely wrong for some people's needs but what else */         /* can be done?  They should use glXChooseVisual(). */         return save_glx_visual( dpy, visinfo,                                 GL_TRUE,   /* rgb */                                 alphaFlag, /* alpha */

⌨️ 快捷键说明

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