just to keep it complete .. with lwjgl v.2.5 we need to do something like that. notice how the way to access the context class changed :
..( ugly reflection code )..
... so we can use
Drawable d = org.lwjgl.opengl.Display.getDrawable ();
Method getcontext = d.getClass ().getSuperclass ().getDeclaredMethod ( "getContext" );
...
just to keep it complete again .. with lwjgl 2.9.1 and it's very nice openCL integration it's now very easy to use LWJGL with JOCL. it's too clear to be missed but it may be still useful to somebody.
with this little helper method you can get all values required for a gl-shared opencl context :
public static long[] getOpenCLSharingProps()
{
try
{
PointerBuffer propsBuffer = new PointerBuffer(4);
Display.getDrawable().setCLSharingProperties(propsBuffer);
propsBuffer.rewind();
long[] sharingProps = new long[propsBuffer.limit()];
while(propsBuffer.hasRemaining()) sharingProps[propsBuffer.position()] = propsBuffer.get();
return sharingProps;
}
catch(LWJGLException e)
{
Logger.log.error(e);
}
return null;
}
now, when you create the jocl context properties :
[...]
cl_context_properties contextProperties = new cl_context_properties();
contextProperties.addProperty(CL_CONTEXT_PLATFORM,platforms[platform]); // defined somewhere else
if(shareProps != null) // shareProps is that long[] array
{
for(int i = 0; i < shareProps.length; )
{
long prop = shareProps[i++];
long value = shareProps[i++];
// that verify is not really required :
if( //
prop != CL_GL_CONTEXT_KHR && //
prop != CL_WGL_HDC_KHR && //
prop != CL_GLX_DISPLAY_KHR && //
prop != CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) throw new UnsupportedOperationException("prop : " + prop + " value : " + value + " is not supported.");
contextProperties.addProperty(prop,value);
}
}
[...]
works with windows and linux but i cannot confirm apple. actually i cannot find any CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE constant in jocl, what am i missing ? some extension .. or is lwjgl's cl-binding just more advanced ?