mipmap: Add Shader

This commit is contained in:
Hajime Hoshi 2020-05-29 04:12:41 +09:00
parent 18c59e44aa
commit 218b6fc172
2 changed files with 34 additions and 3 deletions

View File

@ -305,5 +305,5 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
src.resolvePendingPixels(true)
i.resolvePendingPixels(false)
i.img.DrawTriangles(src.img, vertices, indices, colorm, mode, filter, address)
i.img.DrawTriangles(src.img, vertices, indices, colorm, mode, filter, address, nil, nil)
}

View File

@ -23,6 +23,7 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/shaderir"
"github.com/hajimehoshi/ebiten/internal/shareable"
)
@ -165,7 +166,7 @@ func (m *Mipmap) DrawImage(src *Mipmap, bounds image.Rectangle, geom GeoM, color
m.disposeMipmaps()
}
func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, shader *Shader, uniforms []interface{}) {
// TODO: Use a mipmap? (#909)
if colorm != nil && colorm.ScaleOnly() {
@ -183,7 +184,22 @@ func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16
vertices[i*n+11] *= ca
}
}
m.orig.DrawTriangles(src.orig, vertices, indices, colorm, mode, filter, address, nil, nil)
var s *shareable.Shader
if shader != nil {
s = shader.shader
}
us := make([]interface{}, len(uniforms))
for k, v := range uniforms {
switch v := v.(type) {
case *Mipmap:
us[k] = v.orig
default:
us[k] = v
}
}
m.orig.DrawTriangles(src.orig, vertices, indices, colorm, mode, filter, address, s, us)
m.disposeMipmaps()
}
@ -428,3 +444,18 @@ func geomScaleSize(geom *GeoM) (sx, sy float32) {
return maxx - minx, maxy - miny
}
type Shader struct {
shader *shareable.Shader
}
func NewShader(program *shaderir.Program) *Shader {
return &Shader{
shader: shareable.NewShader(program),
}
}
func (s *Shader) MarkDisposed() {
s.shader.MarkDisposed()
s.shader = nil
}