From 90a95e6f689b479f3c3ae3caf4e30447030c7682 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 7 Mar 2023 17:56:08 +0100 Subject: GLArrayData: Promote sealed() from GLArrayDataEditable, to correctly being used for getElemCount() instead of 0==position, ... (API change) API Change - sealed() moved up from GLArrayDataEditable -> GLArrayData - GLArrayDataWrapper is sealed by default - getSizeInBytes() -> getByteCount() - Semantics of getElemCount() and getByteCount() - Correctly use sealed() to switch from position to limit - instead of 0==position Aligned method names: - getElemCount() - elemPosition() - remainingElems() - getElemCapacity() to corresponding byte counts: - getByteCount() - bytePosition() - remainingBytes() - getByteCapacity() --- .../com/jogamp/opengl/util/GLArrayDataClient.java | 72 ++++++++++++---------- 1 file changed, 41 insertions(+), 31 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java') diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java index 792d2c474..e5f9e5336 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java @@ -160,9 +160,6 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData @Override public final boolean isVBOWritten() { return bufferWritten; } - @Override - public final boolean sealed() { return sealed; } - @Override public final boolean enabled() { return bufferEnabled; } @@ -172,7 +169,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData @Override public final void setVBOWritten(final boolean written) { - bufferWritten = ( 0 == mappedElementCount ) ? written : true; + bufferWritten = ( 0 == mappedElemCount ) ? written : true; } @Override @@ -232,7 +229,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } sealed = false; bufferEnabled = false; - bufferWritten = ( 0 == mappedElementCount ) ? false : true; + bufferWritten = ( 0 == mappedElemCount ) ? false : true; } @Override @@ -240,7 +237,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData { if( sealed == seal ) return; sealed = seal; - bufferWritten = ( 0 == mappedElementCount ) ? false : true; + bufferWritten = ( 0 == mappedElemCount ) ? false : true; if( seal ) { if ( null != buffer ) { buffer.flip(); @@ -407,17 +404,16 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData return "GLArrayDataClient["+name+ ", index "+index+ ", location "+location+ - ", isVertexAttribute "+isVertexAttribute+ + ", isVertexAttribute "+isVertexAttr+ ", usesGLSL "+usesGLSL+ ", usesShaderState "+(null!=shaderState)+ - ", dataType 0x"+Integer.toHexString(componentType)+ - ", bufferClazz "+componentClazz+ - ", elements "+getElemCount()+ - ", compsPerElem "+componentsPerElement+ + ", dataType 0x"+Integer.toHexString(compType)+ + ", bufferClazz "+compClazz+ + ", compsPerElem "+compsPerElement+ ", stride "+strideB+"b "+strideL+"c"+ - ", mappedElementCount "+mappedElementCount+ - ", initialElementCount "+initialElementCount+ - ", sealed "+sealed+ + ", initElemCount "+initElemCount+ + ", mappedElemCount "+mappedElemCount+ + ", "+elemStatsToString()+ ", bufferEnabled "+bufferEnabled+ ", bufferWritten "+bufferWritten+ ", buffer "+buffer+ @@ -429,7 +425,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * Returning element-count from given componentCount, rounding up to componentsPerElement. */ public int compsToElemCount(final int componentCount) { - return ( componentCount + componentsPerElement - 1 ) / componentsPerElement; + return ( componentCount + compsPerElement - 1 ) / compsPerElement; } /** @@ -441,15 +437,31 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData * @return true if buffer size has changed, i.e. grown. Otherwise false. */ public final boolean growIfNeeded(final int spareComponents) { + if( buffer.remaining() < spareComponents ) { + if( 0 != mappedElemCount ) { + throw new GLException("Mapped buffer can't grow. Insufficient storage size: Needed "+spareComponents+" components, "+ + "mappedElementCount "+mappedElemCount+ + ", has mapped buffer "+buffer+"; "+this); + } + final int has_comps = buffer.capacity(); + final int required_elems = compsToElemCount(has_comps + spareComponents); + final int new_elems = compsToElemCount( (int)( has_comps * growthFactor + 0.5f ) ); + final int elementCount = Math.max( new_elems, required_elems ); + return reserve( elementCount ); + } + return false; + } + + public final boolean growIfNeeded0(final int spareComponents) { if( buffer==null || buffer.remaining() "+(nsize/componentsPerElement)+"/"+nsize+ + System.err.println("*** Size: Reserve: comps: "+compsPerElement+", "+(osize/compsPerElement)+"/"+osize+" -> "+(nsize/compsPerElement)+"/"+nsize+ "; "+oldBuffer+" -> "+buffer+"; "+this); } return true; @@ -556,7 +568,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData } // immutable types - this.initialElementCount = initialElementCount; + this.initElemCount = initialElementCount; this.growthFactor = growthFactor; try { final Constructor ctor = handlerClass.getConstructor(GLArrayDataEditable.class); @@ -597,7 +609,7 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData super(src); // immutable types - this.initialElementCount = src.initialElementCount; + this.initElemCount = src.initElemCount; if( null != src.glArrayHandler ) { final Class clazz = src.glArrayHandler.getClass(); try { @@ -614,7 +626,6 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData // 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; @@ -644,13 +655,12 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData growthFactor = Math.max(1f, v); } - protected final int initialElementCount; + protected final int initElemCount; 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; -- cgit v1.2.3