From 3d537d4239e3772ffdb33592e5e66844d94ac9f3 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Fri, 24 Feb 2023 15:33:39 +0100
Subject: 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.
---
 .../graph/curve/opengl/VBORegion2PMSAAES2.java       | 20 ++++++++------------
 .../graph/curve/opengl/VBORegion2PVBAAES2.java       | 20 ++++++++------------
 .../jogamp/graph/curve/opengl/VBORegionSPES2.java    | 20 +++++++++-----------
 3 files changed, 25 insertions(+), 35 deletions(-)

(limited to 'src/jogl/classes/jogamp/graph/curve/opengl')

diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index 3010fa5ff..798d77b8f 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -193,20 +193,16 @@ public class VBORegion2PMSAAES2  extends GLRegion {
     @Override
     protected final void clearImpl(final GL2ES2 gl) {
         if( null != indicesBuffer ) {
-            indicesBuffer.seal(gl, false);
-            indicesBuffer.rewind();
+            indicesBuffer.clear(gl);
         }
         if( null != gca_VerticesAttr ) {
-            gca_VerticesAttr.seal(gl, false);
-            gca_VerticesAttr.rewind();
+            gca_VerticesAttr.clear(gl);
         }
         if( null != gca_CurveParamsAttr ) {
-            gca_CurveParamsAttr.seal(gl, false);
-            gca_CurveParamsAttr.rewind();
+            gca_CurveParamsAttr.clear(gl);
         }
         if( null != gca_ColorsAttr ) {
-            gca_ColorsAttr.seal(gl, false);
-            gca_ColorsAttr.rewind();
+            gca_ColorsAttr.clear(gl);
         }
         fboDirty = true;
     }
@@ -297,7 +293,7 @@ public class VBORegion2PMSAAES2  extends GLRegion {
 
     @Override
     protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
-        if( 0 >= indicesBuffer.getElementCount() ) {
+        if( 0 >= indicesBuffer.getElemCount() ) {
             if(DEBUG_INSTANCE) {
                 System.err.printf("VBORegion2PMSAAES2.drawImpl: Empty%n");
             }
@@ -432,7 +428,7 @@ public class VBORegion2PMSAAES2  extends GLRegion {
         gca_FboTexCoordsAttr.enableBuffer(gl, true);
         indicesFbo.bindBuffer(gl, true); // keeps VBO binding
 
-        gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+        gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElemCount() * indicesFbo.getCompsPerElem(), GL.GL_UNSIGNED_SHORT, 0);
 
         indicesFbo.bindBuffer(gl, false);
         gca_FboTexCoordsAttr.enableBuffer(gl, false);
@@ -529,10 +525,10 @@ public class VBORegion2PMSAAES2  extends GLRegion {
             gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit());
             gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions
             gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
             tex.disable(gl); // nop on core
         } else {
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
         }
 
         indicesBuffer.bindBuffer(gl, false);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index 092cc55c1..a5af67e0c 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -234,20 +234,16 @@ public class VBORegion2PVBAAES2  extends GLRegion {
             // Thread.dumpStack();
         }
         if( null != indicesBuffer ) {
-            indicesBuffer.seal(gl, false);
-            indicesBuffer.rewind();
+            indicesBuffer.clear(gl);;
         }
         if( null != gca_VerticesAttr ) {
-            gca_VerticesAttr.seal(gl, false);
-            gca_VerticesAttr.rewind();
+            gca_VerticesAttr.clear(gl);
         }
         if( null != gca_CurveParamsAttr ) {
-            gca_CurveParamsAttr.seal(gl, false);
-            gca_CurveParamsAttr.rewind();
+            gca_CurveParamsAttr.clear(gl);
         }
         if( null != gca_ColorsAttr ) {
-            gca_ColorsAttr.seal(gl, false);
-            gca_ColorsAttr.rewind();
+            gca_ColorsAttr.clear(gl);;
         }
         fboDirty = true;
     }
@@ -337,7 +333,7 @@ public class VBORegion2PVBAAES2  extends GLRegion {
 
     @Override
     protected void drawImpl(final GL2ES2 gl, final RegionRenderer renderer, final int[/*1*/] sampleCount) {
-        if( 0 >= indicesBuffer.getElementCount() ) {
+        if( 0 >= indicesBuffer.getElemCount() ) {
             if(DEBUG_INSTANCE) {
                 System.err.printf("VBORegion2PVBAAES2.drawImpl: Empty%n");
             }
@@ -545,7 +541,7 @@ public class VBORegion2PVBAAES2  extends GLRegion {
         gca_FboTexCoordsAttr.enableBuffer(gl, true);
         indicesFbo.bindBuffer(gl, true); // keeps VBO binding
 
-        gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElementCount() * indicesFbo.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+        gl.glDrawElements(GL.GL_TRIANGLES, indicesFbo.getElemCount() * indicesFbo.getCompsPerElem(), GL.GL_UNSIGNED_SHORT, 0);
 
         indicesFbo.bindBuffer(gl, false);
         gca_FboTexCoordsAttr.enableBuffer(gl, false);
@@ -640,10 +636,10 @@ public class VBORegion2PVBAAES2  extends GLRegion {
             gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit());
             gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions
             gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
             tex.disable(gl); // nop on core
         } else {
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
         }
 
         indicesBuffer.bindBuffer(gl, false);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index a8e74aed5..5b0d38929 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -95,20 +95,16 @@ public class VBORegionSPES2 extends GLRegion {
             System.err.println("VBORegionSPES2 Clear: " + this);
         }
         if( null != indicesBuffer ) {
-            indicesBuffer.seal(gl, false);
-            indicesBuffer.rewind();
+            indicesBuffer.clear(gl);
         }
         if( null != gca_VerticesAttr ) {
-            gca_VerticesAttr.seal(gl, false);
-            gca_VerticesAttr.rewind();
+            gca_VerticesAttr.clear(gl);
         }
         if( null != gca_CurveParamsAttr ) {
-            gca_CurveParamsAttr.seal(gl, false);
-            gca_CurveParamsAttr.rewind();
+            gca_CurveParamsAttr.clear(gl);
         }
         if( null != gca_ColorsAttr ) {
-            gca_ColorsAttr.seal(gl, false);
-            gca_ColorsAttr.rewind();
+            gca_ColorsAttr.clear(gl);
         }
     }
 
@@ -218,7 +214,7 @@ public class VBORegionSPES2 extends GLRegion {
         final int renderModes = getRenderModes();
         useShaderProgram(gl, renderer, renderModes, getQuality());
 
-        if( 0 >= indicesBuffer.getElementCount() ) {
+        if( 0 >= indicesBuffer.getElemCount() ) {
             if(DEBUG_INSTANCE) {
                 System.err.printf("VBORegionSPES2.drawImpl: Empty%n");
             }
@@ -244,10 +240,12 @@ public class VBORegionSPES2 extends GLRegion {
             gcu_ColorTexUnit.setData(colorTexSeq.getTextureUnit());
             gl.glUniform(gcu_ColorTexUnit); // Always update, since program maybe used by multiple regions
             gl.glUniform(gcu_ColorTexBBox); // Always update, since program maybe used by multiple regions
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
+            // gl.glDrawElements(GL.GL_LINE_STRIP, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), gl_idx_type, 0);
             tex.disable(gl); // nop on core
         } else {
-            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), GL.GL_UNSIGNED_SHORT, 0);
+            gl.glDrawElements(GL.GL_TRIANGLES, indicesBuffer.getElemCount() * indicesBuffer.getCompsPerElem(), glIdxType(), 0);
+            // gl.glDrawElements(GL.GL_LINE_STRIP, indicesBuffer.getElementCount() * indicesBuffer.getComponentCount(), gl_idx_type, 0);
         }
 
         indicesBuffer.bindBuffer(gl, false);
-- 
cgit v1.2.3