mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
ebiten: reduce duplicated shader compilations
This commit is contained in:
parent
d4e7676daa
commit
0b45ca7057
@ -67,8 +67,8 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
|
||||
|
||||
var (
|
||||
screenShader *Shader
|
||||
nearestFilterShader = &Shader{shader: mipmap.NearestFilterShader}
|
||||
linearFilterShader = &Shader{shader: mipmap.LinearFilterShader}
|
||||
NearestFilterShader = &Shader{shader: mipmap.NearestFilterShader}
|
||||
LinearFilterShader = &Shader{shader: mipmap.LinearFilterShader}
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -242,15 +242,15 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics) {
|
||||
var shader *Shader
|
||||
switch {
|
||||
case !theGlobalState.isScreenFilterEnabled():
|
||||
shader = nearestFilterShader
|
||||
shader = NearestFilterShader
|
||||
case math.Floor(s) == s:
|
||||
shader = nearestFilterShader
|
||||
shader = NearestFilterShader
|
||||
case s > 1:
|
||||
shader = screenShader
|
||||
default:
|
||||
// screenShader works with >=1 scale, but does not well with <1 scale.
|
||||
// Use regular FilterLinear instead so far (#669).
|
||||
shader = linearFilterShader
|
||||
shader = LinearFilterShader
|
||||
}
|
||||
|
||||
dstRegion := graphicsdriver.Region{
|
||||
|
@ -196,7 +196,7 @@ func (i *Image) resolveDotsCacheIfNeeded() {
|
||||
Width: float32(i.width),
|
||||
Height: float32(i.height),
|
||||
}
|
||||
i.mipmap.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nearestFilterShader.shader, nil, false, true)
|
||||
i.mipmap.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader.shader, nil, false, true)
|
||||
}
|
||||
|
||||
func DumpImages(dir string) (string, error) {
|
||||
@ -236,5 +236,5 @@ func (i *Image) Fill(r, g, b, a float32, x, y, width, height int) {
|
||||
|
||||
srcs := [graphics.ShaderImageCount]*Image{emptyImage}
|
||||
|
||||
i.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, nearestFilterShader, nil, false, true)
|
||||
i.DrawTriangles(srcs, vs, is, affine.ColorMIdentity{}, graphicsdriver.CompositeModeCopy, graphicsdriver.FilterNearest, graphicsdriver.AddressUnsafe, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true)
|
||||
}
|
||||
|
24
shader.go
24
shader.go
@ -81,11 +81,23 @@ func builtinShader(filter graphicsdriver.Filter, address graphicsdriver.Address,
|
||||
return s
|
||||
}
|
||||
|
||||
src := builtinshader.Shader(filter, address, useColorM)
|
||||
s, err := NewShader(src)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ebiten: NewShader for a built-in shader failed: %v", err))
|
||||
var shader *Shader
|
||||
if address == graphicsdriver.AddressUnsafe && !useColorM {
|
||||
switch filter {
|
||||
case graphicsdriver.FilterNearest:
|
||||
shader = &Shader{shader: ui.NearestFilterShader}
|
||||
case graphicsdriver.FilterLinear:
|
||||
shader = &Shader{shader: ui.LinearFilterShader}
|
||||
}
|
||||
} else {
|
||||
src := builtinshader.Shader(filter, address, useColorM)
|
||||
s, err := NewShader(src)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ebiten: NewShader for a built-in shader failed: %v", err))
|
||||
}
|
||||
shader = s
|
||||
}
|
||||
builtinShaders[key] = s
|
||||
return s
|
||||
|
||||
builtinShaders[key] = shader
|
||||
return shader
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user