From 7f70797a6d892c5b6be24de8da2d2007f9399642 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 15 Jul 2020 03:33:13 +0900 Subject: [PATCH] ebiten: Rename DrawTriaglesWithShaderOptions.Textures to Images --- examples/shader/main.go | 2 +- image.go | 12 ++++----- internal/buffered/image.go | 16 ++++++------ internal/driver/graphics.go | 2 +- internal/graphicscommand/command.go | 18 ++++++------- internal/graphicscommand/image.go | 8 +++--- internal/graphicsdriver/metal/graphics.go | 2 +- internal/graphicsdriver/opengl/graphics.go | 6 ++--- internal/mipmap/mipmap.go | 10 ++++---- internal/restorable/image.go | 30 +++++++++++----------- internal/shareable/image.go | 14 +++++----- 11 files changed, 60 insertions(+), 60 deletions(-) diff --git a/examples/shader/main.go b/examples/shader/main.go index 2abd6f748..fe99061db 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -130,7 +130,7 @@ func (g *Game) Draw(screen *ebiten.Image) { []float32{float32(cx), float32(cy)}, // Cursor } if g.idx != 0 { - op.Textures = append(op.Textures, gophersImage) + op.Images = append(op.Images, gophersImage) } screen.DrawTrianglesWithShader(vs, is, s, op) diff --git a/image.go b/image.go index bb27f1cbd..5eeccfc7a 100644 --- a/image.go +++ b/image.go @@ -342,7 +342,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o type DrawTrianglesWithShaderOptions struct { Uniforms []interface{} - Textures []*Image // TODO: Rename to Images? + Images []*Image CompositeMode CompositeMode } @@ -375,12 +375,12 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha // The actual value is set at graphicscommand package. us := append([]interface{}{[]float32{0, 0}}, options.Uniforms...) - var ts []*buffered.Image - for _, t := range options.Textures { - if t.isDisposed() { + var imgs []*buffered.Image + for _, img := range options.Images { + if img.isDisposed() { panic("ebiten: the given image to DrawTriangles must not be disposed") } - ts = append(ts, t.buffered) + imgs = append(imgs, img.buffered) } vs := make([]float32, len(vertices)*graphics.VertexFloatNum) @@ -397,7 +397,7 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha is := make([]uint16, len(indices)) copy(is, indices) - i.buffered.DrawTriangles(nil, vs, is, nil, mode, driver.FilterNearest, driver.AddressUnsafe, driver.Region{}, shader.shader, us, ts) + i.buffered.DrawTriangles(nil, vs, is, nil, mode, driver.FilterNearest, driver.AddressUnsafe, driver.Region{}, shader.shader, us, imgs) } // SubImage returns an image representing the portion of the image p visible through r. diff --git a/internal/buffered/image.go b/internal/buffered/image.go index db438ed87..81b35b523 100644 --- a/internal/buffered/image.go +++ b/internal/buffered/image.go @@ -268,13 +268,13 @@ func (i *Image) drawImage(src *Image, bounds image.Rectangle, g mipmap.GeoM, col // DrawTriangles draws the src image with the given vertices. // // 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, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { if src != nil { if i == src { panic("buffered: Image.DrawTriangles: src must be different from the receiver") } } - for _, src := range textures { + for _, src := range images { if i == src { panic("buffered: Image.DrawTriangles: source images must be different from the receiver") } @@ -283,7 +283,7 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, if maybeCanAddDelayedCommand() { if tryAddDelayedCommand(func() error { // Arguments are not copied. Copying is the caller's responsibility. - i.DrawTriangles(src, vertices, indices, colorm, mode, filter, address, sourceRegion, shader, uniforms, textures) + i.DrawTriangles(src, vertices, indices, colorm, mode, filter, address, sourceRegion, shader, uniforms, images) return nil }) { return @@ -293,7 +293,7 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, if src != nil { src.resolvePendingPixels(true) } - for _, src := range textures { + for _, src := range images { src.resolvePendingPixels(true) } i.resolvePendingPixels(false) @@ -308,12 +308,12 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, srcImg = src.img } - var ts []*mipmap.Mipmap - for _, t := range textures { - ts = append(ts, t.img) + var imgs []*mipmap.Mipmap + for _, img := range images { + imgs = append(imgs, img.img) } - i.img.DrawTriangles(srcImg, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, ts) + i.img.DrawTriangles(srcImg, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, imgs) i.invalidatePendingPixels() } diff --git a/internal/driver/graphics.go b/internal/driver/graphics.go index ccfe7bdfd..d03da260c 100644 --- a/internal/driver/graphics.go +++ b/internal/driver/graphics.go @@ -58,7 +58,7 @@ type Graphics interface { // // * float32 // * []float32 - DrawShader(dst ImageID, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, uniforms []interface{}, textures []ImageID) error + DrawShader(dst ImageID, shader ShaderID, indexLen int, indexOffset int, mode CompositeMode, uniforms []interface{}, srcs []ImageID) error } // GraphicsNotReady represents that the graphics driver is not ready for recovering from the context lost. diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 938067778..d2d499a8d 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -143,7 +143,7 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) { } // EnqueueDrawTrianglesCommand enqueues a drawing-image command. -func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { if len(indices) > graphics.IndicesNum { panic(fmt.Sprintf("graphicscommand: len(indices) must be <= graphics.IndicesNum but not at EnqueueDrawTrianglesCommand: len(indices): %d, graphics.IndicesNum: %d", len(indices), graphics.IndicesNum)) } @@ -157,8 +157,8 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []f if src != nil { q.appendVertices(vertices, src) - } else if len(textures) > 0 { - q.appendVertices(vertices, textures[0]) + } else if len(images) > 0 { + q.appendVertices(vertices, images[0]) } else { q.appendVertices(vertices, nil) } @@ -195,7 +195,7 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst, src *Image, vertices []f sourceRegion: sourceRegion, shader: shader, uniforms: uniforms, - textures: textures, + images: images, } q.commands = append(q.commands, c) } @@ -322,7 +322,7 @@ type drawTrianglesCommand struct { sourceRegion driver.Region shader *Shader uniforms []interface{} - textures []*Image + images []*Image } func (c *drawTrianglesCommand) String() string { @@ -407,9 +407,9 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error { } if c.shader != nil { - var ts []driver.ImageID - for _, t := range c.textures { - ts = append(ts, t.image.ID()) + var imgs []driver.ImageID + for _, img := range c.images { + imgs = append(imgs, img.image.ID()) } // The last uniform variables are added at /shader.go and represents a viewport size. @@ -418,7 +418,7 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error { viewport[0] = float32(w) viewport[1] = float32(h) - return theGraphicsDriver.DrawShader(c.dst.image.ID(), c.shader.shader.ID(), c.nindices, indexOffset, c.mode, c.uniforms, ts) + return theGraphicsDriver.DrawShader(c.dst.image.ID(), c.shader.shader.ID(), c.nindices, indexOffset, c.mode, c.uniforms, imgs) } return theGraphicsDriver.Draw(c.dst.image.ID(), c.src.image.ID(), c.nindices, indexOffset, c.mode, c.color, c.filter, c.address, c.sourceRegion) } diff --git a/internal/graphicscommand/image.go b/internal/graphicscommand/image.go index dcb7401d7..336e93d54 100644 --- a/internal/graphicscommand/image.go +++ b/internal/graphicscommand/image.go @@ -154,7 +154,7 @@ func processSrc(src *Image) { // // If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the // elements for the source image are not used. -func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { if i.lastCommand == lastCommandNone { if !i.screen && mode != driver.CompositeModeClear { panic("graphicscommand: the image must be cleared first") @@ -164,12 +164,12 @@ func (i *Image) DrawTriangles(src *Image, vertices []float32, indices []uint16, if src != nil { processSrc(src) } - for _, t := range textures { - processSrc(t) + for _, src := range images { + processSrc(src) } i.resolveBufferedReplacePixels() - theCommandQueue.EnqueueDrawTrianglesCommand(i, src, vertices, indices, clr, mode, filter, address, sourceRegion, shader, uniforms, textures) + theCommandQueue.EnqueueDrawTrianglesCommand(i, src, vertices, indices, clr, mode, filter, address, sourceRegion, shader, uniforms, images) if i.lastCommand == lastCommandNone && !i.screen { i.lastCommand = lastCommandClear diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index eadfc2347..62676ad78 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -796,7 +796,7 @@ func (g *Graphics) NewShader(program *shaderir.Program) (driver.Shader, error) { panic("metal: NewShader is not implemented") } -func (g *Graphics) DrawShader(dst driver.ImageID, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, uniforms []interface{}, textures []driver.ImageID) error { +func (g *Graphics) DrawShader(dst driver.ImageID, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, uniforms []interface{}, srcs []driver.ImageID) error { panic("metal: DrawShader is not implemented") } diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index e4c6112d5..2feac0095 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -275,7 +275,7 @@ func (g *Graphics) removeShader(shader *Shader) { delete(g.shaders, shader.id) } -func (g *Graphics) DrawShader(dst driver.ImageID, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, uniforms []interface{}, textures []driver.ImageID) error { +func (g *Graphics) DrawShader(dst driver.ImageID, shader driver.ShaderID, indexLen int, indexOffset int, mode driver.CompositeMode, uniforms []interface{}, srcs []driver.ImageID) error { d := g.images[dst] s := g.shaders[shader] @@ -292,8 +292,8 @@ func (g *Graphics) DrawShader(dst driver.ImageID, shader driver.ShaderID, indexL us[k].value = v } - ts := make([]textureNative, len(textures)) - for k, v := range textures { + ts := make([]textureNative, len(srcs)) + for k, v := range srcs { ts[k] = g.images[v].textureNative } diff --git a/internal/mipmap/mipmap.go b/internal/mipmap/mipmap.go index bbc76353a..5079f4c6a 100644 --- a/internal/mipmap/mipmap.go +++ b/internal/mipmap/mipmap.go @@ -177,7 +177,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, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Mipmap) { +func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Mipmap) { // TODO: Use a mipmap? (#909) if colorm != nil && colorm.ScaleOnly() { @@ -206,12 +206,12 @@ func (m *Mipmap) DrawTriangles(src *Mipmap, vertices []float32, indices []uint16 srcOrig = src.orig } - var ts []*shareable.Image - for _, t := range textures { - ts = append(ts, t.orig) + var imgs []*shareable.Image + for _, img := range images { + imgs = append(imgs, img.orig) } - m.orig.DrawTriangles(srcOrig, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, ts) + m.orig.DrawTriangles(srcOrig, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, imgs) m.disposeMipmaps() } diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 17471aa18..89889fdb9 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -79,7 +79,7 @@ type drawTrianglesHistoryItem struct { sourceRegion driver.Region shader *Shader uniforms []interface{} - textures []*Image + images []*Image } // Image represents an image that can be restored when GL context is lost. @@ -352,7 +352,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { // 5: Color G // 6: Color B // 7: Color Y -func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { if i.priority { panic("restorable: DrawTriangles cannot be called on a priority image") } @@ -367,7 +367,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, srcstale = true } if !srcstale { - for _, t := range textures { + for _, t := range images { if t.stale || t.volatile { srcstale = true break @@ -378,7 +378,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, if srcstale || i.screen || !needsRestoring() || i.volatile { i.makeStale() } else { - i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address, sourceRegion, shader, uniforms, textures) + i.appendDrawTrianglesHistory(img, vertices, indices, colorm, mode, filter, address, sourceRegion, shader, uniforms, images) } var s *graphicscommand.Shader if shader != nil { @@ -390,14 +390,14 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, } var ts []*graphicscommand.Image - for _, t := range textures { + for _, t := range images { ts = append(ts, t.image) } i.image.DrawTriangles(gimg, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, ts) } // appendDrawTrianglesHistory appends a draw-image history item to the image. -func (i *Image) appendDrawTrianglesHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (i *Image) appendDrawTrianglesHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { if i.stale || i.volatile || i.screen { return } @@ -426,7 +426,7 @@ func (i *Image) appendDrawTrianglesHistory(image *Image, vertices []float32, ind sourceRegion: sourceRegion, shader: shader, uniforms: uniforms, - textures: textures, + images: images, } i.drawTrianglesHistory = append(i.drawTrianglesHistory, item) } @@ -518,8 +518,8 @@ func (i *Image) dependsOn(target *Image) bool { if c.image == target { return true } - for _, t := range c.textures { - if t == target { + for _, img := range c.images { + if img == target { return true } } @@ -544,8 +544,8 @@ func (i *Image) dependingImages() map[*Image]struct{} { if c.image != nil { r[c.image] = struct{}{} } - for _, t := range c.textures { - r[t] = struct{}{} + for _, img := range c.images { + r[img] = struct{}{} } } return r @@ -604,11 +604,11 @@ func (i *Image) restore() error { if c.shader != nil { s = c.shader.shader } - var ts []*graphicscommand.Image - for _, t := range c.textures { - ts = append(ts, t.image) + var imgs []*graphicscommand.Image + for _, img := range c.images { + imgs = append(imgs, img.image) } - gimg.DrawTriangles(img, c.vertices, c.indices, c.colorm, c.mode, c.filter, c.address, c.sourceRegion, s, c.uniforms, ts) + gimg.DrawTriangles(img, c.vertices, c.indices, c.colorm, c.mode, c.filter, c.address, c.sourceRegion, s, c.uniforms, imgs) } if len(i.drawTrianglesHistory) > 0 { diff --git a/internal/shareable/image.go b/internal/shareable/image.go index 0106bf9ba..f0e7393bc 100644 --- a/internal/shareable/image.go +++ b/internal/shareable/image.go @@ -305,7 +305,7 @@ func makeSharedIfNeeded(src *Image) { // 5: Color G // 6: Color B // 7: Color Y -func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, textures []*Image) { +func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode driver.CompositeMode, filter driver.Filter, address driver.Address, sourceRegion driver.Region, shader *Shader, uniforms []interface{}, images []*Image) { backendsM.Lock() // Do not use defer for performance. @@ -318,7 +318,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, i.processSrc(img) } firstImg := img - for _, src := range textures { + for _, src := range images { if firstImg == nil { firstImg = src } @@ -356,16 +356,16 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, s = shader.shader } - var ts []*restorable.Image - for _, t := range textures { - ts = append(ts, t.backend.restorable) + var imgs []*restorable.Image + for _, img := range images { + imgs = append(imgs, img.backend.restorable) } var r *restorable.Image if img != nil { r = img.backend.restorable } - i.backend.restorable.DrawTriangles(r, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, ts) + i.backend.restorable.DrawTriangles(r, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms, imgs) i.nonUpdatedCount = 0 delete(imagesToMakeShared, i) @@ -373,7 +373,7 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, if img != nil { makeSharedIfNeeded(img) } - for _, src := range textures { + for _, src := range images { makeSharedIfNeeded(src) }