}
GLContextImpl ctxImpl = (GLContextImpl)glContext;
glID[0] = glContext.getHandle();
NativeSizeBuffer properties;
if(glContext instanceof X11GLXContext) {
// spec: "When the GLX binding API is supported, the attribute
// CL_GL_CONTEXT_KHR should be set to a GLXContext handle to an
// OpenGL context, and the attribute CL_GLX_DISPLAY_KHR should be
// set to the Display handle of the X Window System display used to
// create the OpenGL context."
properties = NativeSizeBuffer.allocateDirect(7);
long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
.put(CL_GLX_DISPLAY_KHR).put(displayHandle)
.put(CL_CONTEXT_PLATFORM).put(platform.ID);
}else if(glContext instanceof WindowsWGLContext) {
// spec: "When the WGL binding API is supported, the attribute
// CL_GL_CONTEXT_KHR should be set to an HGLRC handle to an OpenGL
// context, and the attribute CL_WGL_HDC_KHR should be set to the
// HDC handle of the display used to create the OpenGL context."
properties = NativeSizeBuffer.allocateDirect(7);
long surfaceHandle = ctxImpl.getDrawableImpl().getNativeSurface().getSurfaceHandle();
properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
.put(CL_WGL_HDC_KHR).put(surfaceHandle)
.put(CL_CONTEXT_PLATFORM).put(platform.ID);
}else if(glContext instanceof MacOSXCGLContext) {
// spec: "When the CGL binding API is supported, the attribute
// CL_CGL_SHAREGROUP_KHR should be set to a CGLShareGroup handle to
// a CGL share group object."
long cgl = CGL.getCGLContext(glID[0]);
long group = CGL.CGLGetShareGroup(cgl);
properties = NativeSizeBuffer.allocateDirect(5);
properties.put(CL_CGL_SHAREGROUP_KHR).put(group)
.put(CL_CONTEXT_PLATFORM).put(platform.ID);
}else if(glContext instanceof EGLContext) {
// TODO test EGL
// spec: "When the EGL binding API is supported, the attribute
// CL_GL_CONTEXT_KHR should be set to an EGLContext handle to an
// OpenGL ES or OpenGL context, and the attribute
// CL_EGL_DISPLAY_KHR should be set to the EGLDisplay handle of the
// display used to create the OpenGL ES or OpenGL context."
properties = NativeSizeBuffer.allocateDirect(7);
long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
properties.put(CL_GL_CONTEXT_KHR).put(glID[0])
.put(CL_EGL_DISPLAY_KHR).put(displayHandle)
.put(CL_CONTEXT_PLATFORM).put(platform.ID);
}else{
throw new RuntimeException("unsupported GLContext: "+glContext);
}
return properties.put(0).rewind(); // 0 terminated array
}