From 307479391f955a5bd611b4ad4db6f53e097d15c5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 24 Feb 2023 22:15:20 +0100 Subject: 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. --- .../com/jogamp/graph/curve/opengl/GLRegion.java | 41 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java') 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 d924fa9c8..69638f60e 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -29,6 +29,8 @@ 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.GLProfile; import jogamp.graph.curve.opengl.VBORegion2PMSAAES2; import jogamp.graph.curve.opengl.VBORegion2PVBAAES2; @@ -37,6 +39,10 @@ import jogamp.graph.curve.opengl.VBORegionSPES2; import com.jogamp.opengl.util.PMVMatrix; import com.jogamp.opengl.util.texture.TextureSequence; 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 @@ -57,31 +63,36 @@ public abstract class GLRegion extends Region { * *

In case {@link Region#VBAA_RENDERING_BIT} is being requested the default texture unit * {@link Region#DEFAULT_TWO_PASS_TEXTURE_UNIT} is being used.

+ * @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(int renderModes, final TextureSequence colorTexSeq) { + public static GLRegion create(final GLProfile glp, int renderModes, final TextureSequence colorTexSeq) { 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(renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT); + return new VBORegion2PVBAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT); } else if( isMSAA(renderModes) ) { - return new VBORegion2PMSAAES2(renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT); + return new VBORegion2PMSAAES2(glp, renderModes, colorTexSeq, Region.DEFAULT_TWO_PASS_TEXTURE_UNIT); } else { - return new VBORegionSPES2(renderModes, colorTexSeq); + return new VBORegionSPES2(glp, renderModes, colorTexSeq); } } + private final int gl_idx_type; protected final TextureSequence colorTexSeq; - protected GLRegion(final int renderModes, final TextureSequence colorTexSeq) { - super(renderModes); + protected GLRegion(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq) { + super(renderModes, glp.isGL2ES3() /* use_int32_idx */); + this.gl_idx_type = usesI32Idx() ? GL.GL_UNSIGNED_INT : GL.GL_UNSIGNED_SHORT; this.colorTexSeq = colorTexSeq; } + protected final int glIdxType() { return this.gl_idx_type; } + /** * Updates a graph region by updating the ogl related * objects for use in rendering if {@link #isShapeDirty()}. @@ -94,12 +105,28 @@ public abstract class GLRegion extends Region { protected abstract void clearImpl(final GL2ES2 gl); + 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("]"); + } else { + out.print("null]"); + } + } + /** * Clears all data, i.e. triangles, vertices etc. + * + * @param gl the current {@link GL2ES2} object + * @return this {@link GLRegion} for chaining. */ - public void clear(final GL2ES2 gl) { + public GLRegion clear(final GL2ES2 gl) { clearImpl(gl); clearImpl(); + return this; } /** -- cgit v1.2.3