CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/glew/visualinfo.c
Views: 1401
/*1** visualinfo.c2**3** Copyright (C) Nate Robins, 19974** Michael Wimmer, 19995** Milan Ikits, 2002-20086** Nigel Stewart, 2008-20137**8** visualinfo is a small utility that displays all available visuals,9** aka. pixelformats, in an OpenGL system along with renderer version10** information. It shows a table of all the visuals that support OpenGL11** along with their capabilities. The format of the table is similar to12** that of glxinfo on Unix systems:13**14** visual ~= pixel format descriptor15** id = visual id (integer from 1 - max visuals)16** tp = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)17** ac = acceleration (ge: generic, fu: full, no: none)18** fm = format (i: integer, f: float, c: color index)19** db = double buffer (y = yes)20** sw = swap method (x: exchange, c: copy, u: undefined)21** st = stereo (y = yes)22** sz = total # bits23** r = # bits of red24** g = # bits of green25** b = # bits of blue26** a = # bits of alpha27** axbf = # aux buffers28** dpth = # bits of depth29** stcl = # bits of stencil30*/3132#include <stdio.h>33#include <stdlib.h>34#include <string.h>35#include <GL/glew.h>36#if defined(GLEW_OSMESA)37#define GLAPI extern38#include <GL/osmesa.h>39#elif defined(GLEW_EGL)40#include <GL/eglew.h>41#elif defined(_WIN32)42#include <GL/wglew.h>43#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)44#include <OpenGL/OpenGL.h>45#include <OpenGL/CGLTypes.h>46#elif !defined(__HAIKU__)47#include <GL/glxew.h>48#endif4950#ifdef GLEW_MX51GLEWContext _glewctx;52# define glewGetContext() (&_glewctx)53# ifdef _WIN3254WGLEWContext _wglewctx;55# define wglewGetContext() (&_wglewctx)56# elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)57GLXEWContext _glxewctx;58# define glxewGetContext() (&_glxewctx)59# endif60#endif /* GLEW_MX */6162typedef struct GLContextStruct63{64#if defined(GLEW_OSMESA)65OSMesaContext ctx;66#elif defined(GLEW_EGL)67EGLContext ctx;68#elif defined(_WIN32)69HWND wnd;70HDC dc;71HGLRC rc;72#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)73CGLContextObj ctx, octx;74#elif !defined(__HAIKU__)75Display* dpy;76XVisualInfo* vi;77GLXContext ctx;78Window wnd;79Colormap cmap;80#endif81} GLContext;8283void InitContext (GLContext* ctx);84GLboolean CreateContext (GLContext* ctx);85void DestroyContext (GLContext* ctx);86void VisualInfo (GLContext* ctx);87void PrintExtensions (const char* s);88GLboolean ParseArgs (int argc, char** argv);8990int showall = 0;91int displaystdout = 0;92int verbose = 0;93int drawableonly = 0;9495char* display = NULL;96int visual = -1;9798FILE* file = 0;99100int101main (int argc, char** argv)102{103GLenum err;104GLContext ctx;105106/* ---------------------------------------------------------------------- */107/* parse arguments */108if (GL_TRUE == ParseArgs(argc-1, argv+1))109{110#if defined(_WIN32)111fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");112fprintf(stderr, " -a: show all visuals\n");113fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n");114fprintf(stderr, " -pf <id>: use given pixelformat\n");115fprintf(stderr, " -h: this screen\n");116#else117fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");118fprintf(stderr, " -h: this screen\n");119fprintf(stderr, " -display <display>: use given display\n");120fprintf(stderr, " -visual <id>: use given visual\n");121#endif122return 1;123}124125/* ---------------------------------------------------------------------- */126/* create OpenGL rendering context */127InitContext(&ctx);128if (GL_TRUE == CreateContext(&ctx))129{130fprintf(stderr, "Error: CreateContext failed\n");131DestroyContext(&ctx);132return 1;133}134135/* ---------------------------------------------------------------------- */136/* initialize GLEW */137glewExperimental = GL_TRUE;138#ifdef GLEW_MX139err = glewContextInit(glewGetContext());140# ifdef _WIN32141err = err || wglewContextInit(wglewGetContext());142# elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)143err = err || glxewContextInit(glxewGetContext());144# endif145#else146err = glewInit();147#endif148if (GLEW_OK != err)149{150fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));151DestroyContext(&ctx);152return 1;153}154155/* ---------------------------------------------------------------------- */156/* open file */157#if defined(_WIN32)158if (!displaystdout)159{160#if defined(_MSC_VER) && (_MSC_VER >= 1400)161if (fopen_s(&file, "visualinfo.txt", "w") != 0)162file = stdout;163#else164file = fopen("visualinfo.txt", "w");165#endif166}167if (file == NULL)168file = stdout;169#else170file = stdout;171#endif172173/* ---------------------------------------------------------------------- */174/* output header information */175/* OpenGL extensions */176fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR));177fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER));178fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION));179fprintf(file, "OpenGL extensions (GL_): \n");180PrintExtensions((const char*)glGetString(GL_EXTENSIONS));181182#ifndef GLEW_NO_GLU183/* GLU extensions */184fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION));185fprintf(file, "GLU extensions (GLU_): \n");186PrintExtensions((const char*)gluGetString(GLU_EXTENSIONS));187#endif188189/* ---------------------------------------------------------------------- */190/* extensions string */191#if defined(GLEW_OSMESA)192#elif defined(GLEW_EGL)193#elif defined(_WIN32)194/* WGL extensions */195if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)196{197fprintf(file, "WGL extensions (WGL_): \n");198PrintExtensions(wglGetExtensionsStringARB ?199(const char*)wglGetExtensionsStringARB(ctx.dc) :200(const char*)wglGetExtensionsStringEXT());201}202#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)203204#elif defined(__HAIKU__)205206/* TODO */207208#else209/* GLX extensions */210fprintf(file, "GLX extensions (GLX_): \n");211PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),212DefaultScreen(glXGetCurrentDisplay())));213#endif214215/* ---------------------------------------------------------------------- */216/* enumerate all the formats */217VisualInfo(&ctx);218219/* ---------------------------------------------------------------------- */220/* release resources */221DestroyContext(&ctx);222if (file != stdout)223fclose(file);224return 0;225}226227/* do the magic to separate all extensions with comma's, except228for the last one that _may_ terminate in a space. */229void PrintExtensions (const char* s)230{231char t[80];232int i=0;233char* p=0;234235t[79] = '\0';236while (*s)237{238t[i++] = *s;239if(*s == ' ')240{241if (*(s+1) != '\0') {242t[i-1] = ',';243t[i] = ' ';244p = &t[i++];245}246else /* zoinks! last one terminated in a space! */247{248t[i-1] = '\0';249}250}251if(i > 80 - 5)252{253*p = t[i] = '\0';254fprintf(file, " %s\n", t);255p++;256i = (int)strlen(p);257#if defined(_MSC_VER) && (_MSC_VER >= 1400)258strcpy_s(t, sizeof(t), p);259#else260strcpy(t, p);261#endif262}263s++;264}265t[i] = '\0';266fprintf(file, " %s.\n", t);267}268269/* ---------------------------------------------------------------------- */270271#if defined(GLEW_OSMESA) || defined(GLEW_EGL)272273void274VisualInfo (GLContext* ctx)275{276}277278#elif defined(_WIN32)279280void281VisualInfoARB (GLContext* ctx)282{283int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;284int i, pf, maxpf;285unsigned int c;286287/* to get pbuffer capable pixel formats */288attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;289attrib[1] = GL_TRUE;290attrib[2] = 0;291wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);292/* query number of pixel formats */293attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;294wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);295maxpf = value[0];296for (i=0; i<32; i++)297value[i] = 0;298299attrib[0] = WGL_SUPPORT_OPENGL_ARB;300attrib[1] = WGL_DRAW_TO_WINDOW_ARB;301attrib[2] = WGL_DRAW_TO_BITMAP_ARB;302attrib[3] = WGL_ACCELERATION_ARB;303/* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */304attrib[4] = WGL_SWAP_METHOD_ARB;305/* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */306attrib[5] = WGL_DOUBLE_BUFFER_ARB;307attrib[6] = WGL_STEREO_ARB;308attrib[7] = WGL_PIXEL_TYPE_ARB;309/* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,310WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */311/* Color buffer information */312attrib[8] = WGL_COLOR_BITS_ARB;313attrib[9] = WGL_RED_BITS_ARB;314attrib[10] = WGL_GREEN_BITS_ARB;315attrib[11] = WGL_BLUE_BITS_ARB;316attrib[12] = WGL_ALPHA_BITS_ARB;317/* Accumulation buffer information */318attrib[13] = WGL_ACCUM_BITS_ARB;319attrib[14] = WGL_ACCUM_RED_BITS_ARB;320attrib[15] = WGL_ACCUM_GREEN_BITS_ARB;321attrib[16] = WGL_ACCUM_BLUE_BITS_ARB;322attrib[17] = WGL_ACCUM_ALPHA_BITS_ARB;323/* Depth, stencil, and aux buffer information */324attrib[18] = WGL_DEPTH_BITS_ARB;325attrib[19] = WGL_STENCIL_BITS_ARB;326attrib[20] = WGL_AUX_BUFFERS_ARB;327/* Layer information */328attrib[21] = WGL_NUMBER_OVERLAYS_ARB;329attrib[22] = WGL_NUMBER_UNDERLAYS_ARB;330attrib[23] = WGL_SWAP_LAYER_BUFFERS_ARB;331attrib[24] = WGL_SAMPLES_ARB;332attrib[25] = WGL_SUPPORT_GDI_ARB;333n_attrib = 26;334if (WGLEW_ARB_pbuffer)335{336attrib[n_attrib] = WGL_DRAW_TO_PBUFFER_ARB;337n_pbuffer = n_attrib;338n_attrib++;339}340if (WGLEW_NV_float_buffer)341{342attrib[n_attrib] = WGL_FLOAT_COMPONENTS_NV;343n_float = n_attrib;344n_attrib++;345}346347if (!verbose)348{349/* print table header */350fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");351fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");352fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");353fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");354/* loop through all the pixel formats */355for(i = 1; i <= maxpf; i++)356{357wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);358/* only describe this format if it supports OpenGL */359if (!value[0]) continue;360/* by default show only fully accelerated window or pbuffer capable visuals */361if (!showall362&& ((value[2] && !value[1])363|| (!WGLEW_ARB_pbuffer || !value[n_pbuffer])364|| (value[3] != WGL_FULL_ACCELERATION_ARB))) continue;365/* print out the information for this visual */366/* visual id */367fprintf(file, " |% 4d | ", i);368/* visual type */369if (value[1])370{371if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "wp ");372else fprintf(file, "wn ");373}374else375{376if (value[2]) fprintf(file, "bm ");377else if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "pb ");378}379/* acceleration */380fprintf(file, "%s ", value[3] == WGL_FULL_ACCELERATION_ARB ? "fu" :381value[3] == WGL_GENERIC_ACCELERATION_ARB ? "ge" :382value[3] == WGL_NO_ACCELERATION_ARB ? "no" : ". ");383/* gdi support */384fprintf(file, " %c ", value[25] ? 'y' : '.');385/* format */386if (WGLEW_NV_float_buffer && value[n_float]) fprintf(file, " f ");387else if (WGLEW_ATI_pixel_format_float && value[7] == WGL_TYPE_RGBA_FLOAT_ATI) fprintf(file, " f ");388else if (value[7] == WGL_TYPE_RGBA_ARB) fprintf(file, " i ");389else if (value[7] == WGL_TYPE_COLORINDEX_ARB) fprintf(file, " c ");390else if (value[7] == WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT) fprintf(file," p ");391else fprintf(file," ? ");392/* double buffer */393fprintf(file, " %c ", value[5] ? 'y' : '.');394/* swap method */395if (value[4] == WGL_SWAP_EXCHANGE_ARB) fprintf(file, " x ");396else if (value[4] == WGL_SWAP_COPY_ARB) fprintf(file, " c ");397else if (value[4] == WGL_SWAP_UNDEFINED_ARB) fprintf(file, " . ");398else fprintf(file, " . ");399/* stereo */400fprintf(file, " %c ", value[6] ? 'y' : '.');401/* multisample */402if (value[24] > 0)403fprintf(file, "%2d | ", value[24]);404else405fprintf(file, " . | ");406/* color size */407if (value[8]) fprintf(file, "%3d ", value[8]);408else fprintf(file, " . ");409/* red */410if (value[9]) fprintf(file, "%2d ", value[9]);411else fprintf(file, " . ");412/* green */413if (value[10]) fprintf(file, "%2d ", value[10]);414else fprintf(file, " . ");415/* blue */416if (value[11]) fprintf(file, "%2d ", value[11]);417else fprintf(file, " . ");418/* alpha */419if (value[12]) fprintf(file, "%2d | ", value[12]);420else fprintf(file, " . | ");421/* aux buffers */422if (value[20]) fprintf(file, "%2d ", value[20]);423else fprintf(file, " . ");424/* depth */425if (value[18]) fprintf(file, "%2d ", value[18]);426else fprintf(file, " . ");427/* stencil */428if (value[19]) fprintf(file, "%2d | ", value[19]);429else fprintf(file, " . | ");430/* accum size */431if (value[13]) fprintf(file, "%3d ", value[13]);432else fprintf(file, " . ");433/* accum red */434if (value[14]) fprintf(file, "%2d ", value[14]);435else fprintf(file, " . ");436/* accum green */437if (value[15]) fprintf(file, "%2d ", value[15]);438else fprintf(file, " . ");439/* accum blue */440if (value[16]) fprintf(file, "%2d ", value[16]);441else fprintf(file, " . ");442/* accum alpha */443if (value[17]) fprintf(file, "%2d | ", value[17]);444else fprintf(file, " . | ");445/* overlay */446if (value[21]) fprintf(file, "%2d ", value[21]);447else fprintf(file, " . ");448/* underlay */449if (value[22]) fprintf(file, "%2d ", value[22]);450else fprintf(file, " . ");451/* layer swap */452if (value[23]) fprintf(file, "y ");453else fprintf(file, " . ");454fprintf(file, "|\n");455}456/* print table footer */457fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");458fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");459fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");460fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");461}462else /* verbose */463{464#if 0465fprintf(file, "\n");466/* loop through all the pixel formats */467for(i = 1; i <= maxpf; i++)468{469DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);470/* only describe this format if it supports OpenGL */471if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)472|| (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;473fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,474pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");475fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);476fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);477fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);478fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);479fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);480fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);481fprintf(file, " Opaque.\n");482}483#endif484}485}486487void488VisualInfoGDI (GLContext* ctx)489{490int i, maxpf;491PIXELFORMATDESCRIPTOR pfd;492493/* calling DescribePixelFormat() with NULL pfd (!!!) return maximum494number of pixel formats */495maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);496497if (!verbose)498{499fprintf(file, "-----------------------------------------------------------------------------\n");500fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");501fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");502fprintf(file, "-----------------------------------------------------------------------------\n");503504/* loop through all the pixel formats */505for(i = 1; i <= maxpf; i++)506{507DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);508/* only describe this format if it supports OpenGL */509if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)510|| (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;511/* other criteria could be tested here for actual pixel format512choosing in an application:513514for (...each pixel format...) {515if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&516pfd.dwFlags & PFD_DOUBLEBUFFER &&517pfd.cDepthBits >= 24 &&518pfd.cColorBits >= 24)519{520goto found;521}522}523... not found so exit ...524found:525... found so use it ...526*/527/* print out the information for this pixel format */528fprintf(file, "0x%02x ", i);529fprintf(file, "%3d ", pfd.cColorBits);530if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");531else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");532else fprintf(file, "pb ");533/* should find transparent pixel from LAYERPLANEDESCRIPTOR */534fprintf(file, " . ");535fprintf(file, "%3d ", pfd.cColorBits);536/* bReserved field indicates number of over/underlays */537if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);538else fprintf(file, " . ");539fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');540fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');541fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');542/* added: */543fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');544fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');545if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)546fprintf(file, "%2d ", pfd.cRedBits);547else fprintf(file, " . ");548if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)549fprintf(file, "%2d ", pfd.cGreenBits);550else fprintf(file, " . ");551if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)552fprintf(file, "%2d ", pfd.cBlueBits);553else fprintf(file, " . ");554if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)555fprintf(file, "%2d ", pfd.cAlphaBits);556else fprintf(file, " . ");557if(pfd.cAuxBuffers) fprintf(file, "%2d ", pfd.cAuxBuffers);558else fprintf(file, " . ");559if(pfd.cDepthBits) fprintf(file, "%2d ", pfd.cDepthBits);560else fprintf(file, " . ");561if(pfd.cStencilBits) fprintf(file, "%2d ", pfd.cStencilBits);562else fprintf(file, " . ");563if(pfd.cAccumBits) fprintf(file, "%3d ", pfd.cAccumBits);564else fprintf(file, " . ");565if(pfd.cAccumRedBits) fprintf(file, "%2d ", pfd.cAccumRedBits);566else fprintf(file, " . ");567if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);568else fprintf(file, " . ");569if(pfd.cAccumBlueBits) fprintf(file, "%2d ", pfd.cAccumBlueBits);570else fprintf(file, " . ");571if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);572else fprintf(file, " . ");573/* no multisample in win32 */574fprintf(file, " . .\n");575}576/* print table footer */577fprintf(file, "-----------------------------------------------------------------------------\n");578fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");579fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");580fprintf(file, "-----------------------------------------------------------------------------\n");581}582else /* verbose */583{584fprintf(file, "\n");585/* loop through all the pixel formats */586for(i = 1; i <= maxpf; i++)587{588DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);589/* only describe this format if it supports OpenGL */590if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)591|| (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;592fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,593pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");594fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%ld stereo=%ld\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);595fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);596fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);597fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);598fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);599fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);600fprintf(file, " Opaque.\n");601}602}603}604605void606VisualInfo (GLContext* ctx)607{608if (WGLEW_ARB_pixel_format)609VisualInfoARB(ctx);610else611VisualInfoGDI(ctx);612}613614/* ---------------------------------------------------------------------- */615616#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)617618void619VisualInfo (__attribute__((unused)) GLContext* ctx)620{621/*622int attrib[] = { AGL_RGBA, AGL_NONE };623AGLPixelFormat pf;624GLint value;625pf = aglChoosePixelFormat(NULL, 0, attrib);626while (pf != NULL)627{628aglDescribePixelFormat(pf, GL_RGBA, &value);629fprintf(stderr, "%d\n", value);630pf = aglNextPixelFormat(pf);631}632*/633}634635/* ---------------------------------------------------------------------- */636637#elif defined(__HAIKU__)638639void640VisualInfo (GLContext* ctx)641{642/* TODO */643}644645#else /* GLX */646647void648VisualInfo (GLContext* ctx)649{650int n_fbc;651GLXFBConfig* fbc;652int value, ret, i;653654fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);655656if (fbc)657{658if (!verbose)659{660/* print table header */661fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");662fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");663fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");664fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");665/* loop through all the fbcs */666for (i=0; i<n_fbc; i++)667{668/* print out the information for this fbc */669/* visual id */670ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FBCONFIG_ID, &value);671if (ret != Success)672{673fprintf(file, "| ? |");674}675else676{677fprintf(file, " |% 4d | ", value);678}679/* visual type */680ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DRAWABLE_TYPE, &value);681if (ret != Success)682{683fprintf(file, " ? ");684}685else686{687if (value & GLX_WINDOW_BIT)688{689if (value & GLX_PBUFFER_BIT)690{691fprintf(file, "wp ");692}693else694{695fprintf(file, "wn ");696}697}698else699{700if (value & GLX_PBUFFER_BIT)701{702fprintf(file, "pb ");703}704else if (value & GLX_PIXMAP_BIT)705{706fprintf(file, "pm ");707}708else709{710fprintf(file, " ? ");711}712}713}714/* x renderable */715ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_RENDERABLE, &value);716if (ret != Success)717{718fprintf(file, " ? ");719}720else721{722fprintf(file, value ? " y " : " n ");723}724/* class */725ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_VISUAL_TYPE, &value);726if (ret != Success)727{728fprintf(file, " ? ");729}730else731{732if (GLX_TRUE_COLOR == value)733fprintf(file, "tc ");734else if (GLX_DIRECT_COLOR == value)735fprintf(file, "dc ");736else if (GLX_PSEUDO_COLOR == value)737fprintf(file, "pc ");738else if (GLX_STATIC_COLOR == value)739fprintf(file, "sc ");740else if (GLX_GRAY_SCALE == value)741fprintf(file, "gs ");742else if (GLX_STATIC_GRAY == value)743fprintf(file, "sg ");744else if (GLX_X_VISUAL_TYPE == value)745fprintf(file, " . ");746else747fprintf(file, " ? ");748}749/* format */750ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RENDER_TYPE, &value);751if (ret != Success)752{753fprintf(file, " ? ");754}755else756{757if (GLXEW_NV_float_buffer)758{759int ret2, value2;760ret2 = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FLOAT_COMPONENTS_NV, &value2);761if (Success == ret2 && GL_TRUE == value2)762{763fprintf(file, " f ");764}765else if (value & GLX_RGBA_BIT)766fprintf(file, " i ");767else if (value & GLX_COLOR_INDEX_BIT)768fprintf(file, " c ");769else770fprintf(file, " ? ");771}772else773{774if (value & GLX_RGBA_FLOAT_ATI_BIT)775fprintf(file, " f ");776else if (value & GLX_RGBA_BIT)777fprintf(file, " i ");778else if (value & GLX_COLOR_INDEX_BIT)779fprintf(file, " c ");780else781fprintf(file, " ? ");782}783}784/* double buffer */785ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DOUBLEBUFFER, &value);786fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));787/* stereo */788ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STEREO, &value);789fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));790/* level */791ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_LEVEL, &value);792if (Success != ret)793{794fprintf(file, " ? ");795}796else797{798fprintf(file, "%2d ", value);799}800/* transparency */801ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_TRANSPARENT_TYPE, &value);802if (Success != ret)803{804fprintf(file, " ? | ");805}806else807{808if (GLX_TRANSPARENT_RGB == value)809fprintf(file, " r | ");810else if (GLX_TRANSPARENT_INDEX == value)811fprintf(file, " i | ");812else if (GLX_NONE == value)813fprintf(file, " . | ");814else815fprintf(file, " ? | ");816}817/* color size */818ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BUFFER_SIZE, &value);819if (Success != ret)820{821fprintf(file, " ? ");822}823else824{825if (value)826fprintf(file, "%3d ", value);827else828fprintf(file, " . ");829}830/* red size */831ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RED_SIZE, &value);832if (Success != ret)833{834fprintf(file, " ? ");835}836else837{838if (value)839fprintf(file, "%2d ", value);840else841fprintf(file, " . ");842}843/* green size */844ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_GREEN_SIZE, &value);845if (Success != ret)846{847fprintf(file, " ? ");848}849else850{851if (value)852fprintf(file, "%2d ", value);853else854fprintf(file, " . ");855}856/* blue size */857ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BLUE_SIZE, &value);858if (Success != ret)859{860fprintf(file, " ? ");861}862else863{864if (value)865fprintf(file, "%2d ", value);866else867fprintf(file, " . ");868}869/* alpha size */870ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ALPHA_SIZE, &value);871if (Success != ret)872{873fprintf(file, " ? | ");874}875else876{877if (value)878fprintf(file, "%2d | ", value);879else880fprintf(file, " . | ");881}882/* aux buffers */883ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_AUX_BUFFERS, &value);884if (Success != ret)885{886fprintf(file, " ? ");887}888else889{890if (value)891fprintf(file, "%2d ", value);892else893fprintf(file, " . ");894}895/* depth size */896ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DEPTH_SIZE, &value);897if (Success != ret)898{899fprintf(file, " ? ");900}901else902{903if (value)904fprintf(file, "%2d ", value);905else906fprintf(file, " . ");907}908/* stencil size */909ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STENCIL_SIZE, &value);910if (Success != ret)911{912fprintf(file, " ? | ");913}914else915{916if (value)917fprintf(file, "%2d | ", value);918else919fprintf(file, " . | ");920}921/* accum red size */922ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_RED_SIZE, &value);923if (Success != ret)924{925fprintf(file, " ? ");926}927else928{929if (value)930fprintf(file, "%2d ", value);931else932fprintf(file, " . ");933}934/* accum green size */935ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_GREEN_SIZE, &value);936if (Success != ret)937{938fprintf(file, " ? ");939}940else941{942if (value)943fprintf(file, "%2d ", value);944else945fprintf(file, " . ");946}947/* accum blue size */948ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_BLUE_SIZE, &value);949if (Success != ret)950{951fprintf(file, " ? ");952}953else954{955if (value)956fprintf(file, "%2d ", value);957else958fprintf(file, " . ");959}960/* accum alpha size */961ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_ALPHA_SIZE, &value);962if (Success != ret)963{964fprintf(file, " ? | ");965}966else967{968if (value)969fprintf(file, "%2d | ", value);970else971fprintf(file, " . | ");972}973/* multisample */974ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLES, &value);975if (Success != ret)976{977fprintf(file, " ? ");978}979else980{981fprintf(file, "%2d ", value);982}983ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLE_BUFFERS, &value);984if (Success != ret)985{986fprintf(file, " ? | ");987}988else989{990fprintf(file, "%2d | ", value);991}992/* caveat */993ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_CONFIG_CAVEAT, &value);994if (Success != ret)995{996fprintf(file, "???? |");997}998else999{1000if (GLX_NONE == value)1001fprintf(file, "none |\n");1002else if (GLX_SLOW_CONFIG == value)1003fprintf(file, "slow |\n");1004else if (GLX_NON_CONFORMANT_CONFIG == value)1005fprintf(file, "ncft |\n");1006else1007fprintf(file, "???? |\n");1008}1009}1010/* print table footer */1011fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");1012fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");1013fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");1014fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");1015}1016}1017}10181019#endif10201021/* ------------------------------------------------------------------------ */10221023#if defined(GLEW_OSMESA)1024void InitContext (GLContext* ctx)1025{1026ctx->ctx = NULL;1027}10281029static const GLint osmFormat = GL_UNSIGNED_BYTE;1030static const GLint osmWidth = 640;1031static const GLint osmHeight = 480;1032static GLubyte *osmPixels = NULL;10331034GLboolean CreateContext (GLContext* ctx)1035{1036if (NULL == ctx) return GL_TRUE;1037ctx->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);1038if (NULL == ctx->ctx) return GL_TRUE;1039if (NULL == osmPixels)1040{1041osmPixels = (GLubyte *) calloc(osmWidth*osmHeight*4, 1);1042}1043if (!OSMesaMakeCurrent(ctx->ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))1044{1045return GL_TRUE;1046}1047return GL_FALSE;1048}10491050void DestroyContext (GLContext* ctx)1051{1052if (NULL == ctx) return;1053if (NULL != ctx->ctx) OSMesaDestroyContext(ctx->ctx);1054}1055/* ------------------------------------------------------------------------ */10561057#elif defined(GLEW_EGL)1058void InitContext (GLContext* ctx)1059{1060ctx->ctx = NULL;1061}10621063GLboolean CreateContext (GLContext* ctx)1064{1065return GL_FALSE;1066}10671068void DestroyContext (GLContext* ctx)1069{1070if (NULL == ctx) return;1071return;1072}10731074/* ------------------------------------------------------------------------ */10751076#elif defined(_WIN32)10771078void InitContext (GLContext* ctx)1079{1080ctx->wnd = NULL;1081ctx->dc = NULL;1082ctx->rc = NULL;1083}10841085GLboolean CreateContext (GLContext* ctx)1086{1087WNDCLASS wc;1088PIXELFORMATDESCRIPTOR pfd;1089/* check for input */1090if (NULL == ctx) return GL_TRUE;1091/* register window class */1092ZeroMemory(&wc, sizeof(WNDCLASS));1093wc.hInstance = GetModuleHandle(NULL);1094wc.lpfnWndProc = DefWindowProc;1095wc.lpszClassName = "GLEW";1096if (0 == RegisterClass(&wc)) return GL_TRUE;1097/* create window */1098ctx->wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT,1099CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,1100GetModuleHandle(NULL), NULL);1101if (NULL == ctx->wnd) return GL_TRUE;1102/* get the device context */1103ctx->dc = GetDC(ctx->wnd);1104if (NULL == ctx->dc) return GL_TRUE;1105/* find pixel format */1106ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));1107if (visual == -1) /* find default */1108{1109pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);1110pfd.nVersion = 1;1111pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;1112visual = ChoosePixelFormat(ctx->dc, &pfd);1113if (0 == visual) return GL_TRUE;1114}1115/* set the pixel format for the dc */1116if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;1117/* create rendering context */1118ctx->rc = wglCreateContext(ctx->dc);1119if (NULL == ctx->rc) return GL_TRUE;1120if (FALSE == wglMakeCurrent(ctx->dc, ctx->rc)) return GL_TRUE;1121return GL_FALSE;1122}11231124void DestroyContext (GLContext* ctx)1125{1126if (NULL == ctx) return;1127if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);1128if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());1129if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);1130if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);1131UnregisterClass("GLEW", GetModuleHandle(NULL));1132}11331134/* ------------------------------------------------------------------------ */11351136#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)11371138void InitContext (GLContext* ctx)1139{1140ctx->ctx = NULL;1141ctx->octx = NULL;1142}11431144GLboolean CreateContext (GLContext* ctx)1145{1146CGLPixelFormatAttribute attrib[] = { kCGLPFAAccelerated, 0 };1147CGLPixelFormatObj pf;1148GLint npix;1149CGLError error;1150/* check input */1151if (NULL == ctx) return GL_TRUE;1152error = CGLChoosePixelFormat(attrib, &pf, &npix);1153if (error) return GL_TRUE;1154error = CGLCreateContext(pf, NULL, &ctx->ctx);1155if (error) return GL_TRUE;1156CGLReleasePixelFormat(pf);1157ctx->octx = CGLGetCurrentContext();1158error = CGLSetCurrentContext(ctx->ctx);1159if (error) return GL_TRUE;1160return GL_FALSE;1161}11621163void DestroyContext (GLContext* ctx)1164{1165if (NULL == ctx) return;1166CGLSetCurrentContext(ctx->octx);1167if (NULL != ctx->ctx) CGLReleaseContext(ctx->ctx);1168}11691170/* ------------------------------------------------------------------------ */11711172#elif defined(__HAIKU__)11731174void1175InitContext (GLContext* ctx)1176{1177/* TODO */1178}11791180GLboolean1181CreateContext (GLContext* ctx)1182{1183/* TODO */1184return GL_FALSE;1185}11861187void1188DestroyContext (GLContext* ctx)1189{1190/* TODO */1191}11921193/* ------------------------------------------------------------------------ */11941195#else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */11961197void InitContext (GLContext* ctx)1198{1199ctx->dpy = NULL;1200ctx->vi = NULL;1201ctx->ctx = NULL;1202ctx->wnd = 0;1203ctx->cmap = 0;1204}12051206GLboolean CreateContext (GLContext* ctx)1207{1208int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };1209int erb, evb;1210XSetWindowAttributes swa;1211/* check input */1212if (NULL == ctx) return GL_TRUE;1213/* open display */1214ctx->dpy = XOpenDisplay(display);1215if (NULL == ctx->dpy) return GL_TRUE;1216/* query for glx */1217if (!glXQueryExtension(ctx->dpy, &erb, &evb)) return GL_TRUE;1218/* choose visual */1219ctx->vi = glXChooseVisual(ctx->dpy, DefaultScreen(ctx->dpy), attrib);1220if (NULL == ctx->vi) return GL_TRUE;1221/* create context */1222ctx->ctx = glXCreateContext(ctx->dpy, ctx->vi, None, True);1223if (NULL == ctx->ctx) return GL_TRUE;1224/* create window */1225/*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/1226ctx->cmap = XCreateColormap(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),1227ctx->vi->visual, AllocNone);1228swa.border_pixel = 0;1229swa.colormap = ctx->cmap;1230ctx->wnd = XCreateWindow(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),12310, 0, 1, 1, 0, ctx->vi->depth, InputOutput, ctx->vi->visual,1232CWBorderPixel | CWColormap, &swa);1233/* make context current */1234if (!glXMakeCurrent(ctx->dpy, ctx->wnd, ctx->ctx)) return GL_TRUE;1235return GL_FALSE;1236}12371238void DestroyContext (GLContext* ctx)1239{1240if (NULL != ctx->dpy && NULL != ctx->ctx) glXDestroyContext(ctx->dpy, ctx->ctx);1241if (NULL != ctx->dpy && 0 != ctx->wnd) XDestroyWindow(ctx->dpy, ctx->wnd);1242if (NULL != ctx->dpy && 0 != ctx->cmap) XFreeColormap(ctx->dpy, ctx->cmap);1243if (NULL != ctx->vi) XFree(ctx->vi);1244if (NULL != ctx->dpy) XCloseDisplay(ctx->dpy);1245}12461247#endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */12481249GLboolean ParseArgs (int argc, char** argv)1250{1251int p = 0;1252while (p < argc)1253{1254#if defined(_WIN32)1255if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))1256{1257if (++p >= argc) return GL_TRUE;1258display = NULL;1259visual = strtol(argv[p], NULL, 0);1260}1261else if (!strcmp(argv[p], "-a"))1262{1263showall = 1;1264}1265else if (!strcmp(argv[p], "-s"))1266{1267displaystdout = 1;1268}1269else if (!strcmp(argv[p], "-h"))1270{1271return GL_TRUE;1272}1273else1274return GL_TRUE;1275#else1276if (!strcmp(argv[p], "-display"))1277{1278if (++p >= argc) return GL_TRUE;1279display = argv[p];1280}1281else if (!strcmp(argv[p], "-visual"))1282{1283if (++p >= argc) return GL_TRUE;1284visual = (int)strtol(argv[p], NULL, 0);1285}1286else if (!strcmp(argv[p], "-h"))1287{1288return GL_TRUE;1289}1290else1291return GL_TRUE;1292#endif1293p++;1294}1295return GL_FALSE;1296}129712981299