aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLGLContext.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-02 00:15:55 +0100
committerMichael Bien <[email protected]>2010-01-02 00:15:55 +0100
commita5efe050242d1d6a45e03fcac1763ff90877e322 (patch)
treeb8135791915083d1e36b383a182f2973927c8ead /src/com/mbien/opencl/CLGLContext.java
parent72203a5d1f8896463ded10d1b21ca116621d1900 (diff)
introduced CLGLContext, refactored dependencies, cleanup in opencl code.
Diffstat (limited to 'src/com/mbien/opencl/CLGLContext.java')
-rw-r--r--src/com/mbien/opencl/CLGLContext.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java
new file mode 100644
index 00000000..9699c1ba
--- /dev/null
+++ b/src/com/mbien/opencl/CLGLContext.java
@@ -0,0 +1,83 @@
+package com.mbien.opencl;
+
+import java.nio.Buffer;
+import com.mbien.opencl.CLBuffer.Mem;
+import com.sun.opengl.impl.GLContextImpl;
+import com.sun.opengl.impl.macosx.cgl.MacOSXCGLContext;
+import com.sun.opengl.impl.windows.wgl.WindowsWGLContext;
+import com.sun.opengl.impl.x11.glx.X11GLXContext;
+import com.sun.opengl.impl.x11.glx.X11GLXGraphicsConfiguration;
+import java.nio.LongBuffer;
+import javax.media.nativewindow.DefaultGraphicsConfiguration;
+import javax.media.opengl.GLContext;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public final class CLGLContext extends CLContext {
+
+ final long glContextID;
+
+ private CLGLContext(long clContextID, long glContextID) {
+ super(clContextID);
+ this.glContextID = glContextID;
+ }
+
+ public static CLGLContext create(GLContext glContext) {
+
+ long glID = glContext.getContext();
+
+//UNIX
+//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)cpPlatform, 0};
+
+//WIN32
+//cl_context_properties props[] = {
+// CL_GL_CONTEXT_KHR, (cl_context_properties)TODO0,
+// CL_WGL_HDC_KHR, (cl_context_properties)TODO 0,
+// CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform, 0};
+
+//MACOSX
+//cl_context_properties props[] = {
+// CL_CGL_SHAREGROUP_KHR, (cl_context_properties)TODO 0,
+// CL_CONTEXT_PLATFORM, (cl_context_properties)cpPlatform, 0};
+
+ GLContextImpl ctxImpl = (GLContextImpl)glContext;
+
+ DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration)ctxImpl.getDrawableImpl()
+ .getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
+
+ LongBuffer properties = LongBuffer.allocate(5);
+ if(glContext instanceof X11GLXContext) {
+ long handle = config.getScreen().getDevice().getHandle();
+ properties.put(CLGLI.CL_GL_CONTEXT_KHR).put(glID)
+ .put(CLGLI.CL_GLX_DISPLAY_KHR).put(handle);
+ }else if(glContext instanceof WindowsWGLContext) {
+ // TODO test on windows
+ throw new RuntimeException("cl-gl interoperability on windows not yet implemented");
+ }else if(glContext instanceof MacOSXCGLContext) {
+ // TODO test on mac
+ throw new RuntimeException("cl-gl interoperability on mac not yet implemented");
+ }
+
+ properties.put(0).rewind(); // 0 terminated array
+
+ long clID = createContextFromType(properties, CL.CL_DEVICE_TYPE_ALL);
+
+ return new CLGLContext(clID, glID);
+ }
+
+
+ public final <B extends Buffer> CLBuffer<B> createFromGLBuffer(B directBuffer, int glBuffer, Mem... flags) {
+ return createFromGLBuffer(directBuffer, glBuffer, Mem.flagsToInt(flags));
+ }
+
+ public final <B extends Buffer> CLBuffer<B> createFromGLBuffer(B directBuffer, int glBuffer, int flags) {
+ CLBuffer<B> buffer = new CLBuffer<B>(this, directBuffer, glBuffer, flags);
+ buffers.add(buffer);
+ return buffer;
+ }
+}