29package com.jogamp.opencl.gl;
31import java.nio.Buffer;
33import com.jogamp.opengl.GLContext;
35import jogamp.opengl.GLContextImpl;
36import jogamp.opengl.egl.EGLContext;
37import jogamp.opengl.macosx.cgl.CGL;
38import jogamp.opengl.macosx.cgl.MacOSXCGLContext;
39import jogamp.opengl.windows.wgl.WindowsWGLContext;
40import jogamp.opengl.x11.glx.X11GLXContext;
42import com.jogamp.common.nio.PointerBuffer;
43import com.jogamp.opencl.CLContext;
44import com.jogamp.opencl.CLDevice;
45import com.jogamp.opencl.CLMemory.Mem;
46import com.jogamp.opencl.CLPlatform;
47import com.jogamp.opencl.llb.CL;
56 private final GLContext glContext;
59 super(
platform, clContextID, dispatcher);
60 this.glID = glContextID;
61 this.glContext = glContext;
86 return create(glContext,
null, deviceTypes);
100 final long[] glID =
new long[1];
101 final PointerBuffer properties = setupContextProperties(
platform, glContext, glID);
117 throw new IllegalArgumentException(
"no devices specified");
119 throw new IllegalArgumentException(
"first device was null");
124 final long[] glID =
new long[1];
125 final PointerBuffer properties = setupContextProperties(
platform, glContext, glID);
131 for (
int i = 0; i <
devices.length; i++) {
139 private static PointerBuffer setupContextProperties(
final CLPlatform platform,
final GLContext glContext,
final long[] glID) {
142 throw new RuntimeException(
"no OpenCL installation found");
144 if(glContext ==
null) {
145 throw new IllegalArgumentException(
"GLContext was null.");
149 if(!glContext.isCurrent()) {
150 throw new IllegalArgumentException(
"OpenGL context is not current,\n"+
151 " creating a OpenCL context for context sharing is not allowed in this situation.");
154 final GLContextImpl ctxImpl = (GLContextImpl)glContext;
155 glID[0] = glContext.getHandle();
157 PointerBuffer properties;
158 if(glContext instanceof X11GLXContext) {
164 properties = PointerBuffer.allocateDirect(7);
165 final long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
166 properties.put(CL.CL_GL_CONTEXT_KHR).put(glID[0])
167 .put(CL.CL_GLX_DISPLAY_KHR).put(displayHandle)
168 .put(CL.CL_CONTEXT_PLATFORM).put(
platform.
ID);
169 }
else if(glContext instanceof WindowsWGLContext) {
174 properties = PointerBuffer.allocateDirect(7);
175 final long surfaceHandle = ctxImpl.getDrawableImpl().getNativeSurface().getSurfaceHandle();
176 properties.put(CL.CL_GL_CONTEXT_KHR).put(glID[0])
177 .put(CL.CL_WGL_HDC_KHR).put(surfaceHandle)
178 .put(CL.CL_CONTEXT_PLATFORM).put(
platform.
ID);
179 }
else if(glContext instanceof MacOSXCGLContext) {
190 final long cgl = CGL.getCGLContext(glID[0]);
191 final long group = CGL.CGLGetShareGroup(cgl);
192 properties = PointerBuffer.allocateDirect(5);
193 properties.put(CL.CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE).put(group)
194 .put(CL.CL_CONTEXT_PLATFORM).put(
platform.
ID);
195 }
else if(glContext instanceof EGLContext) {
202 properties = PointerBuffer.allocateDirect(7);
203 final long displayHandle = ctxImpl.getDrawableImpl().getNativeSurface().getDisplayHandle();
204 properties.put(CL.CL_GL_CONTEXT_KHR).put(glID[0])
205 .put(CL.CL_EGL_DISPLAY_KHR).put(displayHandle)
206 .put(CL.CL_CONTEXT_PLATFORM).put(
platform.
ID);
208 throw new RuntimeException(
"unsupported GLContext: "+glContext);
211 return properties.put(0).rewind();
321 return super.getCL();
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
void overrideContext(final CLDevice device)
static long createContextFromType(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final long deviceType)
static CLContext create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL).
final Set< CLMemory<? extends Buffer > > memoryObjects
static long createContext(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final CLDevice... devices)
static long toDeviceBitmap(final Type[] deviceTypes)
static ErrorDispatcher createErrorHandler()
final CLPlatform platform
This object represents an OpenCL device.
CLPlatform getPlatform()
Returns the platform for this OpenCL object.
Shared buffer between OpenGL and OpenCL contexts.
OpenCL Context supporting JOGL-JOCL interoperablity.
final< B extends Buffer > CLGLBuffer< B > createFromGLBuffer(final B directBuffer, final int glBuffer, final long glBufferSize, final int flags)
Creates a CLGLBuffer for memory sharing with the specified OpenGL buffer.
final CLGLTexture2d<?> createFromGLTexture2d(final int target, final int texture, final int mipmap, final int flags)
final< B extends Buffer > CLGLTexture2d< B > createFromGLTexture2d(final B directBuffer, final int target, final int texture, final int mipmap, final int flags)
static CLGLContext create(final GLContext glContext, CLPlatform platform, final CLDevice.Type... deviceTypes)
Creates a shared context on the specified platform and with the specified device types.
final< B extends Buffer > CLGLBuffer< B > createFromGLBuffer(final B directBuffer, final int glBuffer, final long glBufferSize, final Mem... flags)
Creates a CLGLBuffer for memory sharing with the specified OpenGL buffer.
final CLGLBuffer<?> createFromGLBuffer(final int glBuffer, final long glBufferSize, final Mem... flags)
Creates a CLGLBuffer for memory sharing with the specified OpenGL buffer.
CL getCL()
Return the low level OpenCL interface with OpenGL interoperability.
final CLGLImage2d<?> createFromGLRenderbuffer(final int glBuffer, final Mem... flags)
final CLGLBuffer<?> createFromGLBuffer(final int glBuffer, final long glBufferSize, final int flags)
Creates a CLGLBuffer for memory sharing with the specified OpenGL buffer.
final< B extends Buffer > CLGLTexture3d< B > createFromGLTexture3d(final B directBuffer, final int target, final int texture, final int mipmap, final Mem... flags)
final< B extends Buffer > CLGLImage2d< B > createFromGLRenderbuffer(final B directBuffer, final int glBuffer, final int flags)
final CLGLTexture2d<?> createFromGLTexture2d(final int target, final int texture, final int mipmap, final Mem... flags)
final CLGLTexture3d<?> createFromGLTexture3d(final int target, final int texture, final int mipmap, final int flags)
final CLGLTexture3d<?> createFromGLTexture3d(final int target, final int texture, final int mipmap, final Mem... flags)
GLContext getGLContext()
Returns the OpenGL context this context was shared with.
final< B extends Buffer > CLGLImage2d< B > createFromGLRenderbuffer(final B directBuffer, final int glBuffer, final Mem... flags)
final< B extends Buffer > CLGLTexture2d< B > createFromGLTexture2d(final B directBuffer, final int target, final int texture, final int mipmap, final Mem... flags)
static CLGLContext create(final GLContext glContext, final CLDevice... devices)
Creates a shared context on the specified platform and with the specified devices.
static CLGLContext create(final GLContext glContext)
Creates a shared context on all available devices (CL_DEVICE_TYPE_ALL).
CLGLContext getContext()
Returns the context for this OpenCL object.
static CLGLContext create(final GLContext glContext, final CLDevice.Type... deviceTypes)
Creates a shared context on the specified platform and with the specified device types.
static CLGLContext create(final GLContext glContext, final CLPlatform platform)
Creates a shared context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).
final CLGLImage2d<?> createFromGLRenderbuffer(final int glBuffer, final int flags)
final< B extends Buffer > CLGLTexture3d< B > createFromGLTexture3d(final B directBuffer, final int target, final int texture, final int mipmap, final int flags)
2D OpenCL image representing an OpenGL renderbuffer.
2D OpenCL image representing an 2D OpenGL texture.
3D OpenCL image representing an 3D OpenGL texture.
Enumeration for the type of a device.
Memory settings for configuring CLMemory.
static int flagsToInt(final Mem[] flags)
Java bindings to OpenCL, the Open Computing Language.