From 218b6fc172e655742f071f8f1af6b3d4bd8e8641 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 29 May 2020 04:12:41 +0900 Subject: [PATCH] mipmap: Add Shader --- internal/buffered/image.go | 2 +- internal/mipmap/mipmap.go | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/internal/buffered/image.go b/internal/buffered/image.go index 1822db70d..4832c6e3b 100644 --- a/internal/buffered/image.go +++ b/internal/buffered/image.go @@ -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) } diff --git a/internal/mipmap/mipmap.go b/internal/mipmap/mipmap.go index b51820bee..1ac39799e 100644 --- a/internal/mipmap/mipmap.go +++ b/internal/mipmap/mipmap.go @@ -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 +}