From fad6cd0cc8033b6ef1ee16998cccd0d756030147 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 20 Apr 2023 04:39:30 +0200 Subject: GraphUI Button.createGLRegion(): Pre-calc Region buffer size for BaseButton (16) + Label-Text to avoid buffer grow --- .../classes/com/jogamp/graph/ui/shapes/Button.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/graphui/classes/com/jogamp/graph') diff --git a/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java b/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java index c1be8064d..a19a58003 100644 --- a/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java +++ b/src/graphui/classes/com/jogamp/graph/ui/shapes/Button.java @@ -28,9 +28,10 @@ package com.jogamp.graph.ui.shapes; import com.jogamp.opengl.GL2ES2; - +import com.jogamp.opengl.GLProfile; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.curve.Region; +import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.font.Font; import com.jogamp.graph.geom.plane.AffineTransform; @@ -95,6 +96,18 @@ public class Button extends BaseButton { // gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); } + @Override + protected GLRegion createGLRegion(final GLProfile glp) { + final int[] vertIndexCount = { 0, 0 }; + final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() { + @Override + public final void visit(final char symbol, final Font.Glyph glyph) { + Region.countOutlineShape(glyph.getShape(), vertIndexCount); + } }; + this.label.getFont().processString(visitor, this.label.getText()); + return GLRegion.create(glp, renderModes, null, 16+vertIndexCount[0], 16+vertIndexCount[1]); + } + @Override protected void addShapeToRegion() { addBaseShapeToRegion( FloatUtil.isZero(labelZOffset) ? 0f : -labelZOffset ); -- cgit v1.2.3