static bool create_gl_context(struct MPGLContext *ctx) { struct cgl_context *p = ctx->priv; CGLError err; CGLOpenGLProfile gl_versions[] = { kCGLOGLPVersion_3_2_Core, kCGLOGLPVersion_Legacy, }; for (int n = 0; n < MP_ARRAY_SIZE(gl_versions); n++) { err = test_gl_version(ctx->vo, &p->ctx, &p->pix, gl_versions[n]); if (err == kCGLNoError) break; } if (err != kCGLNoError) { MP_FATAL(ctx->vo, "error creating CGL context: %s (%d)\n", CGLErrorString(err), err); return false; } vo_cocoa_set_opengl_ctx(ctx->vo, p->ctx); CGLSetCurrentContext(p->ctx); ctx->depth_r = ctx->depth_g = ctx->depth_b = cgl_color_size(ctx); mpgl_load_functions(ctx->gl, (void *)cocoa_glgetaddr, NULL, ctx->vo->log); CGLReleasePixelFormat(p->pix); return true; }
static bool setup_gl_context() { CGLPixelFormatAttribute attributes[] = { (CGLPixelFormatAttribute)0 }; CGLPixelFormatObj format; GLint npix; CGLChoosePixelFormat(attributes, &format, &npix); CGLContextObj context; CGLCreateContext(format, nullptr, &context); CGLSetCurrentContext(context); CGLReleasePixelFormat(format); return true; }
int main (void) { CGLPixelFormatAttribute attribs[] = {0}; CGLPixelFormatObj pix; CGLContextObj ctx; const char *string; bool pass = true; int npix; GLint shader; CGLChoosePixelFormat(attribs, &pix, &npix); CGLCreateContext(pix, (void *) 0, &ctx); CGLSetCurrentContext(ctx); if (!epoxy_is_desktop_gl()) { fputs("Claimed not to be desktop\n", stderr); pass = false; } if (epoxy_gl_version() < 20) { fprintf(stderr, "Claimed to be GL version %d\n", epoxy_gl_version()); pass = false; } if (epoxy_glsl_version() < 100) { fprintf(stderr, "Claimed to have GLSL version %d\n", epoxy_glsl_version()); pass = false; } string = (const char *)glGetString(GL_VERSION); printf("GL version: %s - Epoxy: %d\n", string, epoxy_gl_version()); string = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION); printf("GLSL version: %s - Epoxy: %d\n", string, epoxy_glsl_version()); shader = glCreateShader(GL_FRAGMENT_SHADER); pass = glIsShader(shader); CGLSetCurrentContext(NULL); CGLReleaseContext(ctx); CGLReleasePixelFormat(pix); return pass != true; }
static GLboolean CreateContext(GLContext* ctx) { CGLPixelFormatAttribute attrib[] = { kCGLPFAAccelerated, 0 }; CGLPixelFormatObj pf; GLint npix; CGLError error; /* check input */ if (NULL == ctx) return GL_TRUE; error = CGLChoosePixelFormat(attrib, &pf, &npix); if (error) return GL_TRUE; error = CGLCreateContext(pf, NULL, &ctx->ctx); if (error) return GL_TRUE; CGLReleasePixelFormat(pf); ctx->octx = CGLGetCurrentContext(); error = CGLSetCurrentContext(ctx->ctx); if (error) return GL_TRUE; return GL_FALSE; }
VOID GL3OSXRenderWindow::ReleaseOpenGL() { if(m_pContextObj) { CGLContextObj pContextObj = CGLGetCurrentContext(); if(pContextObj == m_pContextObj) { CGLSetCurrentContext(NULL); } CGLReleaseContext(m_pContextObj); m_pContextObj = NULL; } if(m_pPixelFormatObj) { //CGLDestroyPixelFormat : Calling this function is equivalent to calling CGLReleasePixelFormat. CGLReleasePixelFormat(m_pPixelFormatObj); m_pPixelFormatObj = NULL; } }
int createTestGLContext(void) { CGLPixelFormatAttribute attributes[] = { kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, kCGLPFADoubleBuffer, 0 }; CGLPixelFormatObj pixelFormat; GLint numScreens; CGLError error; error = CGLChoosePixelFormat(attributes, &pixelFormat, &numScreens); if (error != kCGLNoError) return 0; error = CGLCreateContext(pixelFormat, 0, &g_context); CGLReleasePixelFormat(pixelFormat); if (error != kCGLNoError) return 0; CGLSetCurrentContext(g_context); return 1; }
GLboolean glewCreateContext (struct createParams *params) { CGLPixelFormatAttribute contextAttrs[20]; int i; CGLPixelFormatObj pf; GLint npix; CGLError error; 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; CGLReleasePixelFormat(pf); octx = CGLGetCurrentContext(); error = CGLSetCurrentContext(ctx); if (error) return GL_TRUE; /* Needed for Regal on the Mac */ #if defined(GLEW_REGAL) && defined(__APPLE__) RegalMakeCurrent(ctx); #endif return GL_FALSE; }
PixelFormat::~PixelFormat() { CGLReleasePixelFormat(_pixel_format); }