mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
graphics: Reduce int16 converting
This commit is contained in:
parent
b02df7b542
commit
15d0ec3775
@ -69,12 +69,12 @@ func (w *wholeImage) Src(i int) (x0, y0, x1, y1 int) {
|
|||||||
return 0, 0, w.width, w.height
|
return 0, 0, w.width, w.height
|
||||||
}
|
}
|
||||||
|
|
||||||
func u(x int, width int) int {
|
func u(x int, width int) int16 {
|
||||||
return math.MaxInt16 * x / int(graphics.NextPowerOf2Int32(int32(width)))
|
return int16(math.MaxInt16 * x / int(graphics.NextPowerOf2Int32(int32(width))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func v(y int, height int) int {
|
func v(y int, height int) int16 {
|
||||||
return math.MaxInt16 * y / int(graphics.NextPowerOf2Int32(int32(height)))
|
return int16(math.MaxInt16 * y / int(graphics.NextPowerOf2Int32(int32(height))))
|
||||||
}
|
}
|
||||||
|
|
||||||
type textureQuads struct {
|
type textureQuads struct {
|
||||||
@ -90,37 +90,38 @@ func (t *textureQuads) Len() int {
|
|||||||
func (t *textureQuads) SetVertices(vertices []int16) int {
|
func (t *textureQuads) SetVertices(vertices []int16) int {
|
||||||
l := t.Len()
|
l := t.Len()
|
||||||
if len(vertices) < l*16 {
|
if len(vertices) < l*16 {
|
||||||
panic(fmt.Sprintf("grphics: vertices size must be greater than %d but %d", l*16, len(vertices)))
|
panic(fmt.Sprintf("graphics: vertices size must be greater than %d but %d", l*16, len(vertices)))
|
||||||
}
|
}
|
||||||
p := t.parts
|
p := t.parts
|
||||||
w, h := t.width, t.height
|
w, h := t.width, t.height
|
||||||
n := 0
|
n := 0
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
x0, y0, x1, y1 := p.Dst(i)
|
dx0, dy0, dx1, dy1 := p.Dst(i)
|
||||||
if x0 == x1 || y0 == y1 {
|
if dx0 == dx1 || dy0 == dy1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
x0, y0, x1, y1 := int16(dx0), int16(dy0), int16(dx1), int16(dy1)
|
||||||
sx0, sy0, sx1, sy1 := p.Src(i)
|
sx0, sy0, sx1, sy1 := p.Src(i)
|
||||||
u0, v0, u1, v1 := u(sx0, w), v(sy0, h), u(sx1, w), v(sy1, h)
|
if sx0 == sx1 || sy0 == sy1 {
|
||||||
if u0 == u1 || v0 == v1 {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
vertices[16*n] = int16(x0)
|
u0, v0, u1, v1 := u(sx0, w), v(sy0, h), u(sx1, w), v(sy1, h)
|
||||||
vertices[16*n+1] = int16(y0)
|
vertices[16*n] = x0
|
||||||
vertices[16*n+2] = int16(u0)
|
vertices[16*n+1] = y0
|
||||||
vertices[16*n+3] = int16(v0)
|
vertices[16*n+2] = u0
|
||||||
vertices[16*n+4] = int16(x1)
|
vertices[16*n+3] = v0
|
||||||
vertices[16*n+5] = int16(y0)
|
vertices[16*n+4] = x1
|
||||||
vertices[16*n+6] = int16(u1)
|
vertices[16*n+5] = y0
|
||||||
vertices[16*n+7] = int16(v0)
|
vertices[16*n+6] = u1
|
||||||
vertices[16*n+8] = int16(x0)
|
vertices[16*n+7] = v0
|
||||||
vertices[16*n+9] = int16(y1)
|
vertices[16*n+8] = x0
|
||||||
vertices[16*n+10] = int16(u0)
|
vertices[16*n+9] = y1
|
||||||
vertices[16*n+11] = int16(v1)
|
vertices[16*n+10] = u0
|
||||||
vertices[16*n+12] = int16(x1)
|
vertices[16*n+11] = v1
|
||||||
vertices[16*n+13] = int16(y1)
|
vertices[16*n+12] = x1
|
||||||
vertices[16*n+14] = int16(u1)
|
vertices[16*n+13] = y1
|
||||||
vertices[16*n+15] = int16(v1)
|
vertices[16*n+14] = u1
|
||||||
|
vertices[16*n+15] = v1
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
|
Loading…
Reference in New Issue
Block a user