私は 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);
コンテキストを取得する前に、init コードが呼び出されます。
glXGetCurrentContext() はセグメンテーション違反をしませんでしたが、glXGetCurrentDisplay() はしました。
相互運用を除いて、なぜ glutInit() を呼び出した後でも glXGetCurrentDisplay() seg fault になるのか
PS OpenGL でプラットフォーム/デバイスを明示的に選択する方法はありますか?