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
|
// 9: Color G
|
||||||
// 10: Color B
|
// 10: Color B
|
||||||
// 11: Color Y
|
// 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 {
|
if src.screen {
|
||||||
panic("graphicscommand: the screen image cannot be the rendering source")
|
panic("graphicscommand: the screen image cannot be the rendering source")
|
||||||
}
|
}
|
||||||
@ -153,36 +155,24 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
src.resolveBufferedReplacePixels()
|
var us map[int]interface{}
|
||||||
i.resolveBufferedReplacePixels()
|
if src != nil {
|
||||||
|
src.resolveBufferedReplacePixels()
|
||||||
theCommandQueue.EnqueueDrawTrianglesCommand(i, src, vertices, indices, clr, mode, filter, address, nil, nil)
|
|
||||||
|
|
||||||
if i.lastCommand == lastCommandNone && !i.screen {
|
|
||||||
i.lastCommand = lastCommandClear
|
|
||||||
} else {
|
} else {
|
||||||
i.lastCommand = lastCommandDrawTriangles
|
us = map[int]interface{}{}
|
||||||
}
|
for k, v := range uniforms {
|
||||||
}
|
switch v := v.(type) {
|
||||||
|
case *Image:
|
||||||
func (i *Image) DrawShader(shader *Shader, vertices []float32, indices []uint16, mode driver.CompositeMode, uniforms map[int]interface{}) {
|
v.resolveBufferedReplacePixels()
|
||||||
if i.lastCommand == lastCommandNone {
|
us[k] = v.image
|
||||||
panic("graphicscommand: the image must be cleared first before DrawShader")
|
default:
|
||||||
}
|
us[k] = v
|
||||||
|
}
|
||||||
us := map[int]interface{}{}
|
|
||||||
for k, v := range uniforms {
|
|
||||||
switch v := v.(type) {
|
|
||||||
case *Image:
|
|
||||||
v.resolveBufferedReplacePixels()
|
|
||||||
us[k] = v.image
|
|
||||||
default:
|
|
||||||
us[k] = v
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i.resolveBufferedReplacePixels()
|
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 {
|
if i.lastCommand == lastCommandNone && !i.screen {
|
||||||
i.lastCommand = lastCommandClear
|
i.lastCommand = lastCommandClear
|
||||||
|
@ -46,7 +46,7 @@ func TestClear(t *testing.T) {
|
|||||||
|
|
||||||
vs := quadVertices(w/2, h/2)
|
vs := quadVertices(w/2, h/2)
|
||||||
is := graphics.QuadIndices()
|
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()
|
pix, err := dst.Pixels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -76,8 +76,8 @@ func TestReplacePixelsPartAfterDrawTriangles(t *testing.T) {
|
|||||||
dst := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
vs := quadVertices(w/2, h/2)
|
vs := quadVertices(w/2, h/2)
|
||||||
is := graphics.QuadIndices()
|
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)
|
||||||
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero)
|
dst.DrawTriangles(src, vs, is, nil, driver.CompositeModeSourceOver, driver.FilterNearest, driver.AddressClampToZero, nil, nil)
|
||||||
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
dst.ReplacePixels(make([]byte, 4), 0, 0, 1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func TestShader(t *testing.T) {
|
|||||||
dst := NewImage(w, h)
|
dst := NewImage(w, h)
|
||||||
vs := quadVertices(w, h)
|
vs := quadVertices(w, h)
|
||||||
is := graphics.QuadIndices()
|
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{
|
mat := shaderir.Expr{
|
||||||
Type: shaderir.Call,
|
Type: shaderir.Call,
|
||||||
@ -306,7 +306,7 @@ func TestShader(t *testing.T) {
|
|||||||
us := map[int]interface{}{
|
us := map[int]interface{}{
|
||||||
0: []float32{w, h},
|
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()
|
pix, err := dst.Pixels()
|
||||||
if err != nil {
|
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)
|
vs := quadVertices(0, 0, float32(dw), float32(dh), 0, 0, float32(sw), float32(sh), rf, gf, bf, af)
|
||||||
is := graphics.QuadIndices()
|
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.
|
// BasePixelsForTesting returns the image's basePixels for testing.
|
||||||
@ -369,7 +369,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16,
|
|||||||
} else {
|
} else {
|
||||||
i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address)
|
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.
|
// appendDrawTrianglesHistory appends a draw-image history item to the image.
|
||||||
@ -536,7 +536,7 @@ func (i *Image) restore() error {
|
|||||||
if c.image.hasDependency() {
|
if c.image.hasDependency() {
|
||||||
panic("restorable: all dependencies must be already resolved but not")
|
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 {
|
if len(i.drawTrianglesHistory) > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user