mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Reduce calls of glUniformMatrix4fv
This commit is contained in:
parent
bddd3c9467
commit
4812f2e76e
22
image.go
22
image.go
@ -269,6 +269,24 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
parts = &wholeImage{image.impl.width, image.impl.height}
|
||||
}
|
||||
}
|
||||
geom := &options.GeoM
|
||||
colorm := &options.ColorM
|
||||
dxf := geom.Element(0, 2)
|
||||
dyf := geom.Element(1, 2)
|
||||
// If possible, avoid using a geometry matrix so that we can reduce calls of
|
||||
// glUniformMatrix4fv.
|
||||
if geom.Element(0, 0) == 1 && geom.Element(1, 0) == 0 && geom.Element(0, 1) == 0 && geom.Element(1, 1) == 1 && (dxf != 0 && dyf != 0) {
|
||||
if dxf == float64(int64(dxf)) && dyf == float64(int64(dyf)) {
|
||||
dx := int(dxf)
|
||||
dy := int(dyf)
|
||||
parts = &transitionImageParts{
|
||||
parts: parts,
|
||||
dx: dx,
|
||||
dy: dy,
|
||||
}
|
||||
geom = &GeoM{}
|
||||
}
|
||||
}
|
||||
quads := &textureQuads{parts: parts, width: image.impl.width, height: image.impl.height}
|
||||
// TODO: Reuse one vertices instead of making here, but this would need locking.
|
||||
vertices := make([]int16, parts.Len()*16)
|
||||
@ -286,8 +304,8 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
}
|
||||
i.pixels = nil
|
||||
m := opengl.CompositeMode(options.CompositeMode)
|
||||
return i.framebuffer.DrawTexture(ui.GLContext(), image.impl.texture, vertices[:16*n], &options.GeoM, &options.ColorM, m)
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
return i.framebuffer.DrawTexture(ui.GLContext(), image.impl.texture, vertices[:16*n], geom, colorm, mode)
|
||||
}
|
||||
if theDelayedImageTasks.add(f) {
|
||||
return nil
|
||||
|
@ -124,3 +124,22 @@ func (t *textureQuads) vertices(vertices []int16) int {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type transitionImageParts struct {
|
||||
parts ImageParts
|
||||
dx int
|
||||
dy int
|
||||
}
|
||||
|
||||
func (t *transitionImageParts) Len() int {
|
||||
return t.parts.Len()
|
||||
}
|
||||
|
||||
func (t *transitionImageParts) Dst(index int) (int, int, int, int) {
|
||||
x0, y0, x1, y1 := t.parts.Dst(index)
|
||||
return x0 + t.dx, y0 + t.dy, x1 + t.dx, y1 + t.dy
|
||||
}
|
||||
|
||||
func (t *transitionImageParts) Src(index int) (int, int, int, int) {
|
||||
return t.parts.Src(index)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user