fixed visualinfo and ptrdiff bug

git-svn-id: https://glew.svn.sourceforge.net/svnroot/glew/trunk/glew@283 783a27ee-832a-0410-bc00-9f386506c6dd
This commit is contained in:
ikits 2004-09-06 15:12:40 +00:00
parent 82b540177c
commit 065a445c51
2 changed files with 418 additions and 394 deletions

View File

@ -132,13 +132,14 @@
# define _W64 # define _W64
# endif # endif
#endif #endif
#ifndef _PTRDIFF_T_DEFINED #if !defined(_PTRDIFF_T_DEFINED) && !defined(_PTRDIFF_T_)
# ifdef _WIN64 # ifdef _WIN64
typedef __int64 ptrdiff_t; typedef __int64 ptrdiff_t;
# else # else
typedef _W64 int ptrdiff_t; typedef _W64 int ptrdiff_t;
# endif # endif
# define _PTRDIFF_T_DEFINED # define _PTRDIFF_T_DEFINED
# define _PTRDIFF_T_
#endif #endif
#ifndef GLAPI #ifndef GLAPI

View File

@ -35,7 +35,9 @@
#include <GL/glew.h> #include <GL/glew.h>
#if defined(_WIN32) #if defined(_WIN32)
#include <GL/wglew.h> #include <GL/wglew.h>
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
#include <AGL/agl.h>
#else
#include <GL/glxew.h> #include <GL/glxew.h>
#endif #endif
@ -57,14 +59,14 @@ typedef struct GLContextStruct
HWND wnd; HWND wnd;
HDC dc; HDC dc;
HGLRC rc; HGLRC rc;
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
AGLContext ctx, octx;
#else
Display* dpy; Display* dpy;
XVisualInfo* vi; XVisualInfo* vi;
GLXContext ctx; GLXContext ctx;
Window wnd; Window wnd;
Colormap cmap; Colormap cmap;
#else
AGLContext ctx, octx;
#endif #endif
} GLContext; } GLContext;
@ -78,26 +80,37 @@ GLboolean ParseArgs (int argc, char** argv);
int showall = 0; int showall = 0;
int displaystdout = 0; int displaystdout = 0;
int verbose = 0; int verbose = 0;
int drawableonly = 0;
char* display = NULL; char* display = NULL;
int visual = -1; int visual = -1;
FILE* file = 0; FILE* file = 0;
GLContext ctx; GLContext ctx;
GLenum err;
int int
main (int argc, char** argv) main (int argc, char** argv)
{ {
GLenum err;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* parse arguments */ /* parse arguments */
if (GL_TRUE == ParseArgs(argc-1, argv+1)) if (GL_TRUE == ParseArgs(argc-1, argv+1))
{ {
fprintf(stderr, "Usage: visualinfo [-v] [-a] [-s] [-h] [-display <display>] [-visual <id>]\n"); #if defined(_WIN32)
fprintf(stderr, " -v: print visual info in verbose form\n"); fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
fprintf(stderr, " -a: show all visuals\n");
fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n");
fprintf(stderr, " -pf <id>: use given pixelformat\n");
fprintf(stderr, " -h: this screen\n");
#else
fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-display <display>] [-visual <id>]\n");
fprintf(stderr, " -a: show all visuals\n"); fprintf(stderr, " -a: show all visuals\n");
fprintf(stderr, " -s: display to stdout instead of visualinfo.txt (Windows only)\n"); fprintf(stderr, " -s: display to stdout instead of visualinfo.txt (Windows only)\n");
fprintf(stderr, " -h: this screen\n"); fprintf(stderr, " -h: this screen\n");
fprintf(stderr, " -display <display>: use given display\n");
fprintf(stderr, " -visual <id>: use given visual\n");
#endif
return 1; return 1;
} }
@ -162,9 +175,12 @@ main (int argc, char** argv)
if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string) if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)
{ {
fprintf(file, "WGL extensions (WGL_): \n"); fprintf(file, "WGL extensions (WGL_): \n");
PrintExtensions(wglGetExtensionsStringARB ? (char*)wglGetExtensionsStringARB(hDC) : PrintExtensions(wglGetExtensionsStringARB ?
(char*)wglGetExtensionsStringARB(ctx.dc) :
(char*)wglGetExtensionsStringEXT()); (char*)wglGetExtensionsStringEXT());
} }
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
#else #else
/* GLX extensions */ /* GLX extensions */
fprintf(file, "GLX extensions (GLX_): \n"); fprintf(file, "GLX extensions (GLX_): \n");
@ -230,24 +246,19 @@ void PrintExtensions (const char* s)
void void
VisualInfoARB (GLContext* ctx) VisualInfoARB (GLContext* ctx)
{ {
int attrib[32], value[32], n_attrib, n_pbuffer, n_float; int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;
int i, maxpf; int i, pf, maxpf;
int attrib[16], value[16], pf;
unsigned int c; unsigned int c;
/* to get pbuffer capable pixel formats */
attrib[0] = WGL_DRAW_TO_PBUFFER_ARB; attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;
attrib[1] = GL_TRUE; attrib[1] = GL_TRUE;
attrib[2] = 0; attrib[2] = 0;
wglChoosePixelFormatARB(hDC, attrib, 0, 1, &pf, &c); wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);
/* query number of pixel formats */
attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB; attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
wglGetPixelFormatAttribivARB(hDC, 0, 0, 1, attrib, value); wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);
attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
wglGetPixelFormatAttribivARB(hDC, 1, 0, 1, attrib, value);
maxpf = value[0]; maxpf = value[0];
for (i=0; i<32; i++) for (i=0; i<32; i++)
value[i] = 0; value[i] = 0;
@ -309,7 +320,7 @@ VisualInfoARB (GLContext* ctx)
/* loop through all the pixel formats */ /* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++) for(i = 1; i <= maxpf; i++)
{ {
wglGetPixelFormatAttribivARB(hDC, i, 0, n_attrib, attrib, value); wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);
/* only describe this format if it supports OpenGL */ /* only describe this format if it supports OpenGL */
if (!value[0]) continue; if (!value[0]) continue;
/* by default show only fully accelerated window or pbuffer capable visuals */ /* by default show only fully accelerated window or pbuffer capable visuals */
@ -355,7 +366,7 @@ VisualInfoARB (GLContext* ctx)
if (value[24] > 0) if (value[24] > 0)
fprintf(file, "%2d | ", value[24]); fprintf(file, "%2d | ", value[24]);
else else
fprintf(file, " . | ", value[24]); fprintf(file, " . | ");
/* color size */ /* color size */
if (value[8]) fprintf(file, "%3d ", value[8]); if (value[8]) fprintf(file, "%3d ", value[8]);
else fprintf(file, " . "); else fprintf(file, " . ");
@ -419,7 +430,7 @@ VisualInfoARB (GLContext* ctx)
/* loop through all the pixel formats */ /* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++) for(i = 1; i <= maxpf; i++)
{ {
DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* only describe this format if it supports OpenGL */ /* only describe this format if it supports OpenGL */
if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL) if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
|| (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue; || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
@ -438,14 +449,14 @@ VisualInfoARB (GLContext* ctx)
} }
void void
VisualInfo (HDC hDC, int verbose) VisualInfoGDI (GLContext* ctx)
{ {
int i, maxpf; int i, maxpf;
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
/* calling DescribePixelFormat() with NULL pfd (!!!) return maximum /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
number of pixel formats */ number of pixel formats */
maxpf = DescribePixelFormat(hDC, 1, 0, NULL); maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
if (!verbose) if (!verbose)
{ {
@ -457,7 +468,7 @@ VisualInfo (HDC hDC, int verbose)
/* loop through all the pixel formats */ /* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++) for(i = 1; i <= maxpf; i++)
{ {
DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* only describe this format if it supports OpenGL */ /* only describe this format if it supports OpenGL */
if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL) if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
|| (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue; || (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
@ -538,13 +549,13 @@ VisualInfo (HDC hDC, int verbose)
/* loop through all the pixel formats */ /* loop through all the pixel formats */
for(i = 1; i <= maxpf; i++) for(i = 1; i <= maxpf; i++)
{ {
DescribePixelFormat(hDC, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
/* only describe this format if it supports OpenGL */ /* only describe this format if it supports OpenGL */
if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL) if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
|| (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue; || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits, fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor"); pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
fprintf(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); fprintf(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);
fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED); fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits); fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits); fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
@ -566,7 +577,26 @@ VisualInfo (GLContext* ctx)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
#else /* _WIN32 */ #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
void
VisualInfo (GLContext* ctx)
{
/*
int attrib[] = { AGL_RGBA, AGL_NONE };
AGLPixelFormat pf;
GLint value;
pf = aglChoosePixelFormat(NULL, 0, attrib);
while (pf != NULL)
{
aglDescribePixelFormat(pf, GL_RGBA, &value);
fprintf(stderr, "%d\n", value);
pf = aglNextPixelFormat(pf);
}
*/
}
#else /* GLX */
void void
VisualInfo (GLContext* ctx) VisualInfo (GLContext* ctx)
@ -577,6 +607,8 @@ VisualInfo (GLContext* ctx)
fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc); fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);
if (fbc)
{
if (!verbose) if (!verbose)
{ {
/* print table header */ /* print table header */
@ -936,6 +968,7 @@ VisualInfo (GLContext* ctx)
fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n"); fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
} }
} }
}
#endif #endif
@ -954,7 +987,6 @@ GLboolean CreateContext (GLContext* ctx)
{ {
WNDCLASS wc; WNDCLASS wc;
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd;
int pf;
/* check for input */ /* check for input */
if (NULL == ctx) return GL_TRUE; if (NULL == ctx) return GL_TRUE;
/* register window class */ /* register window class */
@ -973,13 +1005,16 @@ GLboolean CreateContext (GLContext* ctx)
if (NULL == ctx->dc) return GL_TRUE; if (NULL == ctx->dc) return GL_TRUE;
/* find pixel format */ /* find pixel format */
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR)); ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
if (visual == -1) /* find default */
{
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1; pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pf = ChoosePixelFormat(ctx->dc, &pfd); visual = ChoosePixelFormat(ctx->dc, &pfd);
if (0 == pf) return GL_TRUE; if (0 == visual) return GL_TRUE;
}
/* set the pixel format for the dc */ /* set the pixel format for the dc */
if (FALSE == SetPixelFormat(ctx->dc, pf, &pfd)) return GL_TRUE; if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;
/* create rendering context */ /* create rendering context */
ctx->rc = wglCreateContext(ctx->dc); ctx->rc = wglCreateContext(ctx->dc);
if (NULL == ctx->rc) return GL_TRUE; if (NULL == ctx->rc) return GL_TRUE;
@ -1001,8 +1036,6 @@ void DestroyContext (GLContext* ctx)
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
#include <AGL/agl.h>
void InitContext (GLContext* ctx) void InitContext (GLContext* ctx)
{ {
ctx->ctx = NULL; ctx->ctx = NULL;
@ -1093,7 +1126,6 @@ void DestroyContext (GLContext* ctx)
#endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */ #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean ParseArgs (int argc, char** argv) GLboolean ParseArgs (int argc, char** argv)
{ {
int p = 0; int p = 0;
@ -1104,7 +1136,19 @@ GLboolean ParseArgs (int argc, char** argv)
{ {
if (++p >= argc) return GL_TRUE; if (++p >= argc) return GL_TRUE;
display = NULL; display = NULL;
visual = strtol(argv[p++], NULL, 0); visual = strtol(argv[p], NULL, 0);
}
else if (!strcmp(argv[p], "-a"))
{
showall = 1;
}
else if (!strcmp(argv[p], "-s"))
{
displaystdout = 1;
}
else if (!strcmp(argv[p], "-h"))
{
return GL_TRUE;
} }
else else
return GL_TRUE; return GL_TRUE;
@ -1112,38 +1156,17 @@ GLboolean ParseArgs (int argc, char** argv)
if (!strcmp(argv[p], "-display")) if (!strcmp(argv[p], "-display"))
{ {
if (++p >= argc) return GL_TRUE; if (++p >= argc) return GL_TRUE;
display = argv[p++]; display = argv[p];
} }
else if (!strcmp(argv[p], "-visual")) else if (!strcmp(argv[p], "-visual"))
{ {
if (++p >= argc) return GL_TRUE; if (++p >= argc) return GL_TRUE;
visual = (int)strtol(argv[p++], NULL, 0); visual = (int)strtol(argv[p], NULL, 0);
} }
else else
return GL_TRUE; return GL_TRUE;
#endif #endif
p++;
} }
return GL_FALSE; return GL_FALSE;
} }
#endif
/* while (--argc) */
/* { */
/* if (strcmp("-h", argv[argc]) == 0) */
/* { */
/* } */
/* else if (strcmp("-v", argv[argc]) == 0) */
/* { */
/* verbose = 1; */
/* } */
/* else if (strcmp("-a", argv[argc]) == 0) */
/* { */
/* showall = 1; */
/* } */
/* else if (strcmp("-s", argv[argc]) == 0) */
/* { */
/* displaystdout = 1; */
/* } */
/* else if (str */
/* } */