mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphicscommand: Merge DrawTriangles and DrawShader
This commit is contained in:
parent
3ed9f8ee3b
commit
a4d419bab1
@ -142,7 +142,9 @@ func (i *Image) InternalSize() (int, int) {
|
||||
// 9: Color G
|
||||
// 10: Color B
|
||||
// 11: Color Y
|
||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address) {
|
||||
//
|
||||
// src and shader are exclusive and only either is non-nil.
|
||||
func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, shader *Shader, uniforms map[int]interface{}) {
|
||||
if src.screen {
|
||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||
}
|
||||
@ -153,24 +155,11 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
||||
}
|
||||
}
|
||||
|
||||
var us map[int]interface{}
|
||||
if src != nil {
|
||||
src.resolveBufferedReplacePixels()
|
||||
i.resolveBufferedReplacePixels()
|
||||
|
||||
theCommandQueue.EnqueueDrawTrianglesCommand(i, src, vertices, indices, clr, mode, filter, address, nil, nil)
|
||||
|
||||
if i.lastCommand == lastCommandNone && !i.screen {
|
||||
i.lastCommand = lastCommandClear
|
||||
} else {
|
||||
i.lastCommand = lastCommandDrawTriangles
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Image) DrawShader(shader *Shader, vertices []float32, indices []uint16, mode driver.CompositeMode, uniforms map[int]interface{}) {
|
||||
if i.lastCommand == lastCommandNone {
|
||||
panic("graphicscommand: the image must be cleared first before DrawShader")
|
||||
}
|
||||
|
||||
us := map[int]interface{}{}
|
||||
us = map[int]interface{}{}
|
||||
for k, v := range uniforms {
|
||||
switch v := v.(type) {
|
||||
case *Image:
|
||||
@ -180,9 +169,10 @@ func (i *Image) DrawShader(shader *Shader, vertices []float32, indices []uint16,
|
||||
us[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
i.resolveBufferedReplacePixels()
|
||||
|
||||
theCommandQueue.EnqueueDrawTrianglesCommand(i, nil, vertices, indices, nil, mode, 0, 0, shader, us)
|
||||
theCommandQueue.EnqueueDrawTrianglesCommand(i, src, vertices, indices, clr, mode, filter, address, shader, us)
|
||||
|
||||
if i.lastCommand == lastCommandNone && !i.screen {
|
||||
i.lastCommand = lastCommandClear
|
||||
|
@ -46,7 +46,7 @@ func TestClear(t *testing.T) {
|
||||
|
||||
vs := quadVertices(w/2, h/2)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||
|
||||
pix, err := dst.Pixels()
|
||||
if err != nil {
|
||||
@ -76,8 +76,8 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
||||
dst := NewImage(w, h)
|
||||
vs := quadVertices(w/2, h/2)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(clr, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.DrawTriangles(clr, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func TestShader(t *testing.T) {
|
||||
dst := NewImage(w, h)
|
||||
vs := quadVertices(w, h)
|
||||
is := graphics.QuadIndices()
|
||||
dst.DrawTriangles(clr, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero)
|
||||
dst.DrawTriangles(clr, vs, is, nil, driver.CompositeModeClear, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||
|
||||
mat := shaderir.Expr{
|
||||
Type: shaderir.Call,
|
||||
@ -306,7 +306,7 @@ func TestShader(t *testing.T) {
|
||||
us := map[int]interface{}{
|
||||
0: []float32{w, h},
|
||||
}
|
||||
dst.DrawShader(s, vs, is, driver.CompositeModeSourceOver, us)
|
||||
dst.DrawTriangles(nil, vs, is, nil, driver.CompositeModeSourceOver, 0, 0, s, us)
|
||||
|
||||
pix, err := dst.Pixels()
|
||||
if err != nil {
|
||||
|
@ -252,7 +252,7 @@ func fillImage(i *graphicscommand.Image, clr color.RGBA) {
|
||||
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, float32(sw), float32(sh), rf, gf, bf, af)
|
||||
is := graphics.QuadIndices()
|
||||
|
||||
i.DrawTriangles(emptyImage.image, vs, is, nil, compositemode, driver.FilterNearest, driver.AddressClampToZero)
|
||||
i.DrawTriangles(emptyImage.image, vs, is, nil, compositemode, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||
}
|
||||
|
||||
// BasePixelsForTesting returns the image's basePixels for testing.
|
||||
@ -369,7 +369,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
||||
} else {
|
||||
i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address)
|
||||
}
|
||||
i.image.DrawTriangles(img.image, vertices, indices, colorm, mode, filter, address)
|
||||
i.image.DrawTriangles(img.image, vertices, indices, colorm, mode, filter, address, nil, nil)
|
||||
}
|
||||
|
||||
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||
@ -536,7 +536,7 @@ func (i *Image) restore() error {
|
||||
if c.image.hasDependency() {
|
||||
panic("restorable: all dependencies must be already resolved but not")
|
||||
}
|
||||
gimg.DrawTriangles(c.image.image, c.vertices, c.indices, c.colorm, c.mode, c.filter, c.address)
|
||||
gimg.DrawTriangles(c.image.image, c.vertices, c.indices, c.colorm, c.mode, c.filter, c.address, nil, nil)
|
||||
}
|
||||
|
||||
if len(i.drawTrianglesHistory) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user