aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/nio/AbstractBuffer.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-25 09:31:04 +0200
committerSven Gothel <[email protected]>2013-06-25 09:31:04 +0200
commitc28d5c8d0d83670a548671a1d0da55e3447ea0c7 (patch)
treed13acf6876a404389821c2a7beb900c5962889d3 /src/java/com/jogamp/common/nio/AbstractBuffer.java
parent72f60a534db7c0b731d4dca83481679817ad7574 (diff)
Refine commit 5e01e993aeba4e95fc8aa6e75b3e295011e27bbb, skip Buffers.sizeOfBufferElem(..) call.
Diffstat (limited to 'src/java/com/jogamp/common/nio/AbstractBuffer.java')
-rw-r--r--src/java/com/jogamp/common/nio/AbstractBuffer.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/nio/AbstractBuffer.java b/src/java/com/jogamp/common/nio/AbstractBuffer.java
index 2624254..4afff2a 100644
--- a/src/java/com/jogamp/common/nio/AbstractBuffer.java
+++ b/src/java/com/jogamp/common/nio/AbstractBuffer.java
@@ -42,9 +42,9 @@ import java.nio.Buffer;
@SuppressWarnings("rawtypes")
public abstract class AbstractBuffer<B extends AbstractBuffer> implements NativeBuffer<B> {
- protected final int elementSize;
protected final Buffer buffer;
- protected int capacity;
+ protected final int elementSize;
+ protected final int capacity;
protected int position;
static {
@@ -52,15 +52,20 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
}
/**
- * @param buffer expected in target format
- * @param elementSize the target element size in bytes
+ * capacity and elementSize should be match the equation w/ target buffer type
+ * <pre>
+ * capacity = elementSizeInBytes(buffer) * buffer.capacity() ) / elementSize
+ * </pre>
+ * @param buffer shall be in target format.
+ * @param elementSize the target element size in bytes.
+ * @param capacity the target capacity in elements of size <code>elementSize</code>.
*/
- protected AbstractBuffer(Buffer buffer, int elementSize) {
- this.elementSize = elementSize;
+ protected AbstractBuffer(Buffer buffer, int elementSize, int capacity) {
this.buffer = buffer;
-
- capacity = ( Buffers.sizeOfBufferElem(buffer) * buffer.capacity() ) / elementSize ;
- position = 0;
+ this.elementSize = elementSize;
+ this.capacity = capacity;
+
+ this.position = 0;
}
public final int elementSize() {
@@ -114,7 +119,7 @@ public abstract class AbstractBuffer<B extends AbstractBuffer> implements Native
}
public final int arrayOffset() {
- if(hasArray()) {
+ if( hasArray() ) {
return buffer.arrayOffset();
} else {
return 0;