aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-04-24 05:01:43 +0200
committerMichael Bien <[email protected]>2010-04-24 05:01:43 +0200
commit7543640d906f7ae2339faa40d0fc019c7a787593 (patch)
tree584d9f0624f35bfa07c067d90c962210e348995b
parentbec58034b631656d3ec436ea350fa1652a8f9195 (diff)
CLGLContext.create() makes GLContext current.
made CLContext.release() more bulletproof. added CLGLTest.
-rw-r--r--nbproject/project.properties3
-rw-r--r--src/com/jogamp/opencl/CLContext.java38
-rw-r--r--src/com/jogamp/opencl/gl/CLGLContext.java18
-rw-r--r--test/com/jogamp/opencl/gl/CLGLTest.java95
4 files changed, 137 insertions, 17 deletions
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 48b609e8..eca8446b 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -86,6 +86,9 @@ run.classpath=\
# or test-sys-prop.name=value to set system properties for unit tests):
run.jvmargs=-Xmx256m -Djava.library.path=\
"${basedir}/${rootrel.build}/natives/jocl${path.separator}\
+ ${jogl.root}/${rootrel.build}/jogl/obj${path.separator}\
+ ${jogl.root}/${rootrel.build}/nativewindow/obj${path.separator}\
+ ${jogl.root}/${rootrel.build}/newt/obj${path.separator}\
${gluegen.root}/${rootrel.build}/obj"
run.test.classpath=\
${javac.test.classpath}:\
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index 01159a01..4e172630 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -358,27 +358,31 @@ public class CLContext extends CLObject implements CLResource {
*/
public void release() {
- //release all resources
- while(!programs.isEmpty())
- programs.get(0).release();
-
- while(!memoryObjects.isEmpty())
- memoryObjects.get(0).release();
-
- while(!samplers.isEmpty())
- samplers.get(0).release();
-
- for (CLDevice device : devices) {
- List<CLCommandQueue> list = queuesMap.get(device);
- if(list != null) {
- while(!list.isEmpty()) {
- list.get(0).release();
+ try{
+ //release all resources
+ while(!programs.isEmpty())
+ programs.get(0).release();
+
+ while(!memoryObjects.isEmpty())
+ memoryObjects.get(0).release();
+
+ while(!samplers.isEmpty())
+ samplers.get(0).release();
+
+ for (CLDevice device : getDevices()) {
+ List<CLCommandQueue> list = queuesMap.get(device);
+ if(list != null) {
+ while(!list.isEmpty()) {
+ list.get(0).release();
+ }
}
}
+
+ }finally{
+ int ret = cl.clReleaseContext(ID);
+ checkForError(ret, "error releasing context");
}
- int ret = cl.clReleaseContext(ID);
- checkForError(ret, "error releasing context");
}
public void close() {
diff --git a/src/com/jogamp/opencl/gl/CLGLContext.java b/src/com/jogamp/opencl/gl/CLGLContext.java
index f8ca92f3..7b574664 100644
--- a/src/com/jogamp/opencl/gl/CLGLContext.java
+++ b/src/com/jogamp/opencl/gl/CLGLContext.java
@@ -31,6 +31,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on all available devices (CL_DEVICE_TYPE_ALL).
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext) {
return create(glContext, (CLPlatform)null, CLDevice.Type.ALL);
@@ -38,6 +40,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext, CLPlatform platform) {
return create(glContext, platform, CLDevice.Type.ALL);
@@ -46,6 +50,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on the specified platform and with the specified
* device types.
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext, CLDevice.Type... deviceTypes) {
return create(glContext, null, deviceTypes);
@@ -54,6 +60,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on the specified devices.
* The platform to be used is implementation dependent.
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext, CLDevice... devices) {
return create(glContext, null, devices);
@@ -62,6 +70,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on the specified platform and with the specified
* device types.
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice.Type... deviceTypes) {
@@ -80,6 +90,8 @@ public final class CLGLContext extends CLContext {
/**
* Creates a shared context on the specified platform and with the specified
* devices.
+ * Note: This will make the GLContext current.
+ * @see GLContext#makeCurrent()
*/
public static CLGLContext create(GLContext glContext, CLPlatform platform, CLDevice... devices) {
@@ -106,6 +118,12 @@ public final class CLGLContext extends CLContext {
if(platform == null) {
throw new RuntimeException("no OpenCL installation found");
}
+ if(glContext == null) {
+ throw new IllegalArgumentException("GLContext was null.");
+ }
+
+ // context must be current
+ glContext.makeCurrent();
GLContextImpl ctxImpl = (GLContextImpl)glContext;
diff --git a/test/com/jogamp/opencl/gl/CLGLTest.java b/test/com/jogamp/opencl/gl/CLGLTest.java
new file mode 100644
index 00000000..278206cf
--- /dev/null
+++ b/test/com/jogamp/opencl/gl/CLGLTest.java
@@ -0,0 +1,95 @@
+/*
+ * Created on Saturday, April 24 2010 02:58 AM
+ */
+
+package com.jogamp.opencl.gl;
+
+import com.jogamp.opencl.CLDevice;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opencl.CLContext;
+import com.jogamp.opencl.CLPlatform;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import javax.media.opengl.GLContext;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static java.lang.System.*;
+
+/**
+ * Test testing the JOGL - JOCL interoperability.
+ * @author Michael Bien
+ */
+public class CLGLTest {
+
+ private static GLContext glcontext;
+
+ @BeforeClass
+ public static void init() {
+
+ Display display = NewtFactory.createDisplay(null); // local display
+ assertNotNull(display);
+
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ assertNotNull(screen);
+
+ Window window = NewtFactory.createWindow(screen, new GLCapabilities(GLProfile.getDefault()), false /* undecorated */);
+ assertNotNull(window);
+
+ window.setSize(640, 480);
+
+ GLWindow glWindow = GLWindow.create(window);
+ assertNotNull(glWindow);
+ glWindow.setVisible(true);
+
+ glcontext = glWindow.getContext();
+ }
+
+ @AfterClass
+ public static void release() {
+ if(glcontext!= null) {
+ glcontext.destroy();
+ glcontext = null;
+ }
+ }
+
+ @Test
+ public void createContextTest() {
+
+ out.println(" - - - glcl; createContextTest - - - ");
+
+ CLDevice[] devices = CLPlatform.getDefault().listCLDevices();
+ CLDevice device = null;
+ for (CLDevice d : devices) {
+ if(d.isGLMemorySharingSupported()) {
+ device = d;
+ break;
+ }
+ }
+
+ if(device == null) {
+ out.println("Aborting test: no GLCL capable devices found.");
+ return;
+ }
+
+ CLContext context = CLGLContext.create(glcontext, device);
+ assertNotNull(context);
+// assertTrue(glcontext.isCurrent());
+
+ try{
+ out.println(context);
+ }finally{
+ context.release();
+ }
+
+
+ }
+
+
+}