diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/mbien/opencl/CLGLBuffer.java | 75 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLContext.java | 62 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLImage2d.java | 60 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLObject.java | 24 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLTexture.java | 23 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLTexture2d.java | 62 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLGLTexture3d.java | 69 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLImage.java | 19 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLImage2d.java | 12 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLImage3d.java | 13 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLImageFormat.java | 3 | ||||
-rw-r--r-- | src/com/mbien/opencl/CLMemory.java | 51 |
12 files changed, 407 insertions, 66 deletions
diff --git a/src/com/mbien/opencl/CLGLBuffer.java b/src/com/mbien/opencl/CLGLBuffer.java index 40298ad7..8b4e5f56 100644 --- a/src/com/mbien/opencl/CLGLBuffer.java +++ b/src/com/mbien/opencl/CLGLBuffer.java @@ -1,15 +1,15 @@ package com.mbien.opencl; +import com.mbien.opencl.CLMemory.GLObjectType; import java.nio.Buffer; -import static com.mbien.opencl.CLGLI.*; - /** * Shared buffer between OpenGL and OpenCL contexts. * @author Michael Bien */ -public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> { +public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> implements CLGLObject { + /** * The OpenGL object handle. @@ -23,13 +23,7 @@ public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> { static <B extends Buffer> CLGLBuffer<B> create(CLContext context, B directBuffer, int flags, int glObject) { - if(directBuffer != null && !directBuffer.isDirect()) - throw new IllegalArgumentException("buffer is not a direct buffer"); - - if(isHostPointerFlag(flags)) { - throw new IllegalArgumentException( - "CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR can not be used with OpenGL Buffers."); - } + checkBuffer(directBuffer, flags); CL cl = context.cl; int[] result = new int[1]; @@ -40,60 +34,31 @@ public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> { return new CLGLBuffer<B>(context, directBuffer, id, glObject); } - @Override - public <T extends Buffer> CLGLBuffer<T> cloneWith(T directBuffer) { - return new CLGLBuffer<T>(context, directBuffer, ID, GLID); + static <B extends Buffer> void checkBuffer(B directBuffer, int flags) throws IllegalArgumentException { + if (directBuffer != null && !directBuffer.isDirect()) { + throw new IllegalArgumentException("buffer is not a direct buffer"); + } + if (isHostPointerFlag(flags)) { + throw new IllegalArgumentException("CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR can not be used with OpenGL Buffers."); + } } - /** - * Returns the OpenGL buffer type of this shared buffer. - */ - public GLObjectType getGLObjectType() { - int[] array = new int[1]; - int ret = ((CLGLI)cl).clGetGLObjectInfo(ID, array, 0, null, 0); - CLException.checkForError(ret, "error while asking for gl object info"); - return GLObjectType.valueOf(array[0]); + public int getGLObjectID() { + return GLID; } - /** - * Returns the OpenGL object id of this shared buffer. - */ - public int getGLObjectID() { - int[] array = new int[1]; - int ret = ((CLGLI)cl).clGetGLObjectInfo(ID, null, 0, array, 0); - CLException.checkForError(ret, "error while asking for gl object info"); - return array[0]; + public GLObjectType getGLObjectType() { + return GLObjectType.GL_OBJECT_BUFFER; } @Override - public String toString() { - return "CLMemory [id: " + ID+" glID: "+GLID+"]"; + public <T extends Buffer> CLGLBuffer<T> cloneWith(T directBuffer) { + return new CLGLBuffer<T>(context, directBuffer, ID, GLID); } - public enum GLObjectType { - - GL_OBJECT_BUFFER(CL_GL_OBJECT_BUFFER), - GL_OBJECT_TEXTURE2D(CL_GL_OBJECT_TEXTURE2D), - GL_OBJECT_TEXTURE3D(CL_GL_OBJECT_TEXTURE3D), - GL_OBJECT_RENDERBUFFER(CL_GL_OBJECT_RENDERBUFFER); - - public final int TYPE; - - private GLObjectType(int type) { - this.TYPE = type; - } - - public static GLObjectType valueOf(int type) { - if(type == CL_GL_OBJECT_BUFFER) - return GL_OBJECT_BUFFER; - else if(type == CL_GL_OBJECT_TEXTURE2D) - return GL_OBJECT_TEXTURE2D; - else if(type == CL_GL_OBJECT_TEXTURE3D) - return GL_OBJECT_TEXTURE3D; - else if(type == CL_GL_OBJECT_RENDERBUFFER) - return GL_OBJECT_RENDERBUFFER; - return null; - } + @Override + public String toString() { + return "CLGLBuffer [id: " + ID+" glID: "+GLID+"]"; } } diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java index 49fa7fac..5c7226c9 100644 --- a/src/com/mbien/opencl/CLGLContext.java +++ b/src/com/mbien/opencl/CLGLContext.java @@ -13,7 +13,7 @@ import javax.media.opengl.GLContext; import static com.mbien.opencl.CLGLI.*; /** - * OpenCL Context supporting interoperablity between JOGL and JOCL. + * OpenCL Context supporting JOGL-JOCL interoperablity. * @author Michael Bien */ public final class CLGLContext extends CLContext { @@ -146,7 +146,7 @@ public final class CLGLContext extends CLContext { return properties.put(0).rewind(); // 0 terminated array } - + // Buffers public final CLGLBuffer<?> createFromGLBuffer(int glBuffer, Mem... flags) { return createFromGLBuffer(null, glBuffer, Mem.flagsToInt(flags)); } @@ -165,4 +165,62 @@ public final class CLGLContext extends CLContext { return buffer; } + // Renderbuffers + public final CLGLImage2d<?> createFromGLRenderbuffer(int glBuffer, Mem... flags) { + return createFromGLRenderbuffer(null, glBuffer, Mem.flagsToInt(flags)); + } + + public final CLGLImage2d<?> createFromGLRenderbuffer(int glBuffer, int flags) { + return createFromGLRenderbuffer(null, glBuffer, flags); + } + + public final <B extends Buffer> CLGLImage2d<B> createFromGLRenderbuffer(B directBuffer, int glBuffer, Mem... flags) { + return createFromGLRenderbuffer(directBuffer, glBuffer, Mem.flagsToInt(flags)); + } + + public final <B extends Buffer> CLGLImage2d<B> createFromGLRenderbuffer(B directBuffer, int glBuffer, int flags) { + CLGLImage2d<B> buffer = CLGLImage2d.createFromGLRenderbuffer(this, directBuffer, flags, glBuffer); + memoryObjects.add(buffer); + return buffer; + } + + //2d Textures + public final CLGLTexture2d<?> createFromGLTexture2d(int target, int texture, int mipmap, Mem... flags) { + return createFromGLTexture2d(null, target, texture, mipmap, Mem.flagsToInt(flags)); + } + + public final CLGLTexture2d<?> createFromGLTexture2d(int target, int texture, int mipmap, int flags) { + return createFromGLTexture2d(null, target, texture, mipmap, flags); + } + + public final <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(B directBuffer, int target, int texture, int mipmap, Mem... flags) { + return createFromGLTexture2d(directBuffer, target, texture, mipmap, Mem.flagsToInt(flags)); + } + + public final <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(B directBuffer, int target, int texture, int mipmap, int flags) { + CLGLTexture2d<B> buffer = CLGLTexture2d.createFromGLTexture2d(this, directBuffer, target, texture, mipmap, flags); + memoryObjects.add(buffer); + return buffer; + } + + //3d Textures + public final CLGLTexture3d<?> createFromGLTexture3d(int target, int texture, int mipmap, Mem... flags) { + return createFromGLTexture3d(null, target, texture, mipmap, Mem.flagsToInt(flags)); + } + + public final CLGLTexture3d<?> createFromGLTexture3d(int target, int texture, int mipmap, int flags) { + return createFromGLTexture3d(null, target, texture, mipmap, flags); + } + + public final <B extends Buffer> CLGLTexture3d<B> createFromGLTexture3d(B directBuffer, int target, int texture, int mipmap, Mem... flags) { + return createFromGLTexture3d(directBuffer, target, texture, mipmap, Mem.flagsToInt(flags)); + } + + public final <B extends Buffer> CLGLTexture3d<B> createFromGLTexture3d(B directBuffer, int target, int texture, int mipmap, int flags) { + CLGLTexture3d<B> buffer = CLGLTexture3d.createFromGLTexture3d(this, directBuffer, target, texture, mipmap, flags); + memoryObjects.add(buffer); + return buffer; + } + + } diff --git a/src/com/mbien/opencl/CLGLImage2d.java b/src/com/mbien/opencl/CLGLImage2d.java new file mode 100644 index 00000000..dc64fc55 --- /dev/null +++ b/src/com/mbien/opencl/CLGLImage2d.java @@ -0,0 +1,60 @@ +package com.mbien.opencl; + +import com.mbien.opencl.CLMemory.GLObjectType; +import com.mbien.opencl.impl.CLImageFormatImpl; +import java.nio.Buffer; + +import static com.mbien.opencl.CL.*; + +/** + * 2D OpenCL image representing an OpenGL renderbuffer. + * @author Michael Bien + */ +public class CLGLImage2d<B extends Buffer> extends CLImage2d<B> implements CLGLObject { + + /** + * The OpenGL object handle. + */ + public final int GLID; + + protected CLGLImage2d(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int width, int height, long id, int glid) { + super(context, directBuffer, format, accessor, width, height, id); + this.GLID = glid; + } + + static <B extends Buffer> CLGLImage2d<B> createFromGLRenderbuffer(CLContext context, B directBuffer, int flags, int glObject) { + + CLGLBuffer.checkBuffer(directBuffer, flags); + + CL cl = context.cl; + int[] result = new int[1]; + CLGLI clgli = (CLGLI)cl; + + long id = clgli.clCreateFromGLRenderbuffer(context.ID, flags, glObject, result, 0); + + return createImage(context, id, directBuffer, glObject); + } + + static <B extends Buffer> CLGLImage2d<B> createImage(CLContext context, long id, B directBuffer, int glObject) { + CLImageInfoAccessor accessor = new CLImageInfoAccessor(context.cl, id); + + CLImageFormat format = new CLImageFormat(); + accessor.getInfo(CL_IMAGE_FORMAT, CLImageFormatImpl.size(), format.getFormatImpl().getBuffer(), null); + + int width = (int)accessor.getLong(CL_IMAGE_WIDTH); + int height = (int)accessor.getLong(CL_IMAGE_HEIGHT); + + return new CLGLImage2d<B>(context, directBuffer, format, accessor, width, height, id, glObject); + } + + @Override + public GLObjectType getGLObjectType() { + return GLObjectType.GL_OBJECT_RENDERBUFFER; + } + + @Override + public int getGLObjectID() { + return GLID; + } + +} diff --git a/src/com/mbien/opencl/CLGLObject.java b/src/com/mbien/opencl/CLGLObject.java new file mode 100644 index 00000000..044f2274 --- /dev/null +++ b/src/com/mbien/opencl/CLGLObject.java @@ -0,0 +1,24 @@ +/* + * Created on Friday, February 26 2010 + */ +package com.mbien.opencl; + +import com.mbien.opencl.CLMemory.GLObjectType; + +/** + * + * @author Michael Bien + */ +interface CLGLObject { + + /** + * Returns the OpenGL object id of this shared object. + */ + public int getGLObjectID(); + + /** + * Returns the OpenGL buffer type of this shared object. + */ + public GLObjectType getGLObjectType(); + +} diff --git a/src/com/mbien/opencl/CLGLTexture.java b/src/com/mbien/opencl/CLGLTexture.java new file mode 100644 index 00000000..9290dc63 --- /dev/null +++ b/src/com/mbien/opencl/CLGLTexture.java @@ -0,0 +1,23 @@ +/* + * Created on Friday, February 26 2010 + */ + +package com.mbien.opencl; + +/** + * + * @author Michael Bien + */ +interface CLGLTexture { + + /** + * Returns the OpenGL texture target of this texture. + */ + public int getTextureTarget(); + + /** + * Returns the OpenGL mipmap level of this texture. + */ + public int getMipMapLevel(); + +} diff --git a/src/com/mbien/opencl/CLGLTexture2d.java b/src/com/mbien/opencl/CLGLTexture2d.java new file mode 100644 index 00000000..d23d7e3e --- /dev/null +++ b/src/com/mbien/opencl/CLGLTexture2d.java @@ -0,0 +1,62 @@ +package com.mbien.opencl; + +import com.mbien.opencl.CLImage.CLImageInfoAccessor; +import com.mbien.opencl.CLMemory.GLObjectType; +import com.mbien.opencl.impl.CLImageFormatImpl; +import java.nio.Buffer; + +import static com.mbien.opencl.CL.*; + +/** + * 2D OpenCL image representing an 2D OpenGL texture. + * @author Michael Bien + */ +public class CLGLTexture2d<B extends Buffer> extends CLGLImage2d<B> implements CLGLTexture { + + public final int target; + + public final int mipMapLevel; + + public CLGLTexture2d(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int target, int mipLevel, int width, int height, long id, int glid) { + super(context, directBuffer, format, accessor, width, height, id, glid); + this.target = target; + this.mipMapLevel = mipLevel; + } + + static <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(CLContext context, B directBuffer, int target, int texture, int mipLevel, int flags) { + + CLGLBuffer.checkBuffer(directBuffer, flags); + + CL cl = context.cl; + int[] result = new int[1]; + CLGLI clgli = (CLGLI)cl; + + long id = clgli.clCreateFromGLTexture2D(context.ID, flags, target, mipLevel, texture, result, 0); + + CLImageInfoAccessor accessor = new CLImageInfoAccessor(cl, id); + + CLImageFormat format = new CLImageFormat(); + accessor.getInfo(CL_IMAGE_FORMAT, CLImageFormatImpl.size(), format.getFormatImpl().getBuffer(), null); + + int width = (int)accessor.getLong(CL_IMAGE_WIDTH); + int height = (int)accessor.getLong(CL_IMAGE_HEIGHT); + + return new CLGLTexture2d<B>(context, directBuffer, format, accessor, target, mipLevel, width, height, id, width); + + } + + public int getTextureTarget() { + return target; + } + + public int getMipMapLevel() { + return mipMapLevel; + } + + @Override + public GLObjectType getGLObjectType() { + return GLObjectType.GL_OBJECT_TEXTURE2D; + } + + +} diff --git a/src/com/mbien/opencl/CLGLTexture3d.java b/src/com/mbien/opencl/CLGLTexture3d.java new file mode 100644 index 00000000..7bc08053 --- /dev/null +++ b/src/com/mbien/opencl/CLGLTexture3d.java @@ -0,0 +1,69 @@ +package com.mbien.opencl; + +import com.mbien.opencl.CLMemory.GLObjectType; +import com.mbien.opencl.impl.CLImageFormatImpl; +import java.nio.Buffer; + +import static com.mbien.opencl.CL.*; + +/** + * 3D OpenCL image representing an 3D OpenGL texture. + * @author Michael Bien + */ +public class CLGLTexture3d<B extends Buffer> extends CLImage3d<B> implements CLGLObject, CLGLTexture { + + /** + * The OpenGL object handle. + */ + public final int GLID; + + public final int target; + + public final int mipMapLevel; + + private CLGLTexture3d(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int target, int mipLevel, int width, int height, int depth, long id, int glid) { + super(context, directBuffer, format, accessor, width, height, depth, id); + this.GLID = glid; + this.target = target; + this.mipMapLevel = mipLevel; + } + + static <B extends Buffer> CLGLTexture3d<B> createFromGLTexture3d(CLContext context, B directBuffer, int flags, int target, int mipLevel, int texture) { + + CLGLBuffer.checkBuffer(directBuffer, flags); + + CL cl = context.cl; + int[] result = new int[1]; + CLGLI clgli = (CLGLI)cl; + + long id = clgli.clCreateFromGLTexture3D(context.ID, flags, target, mipLevel, texture, result, 0); + + CLImageInfoAccessor accessor = new CLImageInfoAccessor(cl, id); + + CLImageFormat format = new CLImageFormat(); + accessor.getInfo(CL_IMAGE_FORMAT, CLImageFormatImpl.size(), format.getFormatImpl().getBuffer(), null); + + int width = (int)accessor.getLong(CL_IMAGE_WIDTH); + int height = (int)accessor.getLong(CL_IMAGE_HEIGHT); + int depth = (int)accessor.getLong(CL_IMAGE_DEPTH); + + return new CLGLTexture3d<B>(context, directBuffer, format, accessor, target, mipLevel, width, height, depth, id, texture); + } + + public int getGLObjectID() { + return GLID; + } + + public int getTextureTarget() { + return target; + } + + public int getMipMapLevel() { + return mipMapLevel; + } + + public GLObjectType getGLObjectType() { + return GLObjectType.GL_OBJECT_TEXTURE3D; + } + +} diff --git a/src/com/mbien/opencl/CLImage.java b/src/com/mbien/opencl/CLImage.java index a5e44fc0..1da1cc65 100644 --- a/src/com/mbien/opencl/CLImage.java +++ b/src/com/mbien/opencl/CLImage.java @@ -11,7 +11,7 @@ import static com.mbien.opencl.CL.*; */ public abstract class CLImage<B extends Buffer> extends CLMemory<B> { - protected final CLImageFormat format; + protected CLImageFormat format; final CLInfoAccessor imageInfo; @@ -19,8 +19,12 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> { public final int height; protected CLImage(CLContext context, B directBuffer, CLImageFormat format, int width, int height, long id) { + this(context, directBuffer, format, new CLImageInfoAccessor(context.cl, id), width, height, id); + } + + protected CLImage(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int width, int height, long id) { super(context, directBuffer, id); - this.imageInfo = new CLImageInfoAccessor(); + this.imageInfo = accessor; this.format = format; this.width = width; this.height = height; @@ -63,11 +67,18 @@ public abstract class CLImage<B extends Buffer> extends CLMemory<B> { } + protected final static class CLImageInfoAccessor extends CLInfoAccessor { - private final class CLImageInfoAccessor extends CLInfoAccessor { + private final long id; + private final CL cl; + + public CLImageInfoAccessor(CL cl, long id) { + this.cl = cl; + this.id = id; + } @Override protected int getInfo(int name, long valueSize, Buffer value, PointerBuffer valueSizeRet) { - return cl.clGetImageInfo(ID, name, valueSize, value, valueSizeRet); + return cl.clGetImageInfo(id, name, valueSize, value, valueSizeRet); } } diff --git a/src/com/mbien/opencl/CLImage2d.java b/src/com/mbien/opencl/CLImage2d.java index 882cedc4..a04756b9 100644 --- a/src/com/mbien/opencl/CLImage2d.java +++ b/src/com/mbien/opencl/CLImage2d.java @@ -10,11 +10,15 @@ import static com.mbien.opencl.CLException.*; * * @author Michael Bien */ -public final class CLImage2d<B extends Buffer> extends CLImage<B> { +public class CLImage2d<B extends Buffer> extends CLImage<B> { private CLImage2d(CLContext context, B directBuffer, CLImageFormat format, int width, int height, long id) { super(context, directBuffer, format, width, height, id); } + + protected CLImage2d(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int width, int height, long id) { + super(context, directBuffer, format, accessor, width, height, id); + } static <B extends Buffer> CLImage2d<B> createImage(CLContext context, B directBuffer, int width, int height, int rowPitch, CLImageFormat format, int flags) { @@ -33,4 +37,10 @@ public final class CLImage2d<B extends Buffer> extends CLImage<B> { return new CLImage2d<T>(context, directBuffer, format, width, height, ID); } + + @Override + public String toString() { + return "CLImage2d [id: " + ID+" width: "+width+" height: "+height+"]"; + } + } diff --git a/src/com/mbien/opencl/CLImage3d.java b/src/com/mbien/opencl/CLImage3d.java index 2549ff21..681f4fbe 100644 --- a/src/com/mbien/opencl/CLImage3d.java +++ b/src/com/mbien/opencl/CLImage3d.java @@ -11,7 +11,7 @@ import static com.mbien.opencl.CLException.*; * * @author Michael Bien */ -public final class CLImage3d<B extends Buffer> extends CLImage<B> { +public class CLImage3d<B extends Buffer> extends CLImage<B> { public final int depth; @@ -20,6 +20,12 @@ public final class CLImage3d<B extends Buffer> extends CLImage<B> { this.depth = depth; } + protected CLImage3d(CLContext context, B directBuffer, CLImageFormat format, CLImageInfoAccessor accessor, int width, int height, int depth, long id) { + super(context, directBuffer, format, accessor, width, height, id); + this.depth = depth; + } + + static <B extends Buffer> CLImage3d<B> createImage(CLContext context, B directBuffer, int width, int height, int depth, int rowPitch, int slicePitch, CLImageFormat format, int flags) { @@ -50,4 +56,9 @@ public final class CLImage3d<B extends Buffer> extends CLImage<B> { public int getDepth() { return depth; } + + @Override + public String toString() { + return "CLImage3d [id: " + ID+" width: "+width+" height: "+height+" depth: "+depth+"]"; + } } diff --git a/src/com/mbien/opencl/CLImageFormat.java b/src/com/mbien/opencl/CLImageFormat.java index d2625f7f..d2e452b8 100644 --- a/src/com/mbien/opencl/CLImageFormat.java +++ b/src/com/mbien/opencl/CLImageFormat.java @@ -12,6 +12,9 @@ public final class CLImageFormat { private final CLImageFormatImpl format = CLImageFormatImpl.create(); + CLImageFormat() { + } + public CLImageFormat(ChannelOrder order, ChannelType type) { setImageChannelOrder(order); setImageChannelDataType(type); diff --git a/src/com/mbien/opencl/CLMemory.java b/src/com/mbien/opencl/CLMemory.java index aa65e806..0be1b530 100644 --- a/src/com/mbien/opencl/CLMemory.java +++ b/src/com/mbien/opencl/CLMemory.java @@ -10,10 +10,10 @@ import java.nio.IntBuffer; import java.nio.ShortBuffer; import static com.mbien.opencl.CLException.*; -import static com.mbien.opencl.CL.*; +import static com.mbien.opencl.CLGLI.*; /** - * + * Common superclass for all OpenCL memory types. * @author Michael Bien */ public abstract class CLMemory <B extends Buffer> extends CLObject implements CLResource { @@ -101,6 +101,27 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL checkForError(ret, "can not release mem object"); } + // kept only for debugging purposes + /** + * Returns the OpenGL buffer type of this shared buffer. + */ + /*public*/ GLObjectType getGLObjectType() { + int[] array = new int[1]; + int ret = ((CLGLI)cl).clGetGLObjectInfo(ID, array, 0, null, 0); + CLException.checkForError(ret, "error while asking for gl object info"); + return GLObjectType.valueOf(array[0]); + } + + /** + * Returns the OpenGL object id of this shared buffer. + */ + /*public*/ int getGLObjectID() { + int[] array = new int[1]; + int ret = ((CLGLI)cl).clGetGLObjectInfo(ID, null, 0, array, 0); + CLException.checkForError(ret, "error while asking for gl object info"); + return array[0]; + } + @Override public boolean equals(Object obj) { if (obj == null) { @@ -276,6 +297,30 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL } - + public enum GLObjectType { + + GL_OBJECT_BUFFER(CL_GL_OBJECT_BUFFER), + GL_OBJECT_TEXTURE2D(CL_GL_OBJECT_TEXTURE2D), + GL_OBJECT_TEXTURE3D(CL_GL_OBJECT_TEXTURE3D), + GL_OBJECT_RENDERBUFFER(CL_GL_OBJECT_RENDERBUFFER); + + public final int TYPE; + + private GLObjectType(int type) { + this.TYPE = type; + } + + public static GLObjectType valueOf(int type) { + if(type == CL_GL_OBJECT_BUFFER) + return GL_OBJECT_BUFFER; + else if(type == CL_GL_OBJECT_TEXTURE2D) + return GL_OBJECT_TEXTURE2D; + else if(type == CL_GL_OBJECT_TEXTURE3D) + return GL_OBJECT_TEXTURE3D; + else if(type == CL_GL_OBJECT_RENDERBUFFER) + return GL_OBJECT_RENDERBUFFER; + return null; + } + } } |