This commit is contained in:
Nigel Stewart 2015-05-29 10:49:05 +00:00
commit 0bbdd5d870
14 changed files with 476 additions and 90 deletions

View File

@ -198,6 +198,15 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
$(BIN)/make_def_var.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_def_var.pl GL $(GL_EXT_SPEC) >> $@
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
echo -e "\nstatic const char * _glewExtensionLookup[] = {" >> $@;
$(BIN)/make_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@
echo -e " NULL\n};\n" >> $@;
echo -e "\n#if !defined(GLEW_MX)" >> $@;
$(BIN)/make_enable_index.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@
echo -e "\n#endif /* !GLEW_MX */\n" >> $@;
$(BIN)/make_initd.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_initd.pl GL $(GL_EXT_SPEC) >> $@
echo -e "" >> $@;
$(BIN)/make_init.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_init.pl GL $(GL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_gl.c >> $@

View File

@ -19,7 +19,7 @@ our $type = shift;
if (@ARGV)
{
@extlist = @ARGV;
@extlist = @ARGV;
foreach my $ext (sort @extlist)
{

45
auto/bin/make_enable_index.pl Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/perl
##
## Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
## Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
##
## This program is distributed under the terms and conditions of the GNU
## General Public License Version 2 as published by the Free Software
## Foundation or, at your option, any later version.
use strict;
use warnings;
do 'bin/make.pl';
##
## Make Extension-enabled Index
##
my @extlist = ();
if (@ARGV)
{
@extlist = @ARGV;
print "/* Detected in the extension string or strings */\n";
print "static GLboolean _glewExtensionString[" . scalar @extlist . "];\n";
print "/* Detected via extension string or experimental mode */\n";
print "static GLboolean* _glewExtensionEnabled[] = {\n";;
foreach my $ext (sort @extlist)
{
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) =
parse_ext($ext);
my $extvar = $extname;
$extvar =~ s/GL(X*)_/GL$1EW_/;
print "#ifdef $extname\n";
print " &__$extvar,\n";
print "#endif\n";
}
print " NULL\n};\n";
}

38
auto/bin/make_index.pl Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/perl
##
## Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
## Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
##
## This program is distributed under the terms and conditions of the GNU
## General Public License Version 2 as published by the Free Software
## Foundation or, at your option, any later version.
use strict;
use warnings;
do 'bin/make.pl';
##
## Make Index
##
## Output sorted array of extension strings for indexing into extension
## enable/disable flags. This provides a way to convert an extension string
## into an integer index.
##
my @extlist = ();
if (@ARGV)
{
@extlist = @ARGV;
foreach my $ext (sort @extlist)
{
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) =
parse_ext($ext);
print "#ifdef $extname\n";
print " \"$extname\",\n";
print "#endif\n";
}
}

View File

@ -38,18 +38,17 @@ if (@ARGV)
parse_ext($ext);
#make_separator($extname);
print "#ifdef $extname\n\n";
my $extvar = $extname;
my $extvardef = $extname;
$extvar =~ s/GL(X*)_/GL$1EW_/;
if (keys %$functions)
{
print "#ifdef $extname\n\n";
print "static GLboolean _glewInit_$extname (" . $type .
"EW_CONTEXT_ARG_DEF_INIT)\n{\n GLboolean r = GL_FALSE;\n";
output_decls($functions, \&make_pfn_def_init);
print "\n return r;\n}\n\n";
print "#endif /* $extname */\n\n";
}
#print "\nGLboolean " . prefix_varname($extvar) . " = GL_FALSE;\n\n";
print "#endif /* $extname */\n\n";
}
}

44
auto/bin/make_initd.pl Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/perl
##
## Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
## Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
##
## This program is distributed under the terms and conditions of the GNU
## General Public License Version 2 as published by the Free Software
## Foundation or, at your option, any later version.
use strict;
use warnings;
do 'bin/make.pl';
## Output declarations for the _glewInit_[extension] functions defined
## by make_init.pl script. These are necessary for for initializers to
## call each other, such as a core GL 3 context that depends on certain
## extensions.
#-------------------------------------------------------------------------------
my @extlist = ();
my %extensions = ();
our $type = shift;
if (@ARGV)
{
@extlist = @ARGV;
foreach my $ext (sort @extlist)
{
my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) =
parse_ext($ext);
#print "#ifdef $extname\n\n";
if (keys %$functions)
{
print "static GLboolean _glewInit_$extname (" . $type .
"EW_CONTEXT_ARG_DEF_INIT);\n";
}
#print "#endif /* $extname */\n\n";
}
}

View File

@ -44,7 +44,7 @@ if (@ARGV)
print "#ifdef $extname\n";
if (length($extstring))
if (length($extstring) && $extstring !~ /^GL_/)
{
print " " . $extvar . " = _glewSearchExtension(\"$extstring\", extStart, extEnd);\n";
}

View File

@ -186,6 +186,7 @@ void* NSGLGetProcAddress (const GLubyte *name)
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
* These functions implement the functionality required in this file.
*/
static GLuint _glewStrLen (const GLubyte* s)
{
GLuint i=0;
@ -202,6 +203,23 @@ static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
return (s[i] == '\0' || s[i] == c) ? i : 0;
}
static GLubyte *_glewStrDup (const GLubyte *s)
{
int n = _glewStrLen(s);
GLubyte *dup = malloc(n+1);
if (dup)
{
GLubyte *i = dup;
for (;;)
{
*i = *s;
if (*i) { ++i; ++s; } else break;
}
}
return dup;
}
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
{
GLuint i=0;
@ -210,6 +228,7 @@ static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++;
return i == n ? GL_TRUE : GL_FALSE;
}
#endif
static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
{
@ -270,6 +289,7 @@ static GLboolean _glewStrSame3 (const GLubyte** a, GLuint* na, const GLubyte* b,
* other extension names. Could use strtok() but the constant
* string returned by glGetString might be in read-only memory.
*/
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end)
{
const GLubyte* p;
@ -283,3 +303,4 @@ static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, c
}
return GL_FALSE;
}
#endif

View File

@ -1,14 +1,60 @@
/* ------------------------------------------------------------------------- */
static int _glewExtensionCompare(const void *a, const void *b)
{
return strcmp((const char *) a, *(const char * const *) b);
}
static GLboolean *_glewGetExtensionString(const char *name)
{
const char **n = (const char **) bsearch(name, _glewExtensionLookup, sizeof(_glewExtensionLookup)/sizeof(char *)-1, sizeof(char *), _glewExtensionCompare);
int i;
if (n)
{
i = n-_glewExtensionLookup;
return _glewExtensionString+i;
}
return NULL;
}
static GLboolean *_glewGetExtensionEnable(const char *name)
{
const char **n = (const char **) bsearch(name, _glewExtensionLookup, sizeof(_glewExtensionLookup)/sizeof(char *)-1, sizeof(char *), _glewExtensionCompare);
int i;
if (n)
{
i = n-_glewExtensionLookup;
return _glewExtensionEnabled[i];
}
return NULL;
}
static char *_glewNextSpace(char *i)
{
char *j = i;
if (j)
while (*j!=' ' && *j) ++j;
return j;
}
static char *_glewNextNonSpace(char *i)
{
char *j = i;
if (j)
while (*j==' ') ++j;
return j;
}
GLboolean GLEWAPIENTRY glewGetExtension (const char* name)
{
const GLubyte* start;
const GLubyte* end;
start = (const GLubyte*)glGetString(GL_EXTENSIONS);
if (start == 0)
return GL_FALSE;
end = start + _glewStrLen(start);
return _glewSearchExtension(name, start, end);
{
GLboolean *enable = _glewGetExtensionString(name);
if (enable)
return *enable;
return GL_FALSE;
}
/* ------------------------------------------------------------------------- */
@ -21,8 +67,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
const GLubyte* s;
GLuint dot;
GLint major, minor;
const GLubyte* extStart;
const GLubyte* extEnd;
/* query opengl version */
s = glGetString(GL_VERSION);
dot = _glewStrCLen(s, '.');
@ -37,7 +82,6 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
if (major<0 || major>9)
return GLEW_ERROR_NO_GL_VERSION;
if (major == 1 && minor == 0)
{
return GLEW_ERROR_GL_VERSION_10_ONLY;
@ -64,10 +108,67 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST)
GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
}
/* query opengl extensions string */
extStart = glGetString(GL_EXTENSIONS);
if (extStart == 0)
extStart = (const GLubyte*)"";
extEnd = extStart + _glewStrLen(extStart);
memset(_glewExtensionString,0,sizeof(_glewExtensionString));
/* initialize extensions */
if (GLEW_VERSION_3_0)
{
GLint n = 0;
GLint i;
PFNGLGETSTRINGIPROC getStringi;
const char *ext;
GLboolean *enable;
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
/* glGetStringi is OpenGL 3.0 */
getStringi = (PFNGLGETSTRINGIPROC) glewGetProcAddress((const GLubyte*)"glGetStringi");
if (getStringi)
for (i = 0; i<n; ++i)
{
ext = (const char *) getStringi(GL_EXTENSIONS, i);
/* Based on extension string(s), glewGetExtension purposes */
enable = _glewGetExtensionString(ext);
if (enable)
*enable = GL_TRUE;
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
enable = _glewGetExtensionEnable(ext);
if (enable)
*enable = GL_TRUE;
}
}
else
{
const GLubyte *ext;
char *begin;
char *end;
char *i;
char *j;
GLboolean *enable;
ext = glGetString(GL_EXTENSIONS);
if (ext)
{
begin = (char *) _glewStrDup(ext);
end = begin + _glewStrLen((GLubyte *) begin);
for (i=begin; i<end; i = j + 1)
{
i = _glewNextNonSpace(i);
j = _glewNextSpace(i);
*j = 0;
/* Based on extension string(s), glewGetExtension purposes */
enable = _glewGetExtensionString(i);
if (enable)
*enable = GL_TRUE;
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
enable = _glewGetExtensionEnable(i);
if (enable)
*enable = GL_TRUE;
}
free(begin);
}
}

View File

@ -87,6 +87,17 @@ void* dlGetProcAddress (const GLubyte* name)
* These functions implement the functionality required in this file.
*/
static GLubyte *_glewStrDup (const GLubyte *str)
{
int n = strlen(str) + 1;
char *dup = malloc(n);
if (dup)
{
strcpy(dup, str);
}
return dup;
}
GLuint _glewStrLen (const GLubyte* s)
{
GLuint i=0;

View File

@ -8,6 +8,10 @@
#include <GL/glxew.h>
#endif
#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#endif
#ifdef GLEW_REGAL
#include <GL/Regal.h>
#endif
@ -26,17 +30,21 @@ GLXEWContext _glxewctx;
#endif
#endif
struct createParams {
#if defined(_WIN32)
GLboolean glewCreateContext (int* pixelformat);
int pixelformat;
#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
GLboolean glewCreateContext (const char* display, int* visual);
#else
GLboolean glewCreateContext ();
const char* display;
int visual;
#endif
int major, minor;
int profile_mask;
int flags;
};
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual);
#endif
GLboolean glewCreateContext (struct createParams *params);
GLboolean glewParseArgs (int argc, char** argv, struct createParams *);
void glewDestroyContext ();

View File

@ -4,36 +4,39 @@
/* ------------------------------------------------------------------------ */
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
int main (int argc, char** argv)
#else
int main (void)
#endif
{
GLuint err;
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
char* display = NULL;
int visual = -1;
if (glewParseArgs(argc-1, argv+1, &display, &visual))
{
struct createParams params = {
#if defined(_WIN32)
fprintf(stderr, "Usage: glewinfo [-pf <id>]\n");
#else
fprintf(stderr, "Usage: glewinfo [-display <display>] [-visual <id>]\n");
-1, /* pixelformat */
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
"", /* display */
-1, /* visual */
#endif
0, /* major */
0, /* minor */
0, /* profile mask */
0 /* flags */
};
if (glewParseArgs(argc-1, argv+1, &params))
{
fprintf(stderr, "Usage: glewinfo "
#if defined(_WIN32)
"[-pf <pixelformat>] "
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
"[-display <display>] "
"[-visual <visual id>] "
#endif
"[-version <OpenGL version>] "
"[-profiles <OpenGL profile mask>] "
"[-flags <OpenGL flags>]"
"\n");
return 1;
}
#endif
#if defined(_WIN32)
if (GL_TRUE == glewCreateContext(&visual))
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
if (GL_TRUE == glewCreateContext())
#else
if (GL_TRUE == glewCreateContext(display, &visual))
#endif
if (GL_TRUE == glewCreateContext(&params))
{
fprintf(stderr, "Error: glewCreateContext failed\n");
glewDestroyContext();
@ -44,7 +47,7 @@ int main (void)
err = glewContextInit(glewGetContext());
#ifdef _WIN32
err = err || wglewContextInit(wglewGetContext());
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
err = err || glxewContextInit(glxewGetContext());
#endif
@ -73,10 +76,10 @@ int main (void)
fprintf(f, "---------------------------\n\n");
fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION));
#if defined(_WIN32)
fprintf(f, "Reporting capabilities of pixelformat %d\n", visual);
fprintf(f, "Reporting capabilities of pixelformat %d\n", params.pixelformat);
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n",
display == NULL ? getenv("DISPLAY") : display, visual);
params.display == NULL ? getenv("DISPLAY") : params.display, params.visual);
#endif
fprintf(f, "Running on a %s from %s\n",
glGetString(GL_RENDERER), glGetString(GL_VENDOR));
@ -94,39 +97,49 @@ int main (void)
/* ------------------------------------------------------------------------ */
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual)
GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
{
int p = 0;
while (p < argc)
{
#if defined(_WIN32)
if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
if (!strcmp(argv[p], "-version"))
{
if (++p >= argc) return GL_TRUE;
*display = 0;
*visual = strtol(argv[p++], NULL, 0);
if (sscanf(argv[p++], "%d.%d", &params->major, &params->minor) != 2) return GL_TRUE;
}
else
return GL_TRUE;
#else
if (!strcmp(argv[p], "-display"))
else if (!strcmp(argv[p], "-profiles"))
{
if (++p >= argc) return GL_TRUE;
*display = argv[p++];
params->profile_mask = (int)strtol(argv[p++], NULL, 0);
}
else if (!strcmp(argv[p], "-flags"))
{
if (++p >= argc) return GL_TRUE;
params->flags = (int)strtol(argv[p++], NULL, 0);
}
#if defined(_WIN32)
else if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
{
if (++p >= argc) return GL_TRUE;
params->pixelformat = strtol(argv[p++], NULL, 0);
}
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
else if (!strcmp(argv[p], "-display"))
{
if (++p >= argc) return GL_TRUE;
params->display = argv[p++];
}
else if (!strcmp(argv[p], "-visual"))
{
if (++p >= argc) return GL_TRUE;
*visual = (int)strtol(argv[p++], NULL, 0);
params->visual = (int)strtol(argv[p++], NULL, 0);
}
#endif
else
return GL_TRUE;
#endif
}
return GL_FALSE;
}
#endif
/* ------------------------------------------------------------------------ */
@ -136,7 +149,7 @@ HWND wnd = NULL;
HDC dc = NULL;
HGLRC rc = NULL;
GLboolean glewCreateContext (int* pixelformat)
GLboolean glewCreateContext (struct createParams* params)
{
WNDCLASS wc;
PIXELFORMATDESCRIPTOR pfd;
@ -155,20 +168,58 @@ GLboolean glewCreateContext (int* pixelformat)
if (NULL == dc) return GL_TRUE;
/* find pixel format */
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
if (*pixelformat == -1) /* find default */
if (params->pixelformat == -1) /* find default */
{
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
*pixelformat = ChoosePixelFormat(dc, &pfd);
if (*pixelformat == 0) return GL_TRUE;
params->pixelformat = ChoosePixelFormat(dc, &pfd);
if (params->pixelformat == 0) return GL_TRUE;
}
/* set the pixel format for the dc */
if (FALSE == SetPixelFormat(dc, *pixelformat, &pfd)) return GL_TRUE;
if (FALSE == SetPixelFormat(dc, params->pixelformat, &pfd)) return GL_TRUE;
/* create rendering context */
rc = wglCreateContext(dc);
if (NULL == rc) return GL_TRUE;
if (FALSE == wglMakeCurrent(dc, rc)) return GL_TRUE;
if (params->major || params->profile_mask || params->flags)
{
HGLRC oldRC = rc;
int contextAttrs[20];
int i;
extern GLenum GLEWAPIENTRY wglewContextInit();
wglewContextInit();
if (!wglewGetExtension("WGL_ARB_create_context_profile"))
return GL_TRUE;
i = 0;
if( params->major )
{
contextAttrs[i++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
contextAttrs[i++] = params->major;
contextAttrs[i++] = WGL_CONTEXT_MINOR_VERSION_ARB;
contextAttrs[i++] = params->minor;
}
if( params->profile_mask )
{
contextAttrs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
contextAttrs[i++] = params->profile_mask;
}
if( params->flags )
{
contextAttrs[i++] = WGL_CONTEXT_FLAGS_ARB;
contextAttrs[i++] = params->flags;
}
contextAttrs[i++] = 0;
rc = wglCreateContextAttribsARB(dc, 0, contextAttrs);
if (NULL == rc) return GL_TRUE;
if (!wglMakeCurrent(dc, rc)) return GL_TRUE;
wglDeleteContext(oldRC);
}
return GL_FALSE;
}
@ -190,22 +241,31 @@ void glewDestroyContext ()
CGLContextObj ctx, octx;
GLboolean glewCreateContext ()
GLboolean glewCreateContext (struct createParams *params)
{
const CGLPixelFormatAttribute attrib[4] =
{
kCGLPFAAccelerated, /* No software rendering */
#if 0
kCGLPFAOpenGLProfile, /* OSX 10.7 Lion onwards */
(CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, /* 3.2 Core Context */
#endif
0
};
CGLPixelFormatAttribute contextAttrs[20];
int i;
CGLPixelFormatObj pf;
GLint npix;
CGLError error;
error = CGLChoosePixelFormat(attrib, &pf, &npix);
i = 0;
contextAttrs[i++] = kCGLPFAAccelerated; /* No software rendering */
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
if (params->profile_mask & GL_CONTEXT_CORE_PROFILE_BIT)
{
if (params->major==3 && params->minor>=2)
{
contextAttrs[i++] = kCGLPFAOpenGLProfile; /* OSX 10.7 Lion onwards */
contextAttrs[i++] = (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core; /* 3.2 Core Context */
}
}
#endif
contextAttrs[i++] = 0;
error = CGLChoosePixelFormat(contextAttrs, &pf, &npix);
if (error) return GL_TRUE;
error = CGLCreateContext(pf, NULL, &ctx);
if (error) return GL_TRUE;
@ -230,7 +290,7 @@ void glewDestroyContext ()
#elif defined(__HAIKU__)
GLboolean glewCreateContext ()
GLboolean glewCreateContext (struct createParams *params)
{
/* TODO: Haiku: We need to call C++ code here */
return GL_FALSE;
@ -252,22 +312,22 @@ GLXContext ctx = NULL;
Window wnd = 0;
Colormap cmap = 0;
GLboolean glewCreateContext (const char* display, int* visual)
GLboolean glewCreateContext (struct createParams *params)
{
int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
int erb, evb;
XSetWindowAttributes swa;
/* open display */
dpy = XOpenDisplay(display);
dpy = XOpenDisplay(params->display);
if (NULL == dpy) return GL_TRUE;
/* query for glx */
if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
/* choose visual */
if (*visual == -1)
if (params->visual == -1)
{
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
if (NULL == vi) return GL_TRUE;
*visual = (int)XVisualIDFromVisual(vi->visual);
params->visual = (int)XVisualIDFromVisual(vi->visual);
}
else
{
@ -275,7 +335,7 @@ GLboolean glewCreateContext (const char* display, int* visual)
vis = XGetVisualInfo(dpy, 0, NULL, &n_vis);
for (i=0; i<n_vis; i++)
{
if ((int)XVisualIDFromVisual(vis[i].visual) == *visual)
if ((int)XVisualIDFromVisual(vis[i].visual) == params->visual)
vi = &vis[i];
}
if (vi == NULL) return GL_TRUE;
@ -293,6 +353,54 @@ GLboolean glewCreateContext (const char* display, int* visual)
CWBorderPixel | CWColormap, &swa);
/* make context current */
if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
if (params->major || params->profile_mask || params->flags)
{
GLXContext oldCtx = ctx;
GLXFBConfig *FBConfigs;
int FBConfigAttrs[] = { GLX_FBCONFIG_ID, 0, None };
int contextAttrs[20];
int nelems, i;
glxewContextInit();
if (!glxewGetExtension("GLX_ARB_create_context_profile"))
return GL_TRUE;
if (glXQueryContext(dpy, oldCtx, GLX_FBCONFIG_ID, &FBConfigAttrs[1]))
return GL_TRUE;
FBConfigs = glXChooseFBConfig(dpy, vi->screen, FBConfigAttrs, &nelems);
if (nelems < 1)
return GL_TRUE;
i = 0;
if( params->major )
{
contextAttrs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
contextAttrs[i++] = params->major;
contextAttrs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
contextAttrs[i++] = params->minor;
}
if( params->profile_mask )
{
contextAttrs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
contextAttrs[i++] = params->profile_mask;
}
if( params->flags )
{
contextAttrs[i++] = GLX_CONTEXT_FLAGS_ARB;
contextAttrs[i++] = params->flags;
}
contextAttrs[i++] = None;
ctx = glXCreateContextAttribsARB(dpy, *FBConfigs, NULL, True, contextAttrs);
if (NULL == ctx) return GL_TRUE;
if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
glXDestroyContext(dpy, oldCtx);
XFree(FBConfigs);
}
return GL_FALSE;
}

View File

@ -2,6 +2,7 @@ NAME = $(GLEW_NAME)
CC = cc
LD = cc
CFLAGS.EXTRA = -dynamic -fno-common
CFLAGS.EXTRA += -ansi -pedantic
#CFLAGS.EXTRA += -no-cpp-precomp
LDFLAGS.EXTRA =
ifneq (undefined, $(origin GLEW_APPLE_GLX))

View File

@ -24,6 +24,7 @@ WARN = -Wall -W
POPT = -O2
CFLAGS.EXTRA += -fPIC
CFLAGS.EXTRA += -Wcast-qual
CFLAGS.EXTRA += -ansi -pedantic
BIN.SUFFIX =
LIB.SONAME = lib$(NAME).so.$(SO_MAJOR)
LIB.DEVLNK = lib$(NAME).so