mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
graphics: Avoid using append
This commit is contained in:
parent
a7803efa9b
commit
537cfea8a4
@ -33,7 +33,7 @@ type Matrix interface {
|
|||||||
Element(i, j int) float64
|
Element(i, j int) float64
|
||||||
}
|
}
|
||||||
|
|
||||||
var vertices = make([]int16, 0, 4*8*quadsMaxNum)
|
var vertices = make([]int16, 16*quadsMaxNum)
|
||||||
|
|
||||||
var shadersInitialized = false
|
var shadersInitialized = false
|
||||||
|
|
||||||
@ -66,26 +66,30 @@ func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
|
|||||||
p.begin()
|
p.begin()
|
||||||
defer p.end()
|
defer p.end()
|
||||||
|
|
||||||
vertices := vertices[0:0]
|
|
||||||
num := 0
|
|
||||||
for i := 0; i < quads.Len(); i++ {
|
for i := 0; i < quads.Len(); i++ {
|
||||||
x0, y0, x1, y1 := quads.Vertex(i)
|
x0, y0, x1, y1 := quads.Vertex(i)
|
||||||
u0, v0, u1, v1 := quads.Texture(i)
|
u0, v0, u1, v1 := quads.Texture(i)
|
||||||
if x0 == x1 || y0 == y1 || u0 == u1 || v0 == v1 {
|
vertices[16*i] = int16(x0)
|
||||||
continue
|
vertices[16*i+1] = int16(y0)
|
||||||
}
|
vertices[16*i+2] = int16(u0)
|
||||||
vertices = append(vertices,
|
vertices[16*i+3] = int16(v0)
|
||||||
int16(x0), int16(y0), int16(u0), int16(v0),
|
vertices[16*i+4] = int16(x1)
|
||||||
int16(x1), int16(y0), int16(u1), int16(v0),
|
vertices[16*i+5] = int16(y0)
|
||||||
int16(x0), int16(y1), int16(u0), int16(v1),
|
vertices[16*i+6] = int16(u1)
|
||||||
int16(x1), int16(y1), int16(u1), int16(v1),
|
vertices[16*i+7] = int16(v0)
|
||||||
)
|
vertices[16*i+8] = int16(x0)
|
||||||
num++
|
vertices[16*i+9] = int16(y1)
|
||||||
|
vertices[16*i+10] = int16(u0)
|
||||||
|
vertices[16*i+11] = int16(v1)
|
||||||
|
vertices[16*i+12] = int16(x1)
|
||||||
|
vertices[16*i+13] = int16(y1)
|
||||||
|
vertices[16*i+14] = int16(u1)
|
||||||
|
vertices[16*i+15] = int16(v1)
|
||||||
}
|
}
|
||||||
if len(vertices) == 0 {
|
if len(vertices) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c.BufferSubData(c.ArrayBuffer, vertices)
|
c.BufferSubData(c.ArrayBuffer, vertices[:16*quads.Len()])
|
||||||
c.DrawElements(c.Triangles, 6*num)
|
c.DrawElements(c.Triangles, 6*quads.Len())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user