From 283abfd6e9170b13e71e11064900dc9992e4bbfd Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Fri, 29 May 2015 20:08:13 +1000 Subject: [PATCH] [CoreSupport] Mac OS X support for glewinfo GL version/profiles/flags. --- auto/src/glewinfo_head.c | 6 ++++-- auto/src/glewinfo_tail.c | 46 +++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/auto/src/glewinfo_head.c b/auto/src/glewinfo_head.c index 9a7f529..0174fdd 100644 --- a/auto/src/glewinfo_head.c +++ b/auto/src/glewinfo_head.c @@ -8,6 +8,10 @@ #include #endif +#if defined(__APPLE__) +#include +#endif + #ifdef GLEW_REGAL #include #endif @@ -40,9 +44,7 @@ struct createParams { GLboolean glewCreateContext (struct createParams *params); -#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX) GLboolean glewParseArgs (int argc, char** argv, struct createParams *); -#endif void glewDestroyContext (); diff --git a/auto/src/glewinfo_tail.c b/auto/src/glewinfo_tail.c index f5cc0e3..6f748a7 100644 --- a/auto/src/glewinfo_tail.c +++ b/auto/src/glewinfo_tail.c @@ -4,17 +4,13 @@ /* ------------------------------------------------------------------------ */ -#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX) int main (int argc, char** argv) -#else -int main (void) -#endif { GLuint err; struct createParams params = { #if defined(_WIN32) -1, /* pixelformat */ -#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) +#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "", /* display */ -1, /* visual */ #endif @@ -24,13 +20,12 @@ int main (void) 0 /* flags */ }; -#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX) if (glewParseArgs(argc-1, argv+1, ¶ms)) { fprintf(stderr, "Usage: glewinfo " #if defined(_WIN32) "[-pf ] " -#else +#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "[-display ] " "[-visual ] " #endif @@ -40,7 +35,6 @@ int main (void) "\n"); return 1; } -#endif if (GL_TRUE == glewCreateContext(¶ms)) { @@ -53,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 @@ -103,7 +97,6 @@ int main (void) /* ------------------------------------------------------------------------ */ -#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX) GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) { int p = 0; @@ -130,7 +123,7 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) if (++p >= argc) return GL_TRUE; params->pixelformat = strtol(argv[p++], NULL, 0); } -#else +#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) else if (!strcmp(argv[p], "-display")) { if (++p >= argc) return GL_TRUE; @@ -147,7 +140,6 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) } return GL_FALSE; } -#endif /* ------------------------------------------------------------------------ */ @@ -251,23 +243,29 @@ CGLContextObj ctx, octx; GLboolean glewCreateContext (struct createParams *params) { - const CGLPixelFormatAttribute attrib[4] = - { - kCGLPFAAccelerated, /* No software rendering */ - kCGLPFAOpenGLProfile, /* OSX 10.7 Lion onwards */ - (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, /* 3.2 Core Context */ - 0 - }; + CGLPixelFormatAttribute contextAttrs[20]; + int i; CGLPixelFormatObj pf; GLint npix; CGLError error; - if( params->major < 3 && - !(params->profile_mask & GL_CONTEXT_CORE_PROFILE_BIT) ) { - attrib[1] = 0; // terminate attrib array before the core profile attribute - } + i = 0; + contextAttrs[i++] = kCGLPFAAccelerated; /* No software rendering */ - error = CGLChoosePixelFormat(attrib, &pf, &npix); + #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;