diff options
author | Michael Bien <[email protected]> | 2010-04-24 05:01:43 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-04-24 05:01:43 +0200 |
commit | 7543640d906f7ae2339faa40d0fc019c7a787593 (patch) | |
tree | 584d9f0624f35bfa07c067d90c962210e348995b /src/com/jogamp/opencl | |
parent | bec58034b631656d3ec436ea350fa1652a8f9195 (diff) |
CLGLContext.create() makes GLContext current.
made CLContext.release() more bulletproof.
added CLGLTest.
Diffstat (limited to 'src/com/jogamp/opencl')
-rw-r--r-- | src/com/jogamp/opencl/CLContext.java | 38 | ||||
-rw-r--r-- | src/com/jogamp/opencl/gl/CLGLContext.java | 18 |
2 files changed, 39 insertions, 17 deletions
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; |