mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
grpahics: Move DrawTriangles implementation to mipmap
This commit is contained in:
parent
504a433540
commit
e585fda253
12
image.go
12
image.go
@ -477,17 +477,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
filter = driver.Filter(img.filter)
|
filter = driver.Filter(img.filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
vs := vertexSlice(len(vertices))
|
i.mipmap.drawTriangles(img.mipmap, img.Bounds(), vertices, indices, options.ColorM.impl, mode, filter, driver.Address(options.Address))
|
||||||
src := img.mipmap.original()
|
|
||||||
r := img.Bounds()
|
|
||||||
for idx, v := range vertices {
|
|
||||||
src.PutVertex(vs[idx*graphics.VertexFloatNum:(idx+1)*graphics.VertexFloatNum],
|
|
||||||
float32(v.DstX), float32(v.DstY), v.SrcX, v.SrcY,
|
|
||||||
float32(r.Min.X), float32(r.Min.Y), float32(r.Max.X), float32(r.Max.Y),
|
|
||||||
v.ColorR, v.ColorG, v.ColorB, v.ColorA)
|
|
||||||
}
|
|
||||||
i.mipmap.original().DrawTriangles(src, vs, indices, options.ColorM.impl, mode, filter, driver.Address(options.Address))
|
|
||||||
i.disposeMipmaps()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
|
// SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
|
||||||
|
13
mipmap.go
13
mipmap.go
@ -20,6 +20,7 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||||
@ -78,6 +79,18 @@ func (m *mipmap) at(x, y int) (r, g, b, a byte) {
|
|||||||
return m.orig.At(x, y)
|
return m.orig.At(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mipmap) drawTriangles(src *mipmap, bounds image.Rectangle, vertices []Vertex, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||||
|
vs := vertexSlice(len(vertices))
|
||||||
|
for idx, v := range vertices {
|
||||||
|
src.orig.PutVertex(vs[idx*graphics.VertexFloatNum:(idx+1)*graphics.VertexFloatNum],
|
||||||
|
float32(v.DstX), float32(v.DstY), v.SrcX, v.SrcY,
|
||||||
|
float32(bounds.Min.X), float32(bounds.Min.Y), float32(bounds.Max.X), float32(bounds.Max.Y),
|
||||||
|
v.ColorR, v.ColorG, v.ColorB, v.ColorA)
|
||||||
|
}
|
||||||
|
m.orig.DrawTriangles(src.orig, vs, indices, clr, mode, filter, address)
|
||||||
|
m.disposeMipmaps()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
||||||
if level == 0 {
|
if level == 0 {
|
||||||
panic("ebiten: level must be non-zero at level")
|
panic("ebiten: level must be non-zero at level")
|
||||||
|
Loading…
Reference in New Issue
Block a user