Search code examples
objective-cmacosopenglopengl-3

CVOpenGLTextureCacheCreate kCVReturnAllocationFailed


I am trying to create a CVOpenGLTextureCache like this..

  NSOpenGLPixelFormatAttribute attrs[] =
    {
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFADepthSize, 32,
        NSOpenGLPFAOpenGLProfile,
        NSOpenGLProfileVersion3_2Core,
        0
    };
    NSOpenGLPixelFormat *pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];

    if (!pf)
    {
        NSLog(@"No OpenGL pixel format");
    }
    m_glesCtx  = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil];
    [(NSOpenGLContext*)m_glesCtx makeCurrentContext];

    CVReturn returnvalue = CVOpenGLTextureCacheCreate(kCFAllocatorDefault, NULL, (CGLContextObj)this->m_glesCtx, [pf CGLPixelFormatObj], NULL, &this->m_textureCache);

But it always fails with error -6662 which is kCVReturnAllocationFailed. Can anyone with some expertise in mac OpenGL help me to find out why it fails ..

Thanks for any help in advance..


Solution

  • My mistake.. Changed the statement

     CVReturn returnvalue = CVOpenGLTextureCacheCreate(kCFAllocatorDefault, NULL,(CGLContextObj)this->m_glesCtx, [pf CGLPixelFormatObj], NULL, &this->m_textureCache);
    

    to

     CVOpenGLTextureCacheCreate(kCFAllocatorDefault, 0, [(NSOpenGLContext*)this->m_glesCtx CGLContextObj], [pf CGLPixelFormatObj], 0, &this->m_textureCache);
    

    and every thing runs smooth.