mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
buffered: Add Shader
This commit is contained in:
parent
218b6fc172
commit
f92253487f
2
image.go
2
image.go
@ -331,7 +331,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
is := make([]uint16, len(indices))
|
is := make([]uint16, len(indices))
|
||||||
copy(is, indices)
|
copy(is, indices)
|
||||||
|
|
||||||
i.buffered.DrawTriangles(img.buffered, vs, is, options.ColorM.impl, mode, filter, driver.Address(options.Address))
|
i.buffered.DrawTriangles(img.buffered, vs, is, options.ColorM.impl, mode, filter, driver.Address(options.Address), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
|
// SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
|
||||||
|
@ -22,6 +22,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/mipmap"
|
"github.com/hajimehoshi/ebiten/internal/mipmap"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/shaderir"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
@ -286,7 +287,7 @@ func (i *Image) drawImage(src *Image, bounds image.Rectangle, g mipmap.GeoM, col
|
|||||||
// DrawTriangles draws the src image with the given vertices.
|
// DrawTriangles draws the src image with the given vertices.
|
||||||
//
|
//
|
||||||
// Copying vertices and indices is the caller's responsibility.
|
// Copying vertices and indices is the caller's responsibility.
|
||||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, shader *Shader, uniforms []interface{}) {
|
||||||
if i == src {
|
if i == src {
|
||||||
panic("buffered: Image.DrawTriangles: src must be different from the receiver")
|
panic("buffered: Image.DrawTriangles: src must be different from the receiver")
|
||||||
}
|
}
|
||||||
@ -297,7 +298,7 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
|||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
delayedCommands = append(delayedCommands, func() error {
|
delayedCommands = append(delayedCommands, func() error {
|
||||||
// Arguments are not copied. Copying is the caller's responsibility.
|
// Arguments are not copied. Copying is the caller's responsibility.
|
||||||
i.DrawTriangles(src, vertices, indices, colorm, mode, filter, address)
|
i.DrawTriangles(src, vertices, indices, colorm, mode, filter, address, shader, uniforms)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -305,5 +306,36 @@ 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, nil, nil)
|
|
||||||
|
var s *mipmap.Shader
|
||||||
|
if shader != nil {
|
||||||
|
s = shader.shader
|
||||||
|
}
|
||||||
|
us := make([]interface{}, len(uniforms))
|
||||||
|
for k, v := range uniforms {
|
||||||
|
switch v := v.(type) {
|
||||||
|
case *Image:
|
||||||
|
i.resolvePendingPixels(true)
|
||||||
|
us[k] = v.img
|
||||||
|
default:
|
||||||
|
us[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i.img.DrawTriangles(src.img, vertices, indices, colorm, mode, filter, address, s, us)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Shader struct {
|
||||||
|
shader *mipmap.Shader
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewShader(program *shaderir.Program) *Shader {
|
||||||
|
return &Shader{
|
||||||
|
shader: mipmap.NewShader(program),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Shader) MarkDisposed() {
|
||||||
|
s.shader.MarkDisposed()
|
||||||
|
s.shader = nil
|
||||||
}
|
}
|
||||||
|
@ -306,3 +306,5 @@ func TestReplacePixelsAndModifyBeforeMain(t *testing.T) {
|
|||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add tests for shaders and ReplacePixels to check resolvePendingPiexles works correctly.
|
||||||
|
@ -184,6 +184,7 @@ func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16
|
|||||||
vertices[i*n+11] *= ca
|
vertices[i*n+11] *= ca
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var s *shareable.Shader
|
var s *shareable.Shader
|
||||||
if shader != nil {
|
if shader != nil {
|
||||||
s = shader.shader
|
s = shader.shader
|
||||||
|
Loading…
Reference in New Issue
Block a user