summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl/CLBuffer.java
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-11-05 02:52:26 +0100
committerMichael Bien <[email protected]>2009-11-05 02:52:26 +0100
commit3d8df0c175ff84ac7b42e0ee5f247099b953514a (patch)
tree41b8a9a7e3b366938919efb75ab38599fc1d8c5b /src/com/mbien/opencl/CLBuffer.java
parent0eebae54517e816aaeb36495dfdbdc1b6d03bfba (diff)
bug fixes in buffer handling.
Diffstat (limited to 'src/com/mbien/opencl/CLBuffer.java')
-rw-r--r--src/com/mbien/opencl/CLBuffer.java31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/com/mbien/opencl/CLBuffer.java b/src/com/mbien/opencl/CLBuffer.java
index 223b074b..42b9586d 100644
--- a/src/com/mbien/opencl/CLBuffer.java
+++ b/src/com/mbien/opencl/CLBuffer.java
@@ -1,6 +1,12 @@
package com.mbien.opencl;
+import com.sun.gluegen.runtime.BufferFactory;
import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
import static com.mbien.opencl.CLException.*;
/**
@@ -31,7 +37,8 @@ public class CLBuffer<B extends Buffer> {
int[] intArray = new int[1];
if(glBuffer == 0) {
- this.ID = cl.clCreateBuffer(context.ID, flags, directBuffer.capacity(), null, intArray, 0);
+ this.ID = cl.clCreateBuffer(context.ID, flags,
+ sizeOfBufferElem(directBuffer)*directBuffer.capacity(), null, intArray, 0);
}else{
CLGLI clgli = (CLGLI)cl;
this.ID = clgli.clCreateFromGLBuffer(context.ID, flags, glBuffer, intArray, 0);
@@ -46,6 +53,28 @@ public class CLBuffer<B extends Buffer> {
checkForError(ret, "can not release mem object");
}
+ //stolen from JOGL project... think about merging
+ private final int sizeOfBufferElem(Buffer buffer) {
+
+ if (buffer instanceof ByteBuffer) {
+ return BufferFactory.SIZEOF_BYTE;
+ } else if (buffer instanceof IntBuffer) {
+ return BufferFactory.SIZEOF_INT;
+ } else if (buffer instanceof ShortBuffer) {
+ return BufferFactory.SIZEOF_SHORT;
+ } else if (buffer instanceof FloatBuffer) {
+ return BufferFactory.SIZEOF_FLOAT;
+ } else if (buffer instanceof DoubleBuffer) {
+ return BufferFactory.SIZEOF_DOUBLE;
+ }
+ throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName());
+ }
+
+ int getSizeInBytes() {
+ return sizeOfBufferElem(buffer)*buffer.capacity();
+ }
+
+
@Override
public boolean equals(Object obj) {
if (obj == null) {