From f991d58cd76d23f7ce504cfff4ddaedb93155156 Mon Sep 17 00:00:00 2001 From: Geronimo Ferruccio Date: Fri, 27 Dec 2024 22:04:48 -0300 Subject: [PATCH] Optimize RoundedBox --- src/com/reco1l/andengine/shape/Box.kt | 35 +++++++++------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/com/reco1l/andengine/shape/Box.kt b/src/com/reco1l/andengine/shape/Box.kt index b8a30de39..d0593c221 100644 --- a/src/com/reco1l/andengine/shape/Box.kt +++ b/src/com/reco1l/andengine/shape/Box.kt @@ -124,7 +124,7 @@ open class RoundedBox : ExtendedEntity() { class RoundedBoxVertexBuffer(private val segmentsPerArc: Int) : VertexBuffer( - (5 /*Quads*/ * 4 + (segmentsPerArc + 2) /*Arcs*/ * 4) * 2, + (3 /*Quads*/ * 4 + (segmentsPerArc + 2) /*Arcs*/ * 4) * 2, GL11.GL_STATIC_DRAW, false ) { @@ -151,41 +151,28 @@ open class RoundedBox : ExtendedEntity() { } // Quads: - // [1] - // [4] [5] [2] - // [3] + // [ ] + // [1] [2] [3] + // [ ] // [1] addQuad( - fromX = cornerRadius, fromY = 0f, - toX = width - cornerRadius, toY = cornerRadius + fromX = 0f, fromY = cornerRadius, + toX = cornerRadius, toY = height - cornerRadius ) // [2] addQuad( - fromX = width - cornerRadius, fromY = cornerRadius, - toX = width, toY = height - cornerRadius - ) - - // [3] - addQuad( - fromX = cornerRadius, fromY = height - cornerRadius, + fromX = cornerRadius, fromY = 0f, toX = width - cornerRadius, toY = height ) - // [4] - addQuad( - fromX = 0f, fromY = cornerRadius, - toX = cornerRadius, toY = height - cornerRadius - ) - - // [5] + // [3] addQuad( - fromX = cornerRadius, fromY = cornerRadius, - toX = width - cornerRadius, toY = height - cornerRadius + fromX = width - cornerRadius, fromY = cornerRadius, + toX = width, toY = height - cornerRadius ) - // Arcs fun addArc(centerX: Float, centerY: Float, startAngle: Float, endAngle: Float) { @@ -234,7 +221,7 @@ open class RoundedBox : ExtendedEntity() { var offset = 0 // Quads - for (i in 0 until 5) { + for (i in 0 until 3) { gl.glDrawArrays(GL_TRIANGLE_STRIP, offset, 4) offset += 4 }