Trying to share data between OpenGL and OpenCL - need OpenGL native context?

Started by Fletcher, August 11, 2012, 22:41:26

Previous topic - Next topic

Fletcher

I'm trying to have OpenCL operate on a pixel buffer object that's being used by OpenGL.
OpenCL needs to be created on the same context as OpenGL to do this.
Other projects I've seen that do this create the context by putting the OpenGL context in the properties argument of CLContext.create().
For example, here's someone's C++ code:

            cl_context_properties props[] =
            {
                CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
                CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
                CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(),
                0
            };
            context = cl::Context(CL_DEVICE_TYPE_GPU, props);


The LWJGL version of CLContext.create() does allow a PointerBuffer argument containing properties, but the only problem I have is passing it the OpenGL context. I can't seem to find any way to get at it.
I understand LWJGL wouldn't want to expose the native OpenGL context but does anyone know if there's any way at all to find it in Java, either through LWJGL or even some native library?

spasi

You need to pass an LWJGL Drawable (e.g. Display.getDrawable()) to CLContext.create. There's an example in the LWJGL test package, class org.lwjgl.test.opencl.gl.DemoFractal.

Fletcher

Oh, fantastic! I should've known there was a much easier way. That works perfectly. Thanks so much!