ebiten: Remove shaders from DrawImage

Updates #1325
This commit is contained in:
Hajime Hoshi 2020-09-20 18:13:57 +09:00
parent 0db7dc22b2
commit 938d78122f
2 changed files with 12 additions and 44 deletions

View File

@ -116,8 +116,6 @@ type DrawImageOptions struct {
// ColorM is a color matrix to draw.
// The default (zero) value is identity, which doesn't change any color.
//
// If Shader is not nil, ColorM is ignored.
ColorM ColorM
// CompositeMode is a composite mode to draw.
@ -134,18 +132,8 @@ type DrawImageOptions struct {
// FilterNearest is used.
// If either is FilterDefault and the other is not, the latter is used.
// Otherwise, Filter specified at DrawImageOptions is used.
//
// If Shader is not nil, Filter is ignored.
Filter Filter
// Shader is a shader.
Shader *Shader
// Uniforms is a set of uniform variables for the shader.
//
// Uniforms is used only when Shader is not nil.
Uniforms map[string]interface{}
// Deprecated: (as of 1.5.0) Use SubImage instead.
ImageParts ImageParts
@ -181,7 +169,6 @@ type DrawImageOptions struct {
// elements.
// * All CompositeMode values are same
// * All Filter values are same
// * All Shader values are nil
//
// Even when all the above conditions are satisfied, multiple draw commands can
// be used in really rare cases. Ebiten images usually share an internal
@ -193,8 +180,6 @@ type DrawImageOptions struct {
//
// For more performance tips, see https://ebiten.org/documents/performancetips.html
//
// ColorM and Filter are ignored when Shader is not nil.
//
// DrawImage always returns nil as of 1.5.0.
func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
i.copyCheck()
@ -257,13 +242,11 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
mode := driver.CompositeMode(options.CompositeMode)
filter := driver.FilterNearest
if options.Shader == nil {
if options.Filter != FilterDefault {
filter = driver.Filter(options.Filter)
} else if img.filter != FilterDefault {
filter = driver.Filter(img.filter)
}
}
a, b, c, d, tx, ty := options.GeoM.elements32()
@ -275,25 +258,10 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
is := graphics.QuadIndices()
srcs := [graphics.ShaderImageNum]*mipmap.Mipmap{img.mipmap}
if options.Shader == nil {
i.mipmap.DrawTriangles(srcs, vs, is, options.ColorM.impl, mode, filter, driver.AddressUnsafe, driver.Region{}, [graphics.ShaderImageNum - 1][2]float32{}, nil, nil, canSkipMipmap(options.GeoM, filter))
return nil
}
// Pass the source region only when the shader is used, since this affects the condition of merging graphics
// commands (#1293).
sr := driver.Region{
X: float32(bounds.Min.X),
Y: float32(bounds.Min.Y),
Width: float32(bounds.Dx()),
Height: float32(bounds.Dy()),
}
us := options.Shader.convertUniforms(options.Uniforms)
i.mipmap.DrawTriangles(srcs, vs, is, nil, mode, filter, driver.AddressUnsafe, sr, [graphics.ShaderImageNum - 1][2]float32{}, options.Shader.shader, us, canSkipMipmap(options.GeoM, filter))
return nil
}
// Vertex represents a vertex passed to DrawTriangles.
type Vertex struct {
// DstX and DstY represents a point on a destination image.
@ -365,7 +333,7 @@ type DrawTrianglesOptions struct {
// Images is a set of the additional source images.
// All the image must be the same size as the img argument at DrawTriangles.
//
// If Shader is nil, Imagse is ignored.
// Images is used only when Shader is not nil.
Images [3]*Image
}

View File

@ -67,9 +67,9 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
src, _ := NewImage(w/2, h/2, FilterDefault)
op := &DrawImageOptions{}
op.Shader = s
dst.DrawImage(src, op)
op := &DrawRectShaderOptions{}
op.Images[0] = src
dst.DrawRectShader(w/2, h/2, s, op)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
@ -785,9 +785,9 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
src, _ := NewImage(w, h, FilterDefault)
op := &DrawImageOptions{}
op.Shader = s
dst.DrawImage(src, op)
op := &DrawRectShaderOptions{}
op.Images[0] = src
dst.DrawRectShader(w, h, s, op)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {