diff options
author | Sven Gothel <[email protected]> | 2023-03-07 18:25:53 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-03-07 18:25:53 +0100 |
commit | 01aac34c2c08d01d728c7906cb1cc132e8e7fab1 (patch) | |
tree | 3ba7c57478d088a4e5c60355eadbf39970d6d256 /src | |
parent | 657df3d32a291a74e7eb31c8ccef0fde151afcc1 (diff) |
Graph Perf: Region: split addOutlineShape() -> addOutlineShape0() (fast) and addOutlineShape1() (slow perf+debug), rename growBufferSize() -> growBuffer()
Diffstat (limited to 'src')
4 files changed, 84 insertions, 57 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/Region.java b/src/jogl/classes/com/jogamp/graph/curve/Region.java index 252e57e2b..d82348b83 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/Region.java +++ b/src/jogl/classes/com/jogamp/graph/curve/Region.java @@ -28,6 +28,9 @@ package com.jogamp.graph.curve; import java.io.PrintStream; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -198,10 +201,12 @@ public abstract class Region { /** * 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 + * @param verticesCount number of vertices to hold + * @param indicesCount number of indices to hold + * @see #countOutlineShape(OutlineShape, int[]) + * @see #countOutlineShapes(List, int[]) */ - public abstract void growBufferSize(int verticeCount, int indexCount); + public abstract void growBuffer(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, @@ -349,7 +354,6 @@ public abstract class Region { protected static final int GL_INT32_MAX = 0x7fffffff; // 2,147,483,647 static class Perf { - long t0 = 0, t1 = 0, t2 = 0; // all td_ values are in [ns] long td_vertices = 0; long td_tri_push_idx = 0; @@ -373,7 +377,6 @@ public abstract class Region { } public void clear() { - t0 = 0; t1 = 0; t2 = 0; td_vertices = 0; td_tri_push_idx = 0; td_tri_push_vertidx = 0; @@ -433,10 +436,6 @@ public abstract class Region { * @param rgbaColor TODO */ public final void addOutlineShape(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) { - if( null != perf ) { - ++perf.count; - perf.t0 = Clock.currentNanos(); - } if( null != frustum ) { final AABBox shapeBox = shape.getBounds(); final AABBox shapeBoxT; @@ -447,12 +446,56 @@ public abstract class Region { shapeBoxT = shapeBox; } if( frustum.isAABBoxOutside(shapeBoxT) ) { - if(DEBUG_INSTANCE) { - System.err.println("Region.addOutlineShape(): Dropping outside shapeBoxT: "+shapeBoxT); - } return; } } + if( null == perf && !DEBUG_INSTANCE ) { + addOutlineShape0(shape, t, rgbaColor); + } else { + addOutlineShape1(shape, t, rgbaColor); + } + markShapeDirty(); + } + private final void addOutlineShape0(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) { + final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS); + final ArrayList<Vertex> vertsIn = shape.getVertices(); + { + final int verticeCount = vertsIn.size() + shape.getAddedVerticeCount(); + final int indexCount = trisIn.size() * 3; + growBuffer(verticeCount, indexCount); + } + + final int idxOffset = numVertices; + if( vertsIn.size() >= 3 ) { + // + // Processing Vertices + // + for(int i=0; i<vertsIn.size(); i++) { + pushNewVertexImpl(vertsIn.get(i), t, rgbaColor); + } + final int trisIn_sz = trisIn.size(); + for(int i=0; i < trisIn_sz; ++i) { + final Triangle triIn = trisIn.get(i); + // triEx.addVertexIndicesOffset(idxOffset); + // triangles.add( triEx ); + final Vertex[] triInVertices = triIn.getVertices(); + final int tv0Idx = triInVertices[0].getId(); + + if ( max_indices - idxOffset > tv0Idx ) { + // valid 'known' idx - move by offset + pushIndices(tv0Idx+idxOffset, + triInVertices[1].getId()+idxOffset, + triInVertices[2].getId()+idxOffset); + } else { + // FIXME: Invalid idx - generate new one + pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor); + } + } + } + } + private final void addOutlineShape1(final OutlineShape shape, final AffineTransform t, final float[] rgbaColor) { + ++perf.count; + final long t0 = Clock.currentNanos(); final List<Triangle> trisIn = shape.getTriangles(OutlineShape.VerticesState.QUADRATIC_NURBS); final ArrayList<Vertex> vertsIn = shape.getVertices(); { @@ -464,31 +507,29 @@ public abstract class Region { System.err.println("Region.addOutlineShape().0: VerticeCount "+vertsIn.size()+" + "+addedVerticeCount+" = "+verticeCount); System.err.println("Region.addOutlineShape().0: IndexCount "+indexCount); } - growBufferSize(verticeCount, indexCount); + growBuffer(verticeCount, indexCount); } final int idxOffset = numVertices; int vertsVNewIdxCount = 0, vertsTMovIdxCount = 0, vertsTNewIdxCount = 0, tris = 0; final int vertsDupCountV = 0, vertsDupCountT = 0, vertsKnownMovedT = 0; if( vertsIn.size() >= 3 ) { - if(DEBUG_INSTANCE) { - System.err.println("Region.addOutlineShape(): Processing Vertices"); - } + // if(DEBUG_INSTANCE) { + // System.err.println("Region.addOutlineShape(): Processing Vertices"); + // } for(int i=0; i<vertsIn.size(); i++) { pushNewVertexImpl(vertsIn.get(i), t, rgbaColor); vertsVNewIdxCount++; } - if( null != perf ) { - perf.t1 = Clock.currentNanos(); - perf.td_vertices += perf.t1 - perf.t0; - } - if(DEBUG_INSTANCE) { - System.err.println("Region.addOutlineShape(): Processing Triangles"); - } - for(final Triangle triIn : trisIn) { - if( null != perf ) { - perf.t2 = Clock.currentNanos(); - } + final long t1 = Clock.currentNanos(); + perf.td_vertices += t1 - t0; + // if(DEBUG_INSTANCE) { + // System.err.println("Region.addOutlineShape(): Processing Triangles"); + // } + final int trisIn_sz = trisIn.size(); + for(int i=0; i < trisIn_sz; ++i) { + final Triangle triIn = trisIn.get(i); + final long t2 = Clock.currentNanos(); // if(Region.DEBUG_INSTANCE) { // System.err.println("T["+i+"]: "+triIn); // } @@ -497,47 +538,33 @@ public abstract class Region { final Vertex[] triInVertices = triIn.getVertices(); final int tv0Idx = triInVertices[0].getId(); - if( null != perf ) { - perf.td_tri_misc += Clock.currentNanos() - perf.t2; - } + perf.td_tri_misc += Clock.currentNanos() - t2; if ( max_indices - idxOffset > tv0Idx ) { // valid 'known' idx - move by offset // if(Region.DEBUG_INSTANCE) { // System.err.println("T["+i+"]: Moved "+tv0Idx+" + "+idxOffset+" -> "+(tv0Idx+idxOffset)); // } - if( null != perf ) { - final long tpi = Clock.currentNanos(); - pushIndices(tv0Idx+idxOffset, - triInVertices[1].getId()+idxOffset, - triInVertices[2].getId()+idxOffset); - perf.td_tri_push_idx += Clock.currentNanos() - tpi; - } else { - pushIndices(tv0Idx+idxOffset, - triInVertices[1].getId()+idxOffset, - triInVertices[2].getId()+idxOffset); - } + final long tpi = Clock.currentNanos(); + pushIndices(tv0Idx+idxOffset, + triInVertices[1].getId()+idxOffset, + triInVertices[2].getId()+idxOffset); + perf.td_tri_push_idx += Clock.currentNanos() - tpi; vertsTMovIdxCount+=3; } else { // FIXME: Invalid idx - generate new one // if( Region.DEBUG_INSTANCE) { // System.err.println("T["+i+"]: New Idx "+numVertices); // } - if( null != perf ) { - final long tpvi = Clock.currentNanos(); - pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor); - perf.td_tri_push_vertidx += Clock.currentNanos() - tpvi; - } else { - pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor); - } + final long tpvi = Clock.currentNanos(); + pushNewVerticesIdxImpl(triInVertices[0], triInVertices[1], triInVertices[2], t, rgbaColor); + perf.td_tri_push_vertidx += Clock.currentNanos() - tpvi; vertsTNewIdxCount+=3; } tris++; } - if( null != perf ) { - final long ttriX = Clock.currentNanos(); - perf.td_tri_total += ttriX - perf.t1; - perf.td_total += ttriX - perf.t0; - } + final long ttriX = Clock.currentNanos(); + perf.td_tri_total += ttriX - t1; + perf.td_total += ttriX - t0; } if(DEBUG_INSTANCE) { System.err.println("Region.addOutlineShape().X: idx[ui32 "+usesI32Idx()+", offset "+idxOffset+"], tris: "+tris+", verts [idx "+vertsTNewIdxCount+", add "+vertsTNewIdxCount+" = "+(vertsVNewIdxCount+vertsTNewIdxCount)+"]"); @@ -548,7 +575,7 @@ public abstract class Region { System.err.println("Region.addOutlineShape().X: box "+box); printBufferStats(System.err); } - markShapeDirty(); + } } public final void addOutlineShapes(final List<OutlineShape> shapes, final AffineTransform transform, final float[] rgbaColor) { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index cf4fc65fc..d088c0a29 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -197,12 +197,12 @@ public class VBORegion2PMSAAES2 extends GLRegion { } @Override - 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 ) { gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem()); + public void growBuffer(final int verticesCount, final int indicesCount) { } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index e5dcfeb84..436c7cdb8 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -225,7 +225,6 @@ public class VBORegion2PVBAAES2 extends GLRegion { } @Override - 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); @@ -238,6 +237,7 @@ public class VBORegion2PVBAAES2 extends GLRegion { gca_VerticesAttr.setGrowthFactor(growthFactor); } else { gca_VerticesAttr.growIfNeeded(verticeCount * gca_VerticesAttr.getCompsPerElem()); + public void growBuffer(final int verticesCount, final int indicesCount) { } if( null == gca_CurveParamsAttr ) { gca_CurveParamsAttr = GLArrayDataServer.createGLSL(AttributeNames.CURVEPARAMS_ATTR_NAME, 3, GL.GL_FLOAT, diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index dcd5831d4..20170b4ed 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -97,12 +97,12 @@ public class VBORegionSPES2 extends GLRegion { } @Override - 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 ) { gca_ColorsAttr.growIfNeeded(verticeCount * gca_ColorsAttr.getCompsPerElem()); + public void growBuffer(final int verticesCount, final int indicesCount) { } } |