summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-02-24 15:33:39 +0100
committerSven Gothel <[email protected]>2023-02-24 15:33:39 +0100
commit3d537d4239e3772ffdb33592e5e66844d94ac9f3 (patch)
tree191f5edc014e0da8d9aa1588ce875cbbc5397f1d /src/jogl/classes/com
parentd2d09d37be87bebf7700b9f82bccdf94a7ff5e51 (diff)
GLArrayData*: Shorten methods (*API Change*), use proper constructor and finalize immutables, add growthFactor (default golden ratio 1.618), add getCapacity*() and printStats(..)
The growthFactor becomes essential for better growth behavior and can be set via setGrowthFactor(). The other changes were merely to clean up the GLArrayData interface and its 4 implementations. Not great to change its API, but one name was misleading ['getComponentCount' -> 'getCompsPerEleme'], so overall .. readability is enhanced. Motivation for this change was the performance analysis and improvement of our Graph Curve Renderer.
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/GLArrayData.java18
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java131
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java17
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java140
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java154
5 files changed, 247 insertions, 213 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/GLArrayData.java b/src/jogl/classes/com/jogamp/opengl/GLArrayData.java
index ea2dfb0f3..972b10d4e 100644
--- a/src/jogl/classes/com/jogamp/opengl/GLArrayData.java
+++ b/src/jogl/classes/com/jogamp/opengl/GLArrayData.java
@@ -28,6 +28,7 @@
package com.jogamp.opengl;
+import java.io.PrintStream;
import java.nio.Buffer;
import com.jogamp.opengl.fixedfunc.GLPointerFunc;
@@ -159,26 +160,26 @@ public interface GLArrayData {
/**
* The number of components per element
*/
- public int getComponentCount();
+ public int getCompsPerElem();
/**
* The component's GL data type, ie. GL_FLOAT
*/
- public int getComponentType();
+ public int getCompType();
/**
* The component's size in bytes
*/
- public int getComponentSizeInBytes();
+ public int getBytesPerComp();
/**
* The current number of used elements.
* <p>
- * On element consist out of {@link #getComponentCount()} components.
+ * On element consist out of {@link #getCompsPerElem()} components.
* </p>
* In case the buffer's position is 0 (sealed, flipped), it's based on it's limit instead of it's position.
*/
- public int getElementCount();
+ public int getElemCount();
/**
* The currently used size in bytes.<br>
@@ -187,6 +188,13 @@ public interface GLArrayData {
public int getSizeInBytes();
/**
+ * The current capacity in bytes.
+ */
+ public int getCapacityInBytes();
+
+ public void printStats(final PrintStream out);
+
+ /**
* True, if GL shall normalize fixed point data while converting
* them into float.
* <p>
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index 542da4bf1..e790194ca 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -48,6 +48,8 @@ import com.jogamp.opengl.util.glsl.ShaderState;
public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayDataEditable {
+ /** Default growth factor using the golden ratio 1.618 */
+ public static final float DEFAULT_GROWTH_FACTOR = 1.618f;
/**
* Create a client side buffer object, using a predefined fixed function array index
@@ -72,10 +74,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
public static GLArrayDataClient createFixed(final int index, final int comps, final int dataType, final boolean normalized, final int initialElementCount)
throws GLException
{
- final GLArrayDataClient adc = new GLArrayDataClient();
- final GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(null, index, comps, dataType, normalized, 0, null, initialElementCount, 0 /* mappedElementCount */, false, glArrayHandler, 0, 0, 0, 0, false);
- return adc;
+ return new GLArrayDataClient(null, index, comps, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLFixedArrayHandler.class, 0, 0, 0, 0, false);
}
/**
@@ -103,10 +103,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
final Buffer buffer)
throws GLException
{
- final GLArrayDataClient adc = new GLArrayDataClient();
- final GLArrayHandler glArrayHandler = new GLFixedArrayHandler(adc);
- adc.init(null, index, comps, dataType, normalized, stride, buffer, comps*comps, 0 /* mappedElementCount */, false, glArrayHandler, 0, 0, 0, 0, false);
- return adc;
+ return new GLArrayDataClient(null, index, comps, dataType, normalized, stride, buffer, comps*comps, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLFixedArrayHandler.class, 0, 0, 0, 0, false);
}
/**
@@ -122,10 +120,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
final int dataType, final boolean normalized, final int initialElementCount)
throws GLException
{
- final GLArrayDataClient adc = new GLArrayDataClient();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, 0, null, initialElementCount, 0 /* mappedElementCount */, true, glArrayHandler, 0, 0, 0, 0, true);
- return adc;
+ return new GLArrayDataClient(name, -1, comps, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ true, GLSLArrayHandler.class, 0, 0, 0, 0, true);
}
/**
@@ -142,10 +138,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
final int dataType, final boolean normalized, final int stride, final Buffer buffer)
throws GLException
{
- final GLArrayDataClient adc = new GLArrayDataClient();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandler(adc);
- adc.init(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, 0 /* mappedElementCount */, true, glArrayHandler, 0, 0, 0, 0, true);
- return adc;
+ return new GLArrayDataClient(name, -1, comps, dataType, normalized, stride, buffer, comps*comps, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ true, GLSLArrayHandler.class, 0, 0, 0, 0, true);
}
@Override
@@ -183,14 +177,14 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
@Override
public void destroy(final GL gl) {
- reset(gl);
+ clear(gl);
super.destroy(gl);
}
@Override
- public void reset(final GL gl) {
- enableBuffer(gl, false);
- reset();
+ public void clear(final GL gl) {
+ seal(gl, false);
+ clear();
}
@Override
@@ -232,7 +226,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
//
@Override
- public void reset() {
+ public void clear() {
if( buffer != null ) {
buffer.clear();
}
@@ -334,7 +328,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
", usesShaderState "+(null!=shaderState)+
", dataType 0x"+Integer.toHexString(componentType)+
", bufferClazz "+componentClazz+
- ", elements "+getElementCount()+
+ ", elements "+getElemCount()+
", components "+componentsPerElement+
", stride "+strideB+"b "+strideL+"c"+
", mappedElementCount "+mappedElementCount+
@@ -349,20 +343,27 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
// non public matters
- protected final boolean growBufferIfNecessary(final int spareComponents) {
+ private final boolean growBufferIfNecessary(final int spareComponents) {
if( buffer==null || buffer.remaining()<spareComponents ) {
if( 0 != mappedElementCount ) {
throw new GLException("Mapped buffer can't grow. Insufficient storage size: Needed "+spareComponents+" components, "+
"mappedElementCount "+mappedElementCount+
", has mapped buffer "+buffer+"; "+this);
}
- growBuffer(Math.max(initialElementCount, (spareComponents+componentsPerElement-1)/componentsPerElement));
+ final int required_elems = ( spareComponents + componentsPerElement - 1 ) / componentsPerElement;
+ if( null == buffer ) {
+ growBuffer( Math.max( initialElementCount, required_elems ) );
+ } else {
+ final int add_comps = (int)( buffer.capacity() * ( growthFactor - 1.0f ) + 0.5f );
+ final int add_elems = ( add_comps + componentsPerElement - 1 ) / componentsPerElement;
+ growBuffer( Math.max( add_elems, required_elems ) );
+ }
return true;
}
return false;
}
- protected final void growBuffer(int additionalElements) {
+ private final void growBuffer(int additionalElements) {
if(!alive || sealed) {
throw new GLException("Invalid state: "+this);
}
@@ -424,20 +425,32 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
}
- protected void init(final String name, final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer data,
- final int initialElementCount, final int mappedElementCount, final boolean isVertexAttribute,
- final GLArrayHandler handler, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
+ protected GLArrayDataClient(final String name, final int index, final int comps, final int dataType, final boolean normalized, final int stride, final Buffer data,
+ final int initialElementCount, final float growthFactor,
+ final int mappedElementCount, final boolean isVertexAttribute,
+ final Class<? extends GLArrayHandler> handlerClass,
+ final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
throws GLException
{
- super.init(name, index, comps, dataType, normalized, stride, data, mappedElementCount,
- isVertexAttribute, vboName, vboOffset, vboUsage, vboTarget);
+ super(name, index, comps, dataType, normalized, stride, data, mappedElementCount,
+ isVertexAttribute, vboName, vboOffset, vboUsage, vboTarget);
if( 0<mappedElementCount && 0<initialElementCount ) { // null!=buffer case validated in super.init(..)
throw new IllegalArgumentException("mappedElementCount:="+mappedElementCount+" specified, but passing non zero initialElementSize");
}
+
+ // immutable types
this.initialElementCount = initialElementCount;
- this.glArrayHandler = handler;
+ this.growthFactor = growthFactor;
+ try {
+ final Constructor<? extends GLArrayHandler> ctor = handlerClass.getConstructor(GLArrayDataEditable.class);
+ this.glArrayHandler = ctor.newInstance(this);
+ } catch (final Exception e) {
+ throw new RuntimeException("Could not ctor "+handlerClass.getName()+"("+this.getClass().getName()+")", e);
+ }
this.usesGLSL = usesGLSL;
+
+ // mutable types
this.sealed=false;
this.bufferEnabled=false;
this.enableBufferAlways=false;
@@ -448,8 +461,6 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
}
- private boolean isValidated = false;
-
protected void init_vbo(final GL gl) {
if(!isValidated ) {
isValidated = true;
@@ -457,8 +468,6 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
}
}
- protected GLArrayDataClient() { }
-
/**
* Copy Constructor
* <p>
@@ -470,11 +479,8 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
*/
public GLArrayDataClient(final GLArrayDataClient src) {
super(src);
- this.isValidated = src.isValidated;
- this.sealed = src.sealed;
- this.bufferEnabled = src.bufferEnabled;
- this.bufferWritten = src.bufferWritten;
- this.enableBufferAlways = src.enableBufferAlways;
+
+ // immutable types
this.initialElementCount = src.initialElementCount;
if( null != src.glArrayHandler ) {
final Class<? extends GLArrayHandler> clazz = src.glArrayHandler.getClass();
@@ -488,18 +494,55 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
this.glArrayHandler = null;
}
this.usesGLSL = src.usesGLSL;
+
+ // mutable types
+ this.growthFactor = src.growthFactor;
+ this.isValidated = src.isValidated;
+ this.sealed = src.sealed;
+ this.bufferEnabled = src.bufferEnabled;
+ this.bufferWritten = src.bufferWritten;
+ this.enableBufferAlways = src.enableBufferAlways;
this.shaderState = src.shaderState;
}
+ /**
+ * Returns this buffer's growth factor.
+ * <p>
+ * Default is {@link #DEFAULT_GROWTH_FACTOR}, i.e. the golden ratio 1.618.
+ * </p>
+ * @see #setGrowthFactor(float)
+ * @see #DEFAULT_GROWTH_FACTOR
+ */
+ public float getGrowthFactor() { return growthFactor; }
+
+ /**
+ * Sets a new growth factor for this buffer.
+ * <p>
+ * Default is {@link #DEFAULT_GROWTH_FACTOR}, i.e. the golden ratio 1.618.
+ * </p>
+ * @param v new growth factor, which must be >= 1.1, i.e. 10%
+ * @throws IllegalArgumentException if growth factor is < 1.1
+ * @see #getGrowthFactor()
+ * @see #DEFAULT_GROWTH_FACTOR
+ */
+ public void setGrowthFactor(final float v) {
+ if( v < 1.1f ) {
+ throw new IllegalArgumentException("New growth factor must be > 1.1 but is "+v);
+ }
+ growthFactor = v;
+ }
+
+ protected final int initialElementCount;
+ protected final GLArrayHandler glArrayHandler;
+ protected final boolean usesGLSL;
+
+ protected float growthFactor;
+ private boolean isValidated = false;
protected boolean sealed;
protected boolean bufferEnabled;
protected boolean bufferWritten;
protected boolean enableBufferAlways;
- protected int initialElementCount;
-
- protected GLArrayHandler glArrayHandler;
- protected boolean usesGLSL;
protected ShaderState shaderState;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
index 7524fe1d1..50bcf7c5b 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataEditable.java
@@ -34,7 +34,16 @@ public interface GLArrayDataEditable extends GLArrayData {
@Override
public void destroy(GL gl);
- public void reset(GL gl);
+ /**
+ * Clears this buffer.
+ * <p>
+ * Implementation must call {@link #seal(GL, boolean) seal(gl, false)} and {@link #clear()},
+ * i.e. turns-off the GL buffer and then clearing it.
+ * </p>
+ * @see #seal(GL, boolean)
+ * @see #clear()
+ */
+ public void clear(GL gl);
/**
* Convenience method calling {@link #seal(boolean)} and {@link #enableBuffer(GL, boolean)}.
@@ -105,7 +114,11 @@ public interface GLArrayDataEditable extends GLArrayData {
// Data modification ..
//
- public void reset();
+ /**
+ * Clears this buffer and resets states accordingly.
+ * @see #clear(GL)
+ */
+ public void clear();
/**
* <p>If <i>seal</i> is true, it
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
index 6b7c31d13..9c803d36e 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataServer.java
@@ -85,11 +85,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final Buffer buffer, final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(null, index, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
- return ads;
+ return new GLArrayDataServer(null, index, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLFixedArrayHandler.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
}
/**
@@ -117,11 +114,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLFixedArrayHandler(ads);
- ads.init(null, index, compsPerElement, dataType, normalized, 0, null, initialElementCount, 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
- return ads;
+ return new GLArrayDataServer(null, index, compsPerElement, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLFixedArrayHandler.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
}
/**
@@ -138,11 +132,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
- ads.init(name, -1, compsPerElement, dataType, normalized, 0, null, initialElementCount,
- 0 /* mappedElementCount */, true, glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
- return ads;
+ return new GLArrayDataServer(name, -1, compsPerElement, dataType, normalized, 0, null, initialElementCount,
+ DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */, true, GLSLArrayHandler.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
}
/**
@@ -159,10 +150,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
- ads.init(name, -1, compsPerElement, dataType, normalized, 0, null, 0 /* initialElementCount */,
- mappedElementCount, true, glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
+ final GLArrayDataServer ads = new GLArrayDataServer(name, -1, compsPerElement, dataType, normalized, 0, null, 0 /* initialElementCount */,
+ DEFAULT_GROWTH_FACTOR, mappedElementCount, true, GLSLArrayHandler.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
ads.seal(true);
return ads;
}
@@ -183,11 +172,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandler(ads);
- ads.init(name, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), 0 /* mappedElementCount */, true,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
- return ads;
+ return new GLArrayDataServer(name, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ true, GLSLArrayHandler.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
}
/**
@@ -207,11 +193,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final Buffer buffer, final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
- ads.init(null, -1, compsPerElement, dataType, false, stride, buffer, buffer.limit(), 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, vboTarget, false);
- return ads;
+ return new GLArrayDataServer(null, -1, compsPerElement, dataType, false, stride, buffer, buffer.limit(), DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLDataArrayHandler.class, 0, 0, vboUsage, vboTarget, false);
}
/**
@@ -229,11 +212,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
- ads.init(null, -1, compsPerElement, dataType, false, 0, null, initialElementCount, 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, vboTarget, false);
- return ads;
+ return new GLArrayDataServer(null, -1, compsPerElement, dataType, false, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLDataArrayHandler.class, 0, 0, vboUsage, vboTarget, false);
}
/**
@@ -253,11 +233,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLDataArrayHandler(ads);
- ads.init(null, -1, compsPerElement, dataType, false, 0, null, 0 /* initialElementCount */, mappedElementCount, false,
- glArrayHandler, 0, 0, vboUsage, vboTarget, false);
- return ads;
+ return new GLArrayDataServer(null, -1, compsPerElement, dataType, false, 0, null, 0 /* initialElementCount */, DEFAULT_GROWTH_FACTOR, mappedElementCount,
+ false, GLDataArrayHandler.class, 0, 0, vboUsage, vboTarget, false);
}
/**
@@ -275,11 +252,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, false, 0, null, initialElementCount, 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
- return ads;
+ return new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, false, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
}
/**
@@ -297,10 +271,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, false, 0, null, 0 /* initialElementCount */, mappedElementCount, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
+ final GLArrayDataServer ads = new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, false, 0, null, 0 /* initialElementCount */, DEFAULT_GROWTH_FACTOR, mappedElementCount,
+ false, GLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
ads.seal(true);
return ads;
}
@@ -321,11 +293,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
- return ads;
+ return new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, false);
}
/**
@@ -343,28 +312,28 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* @param vboTarget {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*/
public GLArrayData addFixedSubArray(final int index, final int comps, final int vboTarget) {
- if(interleavedOffset >= getComponentCount() * getComponentSizeInBytes()) {
- final int iOffC = interleavedOffset / getComponentSizeInBytes();
- throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getComponentCount()+")");
+ if(interleavedOffset >= getCompsPerElem() * getBytesPerComp()) {
+ final int iOffC = interleavedOffset / getBytesPerComp();
+ throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getCompsPerElem()+")");
}
if(usesGLSL) {
throw new GLException("buffer uses GLSL");
}
- final int subStrideB = ( 0 == getStride() ) ? getComponentCount() * getComponentSizeInBytes() : getStride();
+ final int subStrideB = ( 0 == getStride() ) ? getCompsPerElem() * getBytesPerComp() : getStride();
final GLArrayDataWrapper ad;
if( 0 < mappedElementCount ) {
ad = GLArrayDataWrapper.createFixed(
- index, comps, getComponentType(),
+ index, comps, getCompType(),
getNormalized(), subStrideB, mappedElementCount,
getVBOName(), interleavedOffset, getVBOUsage(), vboTarget);
} else {
ad = GLArrayDataWrapper.createFixed(
- index, comps, getComponentType(),
+ index, comps, getCompType(),
getNormalized(), subStrideB, getBuffer(),
getVBOName(), interleavedOffset, getVBOUsage(), vboTarget);
}
ad.setVBOEnabled(isVBO());
- interleavedOffset += comps * getComponentSizeInBytes();
+ interleavedOffset += comps * getBytesPerComp();
if(GL.GL_ARRAY_BUFFER == vboTarget) {
glArrayHandler.addSubHandler(new GLFixedArrayHandlerFlat(ad));
}
@@ -386,11 +355,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, 0, null, initialElementCount, 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
- return ads;
+ return new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, 0, null, initialElementCount, DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLSLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
}
/**
@@ -407,10 +373,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
public static GLArrayDataServer createGLSLInterleavedMapped(final int compsPerElement, final int dataType, final boolean normalized, final int mappedElementCount, final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, 0, null, 0 /* initialElementCount */, mappedElementCount, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
+ final GLArrayDataServer ads = new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, 0, null, 0 /* initialElementCount */, DEFAULT_GROWTH_FACTOR, mappedElementCount,
+ false, GLSLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
ads.seal(true);
return ads;
}
@@ -431,11 +395,8 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
final int vboUsage)
throws GLException
{
- final GLArrayDataServer ads = new GLArrayDataServer();
- final GLArrayHandler glArrayHandler = new GLSLArrayHandlerInterleaved(ads);
- ads.init(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), 0 /* mappedElementCount */, false,
- glArrayHandler, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
- return ads;
+ return new GLArrayDataServer(GLPointerFuncUtil.mgl_InterleaveArray, -1, compsPerElement, dataType, normalized, stride, buffer, buffer.limit(), DEFAULT_GROWTH_FACTOR, 0 /* mappedElementCount */,
+ false, GLSLArrayHandlerInterleaved.class, 0, 0, vboUsage, GL.GL_ARRAY_BUFFER, true);
}
/**
@@ -452,28 +413,28 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
* @param vboTarget {@link GL#GL_ARRAY_BUFFER} or {@link GL#GL_ELEMENT_ARRAY_BUFFER}
*/
public GLArrayData addGLSLSubArray(final String name, final int comps, final int vboTarget) {
- if(interleavedOffset >= getComponentCount() * getComponentSizeInBytes()) {
- final int iOffC = interleavedOffset / getComponentSizeInBytes();
- throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getComponentCount()+")");
+ if(interleavedOffset >= getCompsPerElem() * getBytesPerComp()) {
+ final int iOffC = interleavedOffset / getBytesPerComp();
+ throw new GLException("Interleaved offset > total components ("+iOffC+" > "+getCompsPerElem()+")");
}
if(!usesGLSL) {
throw new GLException("buffer uses fixed function");
}
- final int subStrideB = ( 0 == getStride() ) ? getComponentCount() * getComponentSizeInBytes() : getStride();
+ final int subStrideB = ( 0 == getStride() ) ? getCompsPerElem() * getBytesPerComp() : getStride();
final GLArrayDataWrapper ad;
if( 0 < mappedElementCount ) {
ad = GLArrayDataWrapper.createGLSL(
- name, comps, getComponentType(),
+ name, comps, getCompType(),
getNormalized(), subStrideB, mappedElementCount,
getVBOName(), interleavedOffset, getVBOUsage(), vboTarget);
} else {
ad = GLArrayDataWrapper.createGLSL(
- name, comps, getComponentType(),
+ name, comps, getCompType(),
getNormalized(), subStrideB, getBuffer(),
getVBOName(), interleavedOffset, getVBOUsage(), vboTarget);
}
ad.setVBOEnabled(isVBO());
- interleavedOffset += comps * getComponentSizeInBytes();
+ interleavedOffset += comps * getBytesPerComp();
if(GL.GL_ARRAY_BUFFER == vboTarget) {
glArrayHandler.addSubHandler(new GLSLArrayHandlerFlat(ad));
}
@@ -597,7 +558,7 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
", usesShaderState "+(null!=shaderState)+
", dataType 0x"+Integer.toHexString(componentType)+
", bufferClazz "+componentClazz+
- ", elements "+getElementCount()+
+ ", elements "+getElemCount()+
", components "+componentsPerElement+
", stride "+strideB+"b "+strideL+"c"+
", initialElementCount "+initialElementCount+
@@ -620,15 +581,14 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
// non public matters ..
//
- @Override
- protected void init(final String name, final int index, final int comps, final int dataType, final boolean normalized,
- final int stride, final Buffer data, final int initialElementCount, final int mappedElementCount,
- final boolean isVertexAttribute,
- final GLArrayHandler glArrayHandler, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
+ protected GLArrayDataServer(final String name, final int index, final int comps, final int dataType, final boolean normalized,
+ final int stride, final Buffer data, final int initialElementCount, final float growthFactor,
+ final int mappedElementCount, final boolean isVertexAttribute,
+ final Class<? extends GLArrayHandler> handlerClass, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget, final boolean usesGLSL)
throws GLException
{
- super.init(name, index, comps, dataType, normalized, stride, data, initialElementCount, mappedElementCount, isVertexAttribute,
- glArrayHandler, vboName, vboOffset, vboUsage, vboTarget, usesGLSL);
+ super(name, index, comps, dataType, normalized, stride, data, initialElementCount, growthFactor, mappedElementCount,
+ isVertexAttribute, handlerClass, vboName, vboOffset, vboUsage, vboTarget, usesGLSL);
vboEnabled=true;
}
@@ -646,8 +606,6 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE
}
}
- protected GLArrayDataServer() { }
-
/**
* Copy Constructor
* <p>
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
index 3f759c6d8..ae19d788f 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataWrapper.java
@@ -28,6 +28,7 @@
package com.jogamp.opengl.util;
+import java.io.PrintStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
@@ -35,7 +36,6 @@ import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2ES1;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLArrayData;
import com.jogamp.opengl.GLException;
@@ -70,10 +70,8 @@ public class GLArrayDataWrapper implements GLArrayData {
final Buffer buffer, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataWrapper adc = new GLArrayDataWrapper();
- adc.init(null, index, comps, dataType, normalized, stride, buffer, 0 /* mappedElementCount */,
- false, vboName, vboOffset, vboUsage, vboTarget);
- return adc;
+ return new GLArrayDataWrapper(null, index, comps, dataType, normalized, stride, buffer, 0 /* mappedElementCount */,
+ false, vboName, vboOffset, vboUsage, vboTarget);
}
/**
@@ -97,10 +95,8 @@ public class GLArrayDataWrapper implements GLArrayData {
final int mappedElementCount, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataWrapper adc = new GLArrayDataWrapper();
- adc.init(null, index, comps, dataType, normalized, stride, null, mappedElementCount,
- false, vboName, vboOffset, vboUsage, vboTarget);
- return adc;
+ return new GLArrayDataWrapper(null, index, comps, dataType, normalized, stride, null, mappedElementCount,
+ false, vboName, vboOffset, vboUsage, vboTarget);
}
/**
@@ -123,10 +119,8 @@ public class GLArrayDataWrapper implements GLArrayData {
final Buffer buffer, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataWrapper adc = new GLArrayDataWrapper();
- adc.init(name, -1, comps, dataType, normalized, stride, buffer, 0 /* mappedElementCount */,
- true, vboName, vboOffset, vboUsage, vboTarget);
- return adc;
+ return new GLArrayDataWrapper(name, -1, comps, dataType, normalized, stride, buffer, 0 /* mappedElementCount */,
+ true, vboName, vboOffset, vboUsage, vboTarget);
}
/**
@@ -149,10 +143,8 @@ public class GLArrayDataWrapper implements GLArrayData {
final int mappedElementCount, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
throws GLException
{
- final GLArrayDataWrapper adc = new GLArrayDataWrapper();
- adc.init(name, -1, comps, dataType, normalized, stride, null, mappedElementCount,
- true, vboName, vboOffset, vboUsage, vboTarget);
- return adc;
+ return new GLArrayDataWrapper(name, -1, comps, dataType, normalized, stride, null, mappedElementCount,
+ true, vboName, vboOffset, vboUsage, vboTarget);
}
/**
@@ -176,7 +168,7 @@ public class GLArrayDataWrapper implements GLArrayData {
}
return false;
}
- return glp.isValidArrayDataType(getIndex(), getComponentCount(), getComponentType(), isVertexAttribute(), throwException);
+ return glp.isValidArrayDataType(getIndex(), getCompsPerElem(), getCompType(), isVertexAttribute(), throwException);
}
@Override
@@ -235,21 +227,21 @@ public class GLArrayDataWrapper implements GLArrayData {
public Buffer getBuffer() { return buffer; }
@Override
- public final int getComponentCount() { return componentsPerElement; }
+ public final int getCompsPerElem() { return componentsPerElement; }
@Override
- public final int getComponentType() { return componentType; }
+ public final int getCompType() { return componentType; }
@Override
- public final int getComponentSizeInBytes() { return componentByteSize; }
+ public final int getBytesPerComp() { return bytesPerComponent; }
@Override
- public final int getElementCount() {
+ public final int getElemCount() {
if( 0 != mappedElementCount ) {
return mappedElementCount;
} else if( null != buffer ) {
final int remainingComponents = ( 0 == buffer.position() ) ? buffer.limit() : buffer.position();
- return ( remainingComponents * componentByteSize ) / strideB ;
+ return ( remainingComponents * bytesPerComponent ) / strideB ;
} else {
return 0;
}
@@ -258,15 +250,29 @@ public class GLArrayDataWrapper implements GLArrayData {
@Override
public final int getSizeInBytes() {
if( 0 != mappedElementCount ) {
- return mappedElementCount * componentsPerElement * componentByteSize ;
+ return mappedElementCount * componentsPerElement * bytesPerComponent ;
} else if( null != buffer ) {
- return ( buffer.position()==0 ) ? ( buffer.limit() * componentByteSize ) : ( buffer.position() * componentByteSize ) ;
+ return ( buffer.position()==0 ) ? ( buffer.limit() * bytesPerComponent ) : ( buffer.position() * bytesPerComponent ) ;
} else {
return 0;
}
}
@Override
+ public int getCapacityInBytes() {
+ if( null != buffer ) {
+ return buffer.capacity() * bytesPerComponent;
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ public void printStats(final PrintStream out) {
+ out.printf("elements %,d, bytes %,d / %,d", getElemCount(), getSizeInBytes(), getCapacityInBytes());
+ }
+
+ @Override
public final boolean getNormalized() { return normalized; }
@Override
@@ -291,7 +297,7 @@ public class GLArrayDataWrapper implements GLArrayData {
", isVertexAttribute "+isVertexAttribute+
", dataType 0x"+Integer.toHexString(componentType)+
", bufferClazz "+componentClazz+
- ", elements "+getElementCount()+
+ ", elements "+getElemCount()+
", components "+componentsPerElement+
", stride "+strideB+"b "+strideL+"c"+
", mappedElementCount "+mappedElementCount+
@@ -364,17 +370,14 @@ public class GLArrayDataWrapper implements GLArrayData {
this.vboTarget = vboTarget;
}
- protected void init(final String name, final int index, final int componentsPerElement, final int componentType,
- final boolean normalized, final int stride, final Buffer data, final int mappedElementCount,
- final boolean isVertexAttribute, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
+ protected GLArrayDataWrapper(final String name, final int index, final int componentsPerElement, final int componentType,
+ final boolean normalized, final int stride, final Buffer data, final int mappedElementCount,
+ final boolean isVertexAttribute, final int vboName, final long vboOffset, final int vboUsage, final int vboTarget)
throws GLException
{
if( 0<mappedElementCount && null != data ) {
throw new IllegalArgumentException("mappedElementCount:="+mappedElementCount+" specified, but passing non null buffer");
}
- this.isVertexAttribute = isVertexAttribute;
- this.index = index;
- this.location = -1;
// We can't have any dependence on the FixedFuncUtil class here for build bootstrapping reasons
if( GL.GL_ELEMENT_ARRAY_BUFFER == vboTarget ) {
@@ -389,15 +392,11 @@ public class GLArrayDataWrapper implements GLArrayData {
throw new GLException("Invalid GPUBuffer target: 0x"+Integer.toHexString(vboTarget));
}
+ // immutable types
this.componentType = componentType;
componentClazz = getBufferClass(componentType);
- if( GLBuffers.isGLTypeFixedPoint(componentType) ) {
- this.normalized = normalized;
- } else {
- this.normalized = false;
- }
- componentByteSize = GLBuffers.sizeOfGLType(componentType);
- if(0 > componentByteSize) {
+ bytesPerComponent = GLBuffers.sizeOfGLType(componentType);
+ if(0 > bytesPerComponent) {
throw new GLException("Given componentType not supported: "+componentType+":\n\t"+this);
}
if(0 >= componentsPerElement) {
@@ -405,19 +404,30 @@ public class GLArrayDataWrapper implements GLArrayData {
}
this.componentsPerElement = componentsPerElement;
- if(0<stride && stride<componentsPerElement*componentByteSize) {
- throw new GLException("stride ("+stride+") lower than component bytes, "+componentsPerElement+" * "+componentByteSize);
+ if(0<stride && stride<componentsPerElement*bytesPerComponent) {
+ throw new GLException("stride ("+stride+") lower than component bytes, "+componentsPerElement+" * "+bytesPerComponent);
}
- if(0<stride && stride%componentByteSize!=0) {
- throw new GLException("stride ("+stride+") not a multiple of bpc "+componentByteSize);
+ if(0<stride && stride%bytesPerComponent!=0) {
+ throw new GLException("stride ("+stride+") not a multiple of bpc "+bytesPerComponent);
+ }
+ this.strideB=(0==stride)?componentsPerElement*bytesPerComponent:stride;
+ this.strideL=strideB/bytesPerComponent;
+
+ if( GLBuffers.isGLTypeFixedPoint(componentType) ) {
+ this.normalized = normalized;
+ } else {
+ this.normalized = false;
}
- this.buffer = data;
this.mappedElementCount = mappedElementCount;
- this.strideB=(0==stride)?componentsPerElement*componentByteSize:stride;
- this.strideL=strideB/componentByteSize;
+ this.isVertexAttribute = isVertexAttribute;
+
+ // mutable types
+ this.index = index;
+ this.location = -1;
+ this.buffer = data;
this.vboName= vboName;
- this.vboEnabled= 0 != vboName ;
this.vboOffset=vboOffset;
+ this.vboEnabled= 0 != vboName ;
switch(vboUsage) {
case 0: // nop
@@ -441,8 +451,6 @@ public class GLArrayDataWrapper implements GLArrayData {
this.alive=true;
}
- protected GLArrayDataWrapper() { }
-
/**
* Copy Constructor
* <p>
@@ -453,17 +461,22 @@ public class GLArrayDataWrapper implements GLArrayData {
* </p>
*/
public GLArrayDataWrapper(final GLArrayDataWrapper src) {
- this.alive = src.alive;
- this.index = src.index;
- this.location = src.location;
- this.name = src.name;
- this.componentsPerElement = src.componentsPerElement;
+ // immutable types
this.componentType = src.componentType;
this.componentClazz = src.componentClazz;
- this.componentByteSize = src.componentByteSize;
- this.normalized = src.normalized;
+ this.bytesPerComponent = src.bytesPerComponent;
+ this.componentsPerElement = src.componentsPerElement;
this.strideB = src.strideB;
this.strideL = src.strideL;
+ this.normalized = src.normalized;
+ this.mappedElementCount = src.mappedElementCount;
+ this.isVertexAttribute = src.isVertexAttribute;
+
+ // mutable types
+ this.alive = src.alive;
+ this.index = src.index;
+ this.location = src.location;
+ this.name = src.name;
if( null != src.buffer ) {
if( src.buffer.position() == 0 ) {
this.buffer = Buffers.slice(src.buffer);
@@ -473,33 +486,32 @@ public class GLArrayDataWrapper implements GLArrayData {
} else {
this.buffer = null;
}
- this.mappedElementCount = src.mappedElementCount;
- this.isVertexAttribute = src.isVertexAttribute;
- this.vboOffset = src.vboOffset;
this.vboName = src.vboName;
+ this.vboOffset = src.vboOffset;
this.vboEnabled = src.vboEnabled;
this.vboUsage = src.vboUsage;
this.vboTarget = src.vboTarget;
}
+ protected final int componentType;
+ protected final Class<?> componentClazz;
+ protected final int bytesPerComponent;
+ protected final int componentsPerElement;
+ /** stride in bytes; strideB >= componentsPerElement * componentByteSize */
+ protected final int strideB;
+ /** stride in logical components */
+ protected final int strideL;
+ protected final boolean normalized;
+ protected final int mappedElementCount;
+ protected final boolean isVertexAttribute;
+
protected boolean alive;
protected int index;
protected int location;
protected String name;
- protected int componentsPerElement;
- protected int componentType;
- protected Class<?> componentClazz;
- protected int componentByteSize;
- protected boolean normalized;
- /** stride in bytes; strideB >= componentsPerElement * componentByteSize */
- protected int strideB;
- /** stride in logical components */
- protected int strideL;
protected Buffer buffer;
- protected int mappedElementCount;
- protected boolean isVertexAttribute;
- protected long vboOffset;
protected int vboName;
+ protected long vboOffset;
protected boolean vboEnabled;
protected int vboUsage;
protected int vboTarget;