summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java155
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java52
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java70
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java116
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java68
5 files changed, 353 insertions, 108 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index 8843188b4..01bdba633 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -30,6 +30,7 @@ package com.jogamp.graph.curve;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import jogamp.opengl.Debug;
@@ -193,10 +194,18 @@ public abstract class Region {
*/
public final boolean usesI32Idx() { return this.use_int32_idx; }
- protected abstract void growBufferSize(int verticeCount, int indexCount);
+ /**
+ * Allow the renderer buffers to pre-emptively grow for given vertices- and index counts.
+ * @param verticeCount number of vertices to hold
+ * @param indexCount number of indices to hold
+ */
+ public abstract void growBufferSize(int verticeCount, int indexCount);
protected abstract void pushVertex(final float[] coords, final float[] texParams, float[] rgba);
+ protected abstract void pushVertices(final float[] coords1, final float[] coords2, final float[] coords3,
+ final float[] texParams1, final float[] texParams2, final float[] texParams3, float[] rgba);
protected abstract void pushIndex(int idx);
+ protected abstract void pushIndices(int idx1, int idx2, int idx3);
/**
* Return bit-field of render modes, see {@link GLRegion#create(GLProfile, int, TextureSequence)}.
@@ -265,32 +274,121 @@ public abstract class Region {
this.frustum = frustum;
}
- final float[] coordsEx = new float[3];
-
private void pushNewVertexImpl(final Vertex vertIn, final AffineTransform transform, final float[] rgba) {
if( null != transform ) {
+ final float[] coordsEx1 = new float[3];
final float[] coordsIn = vertIn.getCoord();
- transform.transform(coordsIn, coordsEx);
- coordsEx[2] = coordsIn[2];
- box.resize(coordsEx[0], coordsEx[1], coordsEx[2]);
- pushVertex(coordsEx, vertIn.getTexCoord(), rgba);
+ transform.transform(coordsIn, coordsEx1);
+ coordsEx1[2] = coordsIn[2];
+ box.resize(coordsEx1);
+ pushVertex(coordsEx1, vertIn.getTexCoord(), rgba);
} else {
- box.resize(vertIn.getX(), vertIn.getY(), vertIn.getZ());
+ box.resize(vertIn.getCoord());
pushVertex(vertIn.getCoord(), vertIn.getTexCoord(), rgba);
}
numVertices++;
}
+ private void pushNewVerticesImpl(final Vertex vertIn1, final Vertex vertIn2, final Vertex vertIn3, final AffineTransform transform, final float[] rgba) {
+ if( null != transform ) {
+ final float[] coordsEx1 = new float[3];
+ final float[] coordsEx2 = new float[3];
+ final float[] coordsEx3 = new float[3];
+ final float[] coordsIn1 = vertIn1.getCoord();
+ final float[] coordsIn2 = vertIn2.getCoord();
+ final float[] coordsIn3 = vertIn3.getCoord();
+ transform.transform(coordsIn1, coordsEx1);
+ transform.transform(coordsIn2, coordsEx2);
+ transform.transform(coordsIn3, coordsEx3);
+ coordsEx1[2] = coordsIn1[2];
+ coordsEx2[2] = coordsIn2[2];
+ coordsEx3[2] = coordsIn3[2];
+ box.resize(coordsEx1);
+ box.resize(coordsEx2);
+ box.resize(coordsEx3);
+ pushVertices(coordsEx1, coordsEx2, coordsEx3,
+ vertIn1.getTexCoord(), vertIn2.getTexCoord(), vertIn3.getTexCoord(), rgba);
+ } else {
+ box.resize(vertIn1.getCoord());
+ box.resize(vertIn2.getCoord());
+ box.resize(vertIn3.getCoord());
+ pushVertices(vertIn1.getCoord(), vertIn2.getCoord(), vertIn3.getCoord(),
+ vertIn1.getTexCoord(), vertIn2.getTexCoord(), vertIn3.getTexCoord(), rgba);
+ }
+ numVertices+=3;
+ }
+
+ @SuppressWarnings("unused")
private void pushNewVertexIdxImpl(final Vertex vertIn, final AffineTransform transform, final float[] rgba) {
pushIndex(numVertices);
pushNewVertexImpl(vertIn, transform, rgba);
}
+ private void pushNewVerticesIdxImpl(final Vertex vertIn1, final Vertex vertIn2, final Vertex vertIn3, final AffineTransform transform, final float[] rgba) {
+ pushIndices(numVertices, numVertices+1, numVertices+2);
+ pushNewVerticesImpl(vertIn1, vertIn2, vertIn3, transform, rgba);
+ }
private final AABBox tmpBox = new AABBox();
protected static final int GL_UINT16_MAX = 0xffff; // 65,535
protected static final int GL_INT32_MAX = 0x7fffffff; // 2,147,483,647
+ static class Perf {
+ long t0, t1;
+ long tac_ns_vertices = 0;
+ long tac_ns_push_idx = 0;
+ long tac_ns_push_vertidx = 0;
+ long tac_ns_triangles = 0;
+ long tac_ns_total = 0;
+ long tac_count = 0;
+
+ public void print(final PrintStream out) {
+ out.printf("Region.add(): count %3d, total %5d [ms], per-add %4.2f [ns]%n", tac_count, TimeUnit.NANOSECONDS.toMillis(tac_ns_total), ((double)tac_ns_total/(double)tac_count));
+ out.printf(" vertices %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_vertices), ((double)tac_ns_vertices/(double)tac_count));
+ out.printf(" push_idx %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_push_idx), ((double)tac_ns_push_idx/(double)tac_count));
+ out.printf(" push_vertidx %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_push_vertidx), ((double)tac_ns_push_vertidx/(double)tac_count));
+ out.printf(" triangles %5d [ms], per-add %4.2f [ns]%n", TimeUnit.NANOSECONDS.toMillis(tac_ns_triangles), ((double)tac_ns_triangles/(double)tac_count));
+ }
+
+ public void clear() {
+ t0 = 0; t1 = 0;
+ tac_ns_vertices = 0;
+ tac_ns_push_idx = 0;
+ tac_ns_push_vertidx = 0;
+ tac_ns_triangles = 0;
+ tac_ns_total = 0;
+ tac_count = 0;
+ }
+ }
+ Perf perf = null;
+
+ /** Enable or disable performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void enablePerf(final boolean enable) {
+ if( enable ) {
+ if( null != perf ) {
+ perf.clear();
+ } else {
+ perf = new Perf();
+ }
+ } else {
+ perf = null;
+ }
+ }
+
+ /** Clear performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void clearPerf() {
+ if( null != perf ) {
+ perf.clear();
+ }
+ }
+
+ /** Print performance counter for {@link #addOutlineShape(OutlineShape, AffineTransform, float[])}. */
+ public void printPerf(final PrintStream out) {
+ if( null != perf ) {
+ perf.print(out);
+ }
+ }
+
/**
* Add the given {@link OutlineShape} to this region with the given optional {@link AffineTransform}.
* <p>
@@ -301,6 +399,10 @@ public abstract class Region {
* @param rgbaColor TODO
*/
public final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) {
+ if( null != perf ) {
+ ++perf.tac_count;
+ perf.t0 = System.nanoTime();
+ }
if( null != frustum ) {
final AABBox shapeBox = shape.getBounds();
final AABBox shapeBoxT;
@@ -342,6 +444,10 @@ public abstract class Region {
pushNewVertexImpl(vertsIn.get(i), t, rgbaColor);
vertsVNewIdxCount++;
}
+ if( null != perf ) {
+ perf.t1 = System.nanoTime();
+ perf.tac_ns_vertices += perf.t1-perf.t0;
+ }
if(DEBUG_INSTANCE) {
System.err.println("Region.addOutlineShape(): Processing Triangles");
}
@@ -359,22 +465,39 @@ public abstract class Region {
if(Region.DEBUG_INSTANCE) {
System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset));
}
- pushIndex(tv0Idx+idxOffset);
- pushIndex(triInVertices[1].getId()+idxOffset);
- pushIndex(triInVertices[2].getId()+idxOffset);
+ if( null != perf ) {
+ final long tpi = System.nanoTime();
+ pushIndices(tv0Idx+idxOffset,
+ triInVertices[1].getId()+idxOffset,
+ triInVertices[2].getId()+idxOffset);
+ perf.tac_ns_push_idx += System.nanoTime() - tpi;
+ } else {
+ pushIndices(tv0Idx+idxOffset,
+ triInVertices[1].getId()+idxOffset,
+ triInVertices[2].getId()+idxOffset);
+ }
vertsTMovIdxCount+=3;
} else {
// FIXME: Invalid idx - generate new one
- if(Region.DEBUG_INSTANCE) {
+ if( Region.DEBUG_INSTANCE) {
System.err.println("T["+i+"]: New Idx "+numVertices);
}
- pushNewVertexIdxImpl(triInVertices[0], t, rgbaColor);
- pushNewVertexIdxImpl(triInVertices[1], t, rgbaColor);
- pushNewVertexIdxImpl(triInVertices[2], t, rgbaColor);
+ if( null != perf ) {
+ final long tpvi = System.nanoTime();
+ pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
+ perf.tac_ns_push_vertidx += System.nanoTime() - tpvi;
+ } else {
+ pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor);
+ }
vertsTNewIdxCount+=3;
}
tris++;
}
+ if( null != perf ) {
+ final long t2 = System.nanoTime();
+ perf.tac_ns_triangles += t2-perf.t1;
+ perf.tac_ns_total += t2-perf.t0;
+ }
}
if(DEBUG_INSTANCE) {
System.err.println("Region.addOutlineShape().X: idx[ui32 "+usesI32Idx()+", offset "+idxOffset+"], tris: "+tris+", verts [idx "+vertsTNewIdxCount+", add "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]");
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
index 69638f60e..9baa99420 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -30,6 +30,7 @@ package com.jogamp.graph.curve.opengl;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLArrayData;
+import com.jogamp.opengl.util.GLArrayDataEditable;
import com.jogamp.opengl.GLProfile;
import jogamp.graph.curve.opengl.VBORegion2PMSAAES2;
@@ -42,7 +43,6 @@ import com.jogamp.graph.curve.Region;
import java.io.PrintStream;
-import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.OutlineShape;
/** A GLRegion is the OGL binding of one or more OutlineShapes
@@ -59,6 +59,25 @@ import com.jogamp.graph.curve.OutlineShape;
public abstract class GLRegion extends Region {
/**
+ * Heuristics with TestTextRendererNEWT00 text_1 + text_2 = 1334 chars
+ * - FreeSans ~ vertices 64/char, indices 33/char
+ * - Ubuntu Light ~ vertices 100/char, indices 50/char
+ * - FreeSerif ~ vertices 115/char, indices 61/char
+ *
+ * Now let's assume a minimum of 10 chars will be rendered
+ */
+
+ /**
+ * Default initial vertices count based on 10 chars w/ FreeSans @ 64 vertices/char avg.
+ */
+ public static final int defaultVerticesCount = 10*64;
+
+ /**
+ * Default initial indices count based on 10 chars w/ FreeSans @ 33 indices/char avg.
+ */
+ public static final int defaultIndicesCount = 10*33;
+
+ /**
* Create a GLRegion using the passed render mode
*
* <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
@@ -66,22 +85,37 @@ public abstract class GLRegion extends Region {
* @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
* @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
* @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
+ * @param initialVerticesCount initial number of vertices in the render-buffer
+ * @param initialIndicesCount initial number of indices in the render-buffer
*/
- public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq) {
+ public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq, final int initialVerticesCount, final int initialIndicesCount) {
if( null != colorTexSeq ) {
renderModes |= Region.COLORTEXTURE_RENDERING_BIT;
} else if( Region.hasColorTexture(renderModes) ) {
throw new IllegalArgumentException("COLORTEXTURE_RENDERING_BIT set but null TextureSequence");
}
if( isVBAA(renderModes) ) {
- return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
+ return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, initialVerticesCount, initialIndicesCount);
} else if( isMSAA(renderModes) ) {
- return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT);
+ return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT, initialVerticesCount, initialIndicesCount);
} else {
- return new VBORegionSPES2(glp, renderModes, colorTexSeq);
+ return new VBORegionSPES2(glp, renderModes, colorTexSeq, initialVerticesCount, initialIndicesCount);
}
}
+ /**
+ * Create a GLRegion using the passed render mode
+ *
+ * <p> In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit
+ * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.</p>
+ * @param glp intended GLProfile to use. Instance may use higher OpenGL features if indicated by GLProfile.
+ * @param renderModes bit-field of modes, e.g. {@link Region#VARWEIGHT_RENDERING_BIT}, {@link Region#VBAA_RENDERING_BIT}
+ * @param colorTexSeq optional {@link TextureSequence} for {@link Region#COLORTEXTURE_RENDERING_BIT} rendering mode.
+ */
+ public static GLRegion create(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
+ return GLRegion.create(glp, renderModes, colorTexSeq, defaultVerticesCount, defaultIndicesCount);
+ }
+
private final int gl_idx_type;
protected final TextureSequence colorTexSeq;
@@ -118,10 +152,14 @@ public abstract class GLRegion extends Region {
}
/**
- * Clears all data, i.e. triangles, vertices etc.
+ * Clears all buffers, i.e. triangles, vertices etc and and resets states accordingly, see {@link GLArrayDataEditable#clear(GL)}.
+ * <p>
+ * This method does not actually erase the data in the buffer and will most often be used when erasing the underlying memory is suitable.
+ * </p>
*
* @param gl the current {@link GL2ES2} object
* @return this {@link GLRegion} for chaining.
+ * @see GLArrayDataEditable#clear(GL)
*/
public GLRegion clear(final GL2ES2 gl) {
clearImpl(gl);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index d948a06b4..b7a244f81 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -31,7 +31,6 @@ 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;
@@ -46,7 +45,6 @@ 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;
@@ -138,26 +136,27 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
}
- public VBORegion2PMSAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
+ public VBORegion2PMSAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit,
+ final int initialVerticesCount, final int initialIndicesCount)
+ {
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, glIdxType(), initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialIndicesCount, 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);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
if( hasColorChannel() ) {
gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
} else {
gca_ColorsAttr = null;
}
@@ -196,8 +195,8 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
@Override
- protected void growBufferSize(final int verticeCount, final int indexCount) {
- indicesBuffer.growIfNeeded(indexCount);
+ public void growBufferSize(final int verticeCount, final int indexCount) {
+ indicesBuffer.growIfNeeded(indexCount * indicesBuffer.getCompsPerElem());
gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
if( null != gca_ColorsAttr ) {
@@ -225,7 +224,7 @@ public class VBORegion2PMSAAES2 extends GLRegion {
@Override
public void printBufferStats(final PrintStream out) {
final int[] size= { 0 }, capacity= { 0 };
- out.println("VBORegion2PMSAAES2:");
+ out.println("VBORegion2PMSAAES2: idx32 "+usesI32Idx());
printAndCount(out, " indices ", indicesBuffer, size, capacity);
out.println();
printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
@@ -241,20 +240,36 @@ public class VBORegion2PMSAAES2 extends GLRegion {
@Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
- gca_VerticesAttr.putf(coords[0]);
- gca_VerticesAttr.putf(coords[1]);
- gca_VerticesAttr.putf(coords[2]);
-
- gca_CurveParamsAttr.putf(texParams[0]);
- gca_CurveParamsAttr.putf(texParams[1]);
- gca_CurveParamsAttr.putf(texParams[2]);
+ // NIO array[3] is much slows than group/single
+ // gca_VerticesAttr.putf(coords, 0, 3);
+ // gca_CurveParamsAttr.putf(texParams, 0, 3);
+ gca_VerticesAttr.put3f(coords[0], coords[1], coords[2]);
+ gca_CurveParamsAttr.put3f(texParams[0], texParams[1], texParams[2]);
+ if( null != gca_ColorsAttr ) {
+ if( null != rgba ) {
+ // gca_ColorsAttr.putf(rgba, 0, 4);
+ gca_ColorsAttr.put4f(rgba[0], rgba[1], rgba[2], rgba[3]);
+ } else {
+ throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
+ }
+ }
+ }
+ @Override
+ protected final void pushVertices(final float[] coords1, final float[] coords2, final float[] coords3,
+ final float[] texParams1, final float[] texParams2, final float[] texParams3, final float[] rgba) {
+ gca_VerticesAttr.put3f(coords1[0], coords1[1], coords1[2]);
+ gca_VerticesAttr.put3f(coords2[0], coords2[1], coords2[2]);
+ gca_VerticesAttr.put3f(coords3[0], coords3[1], coords3[2]);
+ gca_CurveParamsAttr.put3f(texParams1[0], texParams1[1], texParams1[2]);
+ gca_CurveParamsAttr.put3f(texParams2[0], texParams2[1], texParams2[2]);
+ gca_CurveParamsAttr.put3f(texParams3[0], texParams3[1], texParams3[2]);
if( null != gca_ColorsAttr ) {
if( null != rgba ) {
- gca_ColorsAttr.putf(rgba[0]);
- gca_ColorsAttr.putf(rgba[1]);
- gca_ColorsAttr.putf(rgba[2]);
- gca_ColorsAttr.putf(rgba[3]);
+ final float r=rgba[0], g=rgba[1], b=rgba[2], a=rgba[3];
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
} else {
throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
}
@@ -271,6 +286,15 @@ public class VBORegion2PMSAAES2 extends GLRegion {
}
@Override
+ protected final void pushIndices(final int idx1, final int idx2, final int idx3) {
+ if( usesI32Idx() ) {
+ indicesBuffer.put3i(idx1, idx2, idx3);
+ } else {
+ indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3);
+ }
+ }
+
+ @Override
protected void updateImpl(final GL2ES2 gl) {
// seal buffers
indicesBuffer.seal(gl, true);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index dc7bc692a..2998f3fe1 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -174,34 +174,19 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
}
- public VBORegion2PVBAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit) {
+ // private static final float growthFactor = 1.2f; // avg +5% size but 15% more overhead (34% total)
+ private static final float growthFactor = GLArrayDataClient.DEFAULT_GROWTH_FACTOR; // avg +20% size, but 15% less CPU overhead compared to 1.2 (19% total)
+
+ public VBORegion2PVBAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit,
+ final int initialVerticesCount, final int initialIndicesCount)
+ {
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, 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);
- gca_VerticesAttr.setGrowthFactor(growthFactor);
-
- gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
- gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ growBufferSize(initialVerticesCount, initialIndicesCount);
- 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;
- }
if( hasColorTexture() ) {
gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit());
colorTexBBox = new float[4];
@@ -238,11 +223,35 @@ 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 ) {
+ public void growBufferSize(final int verticeCount, final int indexCount) {
+ if(null == indicesBuffer ) {
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
+ } else {
+ indicesBuffer.growIfNeeded(indexCount * indicesBuffer.getCompsPerElem());
+ }
+ if( null == gca_VerticesAttr ) {
+ gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
+ } else {
+ gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
+ }
+ if( null == gca_CurveParamsAttr ) {
+ gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ } else {
+ gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
+ }
+
+ if( null == gca_ColorsAttr ) {
+ if( hasColorChannel() ) {
+ gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
+ }
+ } else {
gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem());
}
}
@@ -254,7 +263,7 @@ public class VBORegion2PVBAAES2 extends GLRegion {
// Thread.dumpStack();
}
if( null != indicesBuffer ) {
- indicesBuffer.clear(gl);;
+ indicesBuffer.clear(gl);
}
if( null != gca_VerticesAttr ) {
gca_VerticesAttr.clear(gl);
@@ -271,7 +280,7 @@ public class VBORegion2PVBAAES2 extends GLRegion {
@Override
public void printBufferStats(final PrintStream out) {
final int[] size= { 0 }, capacity= { 0 };
- out.println("VBORegion2PVBAAES2:");
+ out.println("VBORegion2PVBAAES2: idx32 "+usesI32Idx());
printAndCount(out, " indices ", indicesBuffer, size, capacity);
out.println();
printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
@@ -287,20 +296,36 @@ public class VBORegion2PVBAAES2 extends GLRegion {
@Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
- gca_VerticesAttr.putf(coords[0]);
- gca_VerticesAttr.putf(coords[1]);
- gca_VerticesAttr.putf(coords[2]);
-
- gca_CurveParamsAttr.putf(texParams[0]);
- gca_CurveParamsAttr.putf(texParams[1]);
- gca_CurveParamsAttr.putf(texParams[2]);
+ // NIO array[3] is much slows than group/single
+ // gca_VerticesAttr.putf(coords, 0, 3);
+ // gca_CurveParamsAttr.putf(texParams, 0, 3);
+ gca_VerticesAttr.put3f(coords[0], coords[1], coords[2]);
+ gca_CurveParamsAttr.put3f(texParams[0], texParams[1], texParams[2]);
+ if( null != gca_ColorsAttr ) {
+ if( null != rgba ) {
+ // gca_ColorsAttr.putf(rgba, 0, 4);
+ gca_ColorsAttr.put4f(rgba[0], rgba[1], rgba[2], rgba[3]);
+ } else {
+ throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
+ }
+ }
+ }
+ @Override
+ protected final void pushVertices(final float[] coords1, final float[] coords2, final float[] coords3,
+ final float[] texParams1, final float[] texParams2, final float[] texParams3, final float[] rgba) {
+ gca_VerticesAttr.put3f(coords1[0], coords1[1], coords1[2]);
+ gca_VerticesAttr.put3f(coords2[0], coords2[1], coords2[2]);
+ gca_VerticesAttr.put3f(coords3[0], coords3[1], coords3[2]);
+ gca_CurveParamsAttr.put3f(texParams1[0], texParams1[1], texParams1[2]);
+ gca_CurveParamsAttr.put3f(texParams2[0], texParams2[1], texParams2[2]);
+ gca_CurveParamsAttr.put3f(texParams3[0], texParams3[1], texParams3[2]);
if( null != gca_ColorsAttr ) {
if( null != rgba ) {
- gca_ColorsAttr.putf(rgba[0]);
- gca_ColorsAttr.putf(rgba[1]);
- gca_ColorsAttr.putf(rgba[2]);
- gca_ColorsAttr.putf(rgba[3]);
+ final float r=rgba[0], g=rgba[1], b=rgba[2], a=rgba[3];
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
} else {
throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
}
@@ -317,6 +342,15 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
@Override
+ protected final void pushIndices(final int idx1, final int idx2, final int idx3) {
+ if( usesI32Idx() ) {
+ indicesBuffer.put3i(idx1, idx2, idx3);
+ } else {
+ indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3);
+ }
+ }
+
+ @Override
protected void updateImpl(final GL2ES2 gl) {
// seal buffers
indicesBuffer.seal(gl, true);
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 03929b847..5a4c0c731 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010 JogAmp Community. All rights reserved.
+ * Copyright 2010-2023 JogAmp Community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
@@ -60,25 +60,26 @@ public class VBORegionSPES2 extends GLRegion {
private final GLUniformData gcu_ColorTexBBox;
private ShaderProgram spPass1 = null;
- public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) {
+ public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq,
+ final int initialVerticesCount, final int initialIndicesCount)
+ {
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)
- indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialElementCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), initialIndicesCount, 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);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
if( hasColorChannel() ) {
gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
- false, initialElementCount, GL.GL_STATIC_DRAW);
+ false, initialVerticesCount, GL.GL_STATIC_DRAW);
} else {
gca_ColorsAttr = null;
}
@@ -94,8 +95,8 @@ public class VBORegionSPES2 extends GLRegion {
}
@Override
- protected void growBufferSize(final int verticeCount, final int indexCount) {
- indicesBuffer.growIfNeeded(indexCount);
+ public void growBufferSize(final int verticeCount, final int indexCount) {
+ indicesBuffer.growIfNeeded(indexCount * indicesBuffer.getCompsPerElem());
gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem());
gca_CurveParamsAttr.growIfNeeded(verticeCount * gca_CurveParamsAttr.getCompsPerElem());
if( null != gca_ColorsAttr ) {
@@ -125,7 +126,7 @@ public class VBORegionSPES2 extends GLRegion {
@Override
public void printBufferStats(final PrintStream out) {
final int[] size= { 0 }, capacity= { 0 };
- out.println("VBORegionSPES2:");
+ out.println("VBORegionSPES2: idx32 "+usesI32Idx());
printAndCount(out, " indices ", indicesBuffer, size, capacity);
out.println();
printAndCount(out, " vertices ", gca_VerticesAttr, size, capacity);
@@ -141,20 +142,36 @@ public class VBORegionSPES2 extends GLRegion {
@Override
protected final void pushVertex(final float[] coords, final float[] texParams, final float[] rgba) {
- gca_VerticesAttr.putf(coords[0]);
- gca_VerticesAttr.putf(coords[1]);
- gca_VerticesAttr.putf(coords[2]);
-
- gca_CurveParamsAttr.putf(texParams[0]);
- gca_CurveParamsAttr.putf(texParams[1]);
- gca_CurveParamsAttr.putf(texParams[2]);
+ // NIO array[3] is much slows than group/single
+ // gca_VerticesAttr.putf(coords, 0, 3);
+ // gca_CurveParamsAttr.putf(texParams, 0, 3);
+ gca_VerticesAttr.put3f(coords[0], coords[1], coords[2]);
+ gca_CurveParamsAttr.put3f(texParams[0], texParams[1], texParams[2]);
+ if( null != gca_ColorsAttr ) {
+ if( null != rgba ) {
+ // gca_ColorsAttr.putf(rgba, 0, 4);
+ gca_ColorsAttr.put4f(rgba[0], rgba[1], rgba[2], rgba[3]);
+ } else {
+ throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
+ }
+ }
+ }
+ @Override
+ protected final void pushVertices(final float[] coords1, final float[] coords2, final float[] coords3,
+ final float[] texParams1, final float[] texParams2, final float[] texParams3, final float[] rgba) {
+ gca_VerticesAttr.put3f(coords1[0], coords1[1], coords1[2]);
+ gca_VerticesAttr.put3f(coords2[0], coords2[1], coords2[2]);
+ gca_VerticesAttr.put3f(coords3[0], coords3[1], coords3[2]);
+ gca_CurveParamsAttr.put3f(texParams1[0], texParams1[1], texParams1[2]);
+ gca_CurveParamsAttr.put3f(texParams2[0], texParams2[1], texParams2[2]);
+ gca_CurveParamsAttr.put3f(texParams3[0], texParams3[1], texParams3[2]);
if( null != gca_ColorsAttr ) {
if( null != rgba ) {
- gca_ColorsAttr.putf(rgba[0]);
- gca_ColorsAttr.putf(rgba[1]);
- gca_ColorsAttr.putf(rgba[2]);
- gca_ColorsAttr.putf(rgba[3]);
+ final float r=rgba[0], g=rgba[1], b=rgba[2], a=rgba[3];
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
+ gca_ColorsAttr.put4f(r, g, b, a);
} else {
throw new IllegalArgumentException("Null color given for COLOR_CHANNEL rendering mode");
}
@@ -171,6 +188,15 @@ public class VBORegionSPES2 extends GLRegion {
}
@Override
+ protected final void pushIndices(final int idx1, final int idx2, final int idx3) {
+ if( usesI32Idx() ) {
+ indicesBuffer.put3i(idx1, idx2, idx3);
+ } else {
+ indicesBuffer.put3s((short)idx1, (short)idx2, (short)idx3);
+ }
+ }
+
+ @Override
protected void updateImpl(final GL2ES2 gl) {
// seal buffers
gca_VerticesAttr.seal(gl, true);