📄 glut_dstr.c
字号:
/* Copyright (c) Mark J. Kilgard, 1997. *//* This program is freely distributable without licensing fees and is provided without guarantee or warrantee expressed or implied. This program is -not- in the public domain. */#include <assert.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include "glutint.h"/* glxcaps matches the criteria macros listed in glutint.h, but only list the first set (those that correspond to GLX visual attributes). */static int glxcap[NUM_GLXCAPS] ={ GLX_RGBA, GLX_BUFFER_SIZE, GLX_DOUBLEBUFFER, GLX_STEREO, GLX_AUX_BUFFERS, GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, GLX_ALPHA_SIZE, GLX_DEPTH_SIZE, GLX_STENCIL_SIZE, GLX_ACCUM_RED_SIZE, GLX_ACCUM_GREEN_SIZE, GLX_ACCUM_BLUE_SIZE, GLX_ACCUM_ALPHA_SIZE, GLX_LEVEL,};#ifdef TEST#if !defined(_WIN32)char *__glutProgramName = "dstr";Display *__glutDisplay;int __glutScreen;XVisualInfo *(*__glutDetermineVisualFromString) (char *string, Bool * treatAsSingle, Criterion * requiredCriteria, int nRequired, int requiredMask, void **fbc) = NULL;char *__glutDisplayString = NULL;#endifstatic int verbose = 0;static char *compstr[] ={ "none", "=", "!=", "<=", ">=", ">", "<", "~"};static char *capstr[] ={ "rgba", "bufsize", "double", "stereo", "auxbufs", "red", "green", "blue", "alpha", "depth", "stencil", "acred", "acgreen", "acblue", "acalpha", "level", "xvisual", "transparent", "samples", "xstaticgray", "xgrayscale", "xstaticcolor", "xpseudocolor", "xtruecolor", "xdirectcolor", "slow", "conformant", "num"};static voidprintCriteria(Criterion * criteria, int ncriteria){ int i; printf("Criteria: %d\n", ncriteria); for (i = 0; i < ncriteria; i++) { printf(" %s %s %d\n", capstr[criteria[i].capability], compstr[criteria[i].comparison], criteria[i].value); }}#endif /* TEST */static int isMesaGLX = -1;static intdetermineMesaGLX(void){#ifdef GLX_VERSION_1_1 const char *vendor, *version, *ch; vendor = glXGetClientString(__glutDisplay, GLX_VENDOR); if (!strcmp(vendor, "Brian Paul")) { version = glXGetClientString(__glutDisplay, GLX_VERSION); for (ch = version; *ch != ' ' && *ch != '\0'; ch++); for (; *ch == ' ' && *ch != '\0'; ch++);#define MESA_NAME "Mesa " /* Trailing space is intentional. */ if (!strncmp(MESA_NAME, ch, sizeof(MESA_NAME) - 1)) { return 1; } }#else /* Recent versions for Mesa should support GLX 1.1 and therefore glXGetClientString. If we get into this case, we would be compiling against a true OpenGL not supporting GLX 1.1, and the resulting compiled library won't work well with Mesa then. */#endif return 0;}static XVisualInfo **getMesaVisualList(int *n){ XVisualInfo **vlist, *vinfo; int attribs[23]; int i, x, cnt; vlist = (XVisualInfo **) malloc((32 + 16) * sizeof(XVisualInfo *)); if (!vlist) __glutFatalError("out of memory."); cnt = 0; for (i = 0; i < 32; i++) { x = 0; attribs[x] = GLX_RGBA; x++; attribs[x] = GLX_RED_SIZE; x++; attribs[x] = 1; x++; attribs[x] = GLX_GREEN_SIZE; x++; attribs[x] = 1; x++; attribs[x] = GLX_BLUE_SIZE; x++; attribs[x] = 1; x++; if (i & 1) { attribs[x] = GLX_DEPTH_SIZE; x++; attribs[x] = 1; x++; } if (i & 2) { attribs[x] = GLX_STENCIL_SIZE; x++; attribs[x] = 1; x++; } if (i & 4) { attribs[x] = GLX_ACCUM_RED_SIZE; x++; attribs[x] = 1; x++; attribs[x] = GLX_ACCUM_GREEN_SIZE; x++; attribs[x] = 1; x++; attribs[x] = GLX_ACCUM_BLUE_SIZE; x++; attribs[x] = 1; x++; } if (i & 8) { attribs[x] = GLX_ALPHA_SIZE; x++; attribs[x] = 1; x++; if (i & 4) { attribs[x] = GLX_ACCUM_ALPHA_SIZE; x++; attribs[x] = 1; x++; } } if (i & 16) { attribs[x] = GLX_DOUBLEBUFFER; x++; } attribs[x] = None; x++; assert(x <= sizeof(attribs) / sizeof(attribs[0])); vinfo = glXChooseVisual(__glutDisplay, __glutScreen, attribs); if (vinfo) { vlist[cnt] = vinfo; cnt++; } } for (i = 0; i < 16; i++) { x = 0; if (i & 1) { attribs[x] = GLX_DEPTH_SIZE; x++; attribs[x] = 1; x++; } if (i & 2) { attribs[x] = GLX_STENCIL_SIZE; x++; attribs[x] = 1; x++; } if (i & 4) { attribs[x] = GLX_DOUBLEBUFFER; x++; } if (i & 8) { attribs[x] = GLX_LEVEL; x++; attribs[x] = 1; x++;#if defined(GLX_TRANSPARENT_TYPE_EXT) && defined(GLX_TRANSPARENT_INDEX_EXT) attribs[x] = GLX_TRANSPARENT_TYPE_EXT; x++; attribs[x] = GLX_TRANSPARENT_INDEX_EXT; x++;#endif } attribs[x] = None; x++; assert(x <= sizeof(attribs) / sizeof(attribs[0])); vinfo = glXChooseVisual(__glutDisplay, __glutScreen, attribs); if (vinfo) { vlist[cnt] = vinfo; cnt++; } } *n = cnt; return vlist;}static FrameBufferMode *loadVisuals(int *nitems_return){ XVisualInfo *vinfo, **vlist, template; FrameBufferMode *fbmodes, *mode; int n, i, j, rc, glcapable;#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample) int multisample;#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info) int visual_info;#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_rating) int visual_rating;#endif#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig) int fbconfig;#endif isMesaGLX = determineMesaGLX(); if (isMesaGLX) { vlist = getMesaVisualList(&n); } else {#if !defined(_WIN32) template.screen = __glutScreen; vinfo = XGetVisualInfo(__glutDisplay, VisualScreenMask, &template, &n);#else vinfo = XGetVisualInfo(__glutDisplay, 0, &template, &n);#endif if (vinfo == NULL) { *nitems_return = 0; return NULL; } assert(n > 0); /* Make an array of XVisualInfo* pointers to help the Mesa case because each glXChooseVisual call returns a distinct XVisualInfo*, not a handy array like XGetVisualInfo. (Mesa expects us to return the _exact_ pointer returned by glXChooseVisual so we could not just copy the returned structure.) */ vlist = (XVisualInfo **) malloc(n * sizeof(XVisualInfo *)); if (!vlist) __glutFatalError("out of memory."); for (i = 0; i < n; i++) { vlist[i] = &vinfo[i]; } }#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample) multisample = __glutIsSupportedByGLX("GLX_SGIS_multisample");#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info) visual_info = __glutIsSupportedByGLX("GLX_EXT_visual_info");#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_rating) visual_rating = __glutIsSupportedByGLX("GLX_EXT_visual_rating");#endif#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig) fbconfig = __glutIsSupportedByGLX("GLX_SGIX_fbconfig");#endif fbmodes = (FrameBufferMode *) malloc(n * sizeof(FrameBufferMode)); if (fbmodes == NULL) { *nitems_return = -1; return NULL; } for (i = 0; i < n; i++) { mode = &fbmodes[i]; mode->vi = vlist[i];#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig) mode->fbc = NULL;#endif rc = glXGetConfig(__glutDisplay, vlist[i], GLX_USE_GL, &glcapable); if (rc == 0 && glcapable) { mode->valid = 1; /* Assume the best until proven otherwise. */ for (j = 0; j < NUM_GLXCAPS; j++) { rc = glXGetConfig(__glutDisplay, vlist[i], glxcap[j], &mode->cap[j]); if (rc != 0) { mode->valid = 0; } }#if defined(_WIN32) mode->cap[XVISUAL] = ChoosePixelFormat(XHDC, vlist[i]);#else mode->cap[XVISUAL] = (int) vlist[i]->visualid;#endif mode->cap[XSTATICGRAY] = 0; mode->cap[XGRAYSCALE] = 0; mode->cap[XSTATICCOLOR] = 0; mode->cap[XPSEUDOCOLOR] = 0; mode->cap[XTRUECOLOR] = 0; mode->cap[XDIRECTCOLOR] = 0;#if !defined(_WIN32)#if defined(__cplusplus) || defined(c_plusplus) switch (vlist[i]->c_class) {#else switch (vlist[i]->class) {#endif case StaticGray: mode->cap[XSTATICGRAY] = 1; break; case GrayScale: mode->cap[XGRAYSCALE] = 1; break; case StaticColor: mode->cap[XSTATICCOLOR] = 1; break; case PseudoColor: mode->cap[XPSEUDOCOLOR] = 1; break; case TrueColor: mode->cap[XTRUECOLOR] = 1; break; case DirectColor: mode->cap[XDIRECTCOLOR] = 1; break; }#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_rating) if (visual_rating) { int rating;/* babcock@cs.montana.edu reported that DEC UNIX (OSF1) V4.0 564 for Alpha did not properly define GLX_VISUAL_CAVEAT_EXT in <GL/glx.h> despite claiming to support GLX_EXT_visual_rating. */#ifndef GLX_VISUAL_CAVEAT_EXT#define GLX_VISUAL_CAVEAT_EXT 0x20#endif rc = glXGetConfig(__glutDisplay, vlist[i], GLX_VISUAL_CAVEAT_EXT, &rating); if (rc != 0) { mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 1; } else { switch (rating) { case GLX_SLOW_VISUAL_EXT: mode->cap[SLOW] = 1; mode->cap[CONFORMANT] = 1; break;/* IRIX 5.3 for the R10K Indigo2 may have shipped without this properly defined in /usr/include/GL/glxtokens.h */#ifndef GLX_NON_CONFORMANT_VISUAL_EXT#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D#endif case GLX_NON_CONFORMANT_VISUAL_EXT: mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 0; break; case GLX_NONE_EXT: default: /* XXX Hopefully this is a good default assumption. */ mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 1; break; } } } else { mode->cap[TRANSPARENT] = 0; }#else mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 1;#endif#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info) if (visual_info) { int transparent;/* babcock@cs.montana.edu reported that DEC UNIX (OSF1) V4.0 564 for Alpha did not properly define GLX_TRANSPARENT_TYPE_EXT in <GL/glx.h> despite claiming to support GLX_EXT_visual_info. */#ifndef GLX_TRANSPARENT_TYPE_EXT#define GLX_TRANSPARENT_TYPE_EXT 0x23#endif rc = glXGetConfig(__glutDisplay, vlist[i], GLX_TRANSPARENT_TYPE_EXT, &transparent); if (rc != 0) { mode->cap[TRANSPARENT] = 0; } else { mode->cap[TRANSPARENT] = (transparent != GLX_NONE_EXT); } } else { mode->cap[TRANSPARENT] = 0; }#else mode->cap[TRANSPARENT] = 0;#endif#if defined(GLX_VERSION_1_1) && defined(GLX_SGIS_multisample) if (multisample) { rc = glXGetConfig(__glutDisplay, vlist[i], GLX_SAMPLES_SGIS, &mode->cap[SAMPLES]); if (rc != 0) { mode->cap[SAMPLES] = 0; } } else { mode->cap[SAMPLES] = 0; }#else mode->cap[SAMPLES] = 0;#endif } else {#if defined(GLX_VERSION_1_1) && defined(GLX_SGIX_fbconfig) if (fbconfig) { GLXFBConfigSGIX fbc; int fbconfigID, drawType, renderType; fbc = __glut_glXGetFBConfigFromVisualSGIX(__glutDisplay, vlist[i]); if (fbc) { rc = __glut_glXGetFBConfigAttribSGIX(__glutDisplay, fbc, GLX_FBCONFIG_ID_SGIX, &fbconfigID); if ((rc == 0) && (fbconfigID != None)) { rc = __glut_glXGetFBConfigAttribSGIX(__glutDisplay, fbc, GLX_DRAWABLE_TYPE_SGIX, &drawType); if ((rc == 0) && (drawType & GLX_WINDOW_BIT_SGIX)) { rc = __glut_glXGetFBConfigAttribSGIX(__glutDisplay, fbc, GLX_RENDER_TYPE_SGIX, &renderType); if ((rc == 0) && (renderType & GLX_RGBA_BIT_SGIX)) { mode->fbc = fbc; mode->valid = 1; /* Assume the best until proven otherwise. */ assert(glxcap[0] == GLX_RGBA); mode->cap[0] = 1; /* Start with "j = 1" to skip the GLX_RGBA attribute. */ for (j = 1; j < NUM_GLXCAPS; j++) { rc = __glut_glXGetFBConfigAttribSGIX(__glutDisplay, fbc, glxcap[j], &mode->cap[j]); if (rc != 0) { mode->valid = 0; } } mode->cap[XVISUAL] = (int) vlist[i]->visualid; mode->cap[XSTATICGRAY] = 0; mode->cap[XGRAYSCALE] = 0; mode->cap[XSTATICCOLOR] = 0; mode->cap[XPSEUDOCOLOR] = 0; mode->cap[XTRUECOLOR] = 0; mode->cap[XDIRECTCOLOR] = 0;#if defined(__cplusplus) || defined(c_plusplus) switch (vlist[i]->c_class) {#else switch (vlist[i]->class) {#endif case StaticGray: mode->cap[XSTATICGRAY] = 1; break; case GrayScale: mode->cap[XGRAYSCALE] = 1; break; case StaticColor: mode->cap[XSTATICCOLOR] = 1; break; case PseudoColor: mode->cap[XPSEUDOCOLOR] = 1; break; case TrueColor: mode->cap[XTRUECOLOR] = 1; break; case DirectColor: mode->cap[XDIRECTCOLOR] = 1; break; }#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_rating) if (visual_rating) { int rating;/* babcock@cs.montana.edu reported that DEC UNIX (OSF1) V4.0 564 for Alpha did not properly define GLX_VISUAL_CAVEAT_EXT in <GL/glx.h> despite claiming to support GLX_EXT_visual_rating. */#ifndef GLX_VISUAL_CAVEAT_EXT#define GLX_VISUAL_CAVEAT_EXT 0x20#endif rc = __glut_glXGetFBConfigAttribSGIX(__glutDisplay, fbc, GLX_VISUAL_CAVEAT_EXT, &rating); if (rc != 0) { mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 1; } else { switch (rating) { case GLX_SLOW_VISUAL_EXT: mode->cap[SLOW] = 1; mode->cap[CONFORMANT] = 1; break;/* IRIX 5.3 for the R10K Indigo2 may have shipped without this properly defined in /usr/include/GL/glxtokens.h */#ifndef GLX_NON_CONFORMANT_VISUAL_EXT#define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D#endif case GLX_NON_CONFORMANT_VISUAL_EXT: mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 0; break; case GLX_NONE_EXT: default: /* XXX Hopefully this is a good default assumption. */ mode->cap[SLOW] = 0; mode->cap[CONFORMANT] = 1; break; } } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -