我正在学习 OpenGL。为了获得 OpenGL 上下文设置,我遵循 Apple 的GlEssentials示例。GlContext 被锁定在 draw 方法中,如下所示:
- (void) drawView
{
[[self openGLContext] makeCurrentContext];
// We draw on a secondary thread through the display link
// When resizing the view, -reshape is called automatically on the main
// thread. Add a mutex around to avoid the threads accessing the context
// simultaneously when resizing
CGLLockContext([[self openGLContext] CGLContextObj]);
[m_renderer render];
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
CGLUnlockContext([[self openGLContext] CGLContextObj]);
}
当我尝试CGLLockContext
在视图类中使用与上面完全相同的参数调用时,出现以下错误:
No matching function for call to 'CGLLockContext
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework/Headers/OpenGL.h:111:17: Candidate function not viable: cannot convert argument of incomplete type 'void *' to 'CGLContextObj' (aka '_CGLContextObject *')
快速插入类型转换解决了这个问题:
CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
问题是为什么?在 Apples 示例中,没有这种类型转换它可以正常工作。