mip87's picture

Cloo - CLGL on Mac

Hi guys.

I was wondering if anyone of you was able to get CLGL shared context on a Mac ?

Everything works fine on Windows:

	[DllImport("opengl32.dll")]
	extern static IntPtr wglGetCurrentDC();
	[DllImport("opengl32.dll")]
	extern static IntPtr wglGetCurrentContext();
 
...
...
...
		ComputePlatform platform = ComputePlatform.Platforms[0]; 
		IntPtr deviceContextHandle = wglGetCurrentDC();
		IntPtr openGLContextHandle = wglGetCurrentContext();
 
 
		ComputeContextProperty p1 = new ComputeContextProperty(ComputeContextPropertyName.Platform, platform.Handle.Value);
		ComputeContextProperty p2 = new ComputeContextProperty(ComputeContextPropertyName.CL_GL_CONTEXT_KHR, openGLContextHandle);
		ComputeContextProperty p3 = new ComputeContextProperty(ComputeContextPropertyName.CL_WGL_HDC_KHR, deviceContextHandle);
		ComputeContextPropertyList cpl = new ComputeContextPropertyList(new ComputeContextProperty[] { p1 , p2, p3 });
 
		context = new ComputeContext(ComputeDeviceTypes.Gpu, cpl, null, IntPtr.Zero);

Works like charm. (Note: I'm actually not using OpenTK here... )

However... If i am trying the same thing for Mac (with Mac specific ComputeContextProperty) i get an InvalidValueComputeException: OpenCL error code detected: InvalidValue when trying to create ComputeContext.
In general i am doing the same as described here: http://www.opentk.com/node/2842 (however, they do not confirm that it works on MAC)

    [DllImport(GLLibrary)]
    private static extern IntPtr CGLGetCurrentContext();
    [DllImport(GLLibrary)]
    extern static IntPtr CGLGetShareGroup(IntPtr context);
 
 IntPtr context = CGLGetCurrentContext();
 
ComputeContextProperty p1 = new ComputeContextProperty(ComputeContextPropertyName.CL_CGL_SHAREGROUP_KHR, CGLGetShareGroup(context ));
ComputeContextPropertyList cpl = new ComputeContextPropertyList(new ComputeContextProperty[] { p1  });
 
context = new ComputeContext(ComputeDeviceTypes.Gpu, cpl, null, IntPtr.Zero);

What am i doing wrong ? :)
Has anyone successfully got Cloo GLCL interopt running on MAC ?