mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphics: Remove one bound check from fragment shader (#461)
This commit is contained in:
parent
654a88c140
commit
d6878d6887
3
image.go
3
image.go
@ -140,6 +140,9 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
}
|
||||
}
|
||||
vs := vertices(sx0, sy0, sx1, sy1, w, h, &options.GeoM.impl)
|
||||
if vs == nil {
|
||||
return nil
|
||||
}
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
i.restorable.DrawImage(img.restorable, vs, &options.ColorM.impl, mode)
|
||||
return nil
|
||||
|
@ -83,9 +83,6 @@ highp vec2 roundTexel(highp vec2 p) {
|
||||
}
|
||||
|
||||
vec4 getColorAt(highp vec2 pos) {
|
||||
if (pos.x < 0.0 || pos.y < 0.0) {
|
||||
return vec4(0, 0, 0, 0);
|
||||
}
|
||||
if (pos.x < varying_tex_coord_min.x ||
|
||||
pos.y < varying_tex_coord_min.y ||
|
||||
varying_tex_coord_max.x <= pos.x ||
|
||||
|
22
vertices.go
22
vertices.go
@ -47,8 +47,30 @@ func vertices(sx0, sy0, sx1, sy1 int, width, height int, geo *affine.GeoM) []flo
|
||||
if sx0 >= sx1 || sy0 >= sy1 {
|
||||
return nil
|
||||
}
|
||||
if sx1 <= 0 || sy1 <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: This function should be in graphics package?
|
||||
vs := theVerticesBackend.get()
|
||||
|
||||
if sx0 < 0 || sy0 < 0 {
|
||||
dx := 0.0
|
||||
dy := 0.0
|
||||
if sx0 < 0 {
|
||||
dx = -float64(sx0)
|
||||
sx0 = 0
|
||||
}
|
||||
if sy0 < 0 {
|
||||
dy = -float64(sy0)
|
||||
sy0 = 0
|
||||
}
|
||||
g := affine.GeoM{}
|
||||
g.Translate(dx, dy)
|
||||
g.Concat(geo)
|
||||
geo = &g
|
||||
}
|
||||
|
||||
a, b, c, d, tx, ty := geo.Elements()
|
||||
g0 := float32(a)
|
||||
g1 := float32(b)
|
||||
|
Loading…
Reference in New Issue
Block a user