[CoreSupport] Mac OS X support for glewinfo GL version/profiles/flags.

This commit is contained in:
Nigel Stewart 2015-05-29 20:08:13 +10:00
parent 2d0899283f
commit 60b0fc5c05
2 changed files with 26 additions and 26 deletions

View File

@ -8,6 +8,10 @@
#include <GL/glxew.h> #include <GL/glxew.h>
#endif #endif
#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#endif
#ifdef GLEW_REGAL #ifdef GLEW_REGAL
#include <GL/Regal.h> #include <GL/Regal.h>
#endif #endif
@ -40,9 +44,7 @@ struct createParams {
GLboolean glewCreateContext (struct createParams *params); GLboolean glewCreateContext (struct createParams *params);
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean glewParseArgs (int argc, char** argv, struct createParams *); GLboolean glewParseArgs (int argc, char** argv, struct createParams *);
#endif
void glewDestroyContext (); void glewDestroyContext ();

View File

@ -4,17 +4,13 @@
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
int main (int argc, char** argv) int main (int argc, char** argv)
#else
int main (void)
#endif
{ {
GLuint err; GLuint err;
struct createParams params = { struct createParams params = {
#if defined(_WIN32) #if defined(_WIN32)
-1, /* pixelformat */ -1, /* pixelformat */
#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
"", /* display */ "", /* display */
-1, /* visual */ -1, /* visual */
#endif #endif
@ -24,13 +20,12 @@ int main (void)
0 /* flags */ 0 /* flags */
}; };
#if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
if (glewParseArgs(argc-1, argv+1, &params)) if (glewParseArgs(argc-1, argv+1, &params))
{ {
fprintf(stderr, "Usage: glewinfo " fprintf(stderr, "Usage: glewinfo "
#if defined(_WIN32) #if defined(_WIN32)
"[-pf <pixelformat>] " "[-pf <pixelformat>] "
#else #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
"[-display <display>] " "[-display <display>] "
"[-visual <visual id>] " "[-visual <visual id>] "
#endif #endif
@ -40,7 +35,6 @@ int main (void)
"\n"); "\n");
return 1; return 1;
} }
#endif
if (GL_TRUE == glewCreateContext(&params)) if (GL_TRUE == glewCreateContext(&params))
{ {
@ -53,7 +47,7 @@ int main (void)
err = glewContextInit(glewGetContext()); err = glewContextInit(glewGetContext());
#ifdef _WIN32 #ifdef _WIN32
err = err || wglewContextInit(wglewGetContext()); err = err || wglewContextInit(wglewGetContext());
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
err = err || glxewContextInit(glxewGetContext()); err = err || glxewContextInit(glxewGetContext());
#endif #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) GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
{ {
int p = 0; int p = 0;
@ -130,7 +123,7 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
if (++p >= argc) return GL_TRUE; if (++p >= argc) return GL_TRUE;
params->pixelformat = strtol(argv[p++], NULL, 0); params->pixelformat = strtol(argv[p++], NULL, 0);
} }
#else #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
else if (!strcmp(argv[p], "-display")) else if (!strcmp(argv[p], "-display"))
{ {
if (++p >= argc) return GL_TRUE; if (++p >= argc) return GL_TRUE;
@ -147,7 +140,6 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
} }
return GL_FALSE; return GL_FALSE;
} }
#endif
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -251,23 +243,29 @@ CGLContextObj ctx, octx;
GLboolean glewCreateContext (struct createParams *params) GLboolean glewCreateContext (struct createParams *params)
{ {
const CGLPixelFormatAttribute attrib[4] = CGLPixelFormatAttribute contextAttrs[20];
{ int i;
kCGLPFAAccelerated, /* No software rendering */
kCGLPFAOpenGLProfile, /* OSX 10.7 Lion onwards */
(CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, /* 3.2 Core Context */
0
};
CGLPixelFormatObj pf; CGLPixelFormatObj pf;
GLint npix; GLint npix;
CGLError error; CGLError error;
if( params->major < 3 && i = 0;
!(params->profile_mask & GL_CONTEXT_CORE_PROFILE_BIT) ) { contextAttrs[i++] = kCGLPFAAccelerated; /* No software rendering */
attrib[1] = 0; // terminate attrib array before the core profile attribute
}
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; if (error) return GL_TRUE;
error = CGLCreateContext(pf, NULL, &ctx); error = CGLCreateContext(pf, NULL, &ctx);
if (error) return GL_TRUE; if (error) return GL_TRUE;