diff --git a/jme3-examples/build.gradle b/jme3-examples/build.gradle index be2e106a6..47ee94c72 100644 --- a/jme3-examples/build.gradle +++ b/jme3-examples/build.gradle @@ -32,6 +32,7 @@ dependencies { compile project(':jme3-jogg') compile project(':jme3-jogl') compile project(':jme3-lwjgl') +// compile project(':jme3-lwjgl3') compile project(':jme3-networking') compile project(':jme3-niftygui') compile project(':jme3-plugins') diff --git a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java index f91cf0692..298a13059 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java @@ -203,6 +203,7 @@ public class LwjglBuffer extends Buffer { @Override public Event releaseBufferForSharingAsync(CommandQueue queue) { + Utils.assertSharingPossible(); Utils.pointerBuffers[0].rewind(); long q = ((LwjglCommandQueue) queue).getQueue(); int ret = CL10GL.clEnqueueReleaseGLObjects(q, buffer, null, Utils.pointerBuffers[0]); @@ -212,6 +213,7 @@ public class LwjglBuffer extends Buffer { } @Override public void releaseBufferForSharingNoEvent(CommandQueue queue) { + Utils.assertSharingPossible(); long q = ((LwjglCommandQueue) queue).getQueue(); int ret = CL10GL.clEnqueueReleaseGLObjects(q, buffer, null, null); Utils.checkError(ret, "clEnqueueReleaseGLObjects"); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java index e8c2aca26..932c486a3 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java @@ -161,6 +161,7 @@ public class LwjglContext extends Context { @Override public Buffer bindVertexBuffer(VertexBuffer vb, MemoryAccess access) { + Utils.assertSharingPossible(); int id = vb.getId(); if (id == -1) { throw new IllegalArgumentException("vertex buffer was not yet uploaded to the GPU or is CPU only"); @@ -174,6 +175,7 @@ public class LwjglContext extends Context { @Override public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) { + Utils.assertSharingPossible(); int imageID = image.getId(); if (imageID == -1) { throw new IllegalArgumentException("image was not yet uploaded to the GPU"); @@ -188,6 +190,7 @@ public class LwjglContext extends Context { @Override protected Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access) { + Utils.assertSharingPossible(); int renderbuffer = buffer.getId(); if (renderbuffer == -1) { throw new IllegalArgumentException("renderbuffer was not yet uploaded to the GPU"); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java index ff9606c13..5b9c06e66 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java @@ -544,6 +544,7 @@ public class LwjglImage extends Image { } @Override public Event releaseImageForSharingAsync(CommandQueue queue) { + Utils.assertSharingPossible(); Utils.pointerBuffers[0].rewind(); long q = ((LwjglCommandQueue) queue).getQueue(); int ret = CL10GL.clEnqueueReleaseGLObjects(q, image, null, Utils.pointerBuffers[0]); @@ -553,6 +554,7 @@ public class LwjglImage extends Image { } @Override public void releaseImageForSharingNoEvent(CommandQueue queue) { + Utils.assertSharingPossible(); long q = ((LwjglCommandQueue) queue).getQueue(); int ret = CL10GL.clEnqueueReleaseGLObjects(q, image, null, null); Utils.checkError(ret, "clEnqueueReleaseGLObjects"); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglProgram.java b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglProgram.java index 5e1e06466..15f46fc9c 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglProgram.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/LwjglProgram.java @@ -153,7 +153,7 @@ public class LwjglProgram extends Program { ByteBuffer binaries = ByteBuffer.allocateDirect(size); binaryPointers.put(index, binaries); - //TODO: why the hell does this throw a segfault ?!? + //Fixme: why the hell does this line throw a segfault ?!? ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null); Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES"); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/Utils.java b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/Utils.java index d328a220a..c899dc2ff 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/Utils.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/opencl/lwjgl/Utils.java @@ -50,6 +50,12 @@ public class Utils { private static final Logger LOG = Logger.getLogger(Utils.class.getName()); private Utils() {} + public static final boolean CL_GL_SHARING_POSSIBLE = com.jme3.system.lwjgl.LwjglContext.CL_GL_SHARING_POSSIBLE; + public static void assertSharingPossible() { + if (!CL_GL_SHARING_POSSIBLE) { + throw new OpenCLException("OpenGL/CL sharing not possible"); + } + } public static int getMajorVersion(String version, String prefix) { String s = version.substring(prefix.length()); diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java index 4b60bd0d2..cf32af063 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -75,6 +75,10 @@ public abstract class LwjglContext implements JmeContext { private static final Logger logger = Logger.getLogger(LwjglContext.class.getName()); + //Fixme: OpenGL/CL sharing does not work yet, this line disables the sharing methods + //(They will throw an OpenCLException) + public static final boolean CL_GL_SHARING_POSSIBLE = false; + protected static final String THREAD_NAME = "jME3 Main"; protected AtomicBoolean created = new AtomicBoolean(false); @@ -296,6 +300,11 @@ public abstract class LwjglContext implements JmeContext { logger.info("OpenCL context created"); } private long createContext(final CLPlatform platform, final List devices) throws Exception { + + //Fixme: OpenGL/CL sharing does not work. The properties seem to be setup wrongly + // If it works, set CL_GL_SHARING_POSSIBLE to true to enable the sharing + // methods again + final int propertyCount = 2 + 4 + 1; final PointerBuffer properties = PointerBuffer.allocateDirect(propertyCount + devices.size());