mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphics: Refactoring
This commit is contained in:
parent
e9ffe13739
commit
07da7a2348
@ -69,17 +69,12 @@ func (w *wholeImage) Src(i int) (x0, y0, x1, y1 int) {
|
||||
return 0, 0, w.width, w.height
|
||||
}
|
||||
|
||||
type uv struct {
|
||||
width2p int
|
||||
height2p int
|
||||
func u(x, width2p int) int16 {
|
||||
return int16(math.MaxInt16 * x / width2p)
|
||||
}
|
||||
|
||||
func (c *uv) u(x int) int16 {
|
||||
return int16(math.MaxInt16 * x / c.width2p)
|
||||
}
|
||||
|
||||
func (c *uv) v(y int) int16 {
|
||||
return int16(math.MaxInt16 * y / c.height2p)
|
||||
func v(y, height2p int) int16 {
|
||||
return int16(math.MaxInt16 * y / height2p)
|
||||
}
|
||||
|
||||
type textureQuads struct {
|
||||
@ -96,10 +91,8 @@ func (t *textureQuads) vertices(vertices []int16) int {
|
||||
p := t.parts
|
||||
w, h := t.width, t.height
|
||||
n := 0
|
||||
c := uv{
|
||||
width2p: int(graphics.NextPowerOf2Int32(int32(w))),
|
||||
height2p: int(graphics.NextPowerOf2Int32(int32(h))),
|
||||
}
|
||||
width2p := int(graphics.NextPowerOf2Int32(int32(w)))
|
||||
height2p := int(graphics.NextPowerOf2Int32(int32(h)))
|
||||
for i := 0; i < l; i++ {
|
||||
dx0, dy0, dx1, dy1 := p.Dst(i)
|
||||
if dx0 == dx1 || dy0 == dy1 {
|
||||
@ -110,7 +103,7 @@ func (t *textureQuads) vertices(vertices []int16) int {
|
||||
if sx0 == sx1 || sy0 == sy1 {
|
||||
continue
|
||||
}
|
||||
u0, v0, u1, v1 := c.u(sx0), c.v(sy0), c.u(sx1), c.v(sy1)
|
||||
u0, v0, u1, v1 := u(sx0, width2p), v(sy0, height2p), u(sx1, width2p), v(sy1, height2p)
|
||||
vertices[16*n] = x0
|
||||
vertices[16*n+1] = y0
|
||||
vertices[16*n+2] = u0
|
||||
|
@ -66,7 +66,7 @@ func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
|
||||
}
|
||||
p.begin()
|
||||
defer p.end()
|
||||
c.BufferSubData(c.ArrayBuffer, vertices[:16*n])
|
||||
c.BufferSubData(c.ArrayBuffer, vertices)
|
||||
c.DrawElements(c.Triangles, 6*n)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user