Skip to content

Commit

Permalink
Optimize RoundedBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Reco1I committed Dec 28, 2024
1 parent 85561f5 commit f991d58
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/com/reco1l/andengine/shape/Box.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit f991d58

Please sign in to comment.