mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 04:22:05 +01:00
mipmap: Add Shader
This commit is contained in:
parent
18c59e44aa
commit
218b6fc172
@ -305,5 +305,5 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
|||||||
|
|
||||||
src.resolvePendingPixels(true)
|
src.resolvePendingPixels(true)
|
||||||
i.resolvePendingPixels(false)
|
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)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/shaderir"
|
||||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,7 +166,7 @@ func (m *Mipmap) DrawImage(src *Mipmap, bounds image.Rectangle, geom GeoM, color
|
|||||||
m.disposeMipmaps()
|
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)
|
// TODO: Use a mipmap? (#909)
|
||||||
|
|
||||||
if colorm != nil && colorm.ScaleOnly() {
|
if colorm != nil && colorm.ScaleOnly() {
|
||||||
@ -183,7 +184,22 @@ func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16
|
|||||||
vertices[i*n+11] *= ca
|
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()
|
m.disposeMipmaps()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,3 +444,18 @@ func geomScaleSize(geom *GeoM) (sx, sy float32) {
|
|||||||
|
|
||||||
return maxx - minx, maxy - miny
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user