2003-07-06 15:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2004-02-01 21:26:11 +00:00
|
|
|
int main (int argc, char** argv)
|
2003-07-06 15:01:13 +00:00
|
|
|
{
|
|
|
|
GLuint err;
|
2015-12-06 02:58:46 +00:00
|
|
|
struct createParams params =
|
2015-05-29 10:29:08 +00:00
|
|
|
{
|
2016-01-20 11:55:08 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
#elif defined(GLEW_EGL)
|
2014-06-24 15:03:28 +00:00
|
|
|
#elif defined(_WIN32)
|
2015-02-16 13:16:10 +00:00
|
|
|
-1, /* pixelformat */
|
2015-05-29 10:08:13 +00:00
|
|
|
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2015-02-16 13:16:10 +00:00
|
|
|
"", /* display */
|
|
|
|
-1, /* visual */
|
|
|
|
#endif
|
|
|
|
0, /* major */
|
|
|
|
0, /* minor */
|
|
|
|
0, /* profile mask */
|
|
|
|
0 /* flags */
|
|
|
|
};
|
2004-02-02 02:30:43 +00:00
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
if (glewParseArgs(argc-1, argv+1, ¶ms))
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
2015-02-16 13:16:10 +00:00
|
|
|
fprintf(stderr, "Usage: glewinfo "
|
2016-01-20 11:55:08 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
#elif defined(GLEW_EGL)
|
2014-06-24 15:03:28 +00:00
|
|
|
#elif defined(_WIN32)
|
2015-12-06 02:58:46 +00:00
|
|
|
"[-pf <pixelformat>] "
|
2015-05-29 10:08:13 +00:00
|
|
|
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2015-12-06 02:58:46 +00:00
|
|
|
"[-display <display>] "
|
|
|
|
"[-visual <visual id>] "
|
2004-02-01 21:26:11 +00:00
|
|
|
#endif
|
2015-12-06 02:58:46 +00:00
|
|
|
"[-version <OpenGL version>] "
|
|
|
|
"[-profile core|compatibility] "
|
|
|
|
"[-flag debug|forward]"
|
|
|
|
"\n");
|
2004-02-01 21:26:11 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2004-02-02 02:30:43 +00:00
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
if (GL_TRUE == glewCreateContext(¶ms))
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: glewCreateContext failed\n");
|
|
|
|
glewDestroyContext();
|
|
|
|
return 1;
|
|
|
|
}
|
2003-07-06 15:01:13 +00:00
|
|
|
glewExperimental = GL_TRUE;
|
|
|
|
err = glewInit();
|
|
|
|
if (GLEW_OK != err)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
|
2003-09-26 13:49:28 +00:00
|
|
|
glewDestroyContext();
|
2003-07-06 15:01:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2004-02-02 02:25:18 +00:00
|
|
|
#if defined(_WIN32)
|
2013-12-09 22:15:15 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
|
|
|
if (fopen_s(&f, "glewinfo.txt", "w") != 0)
|
|
|
|
f = stdout;
|
|
|
|
#else
|
2003-07-06 15:01:13 +00:00
|
|
|
f = fopen("glewinfo.txt", "w");
|
2013-12-09 22:15:15 +00:00
|
|
|
#endif
|
2003-07-06 15:01:13 +00:00
|
|
|
if (f == NULL) f = stdout;
|
2003-07-06 20:03:33 +00:00
|
|
|
#else
|
|
|
|
f = stdout;
|
|
|
|
#endif
|
2003-07-06 15:01:13 +00:00
|
|
|
fprintf(f, "---------------------------\n");
|
|
|
|
fprintf(f, " GLEW Extension Info\n");
|
|
|
|
fprintf(f, "---------------------------\n\n");
|
2004-02-01 21:26:11 +00:00
|
|
|
fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION));
|
2016-01-20 11:55:08 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
#elif defined(GLEW_EGL)
|
2014-06-24 15:03:28 +00:00
|
|
|
#elif defined(_WIN32)
|
2015-02-16 13:16:10 +00:00
|
|
|
fprintf(f, "Reporting capabilities of pixelformat %d\n", params.pixelformat);
|
2004-02-02 02:25:18 +00:00
|
|
|
#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2015-12-06 02:58:46 +00:00
|
|
|
fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n",
|
2015-02-16 13:16:10 +00:00
|
|
|
params.display == NULL ? getenv("DISPLAY") : params.display, params.visual);
|
2004-02-01 21:28:36 +00:00
|
|
|
#endif
|
2015-12-06 02:58:46 +00:00
|
|
|
fprintf(f, "Running on a %s from %s\n",
|
|
|
|
glGetString(GL_RENDERER), glGetString(GL_VENDOR));
|
2003-07-06 15:01:13 +00:00
|
|
|
fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION));
|
|
|
|
glewInfo();
|
2016-01-20 11:55:08 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
#elif defined(GLEW_EGL)
|
2016-01-24 11:55:33 +00:00
|
|
|
eglewInfo();
|
2014-06-24 15:03:28 +00:00
|
|
|
#elif defined(_WIN32)
|
2003-07-06 15:01:13 +00:00
|
|
|
wglewInfo();
|
2004-02-02 02:32:10 +00:00
|
|
|
#else
|
2003-07-06 15:01:13 +00:00
|
|
|
glxewInfo();
|
|
|
|
#endif
|
|
|
|
if (f != stdout) fclose(f);
|
2003-09-26 13:49:28 +00:00
|
|
|
glewDestroyContext();
|
2003-07-06 15:01:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-09-26 13:49:28 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
|
|
|
int p = 0;
|
|
|
|
while (p < argc)
|
|
|
|
{
|
2015-02-16 13:16:10 +00:00
|
|
|
if (!strcmp(argv[p], "-version"))
|
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
|
|
|
if (sscanf(argv[p++], "%d.%d", ¶ms->major, ¶ms->minor) != 2) return GL_TRUE;
|
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
else if (!strcmp(argv[p], "-profile"))
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (strcmp("core", argv[p]) == 0) params->profile |= 1;
|
|
|
|
else if (strcmp("compatibility",argv[p]) == 0) params->profile |= 2;
|
|
|
|
else return GL_TRUE;
|
|
|
|
++p;
|
2015-02-16 13:16:10 +00:00
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
else if (!strcmp(argv[p], "-flag"))
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (strcmp("debug", argv[p]) == 0) params->flags |= 1;
|
|
|
|
else if (strcmp("forward",argv[p]) == 0) params->flags |= 2;
|
|
|
|
else return GL_TRUE;
|
|
|
|
++p;
|
2015-02-16 13:16:10 +00:00
|
|
|
}
|
2016-01-20 11:55:08 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
#elif defined(GLEW_EGL)
|
2015-10-08 12:03:16 +00:00
|
|
|
#elif defined(_WIN32)
|
2015-02-16 13:16:10 +00:00
|
|
|
else if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
2015-02-16 13:16:10 +00:00
|
|
|
params->pixelformat = strtol(argv[p++], NULL, 0);
|
2004-02-01 21:26:11 +00:00
|
|
|
}
|
2015-05-29 10:08:13 +00:00
|
|
|
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2015-02-16 13:16:10 +00:00
|
|
|
else if (!strcmp(argv[p], "-display"))
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
2015-02-16 13:16:10 +00:00
|
|
|
params->display = argv[p++];
|
2016-01-24 11:55:33 +00:00
|
|
|
}
|
2004-02-02 02:25:18 +00:00
|
|
|
else if (!strcmp(argv[p], "-visual"))
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
|
|
|
if (++p >= argc) return GL_TRUE;
|
2015-02-16 13:16:10 +00:00
|
|
|
params->visual = (int)strtol(argv[p++], NULL, 0);
|
2004-02-01 21:26:11 +00:00
|
|
|
}
|
2015-02-16 13:16:10 +00:00
|
|
|
#endif
|
2004-02-01 21:26:11 +00:00
|
|
|
else
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2015-12-06 02:58:46 +00:00
|
|
|
#if defined(GLEW_EGL)
|
|
|
|
EGLDisplay display;
|
|
|
|
EGLContext ctx;
|
|
|
|
|
|
|
|
/* See: http://stackoverflow.com/questions/12662227/opengl-es2-0-offscreen-context-for-fbo-rendering */
|
|
|
|
|
|
|
|
GLboolean glewCreateContext (struct createParams *params)
|
|
|
|
{
|
|
|
|
EGLSurface surface;
|
|
|
|
EGLint majorVersion, minorVersion;
|
|
|
|
const EGLint attr[] = {
|
|
|
|
EGL_BUFFER_SIZE, 32,
|
|
|
|
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
|
|
|
|
EGL_CONFORMANT, EGL_OPENGL_BIT,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLConfig config;
|
|
|
|
EGLint numConfig;
|
2016-01-24 11:55:33 +00:00
|
|
|
|
|
|
|
PFNEGLGETDISPLAYPROC getDisplay = NULL;
|
|
|
|
PFNEGLINITIALIZEPROC initialize = NULL;
|
|
|
|
PFNEGLBINDAPIPROC bindAPI = NULL;
|
|
|
|
PFNEGLCHOOSECONFIGPROC chooseConfig = NULL;
|
|
|
|
PFNEGLCREATEWINDOWSURFACEPROC createWindowSurface = NULL;
|
|
|
|
PFNEGLCREATECONTEXTPROC createContext = NULL;
|
|
|
|
PFNEGLMAKECURRENTPROC makeCurrent = NULL;
|
|
|
|
|
|
|
|
/* Load necessary entry points */
|
|
|
|
getDisplay = (PFNEGLGETDISPLAYPROC) eglGetProcAddress("eglGetDisplay");
|
|
|
|
initialize = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize");
|
|
|
|
bindAPI = (PFNEGLBINDAPIPROC) eglGetProcAddress("eglBindAPI");
|
|
|
|
chooseConfig = (PFNEGLCHOOSECONFIGPROC) eglGetProcAddress("eglChooseConfig");
|
|
|
|
createWindowSurface = (PFNEGLCREATEWINDOWSURFACEPROC) eglGetProcAddress("eglCreateWindowSurface");
|
|
|
|
createContext = (PFNEGLCREATECONTEXTPROC) eglGetProcAddress("eglCreateContext");
|
|
|
|
makeCurrent = (PFNEGLMAKECURRENTPROC) eglGetProcAddress("eglMakeCurrent");
|
|
|
|
if (!getDisplay || !initialize || !bindAPI || !chooseConfig || !createWindowSurface || !createContext || !makeCurrent)
|
|
|
|
return GL_TRUE;
|
|
|
|
|
|
|
|
display = getDisplay((EGLNativeDisplayType) 0);
|
|
|
|
if (!initialize(display, &majorVersion, &minorVersion))
|
2015-12-06 02:58:46 +00:00
|
|
|
return GL_TRUE;
|
2016-01-24 11:55:33 +00:00
|
|
|
bindAPI(EGL_OPENGL_API);
|
|
|
|
if (!chooseConfig(display, attr, &config, 1, &numConfig) || (numConfig != 1))
|
2015-12-06 02:58:46 +00:00
|
|
|
return GL_TRUE;
|
2016-01-24 11:55:33 +00:00
|
|
|
surface = createWindowSurface(display, config, (EGLNativeWindowType) NULL, NULL);
|
|
|
|
ctx = createContext(display, config, NULL, NULL);
|
2015-12-06 02:58:46 +00:00
|
|
|
if (NULL == ctx) return GL_TRUE;
|
2016-01-24 11:55:33 +00:00
|
|
|
makeCurrent(display, surface, surface, ctx);
|
2015-12-06 02:58:46 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
|
|
|
if (NULL != ctx) eglDestroyContext(display, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(GLEW_OSMESA)
|
2014-06-24 15:03:28 +00:00
|
|
|
OSMesaContext ctx;
|
|
|
|
|
2015-10-12 10:17:34 +00:00
|
|
|
static const GLint osmFormat = GL_UNSIGNED_BYTE;
|
|
|
|
static const GLint osmWidth = 640;
|
|
|
|
static const GLint osmHeight = 480;
|
|
|
|
static GLubyte *osmPixels = NULL;
|
|
|
|
|
2015-10-08 12:03:16 +00:00
|
|
|
GLboolean glewCreateContext (struct createParams *params)
|
2014-06-24 15:03:28 +00:00
|
|
|
{
|
|
|
|
ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
|
|
|
|
if (NULL == ctx) return GL_TRUE;
|
2015-10-12 10:17:34 +00:00
|
|
|
if (NULL == osmPixels)
|
|
|
|
{
|
|
|
|
osmPixels = (GLubyte *) calloc(osmWidth*osmHeight*4, 1);
|
|
|
|
}
|
|
|
|
if (!OSMesaMakeCurrent(ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))
|
|
|
|
{
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2014-06-24 15:03:28 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
|
|
|
if (NULL != ctx) OSMesaDestroyContext(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(_WIN32)
|
2003-09-26 13:49:28 +00:00
|
|
|
|
2003-09-26 14:45:00 +00:00
|
|
|
HWND wnd = NULL;
|
|
|
|
HDC dc = NULL;
|
|
|
|
HGLRC rc = NULL;
|
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
GLboolean glewCreateContext (struct createParams* params)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
|
|
|
PIXELFORMATDESCRIPTOR pfd;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* register window class */
|
2003-09-26 13:49:28 +00:00
|
|
|
ZeroMemory(&wc, sizeof(WNDCLASS));
|
|
|
|
wc.hInstance = GetModuleHandle(NULL);
|
|
|
|
wc.lpfnWndProc = DefWindowProc;
|
|
|
|
wc.lpszClassName = "GLEW";
|
|
|
|
if (0 == RegisterClass(&wc)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create window */
|
2015-12-06 02:58:46 +00:00
|
|
|
wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
2004-02-02 02:25:18 +00:00
|
|
|
CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
|
2003-09-26 13:49:28 +00:00
|
|
|
if (NULL == wnd) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* get the device context */
|
2003-09-26 13:49:28 +00:00
|
|
|
dc = GetDC(wnd);
|
|
|
|
if (NULL == dc) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* find pixel format */
|
2003-09-26 13:49:28 +00:00
|
|
|
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
|
2015-02-16 13:16:10 +00:00
|
|
|
if (params->pixelformat == -1) /* find default */
|
2004-02-01 21:26:11 +00:00
|
|
|
{
|
|
|
|
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
|
|
pfd.nVersion = 1;
|
|
|
|
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
|
2015-02-16 13:16:10 +00:00
|
|
|
params->pixelformat = ChoosePixelFormat(dc, &pfd);
|
|
|
|
if (params->pixelformat == 0) return GL_TRUE;
|
2004-02-01 21:26:11 +00:00
|
|
|
}
|
2003-09-26 14:17:28 +00:00
|
|
|
/* set the pixel format for the dc */
|
2015-02-16 13:16:10 +00:00
|
|
|
if (FALSE == SetPixelFormat(dc, params->pixelformat, &pfd)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create rendering context */
|
2003-09-26 13:49:28 +00:00
|
|
|
rc = wglCreateContext(dc);
|
|
|
|
if (NULL == rc) return GL_TRUE;
|
|
|
|
if (FALSE == wglMakeCurrent(dc, rc)) return GL_TRUE;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->major || params->profile || params->flags)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
HGLRC oldRC = rc;
|
|
|
|
int contextAttrs[20];
|
|
|
|
int i;
|
|
|
|
|
2015-08-07 06:41:04 +00:00
|
|
|
wglewInit();
|
2015-02-16 13:16:10 +00:00
|
|
|
|
2015-07-24 01:52:16 +00:00
|
|
|
/* Intel HD 3000 has WGL_ARB_create_context, but not WGL_ARB_create_context_profile */
|
|
|
|
if (!wglewGetExtension("WGL_ARB_create_context"))
|
2015-02-16 13:16:10 +00:00
|
|
|
return GL_TRUE;
|
|
|
|
|
|
|
|
i = 0;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->major)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
contextAttrs[i++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
|
|
|
|
contextAttrs[i++] = params->major;
|
|
|
|
contextAttrs[i++] = WGL_CONTEXT_MINOR_VERSION_ARB;
|
|
|
|
contextAttrs[i++] = params->minor;
|
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->profile)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
contextAttrs[i++] = WGL_CONTEXT_PROFILE_MASK_ARB;
|
2015-05-29 10:45:19 +00:00
|
|
|
contextAttrs[i++] = params->profile;
|
2015-02-16 13:16:10 +00:00
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->flags)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2003-09-26 13:49:28 +00:00
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
|
|
|
if (NULL != rc) wglMakeCurrent(NULL, NULL);
|
2009-05-23 04:25:54 +00:00
|
|
|
if (NULL != rc) wglDeleteContext(rc);
|
2003-09-26 13:49:28 +00:00
|
|
|
if (NULL != wnd && NULL != dc) ReleaseDC(wnd, dc);
|
|
|
|
if (NULL != wnd) DestroyWindow(wnd);
|
|
|
|
UnregisterClass("GLEW", GetModuleHandle(NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2004-02-02 02:25:18 +00:00
|
|
|
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
|
2003-09-26 13:49:28 +00:00
|
|
|
|
2015-02-21 10:53:05 +00:00
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
#include <OpenGL/CGLTypes.h>
|
2003-10-27 01:06:34 +00:00
|
|
|
|
2015-02-21 10:53:05 +00:00
|
|
|
CGLContextObj ctx, octx;
|
2003-09-27 06:56:18 +00:00
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
GLboolean glewCreateContext (struct createParams *params)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
2015-05-29 10:08:13 +00:00
|
|
|
CGLPixelFormatAttribute contextAttrs[20];
|
|
|
|
int i;
|
2015-02-21 10:53:05 +00:00
|
|
|
CGLPixelFormatObj pf;
|
|
|
|
GLint npix;
|
|
|
|
CGLError error;
|
|
|
|
|
2015-05-29 10:08:13 +00:00
|
|
|
i = 0;
|
|
|
|
contextAttrs[i++] = kCGLPFAAccelerated; /* No software rendering */
|
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->profile & GL_CONTEXT_CORE_PROFILE_BIT)
|
2015-05-29 10:08:13 +00:00
|
|
|
{
|
|
|
|
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 */
|
|
|
|
}
|
2015-02-16 13:16:10 +00:00
|
|
|
}
|
2015-05-29 10:08:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
contextAttrs[i++] = 0;
|
2015-02-16 13:16:10 +00:00
|
|
|
|
2015-05-29 10:08:13 +00:00
|
|
|
error = CGLChoosePixelFormat(contextAttrs, &pf, &npix);
|
2015-02-21 10:53:05 +00:00
|
|
|
if (error) return GL_TRUE;
|
|
|
|
error = CGLCreateContext(pf, NULL, &ctx);
|
|
|
|
if (error) return GL_TRUE;
|
|
|
|
CGLReleasePixelFormat(pf);
|
|
|
|
octx = CGLGetCurrentContext();
|
|
|
|
error = CGLSetCurrentContext(ctx);
|
|
|
|
if (error) return GL_TRUE;
|
2012-07-23 21:19:50 +00:00
|
|
|
/* Needed for Regal on the Mac */
|
|
|
|
#if defined(GLEW_REGAL) && defined(__APPLE__)
|
2014-01-14 00:58:43 +00:00
|
|
|
RegalMakeCurrent(ctx);
|
2012-07-23 21:19:50 +00:00
|
|
|
#endif
|
2003-09-27 06:56:18 +00:00
|
|
|
return GL_FALSE;
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
2015-02-21 10:53:05 +00:00
|
|
|
CGLSetCurrentContext(octx);
|
|
|
|
CGLReleaseContext(ctx);
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
2013-12-09 21:20:56 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
#elif defined(__HAIKU__)
|
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
GLboolean glewCreateContext (struct createParams *params)
|
2013-12-09 21:20:56 +00:00
|
|
|
{
|
|
|
|
/* TODO: Haiku: We need to call C++ code here */
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
|
|
|
/* TODO: Haiku: We need to call C++ code here */
|
|
|
|
}
|
2003-09-26 13:49:28 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2004-02-02 02:25:18 +00:00
|
|
|
#else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
|
|
|
|
|
2003-09-26 14:45:00 +00:00
|
|
|
Display* dpy = NULL;
|
|
|
|
XVisualInfo* vi = NULL;
|
2004-02-01 22:59:49 +00:00
|
|
|
XVisualInfo* vis = NULL;
|
2003-09-26 14:45:00 +00:00
|
|
|
GLXContext ctx = NULL;
|
2004-02-01 22:59:49 +00:00
|
|
|
Window wnd = 0;
|
|
|
|
Colormap cmap = 0;
|
2003-09-26 14:17:28 +00:00
|
|
|
|
2015-02-16 13:16:10 +00:00
|
|
|
GLboolean glewCreateContext (struct createParams *params)
|
2003-09-26 13:49:28 +00:00
|
|
|
{
|
2003-10-27 08:57:44 +00:00
|
|
|
int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
|
2003-09-26 14:17:28 +00:00
|
|
|
int erb, evb;
|
2003-09-26 16:07:24 +00:00
|
|
|
XSetWindowAttributes swa;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* open display */
|
2015-02-16 13:16:10 +00:00
|
|
|
dpy = XOpenDisplay(params->display);
|
2003-09-26 14:17:28 +00:00
|
|
|
if (NULL == dpy) return GL_TRUE;
|
|
|
|
/* query for glx */
|
2003-09-26 14:45:00 +00:00
|
|
|
if (!glXQueryExtension(dpy, &erb, &evb)) return GL_TRUE;
|
2003-09-26 14:17:28 +00:00
|
|
|
/* choose visual */
|
2015-02-16 13:16:10 +00:00
|
|
|
if (params->visual == -1)
|
2004-02-01 22:59:49 +00:00
|
|
|
{
|
|
|
|
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);
|
|
|
|
if (NULL == vi) return GL_TRUE;
|
2015-02-16 13:16:10 +00:00
|
|
|
params->visual = (int)XVisualIDFromVisual(vi->visual);
|
2004-02-01 22:59:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int n_vis, i;
|
|
|
|
vis = XGetVisualInfo(dpy, 0, NULL, &n_vis);
|
|
|
|
for (i=0; i<n_vis; i++)
|
|
|
|
{
|
2015-02-16 13:16:10 +00:00
|
|
|
if ((int)XVisualIDFromVisual(vis[i].visual) == params->visual)
|
2004-02-01 22:59:49 +00:00
|
|
|
vi = &vis[i];
|
|
|
|
}
|
|
|
|
if (vi == NULL) return GL_TRUE;
|
|
|
|
}
|
2003-09-26 14:17:28 +00:00
|
|
|
/* create context */
|
|
|
|
ctx = glXCreateContext(dpy, vi, None, True);
|
|
|
|
if (NULL == ctx) return GL_TRUE;
|
|
|
|
/* create window */
|
2003-09-26 16:33:19 +00:00
|
|
|
/*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
|
2003-09-26 16:07:24 +00:00
|
|
|
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
|
|
|
|
swa.border_pixel = 0;
|
|
|
|
swa.colormap = cmap;
|
2015-12-06 02:58:46 +00:00
|
|
|
wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
|
|
|
|
0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual,
|
2004-02-02 02:25:18 +00:00
|
|
|
CWBorderPixel | CWColormap, &swa);
|
2003-09-26 16:33:19 +00:00
|
|
|
/* make context current */
|
2003-09-26 14:17:28 +00:00
|
|
|
if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->major || params->profile || params->flags)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
GLXContext oldCtx = ctx;
|
|
|
|
GLXFBConfig *FBConfigs;
|
|
|
|
int FBConfigAttrs[] = { GLX_FBCONFIG_ID, 0, None };
|
|
|
|
int contextAttrs[20];
|
|
|
|
int nelems, i;
|
|
|
|
|
2015-08-07 06:41:04 +00:00
|
|
|
glxewInit();
|
2015-02-16 13:16:10 +00:00
|
|
|
|
2015-07-24 02:16:39 +00:00
|
|
|
if (!glxewGetExtension("GLX_ARB_create_context"))
|
2015-02-16 13:16:10 +00:00
|
|
|
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;
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->major)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
contextAttrs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
|
|
|
|
contextAttrs[i++] = params->major;
|
|
|
|
contextAttrs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB;
|
|
|
|
contextAttrs[i++] = params->minor;
|
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->profile)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
contextAttrs[i++] = GLX_CONTEXT_PROFILE_MASK_ARB;
|
2015-05-29 10:45:19 +00:00
|
|
|
contextAttrs[i++] = params->profile;
|
2015-02-16 13:16:10 +00:00
|
|
|
}
|
2015-05-29 10:45:19 +00:00
|
|
|
if (params->flags)
|
2015-02-16 13:16:10 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2003-09-26 14:17:28 +00:00
|
|
|
return GL_FALSE;
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void glewDestroyContext ()
|
|
|
|
{
|
2003-09-26 14:45:00 +00:00
|
|
|
if (NULL != dpy && NULL != ctx) glXDestroyContext(dpy, ctx);
|
2004-02-01 22:59:49 +00:00
|
|
|
if (NULL != dpy && 0 != wnd) XDestroyWindow(dpy, wnd);
|
2004-02-02 01:57:57 +00:00
|
|
|
if (NULL != dpy && 0 != cmap) XFreeColormap(dpy, cmap);
|
2004-02-01 22:59:49 +00:00
|
|
|
if (NULL != vis)
|
|
|
|
XFree(vis);
|
|
|
|
else if (NULL != vi)
|
|
|
|
XFree(vi);
|
2003-09-26 14:45:00 +00:00
|
|
|
if (NULL != dpy) XCloseDisplay(dpy);
|
2003-09-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
2004-02-02 02:25:18 +00:00
|
|
|
#endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
|