summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/gl/CLGLBuffer.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-04-12 22:18:39 +0200
committerMichael Bien <[email protected]>2010-04-12 22:18:39 +0200
commitbf07b44ed6a8958dd321cc4c08fd2bdd08299611 (patch)
treee24b7c4e4197a80e0ecaad75b9b3667299fd8323 /src/com/jogamp/opencl/gl/CLGLBuffer.java
parent7680472b21ec1e2deacb49addae65c820a2e2a4d (diff)
renamed package com.mbien.* in com.jogamp.* JOCL is now officially a JogAmp team player ;).
Diffstat (limited to 'src/com/jogamp/opencl/gl/CLGLBuffer.java')
-rw-r--r--src/com/jogamp/opencl/gl/CLGLBuffer.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/gl/CLGLBuffer.java b/src/com/jogamp/opencl/gl/CLGLBuffer.java
new file mode 100644
index 00000000..c7f14c4c
--- /dev/null
+++ b/src/com/jogamp/opencl/gl/CLGLBuffer.java
@@ -0,0 +1,77 @@
+package com.jogamp.opencl.gl;
+
+import com.jogamp.opencl.CL;
+import com.jogamp.opencl.CLBuffer;
+import com.jogamp.opencl.CLContext;
+
+import java.nio.Buffer;
+import javax.media.opengl.GLContext;
+
+
+/**
+ * Shared buffer between OpenGL and OpenCL contexts.
+ * @author Michael Bien
+ */
+public final class CLGLBuffer<B extends Buffer> extends CLBuffer<B> implements CLGLObject {
+
+
+ /**
+ * The OpenGL object handle.
+ */
+ public final int GLID;
+
+ private CLGLBuffer(CLContext context, B directBuffer, long id, int glObject, int flags) {
+ super(context, directBuffer, id, flags);
+ this.GLID = glObject;
+ }
+
+
+ static <B extends Buffer> CLGLBuffer<B> create(CLContext context, B directBuffer, int flags, int glObject) {
+ checkBuffer(directBuffer, flags);
+
+ CL cl = getCL(context);
+ int[] result = new int[1];
+ CLGLI clgli = (CLGLI)cl;
+
+ long id = clgli.clCreateFromGLBuffer(context.ID, flags, glObject, result, 0);
+
+ return new CLGLBuffer<B>(context, directBuffer, id, glObject, flags);
+ }
+
+ 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.");
+ }
+ }
+
+ public int getGLObjectID() {
+ return GLID;
+ }
+
+ public GLObjectType getGLObjectType() {
+ return GLObjectType.GL_OBJECT_BUFFER;
+ }
+
+ @Override
+ public CLGLContext getContext() {
+ return (CLGLContext) super.getContext();
+ }
+
+ public GLContext getGLContext() {
+ return getContext().getGLContext();
+ }
+
+ @Override
+ public <T extends Buffer> CLGLBuffer<T> cloneWith(T directBuffer) {
+ return new CLGLBuffer<T>(context, directBuffer, ID, GLID, FLAGS);
+ }
+
+ @Override
+ public String toString() {
+ return "CLGLBuffer [id: " + ID+" glID: "+GLID+"]";
+ }
+
+}