我正在使用OpenCL / OpenGL互操作,并且已经能够使其在OSX上成功运行:

props[0] = CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
props[1] = (cl_context_properties) CGLGetShareGroup( CGLGetCurrentContext() );

但是,使用X通讯员时:
props[0] = CL_GL_CONTEXT_KHR;
props[1] = (cl_context_properties) glXGetCurrentContext();
props[2] = CL_GLX_DISPLAY_KHR;
props[3] = (cl_context_properties) glXGetCurrentDisplay();
props[4] = CL_CONTEXT_PLATFORM;
props[5] = (cl_context_properties) pID;

OpenGL初始化代码:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

screenWidth  = glutGet(GLUT_SCREEN_WIDTH);
screenHeight = glutGet(GLUT_SCREEN_HEIGHT);

glutInitWindowPosition( (screenWidth - width)/2 , (screenHeight - height)/2 );
glutInitWindowSize(width, height);
glutCreateWindow(appName.c_str());

glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);

glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glutDisplayFunc(render_s);
glutIdleFunc(render_s);
glutReshapeFunc(resize_s);
glutKeyboardFunc(keyPress_s);
glutKeyboardUpFunc(keyRelease_s);
glutMouseFunc(mousePress_s);
glutMotionFunc(mouseDrag_s);
glutPassiveMotionFunc(mouseMove_s);

在获取上下文之前会调用初始化代码。

glXGetCurrentContext()不会分段,但glXGetCurrentDisplay()可以。

不包括互操作性,为什么即使调用glutInit()之后glXGetCurrentDisplay()seg也会出错

附言有没有办法在OpenGL下明确选择平台/设备?

最佳答案


glutInit不会创建OpenGL上下文,因此glXGetCurrentDisplay将失败。您需要调用glutCreateWindow来实际创建上下文。

10-06 06:54