summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-02-24 22:15:20 +0100
committerSven Gothel <[email protected]>2023-02-24 22:15:20 +0100
commit307479391f955a5bd611b4ad4db6f53e097d15c5 (patch)
tree90b1e4179caf24a4bb9cead9d5db0cfc43dab771 /src/jogl/classes/jogamp
parent6ac71d7fee514f1bf388990b9373d190424699d9 (diff)
Graph Region: Address overflow issue using GL2ES3 integer indices (WIP...); Ease GLArrayData* buffer growth.
Using integer indices, i.e. GL_UNSIGNED_INT, requires us to pass a GLProfile 'hint' to the GLRegion ctor. Region.max_indices is computed in this regard and used in Region.addOutlineShape(). TODO: If exceeding max_indices, the code path needs some work. Buffer growth is eased via GLArrayData using its golden growth ratio and manually triggering growth before processing all triangles in Region.addOutlineShape(). +++ TextRegionUtil static drawText() won't clear passed Region anymore, caller has to do this if so intended.
Diffstat (limited to 'src/jogl/classes/jogamp')
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java46
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java55
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java43
3 files changed, 128 insertions, 16 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index 798d77b8f..4d88479ea 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -27,9 +27,12 @@
*/
package jogamp.graph.curve.opengl;
+import java.io.PrintStream;
import java.nio.FloatBuffer;
import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLArrayData;
+import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLUniformData;
@@ -43,6 +46,7 @@ import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.FBObject.Attachment;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataClient;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.texture.Texture;
@@ -134,15 +138,16 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
}
- public VBORegion2PMSAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
- super(renderModes, colorTexSeq);
+ public VBORegion2PMSAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
+ super(glp, renderModes, colorTexSeq);
rsLocal = new RenderState.ProgramLocal();
final int initialElementCount = 256;
+ // We leave GLArrayDataClient.DEFAULT_GROWTH_FACTOR intact for avg +19% size, but 15% less CPU overhead compared to 1.2 (19% total)
// Pass 1:
- indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
false, initialElementCount, GL.GL_STATIC_DRAW);
@@ -173,7 +178,7 @@ public class VBORegion2PMSAAES2 extends GLRegion {
// Pass 2:
gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit);
- indicesFbo = GLArrayDataServer.createData(3, GL.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo = GLArrayDataServer.createData(3, GL.GL_UNSIGNED_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
indicesFbo.seal(true);
@@ -191,6 +196,16 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
@Override
+ protected void growBufferSize(final int verticeCount, final int indexCount) {
+ indicesBuffer.growIfNeeded(indexCount);
+ gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ }
+
+ @Override
protected final void clearImpl(final GL2ES2 gl) {
if( null != indicesBuffer ) {
indicesBuffer.clear(gl);
@@ -208,6 +223,23 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
@Override
+ protected void printBufferStats(final PrintStream out) {
+ final int[] size= { 0 }, capacity= { 0 };
+ out.println("VBORegion2PMSAAES2:");
+ printAndCount(out, " indices ", indicesBuffer, size, capacity);
+ out.println();
+ printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
+ out.println();
+ printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity);
+ out.println();
+ printAndCount(out, " color ", gca_ColorsAttr, size, capacity);
+ final float filled = (float)size[0]/(float)capacity[0];
+ out.println();
+ out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n",
+ size[0], capacity[0], filled*100f, (1f-filled)*100f);
+ }
+
+ @Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
gca_VerticesAttr.putf(coords[0]);
gca_VerticesAttr.putf(coords[1]);
@@ -231,7 +263,11 @@ public class VBORegion2PMSAAES2 extends GLRegion {
@Override
protected final void pushIndex(final int idx) {
- indicesBuffer.puts((short)idx);
+ if( usesI32Idx() ) {
+ indicesBuffer.puti(idx);
+ } else {
+ indicesBuffer.puts((short)idx);
+ }
}
@Override
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index a5af67e0c..7e8d76127 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -27,9 +27,11 @@
*/
package jogamp.graph.curve.opengl;
+import java.io.PrintStream;
import java.nio.FloatBuffer;
import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLUniformData;
@@ -47,6 +49,7 @@ import com.jogamp.opengl.FBObject.Attachment;
import com.jogamp.opengl.FBObject.TextureAttachment;
import com.jogamp.opengl.math.FloatUtil;
import com.jogamp.opengl.math.geom.AABBox;
+import com.jogamp.opengl.util.GLArrayDataClient;
import com.jogamp.opengl.util.GLArrayDataServer;
import com.jogamp.opengl.util.glsl.ShaderProgram;
import com.jogamp.opengl.util.texture.Texture;
@@ -171,24 +174,31 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
}
- public VBORegion2PVBAAES2(final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
- super(renderModes, colorTexSeq);
+ public VBORegion2PVBAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
+ super(glp, renderModes, colorTexSeq);
rsLocal = new RenderState.ProgramLocal();
final int initialElementCount = 256;
+ // final float growthFactor = 1.2f; // avg +5% size but 15% more overhead (34% total)
+ final float growthFactor = GLArrayDataClient.DEFAULT_GROWTH_FACTOR; // avg +20% size, but 15% less CPU overhead compared to 1.2 (19% total)
// Pass 1:
- indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialElementCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+
if( hasColorChannel() ) {
gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
false, initialElementCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
} else {
gca_ColorsAttr = null;
}
@@ -210,7 +220,7 @@ public class VBORegion2PVBAAES2 extends GLRegion {
gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit);
gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, FloatBuffer.wrap(new float[2]));
- indicesFbo = GLArrayDataServer.createData(3, GL.GL_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesFbo = GLArrayDataServer.createData(3, GL.GL_UNSIGNED_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3);
indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3);
indicesFbo.seal(true);
@@ -228,6 +238,16 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
@Override
+ protected void growBufferSize(final int verticeCount, final int indexCount) {
+ indicesBuffer.growIfNeeded(indexCount);
+ gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ }
+
+ @Override
protected final void clearImpl(final GL2ES2 gl) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegion2PES2 Clear: " + this);
@@ -249,6 +269,23 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
@Override
+ protected void printBufferStats(final PrintStream out) {
+ final int[] size= { 0 }, capacity= { 0 };
+ out.println("VBORegion2PVBAAES2:");
+ printAndCount(out, " indices ", indicesBuffer, size, capacity);
+ out.println();
+ printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
+ out.println();
+ printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity);
+ out.println();
+ printAndCount(out, " color ", gca_ColorsAttr, size, capacity);
+ final float filled = (float)size[0]/(float)capacity[0];
+ out.println();
+ out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n",
+ size[0], capacity[0], filled*100f, (1f-filled)*100f);
+ }
+
+ @Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
gca_VerticesAttr.putf(coords[0]);
gca_VerticesAttr.putf(coords[1]);
@@ -272,7 +309,11 @@ public class VBORegion2PVBAAES2 extends GLRegion {
@Override
protected final void pushIndex(final int idx) {
- indicesBuffer.puts((short)idx);
+ if( usesI32Idx() ) {
+ indicesBuffer.puti(idx);
+ } else {
+ indicesBuffer.puts((short)idx);
+ }
}
@Override
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 5b0d38929..73f9acb34 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -27,10 +27,12 @@
*/
package jogamp.graph.curve.opengl;
+import java.io.PrintStream;
import java.nio.FloatBuffer;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.GLUniformData;
import jogamp.graph.curve.opengl.shader.AttributeNames;
@@ -58,13 +60,15 @@ public class VBORegionSPES2 extends GLRegion {
private final GLUniformData gcu_ColorTexBBox;
private ShaderProgram spPass1 = null;
- public VBORegionSPES2(final int renderModes, final TextureSequence colorTexSeq) {
- super(renderModes, colorTexSeq);
+ public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
+ super(glp, renderModes, colorTexSeq);
rsLocal = new RenderState.ProgramLocal();
final int initialElementCount = 256;
- indicesBuffer = GLArrayDataServer.createData(3, GL.GL_SHORT, initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ // We leave GLArrayDataClient.DEFAULT_GROWTH_FACTOR intact for avg +19% size, but 15% less CPU overhead compared to 1.2 (19% total)
+
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
false, initialElementCount, GL.GL_STATIC_DRAW);
@@ -90,6 +94,16 @@ public class VBORegionSPES2 extends GLRegion {
}
@Override
+ protected void growBufferSize(final int verticeCount, final int indexCount) {
+ indicesBuffer.growIfNeeded(indexCount);
+ gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ }
+
+ @Override
protected final void clearImpl(final GL2ES2 gl) {
if(DEBUG_INSTANCE) {
System.err.println("VBORegionSPES2 Clear: " + this);
@@ -109,6 +123,23 @@ public class VBORegionSPES2 extends GLRegion {
}
@Override
+ protected void printBufferStats(final PrintStream out) {
+ final int[] size= { 0 }, capacity= { 0 };
+ out.println("VBORegionSPES2:");
+ printAndCount(out, " indices ", indicesBuffer, size, capacity);
+ out.println();
+ printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
+ out.println();
+ printAndCount(out, " params ", gca_CurveParamsAttr, size, capacity);
+ out.println();
+ printAndCount(out, " color ", gca_ColorsAttr, size, capacity);
+ final float filled = (float)size[0]/(float)capacity[0];
+ out.println();
+ out.printf(" total [bytes %,d / %,d], filled %.1f%%, left %.1f%%]%n",
+ size[0], capacity[0], filled*100f, (1f-filled)*100f);
+ }
+
+ @Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
gca_VerticesAttr.putf(coords[0]);
gca_VerticesAttr.putf(coords[1]);
@@ -132,7 +163,11 @@ public class VBORegionSPES2 extends GLRegion {
@Override
protected final void pushIndex(final int idx) {
- indicesBuffer.puts((short)idx);
+ if( usesI32Idx() ) {
+ indicesBuffer.puti(idx);
+ } else {
+ indicesBuffer.puts((short)idx);
+ }
}
@Override