diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java')
-rw-r--r-- | src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java | 116 |
1 files changed, 75 insertions, 41 deletions
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); |