summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/Region.java14
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java10
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java173
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java82
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java71
5 files changed, 224 insertions, 126 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java
index d82348b83..5147008a1 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/Region.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java
@@ -203,11 +203,25 @@ public abstract class Region {
* Allow the renderer buffers to pre-emptively grow for given vertices- and index counts.
* @param verticesCount number of vertices to hold
* @param indicesCount number of indices to hold
+ * @see #setBufferCapacity(int, int)
* @see #countOutlineShape(OutlineShape, int[])
* @see #countOutlineShapes(List, int[])
*/
public abstract void growBuffer(int verticesCount, int indicesCount);
+ /**
+ * Set the renderer buffers pre-emptively for given vertices- and index counts.
+ * <p>
+ * If the buffers already exceeds given numbers, the buffers are unchanged.
+ * </p>
+ * @param verticesCount number of vertices to hold
+ * @param indicesCount number of indices to hold
+ * @see #growBuffer(int, int)
+ * @see #countOutlineShape(OutlineShape, int[])
+ * @see #countOutlineShapes(List, int[])
+ */
+ public abstract void setBufferCapacity(int verticesCount, int indicesCount);
+
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);
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 9baa99420..e02752f73 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java
@@ -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.GLArrayDataClient;
import com.jogamp.opengl.util.GLArrayDataEditable;
import com.jogamp.opengl.GLProfile;
@@ -77,6 +78,9 @@ public abstract class GLRegion extends Region {
*/
public static final int defaultIndicesCount = 10*33;
+ // private static final float growthFactor = 1.2f; // avg +5% size but 15% more overhead (34% total)
+ protected static final float growthFactor = GLArrayDataClient.DEFAULT_GROWTH_FACTOR; // avg +20% size, but 15% less CPU overhead compared to 1.2 (19% total)
+
/**
* Create a GLRegion using the passed render mode
*
@@ -142,9 +146,9 @@ public abstract class GLRegion extends Region {
protected static void printAndCount(final PrintStream out, final String name, final GLArrayData data, final int[] size, final int[] capacity) {
out.print(name+"[");
if( null != data ) {
- data.printStats(out);
- size[0] += data.getSizeInBytes();
- capacity[0] += data.getCapacityInBytes();
+ out.print(data.fillStatsToString());
+ size[0] += data.getByteCount();
+ capacity[0] += data.getByteCapacity();
out.print("]");
} else {
out.print("null]");
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
index d088c0a29..89693bb66 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java
@@ -53,13 +53,15 @@ import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureCoords;
import com.jogamp.opengl.util.texture.TextureSequence;
-public class VBORegion2PMSAAES2 extends GLRegion {
+public final class VBORegion2PMSAAES2 extends GLRegion {
private static final boolean DEBUG_FBO_1 = false;
private static final boolean DEBUG_FBO_2 = false;
private final RenderState.ProgramLocal rsLocal;
// Pass-1:
+ private int curVerticesCap = 0;
+ private int curIndicesCap = 0;
private GLArrayDataServer gca_VerticesAttr;
private GLArrayDataServer gca_CurveParamsAttr;
private GLArrayDataServer gca_ColorsAttr;
@@ -86,58 +88,6 @@ public class VBORegion2PMSAAES2 extends GLRegion {
final int[] maxTexSize = new int[] { -1 } ;
- /**
- * <p>
- * Since multiple {@link Region}s may share one
- * {@link ShaderProgram}, the uniform data must always be updated.
- * </p>
- *
- * @param gl
- * @param renderer
- * @param renderModes
- * @param pass1
- * @param quality
- * @param sampleCount
- */
- public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) {
- final RenderState rs = renderer.getRenderState();
- final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount, colorTexSeq);
- final ShaderProgram sp = renderer.getRenderState().getShaderProgram();
- final boolean updateLocLocal;
- if( pass1 ) {
- updateLocLocal = !sp.equals(spPass1);
- spPass1 = sp;
- if( DEBUG ) {
- System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal);
- }
- if( updateLocLocal ) {
- rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true);
- rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true);
- if( null != gca_ColorsAttr ) {
- rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true);
- }
- }
- rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true);
- rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true);
- if( null != gcu_ColorTexUnit ) {
- rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true);
- rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true);
- }
- } else {
- updateLocLocal = !sp.equals(spPass2);
- spPass2 = sp;
- if( DEBUG ) {
- System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal);
- }
- if( updateLocLocal ) {
- rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true);
- rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true);
- }
- rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true);
- rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit
- }
- }
-
public VBORegion2PMSAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit,
final int initialVerticesCount, final int initialIndicesCount)
{
@@ -148,20 +98,8 @@ public class VBORegion2PMSAAES2 extends GLRegion {
// 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(), initialIndicesCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
-
- gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialVerticesCount, GL.GL_STATIC_DRAW);
-
- gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialVerticesCount, GL.GL_STATIC_DRAW);
+ initBuffer(initialVerticesCount, initialIndicesCount);
- if( hasColorChannel() ) {
- gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
- false, initialVerticesCount, GL.GL_STATIC_DRAW);
- } else {
- gca_ColorsAttr = null;
- }
if( hasColorTexture() ) {
gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit());
colorTexBBox = new float[4];
@@ -196,13 +134,54 @@ public class VBORegion2PMSAAES2 extends GLRegion {
false, 4, GL.GL_STATIC_DRAW);
}
+ private void initBuffer(final int verticeCount, final int indexCount) {
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+
+ gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
+ gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ if( hasColorChannel() ) {
+ gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+
@Override
- indicesBuffer.growIfNeeded(indexCount * indicesBuffer.getCompsPerElem());
- 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());
public void growBuffer(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
+ indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem());
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) {
+ gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+ }
+
+ @Override
+ public void setBufferCapacity(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesCount ) {
+ indicesBuffer.reserve(indicesCount);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < verticesCount ) {
+ gca_VerticesAttr.reserve(verticesCount);
+ gca_CurveParamsAttr.reserve(verticesCount);
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.reserve(verticesCount);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
}
}
@@ -340,6 +319,58 @@ public class VBORegion2PMSAAES2 extends GLRegion {
// the buffers were disabled, since due to real/fbo switching and other vbo usage
}
+ /**
+ * <p>
+ * Since multiple {@link Region}s may share one
+ * {@link ShaderProgram}, the uniform data must always be updated.
+ * </p>
+ *
+ * @param gl
+ * @param renderer
+ * @param renderModes
+ * @param pass1
+ * @param quality
+ * @param sampleCount
+ */
+ public void useShaderProgram(final GL2ES2 gl, final RegionRenderer renderer, final int renderModes, final boolean pass1, final int quality, final int sampleCount) {
+ final RenderState rs = renderer.getRenderState();
+ final boolean updateLocGlobal = renderer.useShaderProgram(gl, renderModes, pass1, quality, sampleCount, colorTexSeq);
+ final ShaderProgram sp = renderer.getRenderState().getShaderProgram();
+ final boolean updateLocLocal;
+ if( pass1 ) {
+ updateLocLocal = !sp.equals(spPass1);
+ spPass1 = sp;
+ if( DEBUG ) {
+ System.err.println("XXX changedSP.p1 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal);
+ }
+ if( updateLocLocal ) {
+ rs.updateAttributeLoc(gl, true, gca_VerticesAttr, true);
+ rs.updateAttributeLoc(gl, true, gca_CurveParamsAttr, true);
+ if( null != gca_ColorsAttr ) {
+ rs.updateAttributeLoc(gl, true, gca_ColorsAttr, true);
+ }
+ }
+ rsLocal.update(gl, rs, updateLocLocal, renderModes, true, true);
+ rs.updateUniformLoc(gl, updateLocLocal, gcu_PMVMatrix02, true);
+ if( null != gcu_ColorTexUnit ) {
+ rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexUnit, true);
+ rs.updateUniformLoc(gl, updateLocLocal, gcu_ColorTexBBox, true);
+ }
+ } else {
+ updateLocLocal = !sp.equals(spPass2);
+ spPass2 = sp;
+ if( DEBUG ) {
+ System.err.println("XXX changedSP.p2 updateLocation loc "+updateLocLocal+" / glob "+updateLocGlobal);
+ }
+ if( updateLocLocal ) {
+ rs.updateAttributeLoc(gl, true, gca_FboVerticesAttr, true);
+ rs.updateAttributeLoc(gl, true, gca_FboTexCoordsAttr, true);
+ }
+ rsLocal.update(gl, rs, updateLocLocal, renderModes, false, true);
+ rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit
+ }
+ }
+
private final AABBox drawWinBox = new AABBox();
private final int[] drawView = new int[] { 0, 0, 0, 0 };
private final float[] drawVec4Tmp0 = new float[4];
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
index 436c7cdb8..9567bab10 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java
@@ -58,7 +58,7 @@ import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureCoords;
import com.jogamp.opengl.util.texture.TextureSequence;
-public class VBORegion2PVBAAES2 extends GLRegion {
+public final class VBORegion2PVBAAES2 extends GLRegion {
private static final boolean DEBUG_FBO_1 = false;
private static final boolean DEBUG_FBO_2 = false;
@@ -95,6 +95,8 @@ public class VBORegion2PVBAAES2 extends GLRegion {
private final RenderState.ProgramLocal rsLocal;
// Pass-1:
+ private int curVerticesCap = 0;
+ private int curIndicesCap = 0;
private GLArrayDataServer gca_VerticesAttr;
private GLArrayDataServer gca_CurveParamsAttr;
private GLArrayDataServer gca_ColorsAttr;
@@ -176,9 +178,6 @@ public class VBORegion2PVBAAES2 extends GLRegion {
}
}
- // 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)
{
@@ -187,7 +186,7 @@ public class VBORegion2PVBAAES2 extends GLRegion {
rsLocal = new RenderState.ProgramLocal();
// Pass 1:
- growBufferSize(initialVerticesCount, initialIndicesCount);
+ initBuffer(initialVerticesCount, initialIndicesCount);
if( hasColorTexture() ) {
gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit());
@@ -224,37 +223,58 @@ public class VBORegion2PVBAAES2 extends GLRegion {
false, 4, GL.GL_STATIC_DRAW);
}
+ private void initBuffer(final int verticeCount, final int indexCount) {
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+
+ gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
+ gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ if( hasColorChannel() ) {
+ gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+
@Override
- 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());
public void growBuffer(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
+ // System.err.printf("XXX Buffer grow - Indices: %d < ( %d = %d + %d ); Status: %s%n",
+ // curIndicesCap, indicesBuffer.elemPosition() + indicesCount, indicesBuffer.elemPosition(), indicesCount, indicesBuffer.elemStatsToString());
+ indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem());
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) {
+ // System.err.printf("XXX Buffer grow - Verices: %d < ( %d = %d + %d ); Status: %s%n",
+ // curVerticesCap, gca_VerticesAttr.elemPosition() + verticesCount, gca_VerticesAttr.elemPosition(), verticesCount, gca_VerticesAttr.elemStatsToString());
+ gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
}
- 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);
+ @Override
+ public void setBufferCapacity(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesCount ) {
+ indicesBuffer.reserve(indicesCount);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < verticesCount ) {
+ gca_VerticesAttr.reserve(verticesCount);
+ gca_CurveParamsAttr.reserve(verticesCount);
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.reserve(verticesCount);
}
- } else {
- gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem());
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
}
}
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
index 20170b4ed..adf3e4bc2 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java
@@ -50,9 +50,11 @@ import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureCoords;
import com.jogamp.opengl.util.texture.TextureSequence;
-public class VBORegionSPES2 extends GLRegion {
+public final class VBORegionSPES2 extends GLRegion {
private final RenderState.ProgramLocal rsLocal;
+ private int curVerticesCap = 0;
+ private int curIndicesCap = 0;
private GLArrayDataServer gca_VerticesAttr = null;
private GLArrayDataServer gca_CurveParamsAttr = null;
private GLArrayDataServer gca_ColorsAttr;
@@ -69,22 +71,8 @@ public class VBORegionSPES2 extends GLRegion {
rsLocal = new RenderState.ProgramLocal();
- // We leave GLArrayDataClient.DEFAULT_GROWTH_FACTOR intact for avg +19% size, but 15% less CPU overhead compared to 1.2 (19% total)
+ initBuffer(initialVerticesCount, initialIndicesCount);
- 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, initialVerticesCount, GL.GL_STATIC_DRAW);
-
- gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
- false, initialVerticesCount, GL.GL_STATIC_DRAW);
-
- if( hasColorChannel() ) {
- gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
- false, initialVerticesCount, GL.GL_STATIC_DRAW);
- } else {
- gca_ColorsAttr = null;
- }
if( hasColorTexture() ) {
gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit());
colorTexBBox = new float[4];
@@ -96,13 +84,54 @@ public class VBORegionSPES2 extends GLRegion {
}
}
+ private void initBuffer(final int verticeCount, final int indexCount) {
+ indicesBuffer = GLArrayDataServer.createData(3, glIdxType(), indexCount, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER);
+ indicesBuffer.setGrowthFactor(growthFactor);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+
+ gca_VerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.VERTEX_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_VerticesAttr.setGrowthFactor(growthFactor);
+ gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_CurveParamsAttr.setGrowthFactor(growthFactor);
+ if( hasColorChannel() ) {
+ gca_ColorsAttr = GLArrayDataServer.createGLSL(AttributeNames.COLOR_ATTR_NAME, 4, GL.GL_FLOAT,
+ false, verticeCount, GL.GL_STATIC_DRAW);
+ gca_ColorsAttr.setGrowthFactor(growthFactor);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+
@Override
- indicesBuffer.growIfNeeded(indexCount * indicesBuffer.getCompsPerElem());
- 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());
public void growBuffer(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesBuffer.elemPosition() + indicesCount ) {
+ indicesBuffer.growIfNeeded(indicesCount * indicesBuffer.getCompsPerElem());
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < gca_VerticesAttr.elemPosition() + verticesCount ) {
+ gca_VerticesAttr.growIfNeeded(verticesCount * gca_VerticesAttr.getCompsPerElem());
+ gca_CurveParamsAttr.growIfNeeded(verticesCount * gca_CurveParamsAttr.getCompsPerElem());
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.growIfNeeded(verticesCount * gca_ColorsAttr.getCompsPerElem());
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
+ }
+ }
+
+ @Override
+ public void setBufferCapacity(final int verticesCount, final int indicesCount) {
+ if( curIndicesCap < indicesCount ) {
+ indicesBuffer.reserve(indicesCount);
+ curIndicesCap = indicesBuffer.getElemCapacity();
+ }
+ if( curVerticesCap < verticesCount ) {
+ gca_VerticesAttr.reserve(verticesCount);
+ gca_CurveParamsAttr.reserve(verticesCount);
+ if( null != gca_ColorsAttr ) {
+ gca_ColorsAttr.reserve(verticesCount);
+ }
+ curVerticesCap = gca_VerticesAttr.getElemCapacity();
}
}