Merge https://github.com/nigels-com/glew.git into master HEAD at Sat Jun 13 17:44:11 GMT 2015

This commit is contained in:
omniavinco 2015-06-14 02:44:11 +09:00
commit f5be4658cb
9 changed files with 202 additions and 405 deletions

View File

@ -245,75 +245,6 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
perl -e "s/\(\(glColorSubTable = /((glBlendEquation = (PFNGLBLENDEQUATIONPROC)glewGetProcAddress((const GLubyte*)\"glBlendEquation\")) == NULL) || r;\n r = ((glColorSubTable = /g" -pi $@
rm -f $@.bak
$(S.DEST)/glew_def.c: $(EXT)/.dummy
cp -f $(SRC)/glew_license.h $@
echo -e "#include \"glew_utils.h\"\n\n#if !defined(_WIN32) || !defined(GLEW_MX)" >> $@
$(BIN)/make_def_fun.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_def_fun.pl GL $(GL_EXT_SPEC) >> $@
echo -e "\n#endif /* !WIN32 || !GLEW_MX */" >> $@
echo -e "\n#if !defined(GLEW_MX)\n\nGLboolean __GLEW_VERSION_1_1 = GL_FALSE;" >> $@
$(BIN)/make_def_var.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_def_var.pl GL $(GL_EXT_SPEC) >> $@
echo -e "\n#if defined(_WIN32)" >> $@
$(BIN)/make_def_fun.pl WGL $(WGL_EXT_SPEC) >> $@
$(BIN)/make_def_var.pl WGL $(WGL_EXT_SPEC) >> $@
echo -e "\n#endif /* _WIN32 */" >> $@
echo -e "\n#endif /* !GLEW_MX */" >> $@;
echo -e "\n#if !defined(_WIN32) && !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))" >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_CORE_SPEC) >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_EXT_SPEC) >> $@
echo -e "\n#if !defined(GLEW_MX)" >> $@;
echo -e "\nGLboolean __GLXEW_VERSION_1_0 = GL_FALSE;" >> $@
echo -e "GLboolean __GLXEW_VERSION_1_1 = GL_FALSE;" >> $@
$(BIN)/make_def_var.pl GLX $(GLX_CORE_SPEC) >> $@
$(BIN)/make_def_var.pl GLX $(GLX_EXT_SPEC) >> $@
echo -e "\n#endif /* !GLEW_MX */" >> $@;
echo -e "\n#endif /* !defined(_WIN32) && !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) */" >> $@;
rm -f $@.bak
$(S.DEST)/glew_init.c: $(EXT)/.dummy
cp -f $(SRC)/glew_license.h $@
echo -e "#include \"glew_utils.h\"\n" >> $@
$(BIN)/make_init.pl GL $(GL_CORE_SPEC) >> $@
$(BIN)/make_init.pl GL $(GL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_gl.c >> $@
$(BIN)/make_list.pl $(GL_CORE_SPEC) | grep -v '\"GL_VERSION' >> $@
$(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n\n#if defined(_WIN32)\n" >> $@;
$(BIN)/make_init.pl WGL $(WGL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_wgl.c >> $@
$(BIN)/make_list.pl $(WGL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n\n" >> $@;
echo -e "\n#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)\n" >> $@
$(BIN)/make_init.pl GLX $(GLX_CORE_SPEC) >> $@
$(BIN)/make_init.pl GLX $(GLX_EXT_SPEC) >> $@
cat $(SRC)/glew_init_glx.c >> $@
$(BIN)/make_list.pl $(CORE)/GLX_VERSION_1_3 | grep -v '\"GLX_VERSION' >> $@
$(BIN)/make_list.pl $(GLX_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n\n#endif /* !__APPLE__ || GLEW_APPLE_GLX */\n" >> $@;
cat $(SRC)/glew_init_tail.c >> $@
perl -e "s/GLEW_VERSION_STRING/$(GLEW_VERSION)/g" -pi $@
perl -e "s/GLEW_VERSION_MAJOR_STRING/$(GLEW_MAJOR)/g" -pi $@
perl -e "s/GLEW_VERSION_MINOR_STRING/$(GLEW_MINOR)/g" -pi $@
perl -e "s/GLEW_VERSION_MICRO_STRING/$(GLEW_MICRO)/g" -pi $@
perl -e "s/GLEW_ARB_vertex_shader = !_glewInit_GL_ARB_vertex_shader\(GLEW_CONTEXT_ARG_VAR_INIT\);/{ GLEW_ARB_vertex_shader = !_glewInit_GL_ARB_vertex_shader(GLEW_CONTEXT_ARG_VAR_INIT); _glewInit_GL_ARB_vertex_program(GLEW_CONTEXT_ARG_VAR_INIT); }/g" -pi $@
perl -e "s/\(\(glBlendColor = /((glBlendEquation = (PFNGLBLENDEQUATIONPROC)glewGetProcAddress((const GLubyte*)\"glBlendEquation\")) == NULL) || r;\n r = ((glBlendColor = /g" -pi $@
rm -f $@.bak
$(S.DEST)/glew_str.c: $(EXT)/.dummy
cp -f $(SRC)/glew_license.h $@
echo -e "\n#include \"glew_utils.h\"\n" >> $@
cat $(SRC)/glew_str_head.c >> $@
$(BIN)/make_str.pl $(GL_CORE_SPEC) $(GL_EXT_SPEC) >> $@
cat $(SRC)/glew_str_wgl.c >> $@
$(BIN)/make_str.pl $(WGL_EXT_SPEC) >> $@
cat $(SRC)/glew_str_glx.c >> $@
$(BIN)/make_str.pl $(GLX_CORE_SPEC) $(GLX_EXT_SPEC) >> $@
cat $(SRC)/glew_str_tail.c >> $@
# perl -e "s/GLEW_VERSION_STRING/$(GLEW_VERSION)/g" -pi $@
# perl -e "s/GLEW_ARB_vertex_shader = !_glewInit_GL_ARB_vertex_shader\(GLEW_CONTEXT_ARG_VAR_INIT\);/{ GLEW_ARB_vertex_shader = !_glewInit_GL_ARB_vertex_shader(GLEW_CONTEXT_ARG_VAR_INIT); _glewInit_GL_ARB_vertex_program(GLEW_CONTEXT_ARG_VAR_INIT); }/g" -pi $@
rm -f $@.bak
$(S.DEST)/glewinfo.c: $(EXT)/.dummy
@echo "--------------------------------------------------------------------"
@echo "Creating glewinfo.c"

View File

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

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";
}
}

View File

@ -1,162 +0,0 @@
/*
** The OpenGL Extension Wrangler Library
** Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <GL/glew.h>
#if defined(_WIN32)
# include <GL/wglew.h>
#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
# include <GL/glxew.h>
#endif
#include "glew_utils.h"
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <string.h>
void* NSGLGetProcAddress (const GLubyte *name)
{
NSSymbol symbol;
char* symbolName;
/* prepend a '_' for the Unix C symbol mangling convention */
symbolName = malloc(strlen((const char*)name) + 2);
strcpy(symbolName+1, (const char*)name);
symbolName[0] = '_';
symbol = NULL;
if (NSIsSymbolNameDefined(symbolName))
symbol = NSLookupAndBindSymbol(symbolName);
free(symbolName);
return symbol ? NSAddressOfSymbol(symbol) : NULL;
}
#endif /* __APPLE__ */
#if defined(__sgi) || defined (__sun)
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
void* dlGetProcAddress (const GLubyte* name)
{
static void* h = NULL;
static void* gpa;
if (h == NULL)
{
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
gpa = dlsym(h, "glXGetProcAddress");
}
if (gpa != NULL)
return ((void*(*)(const GLubyte*))gpa)(name);
else
return dlsym(h, (const char*)name);
}
#endif /* __sgi || __sun */
/*
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
* These functions implement the functionality required in this file.
*/
GLuint _glewStrLen (const GLubyte* s)
{
GLuint i=0;
while (s+i != NULL && s[i] != '\0') i++;
return i;
}
GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
{
GLuint i=0;
while (s+i != NULL && s[i] != '\0' && s[i] != c) i++;
return i;
}
GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
{
GLuint i=0;
while (i < n && a+i != NULL && b+i != NULL && a[i] == b[i]) i++;
return i == n ? GL_TRUE : GL_FALSE;
}
GLboolean _glewStrSame1 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
{
while (*na > 0 && (**a == ' ' || **a == '\n' || **a == '\r' || **a == '\t'))
{
*a++;
*na--;
}
if(*na >= nb)
{
GLuint i=0;
while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++;
if(i == nb)
{
*a = *a + nb;
*na = *na - nb;
return GL_TRUE;
}
}
return GL_FALSE;
}
GLboolean _glewStrSame2 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
{
if(*na >= nb)
{
GLuint i=0;
while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++;
if(i == nb)
{
*a = *a + nb;
*na = *na - nb;
return GL_TRUE;
}
}
return GL_FALSE;
}
GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
{
if(*na >= nb)
{
GLuint i=0;
while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++;
if (i == nb && (*na == nb || *a[i] == ' ' || *a[i] == '\n' || *a[i] == '\r' || *a[i] == '\t'))
{
*a = *a + nb;
*na = *na - nb;
return GL_TRUE;
}
}
return GL_FALSE;
}

View File

@ -1,101 +0,0 @@
/*
** The OpenGL Extension Wrangler Library
** Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org>
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org>
** Copyright (C) 2002, Lev Povalahev
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
** this list of conditions and the following disclaimer in the documentation
** and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __glew_utils_h__
#define __glew_utils_h__
#include <GL/glew.h>
#if defined(_WIN32)
# include <GL/wglew.h>
#elif !defined(__ANDROID__) && !defined(__native_client__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
# include <GL/glxew.h>
#endif
/*
* Define glewGetContext and related helper macros.
*/
#ifdef GLEW_MX
# define glewGetContext() ctx
# ifdef _WIN32
# define GLEW_CONTEXT_ARG_DEF_INIT GLEWContext* ctx
# define GLEW_CONTEXT_ARG_VAR_INIT ctx
# define wglewGetContext() ctx
# define WGLEW_CONTEXT_ARG_DEF_INIT WGLEWContext* ctx
# define WGLEW_CONTEXT_ARG_DEF_LIST WGLEWContext* ctx
# else /* _WIN32 */
# define GLEW_CONTEXT_ARG_DEF_INIT void
# define GLEW_CONTEXT_ARG_VAR_INIT
# define glxewGetContext() ctx
# define GLXEW_CONTEXT_ARG_DEF_INIT void
# define GLXEW_CONTEXT_ARG_DEF_LIST GLXEWContext* ctx
# endif /* _WIN32 */
# define GLEW_CONTEXT_ARG_DEF_LIST GLEWContext* ctx
#else /* GLEW_MX */
# define GLEW_CONTEXT_ARG_DEF_INIT void
# define GLEW_CONTEXT_ARG_VAR_INIT
# define GLEW_CONTEXT_ARG_DEF_LIST void
# define WGLEW_CONTEXT_ARG_DEF_INIT void
# define WGLEW_CONTEXT_ARG_DEF_LIST void
# define GLXEW_CONTEXT_ARG_DEF_INIT void
# define GLXEW_CONTEXT_ARG_DEF_LIST void
#endif /* GLEW_MX */
/*
* Define glewGetProcAddress.
*/
#if defined(_WIN32)
# define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name)
#else
# if defined(__APPLE__)
extern void* NSGLGetProcAddress (const GLubyte* name);
# define glewGetProcAddress(name) NSGLGetProcAddress(name)
# else
# if defined(__sgi) || defined(__sun)
extern void* dlGetProcAddress (const GLubyte* name);
# define glewGetProcAddress(name) dlGetProcAddress(name)
# else /* __linux */
# define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
# endif
# endif
#endif
/*
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
* These functions implement the string processing functionality required in the library.
*/
extern GLuint _glewStrLen (const GLubyte* s);
extern GLuint _glewStrCLen (const GLubyte* s, GLubyte c);
extern GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n);
extern GLboolean _glewStrSame1 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb);
extern GLboolean _glewStrSame2 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb);
extern GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
#endif /* __glew_utils_h__ */

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,26 @@ GLXEWContext _glxewctx;
#endif
#endif
#if defined(_WIN32)
GLboolean glewCreateContext (int* pixelformat);
#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
GLboolean glewCreateContext (const char* display, int* visual);
#else
GLboolean glewCreateContext ();
#endif
/* Command-line parameters for GL context creation */
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean glewParseArgs (int argc, char** argv, char** display, int* visual);
struct createParams
{
#if defined(_WIN32)
int pixelformat;
#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
const char* display;
int visual;
#endif
int major, minor; /* GL context version number */
/* https://www.opengl.org/registry/specs/ARB/glx_create_context.txt */
int profile; /* core = 1, compatibility = 2 */
int flags; /* debug = 1, forward compatible = 2 */
};
GLboolean glewCreateContext (struct createParams *params);
GLboolean glewParseArgs (int argc, char** argv, struct createParams *);
void glewDestroyContext ();

View File

@ -4,36 +4,40 @@
/* ------------------------------------------------------------------------ */
#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>] "
"[-profile core|compatibility] "
"[-flag debug|forward]"
"\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 +48,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 +77,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 +98,55 @@ 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], "-profile"))
{
if (++p >= argc) return GL_TRUE;
*display = argv[p++];
if (strcmp("core", argv[p]) == 0) params->profile |= 1;
else if (strcmp("compatibility",argv[p]) == 0) params->profile |= 2;
else return GL_TRUE;
++p;
}
else if (!strcmp(argv[p], "-flag"))
{
if (++p >= argc) return GL_TRUE;
if (strcmp("debug", argv[p]) == 0) params->flags |= 1;
else if (strcmp("forward",argv[p]) == 0) params->flags |= 2;
else return GL_TRUE;
++p;
}
#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 +156,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 +175,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 || 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)
{
contextAttrs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
contextAttrs[i++] = params->profile;
}
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 +248,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 & 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 +297,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 +319,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 +342,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 +360,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 || 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)
{
contextAttrs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
contextAttrs[i++] = params->profile;
}
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