mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
graphics: Reduce calls of glUniformMatrix4fv
This commit is contained in:
parent
26ef56232b
commit
33b50ed294
26
image.go
26
image.go
@ -252,6 +252,10 @@ func (i *imageImpl) Fill(clr color.Color) error {
|
|||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isWholeNumber(x float64) bool {
|
||||||
|
return x == float64(int64(x))
|
||||||
|
}
|
||||||
|
|
||||||
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||||
// Calculate vertices before locking because the user can do anything in
|
// Calculate vertices before locking because the user can do anything in
|
||||||
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
// options.ImageParts interface without deadlock (e.g. Call Image functions).
|
||||||
@ -270,18 +274,22 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
|||||||
}
|
}
|
||||||
geom := &options.GeoM
|
geom := &options.GeoM
|
||||||
colorm := &options.ColorM
|
colorm := &options.ColorM
|
||||||
dxf := geom.Element(0, 2)
|
scaleX := geom.Element(0, 0)
|
||||||
dyf := geom.Element(1, 2)
|
scaleY := geom.Element(1, 1)
|
||||||
|
dx := geom.Element(0, 2)
|
||||||
|
dy := geom.Element(1, 2)
|
||||||
// If possible, avoid using a geometry matrix so that we can reduce calls of
|
// If possible, avoid using a geometry matrix so that we can reduce calls of
|
||||||
// glUniformMatrix4fv.
|
// 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 isWholeNumber(scaleX) && geom.Element(1, 0) == 0 &&
|
||||||
if dxf == float64(int64(dxf)) && dyf == float64(int64(dyf)) {
|
geom.Element(0, 1) == 0 && isWholeNumber(scaleY) &&
|
||||||
dx := int(dxf)
|
isWholeNumber(dx) && isWholeNumber(dy) {
|
||||||
dy := int(dyf)
|
if scaleX != 1 || scaleY != 1 || dx != 0 || dy != 0 {
|
||||||
parts = &transitionImageParts{
|
parts = &transitionImageParts{
|
||||||
parts: parts,
|
parts: parts,
|
||||||
dx: dx,
|
scaleX: int(scaleX),
|
||||||
dy: dy,
|
scaleY: int(scaleY),
|
||||||
|
dx: int(dx),
|
||||||
|
dy: int(dy),
|
||||||
}
|
}
|
||||||
geom = &GeoM{}
|
geom = &GeoM{}
|
||||||
}
|
}
|
||||||
|
@ -126,9 +126,11 @@ func (t *textureQuads) vertices(vertices []int16) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type transitionImageParts struct {
|
type transitionImageParts struct {
|
||||||
parts ImageParts
|
parts ImageParts
|
||||||
dx int
|
scaleX int
|
||||||
dy int
|
scaleY int
|
||||||
|
dx int
|
||||||
|
dy int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *transitionImageParts) Len() int {
|
func (t *transitionImageParts) Len() int {
|
||||||
@ -137,7 +139,7 @@ func (t *transitionImageParts) Len() int {
|
|||||||
|
|
||||||
func (t *transitionImageParts) Dst(index int) (int, int, int, int) {
|
func (t *transitionImageParts) Dst(index int) (int, int, int, int) {
|
||||||
x0, y0, x1, y1 := t.parts.Dst(index)
|
x0, y0, x1, y1 := t.parts.Dst(index)
|
||||||
return x0 + t.dx, y0 + t.dy, x1 + t.dx, y1 + t.dy
|
return x0*t.scaleX + t.dx, y0*t.scaleY + t.dy, x1*t.scaleX + t.dx, y1*t.scaleY + t.dy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *transitionImageParts) Src(index int) (int, int, int, int) {
|
func (t *transitionImageParts) Src(index int) (int, int, int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user