Move CompositeMode to graphics package

This commit is contained in:
Hajime Hoshi 2018-10-28 20:42:57 +09:00
parent 06f2052817
commit ff54d3b681
14 changed files with 186 additions and 136 deletions

View File

@ -16,7 +16,6 @@ package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/opengl"
)
// Filter represents the type of texture filter to be used when an image is maginified or minified.
@ -46,42 +45,42 @@ type CompositeMode int
const (
// Regular alpha blending
// c_out = c_src + c_dst × (1 - α_src)
CompositeModeSourceOver CompositeMode = CompositeMode(opengl.CompositeModeSourceOver)
CompositeModeSourceOver CompositeMode = CompositeMode(graphics.CompositeModeSourceOver)
// c_out = 0
CompositeModeClear CompositeMode = CompositeMode(opengl.CompositeModeClear)
CompositeModeClear CompositeMode = CompositeMode(graphics.CompositeModeClear)
// c_out = c_src
CompositeModeCopy CompositeMode = CompositeMode(opengl.CompositeModeCopy)
CompositeModeCopy CompositeMode = CompositeMode(graphics.CompositeModeCopy)
// c_out = c_dst
CompositeModeDestination CompositeMode = CompositeMode(opengl.CompositeModeDestination)
CompositeModeDestination CompositeMode = CompositeMode(graphics.CompositeModeDestination)
// c_out = c_src × (1 - α_dst) + c_dst
CompositeModeDestinationOver CompositeMode = CompositeMode(opengl.CompositeModeDestinationOver)
CompositeModeDestinationOver CompositeMode = CompositeMode(graphics.CompositeModeDestinationOver)
// c_out = c_src × α_dst
CompositeModeSourceIn CompositeMode = CompositeMode(opengl.CompositeModeSourceIn)
CompositeModeSourceIn CompositeMode = CompositeMode(graphics.CompositeModeSourceIn)
// c_out = c_dst × α_src
CompositeModeDestinationIn CompositeMode = CompositeMode(opengl.CompositeModeDestinationIn)
CompositeModeDestinationIn CompositeMode = CompositeMode(graphics.CompositeModeDestinationIn)
// c_out = c_src × (1 - α_dst)
CompositeModeSourceOut CompositeMode = CompositeMode(opengl.CompositeModeSourceOut)
CompositeModeSourceOut CompositeMode = CompositeMode(graphics.CompositeModeSourceOut)
// c_out = c_dst × (1 - α_src)
CompositeModeDestinationOut CompositeMode = CompositeMode(opengl.CompositeModeDestinationOut)
CompositeModeDestinationOut CompositeMode = CompositeMode(graphics.CompositeModeDestinationOut)
// c_out = c_src × α_dst + c_dst × (1 - α_src)
CompositeModeSourceAtop CompositeMode = CompositeMode(opengl.CompositeModeSourceAtop)
CompositeModeSourceAtop CompositeMode = CompositeMode(graphics.CompositeModeSourceAtop)
// c_out = c_src × (1 - α_dst) + c_dst × α_src
CompositeModeDestinationAtop CompositeMode = CompositeMode(opengl.CompositeModeDestinationAtop)
CompositeModeDestinationAtop CompositeMode = CompositeMode(graphics.CompositeModeDestinationAtop)
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
CompositeModeXor CompositeMode = CompositeMode(opengl.CompositeModeXor)
CompositeModeXor CompositeMode = CompositeMode(graphics.CompositeModeXor)
// Sum of source and destination (a.k.a. 'plus' or 'additive')
// c_out = c_src + c_dst
CompositeModeLighter CompositeMode = CompositeMode(opengl.CompositeModeLighter)
CompositeModeLighter CompositeMode = CompositeMode(graphics.CompositeModeLighter)
)

View File

@ -22,7 +22,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
"github.com/hajimehoshi/ebiten/internal/opengl"
"github.com/hajimehoshi/ebiten/internal/shareable"
)
@ -92,7 +91,7 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
vs = src.QuadVertices(0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
}
is := graphicsutil.QuadIndices()
s.DrawImage(src, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterLinear)
s.DrawImage(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterLinear)
imgs = append(imgs, s)
w = w2
h = h2
@ -374,7 +373,7 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
geom.Concat(options.GeoM)
}
mode := opengl.CompositeMode(options.CompositeMode)
mode := graphics.CompositeMode(options.CompositeMode)
filter := graphics.FilterNearest
if options.Filter != FilterDefault {
@ -509,7 +508,7 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
options = &DrawTrianglesOptions{}
}
mode := opengl.CompositeMode(options.CompositeMode)
mode := graphics.CompositeMode(options.CompositeMode)
filter := graphics.FilterNearest
if options.Filter != FilterDefault {

View File

@ -0,0 +1,78 @@
// Copyright 2018 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package graphics
type CompositeMode int
const (
CompositeModeSourceOver CompositeMode = iota // This value must be 0 (= initial value)
CompositeModeClear
CompositeModeCopy
CompositeModeDestination
CompositeModeDestinationOver
CompositeModeSourceIn
CompositeModeDestinationIn
CompositeModeSourceOut
CompositeModeDestinationOut
CompositeModeSourceAtop
CompositeModeDestinationAtop
CompositeModeXor
CompositeModeLighter
CompositeModeUnknown
)
type Operation int
const (
Zero Operation = iota
One
SrcAlpha
DstAlpha
OneMinusSrcAlpha
OneMinusDstAlpha
)
func (c CompositeMode) Operations() (src Operation, dst Operation) {
switch c {
case CompositeModeSourceOver:
return One, OneMinusSrcAlpha
case CompositeModeClear:
return Zero, Zero
case CompositeModeCopy:
return One, Zero
case CompositeModeDestination:
return Zero, One
case CompositeModeDestinationOver:
return OneMinusDstAlpha, One
case CompositeModeSourceIn:
return DstAlpha, Zero
case CompositeModeDestinationIn:
return Zero, SrcAlpha
case CompositeModeSourceOut:
return OneMinusDstAlpha, Zero
case CompositeModeDestinationOut:
return Zero, OneMinusSrcAlpha
case CompositeModeSourceAtop:
return DstAlpha, OneMinusSrcAlpha
case CompositeModeDestinationAtop:
return OneMinusDstAlpha, SrcAlpha
case CompositeModeXor:
return OneMinusDstAlpha, OneMinusSrcAlpha
case CompositeModeLighter:
return One, One
default:
panic("not reached")
}
}

View File

@ -37,7 +37,7 @@ type command interface {
NumIndices() int
AddNumVertices(n int)
AddNumIndices(n int)
CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool
CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool
}
// commandQueue is a command queue for drawing commands.
@ -89,7 +89,7 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) {
q.nindices += len(indices)
}
func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter, forceNewCommand bool) {
func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nindices int, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter, forceNewCommand bool) {
if nindices > indicesNum {
panic("not implemented for too many indices")
}
@ -113,7 +113,7 @@ func (q *commandQueue) doEnqueueDrawImageCommand(dst, src *Image, nvertices, nin
}
// EnqueueDrawImageCommand enqueues a drawing-image command.
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, indices []uint16, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
if len(indices) > indicesNum {
panic("not reached")
}
@ -221,7 +221,7 @@ type drawImageCommand struct {
nvertices int
nindices int
color *affine.ColorM
mode opengl.CompositeMode
mode graphics.CompositeMode
filter graphics.Filter
}
@ -276,7 +276,7 @@ func (c *drawImageCommand) AddNumIndices(n int) {
// CanMerge returns a boolean value indicating whether the other drawImageCommand can be merged
// with the drawImageCommand c.
func (c *drawImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *drawImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
if c.dst != dst {
return false
}
@ -333,7 +333,7 @@ func (c *replacePixelsCommand) AddNumVertices(n int) {
func (c *replacePixelsCommand) AddNumIndices(n int) {
}
func (c *replacePixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *replacePixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
return false
}
@ -374,7 +374,7 @@ func (c *pixelsCommand) AddNumVertices(n int) {
func (c *pixelsCommand) AddNumIndices(n int) {
}
func (c *pixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *pixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
return false
}
@ -413,7 +413,7 @@ func (c *disposeCommand) AddNumVertices(n int) {
func (c *disposeCommand) AddNumIndices(n int) {
}
func (c *disposeCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *disposeCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
return false
}
@ -473,7 +473,7 @@ func (c *newImageCommand) AddNumVertices(n int) {
func (c *newImageCommand) AddNumIndices(n int) {
}
func (c *newImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *newImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
return false
}
@ -512,6 +512,6 @@ func (c *newScreenFramebufferImageCommand) AddNumVertices(n int) {
func (c *newScreenFramebufferImageCommand) AddNumIndices(n int) {
}
func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) bool {
func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) bool {
return false
}

View File

@ -87,7 +87,7 @@ func (i *Image) Size() (int, int) {
return i.width, i.height
}
func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
theCommandQueue.EnqueueDrawImageCommand(i, src, vertices, indices, clr, mode, filter)
}

View File

@ -16,6 +16,8 @@ package opengl
import (
"math"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
var (
@ -43,6 +45,25 @@ var (
oneMinusDstAlpha operation
)
func convertOperation(op graphics.Operation) operation {
switch op {
case graphics.Zero:
return zero
case graphics.One:
return one
case graphics.SrcAlpha:
return srcAlpha
case graphics.DstAlpha:
return dstAlpha
case graphics.OneMinusSrcAlpha:
return oneMinusSrcAlpha
case graphics.OneMinusDstAlpha:
return oneMinusDstAlpha
default:
panic("not reached")
}
}
type Context struct {
locationCache *locationCache
screenFramebuffer Framebuffer // This might not be the default frame buffer '0' (e.g. iOS).
@ -50,7 +71,7 @@ type Context struct {
lastTexture Texture
lastViewportWidth int
lastViewportHeight int
lastCompositeMode CompositeMode
lastCompositeMode graphics.CompositeMode
maxTextureSize int
context
}

View File

@ -24,6 +24,8 @@ import (
"fmt"
"github.com/go-gl/gl/v2.1/gl"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
type (
@ -105,12 +107,12 @@ func (c *Context) Reset() error {
c.lastFramebuffer = invalidFramebuffer
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastCompositeMode = CompositeModeUnknown
c.lastCompositeMode = graphics.CompositeModeUnknown
_ = c.runOnContextThread(func() error {
gl.Enable(gl.BLEND)
return nil
})
c.BlendFunc(CompositeModeSourceOver)
c.BlendFunc(graphics.CompositeModeSourceOver)
_ = c.runOnContextThread(func() error {
f := int32(0)
gl.GetIntegerv(gl.FRAMEBUFFER_BINDING, &f)
@ -120,14 +122,15 @@ func (c *Context) Reset() error {
return nil
}
func (c *Context) BlendFunc(mode CompositeMode) {
func (c *Context) BlendFunc(mode graphics.CompositeMode) {
_ = c.runOnContextThread(func() error {
if c.lastCompositeMode == mode {
return nil
}
c.lastCompositeMode = mode
s, d := operations(mode)
gl.BlendFunc(uint32(s), uint32(d))
s, d := mode.Operations()
s2, d2 := convertOperation(s), convertOperation(d)
gl.BlendFunc(uint32(s2), uint32(d2))
return nil
})
}

View File

@ -21,6 +21,8 @@ import (
"fmt"
"github.com/gopherjs/gopherwasm/js"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
type (
@ -149,23 +151,24 @@ func (c *Context) Reset() error {
c.lastFramebuffer = Framebuffer(js.Null())
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastCompositeMode = CompositeModeUnknown
c.lastCompositeMode = graphics.CompositeModeUnknown
gl := c.gl
gl.Call("enable", blend)
c.BlendFunc(CompositeModeSourceOver)
c.BlendFunc(graphics.CompositeModeSourceOver)
f := gl.Call("getParameter", framebufferBinding)
c.screenFramebuffer = Framebuffer(f)
return nil
}
func (c *Context) BlendFunc(mode CompositeMode) {
func (c *Context) BlendFunc(mode graphics.CompositeMode) {
if c.lastCompositeMode == mode {
return
}
c.lastCompositeMode = mode
s, d := operations(mode)
s, d := mode.Operations()
s2, d2 := convertOperation(s), convertOperation(d)
gl := c.gl
gl.Call("blendFunc", int(s), int(d))
gl.Call("blendFunc", int(s2), int(d2))
}
func (c *Context) NewTexture(width, height int) (Texture, error) {

View File

@ -21,6 +21,8 @@ import (
"fmt"
mgl "golang.org/x/mobile/gl"
"github.com/hajimehoshi/ebiten/internal/graphics"
)
type (
@ -111,23 +113,24 @@ func (c *Context) Reset() error {
c.lastFramebuffer = invalidFramebuffer
c.lastViewportWidth = 0
c.lastViewportHeight = 0
c.lastCompositeMode = CompositeModeUnknown
c.lastCompositeMode = graphics.CompositeModeUnknown
c.gl.Enable(mgl.BLEND)
c.BlendFunc(CompositeModeSourceOver)
c.BlendFunc(graphics.CompositeModeSourceOver)
f := c.gl.GetInteger(mgl.FRAMEBUFFER_BINDING)
c.screenFramebuffer = Framebuffer(mgl.Framebuffer{uint32(f)})
// TODO: Need to update screenFramebufferWidth/Height?
return nil
}
func (c *Context) BlendFunc(mode CompositeMode) {
func (c *Context) BlendFunc(mode graphics.CompositeMode) {
gl := c.gl
if c.lastCompositeMode == mode {
return
}
c.lastCompositeMode = mode
s, d := operations(mode)
gl.BlendFunc(mgl.Enum(s), mgl.Enum(d))
s, d := mode.Operations()
s2, d2 := convertOperation(s), convertOperation(d)
gl.BlendFunc(mgl.Enum(s2), mgl.Enum(d2))
}
func (c *Context) NewTexture(width, height int) (Texture, error) {

View File

@ -22,58 +22,6 @@ type (
operation int
)
type CompositeMode int
const (
CompositeModeSourceOver CompositeMode = iota // This value must be 0 (= initial value)
CompositeModeClear
CompositeModeCopy
CompositeModeDestination
CompositeModeDestinationOver
CompositeModeSourceIn
CompositeModeDestinationIn
CompositeModeSourceOut
CompositeModeDestinationOut
CompositeModeSourceAtop
CompositeModeDestinationAtop
CompositeModeXor
CompositeModeLighter
CompositeModeUnknown
)
func operations(mode CompositeMode) (src operation, dst operation) {
switch mode {
case CompositeModeSourceOver:
return one, oneMinusSrcAlpha
case CompositeModeClear:
return zero, zero
case CompositeModeCopy:
return one, zero
case CompositeModeDestination:
return zero, one
case CompositeModeDestinationOver:
return oneMinusDstAlpha, one
case CompositeModeSourceIn:
return dstAlpha, zero
case CompositeModeDestinationIn:
return zero, srcAlpha
case CompositeModeSourceOut:
return oneMinusDstAlpha, zero
case CompositeModeDestinationOut:
return zero, oneMinusSrcAlpha
case CompositeModeSourceAtop:
return dstAlpha, oneMinusSrcAlpha
case CompositeModeDestinationAtop:
return oneMinusDstAlpha, srcAlpha
case CompositeModeXor:
return oneMinusDstAlpha, oneMinusSrcAlpha
case CompositeModeLighter:
return one, one
default:
panic("not reached")
}
}
type DataType int
func (d DataType) SizeInBytes() int {

View File

@ -24,7 +24,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
"github.com/hajimehoshi/ebiten/internal/math"
"github.com/hajimehoshi/ebiten/internal/opengl"
)
// drawImageHistoryItem is an item for history of draw-image commands.
@ -33,7 +32,7 @@ type drawImageHistoryItem struct {
vertices []float32
indices []uint16
colorm *affine.ColorM
mode opengl.CompositeMode
mode graphics.CompositeMode
filter graphics.Filter
}
@ -167,7 +166,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
float32(x), float32(y),
1, 1, 1, 1)
is := graphicsutil.QuadIndices()
i.image.DrawImage(dummyImage.image, vs, is, colorm, opengl.CompositeModeCopy, graphics.FilterNearest)
i.image.DrawImage(dummyImage.image, vs, is, colorm, graphics.CompositeModeCopy, graphics.FilterNearest)
}
if x == 0 && y == 0 && width == w && height == h {
@ -204,7 +203,7 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
}
// DrawImage draws a given image img to the image.
func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
if len(vertices) == 0 {
return
}
@ -219,7 +218,7 @@ func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colo
}
// appendDrawImageHistory appends a draw-image history item to the image.
func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
func (i *Image) appendDrawImageHistory(image *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
if i.stale || i.volatile || i.screen {
return
}

View File

@ -24,7 +24,6 @@ import (
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
"github.com/hajimehoshi/ebiten/internal/opengl"
. "github.com/hajimehoshi/ebiten/internal/restorable"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
@ -118,7 +117,7 @@ func TestRestoreChain(t *testing.T) {
w, h := imgs[i].Size()
vs := graphicsutil.QuadVertices(w, h, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
imgs[i+1].DrawImage(imgs[i], vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
imgs[i+1].DrawImage(imgs[i], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
}
ResolveStaleImages()
if err := Restore(); err != nil {
@ -160,10 +159,10 @@ func TestRestoreChain2(t *testing.T) {
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
imgs[8].DrawImage(imgs[7], vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
imgs[9].DrawImage(imgs[8], vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
imgs[8].DrawImage(imgs[7], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
imgs[9].DrawImage(imgs[8], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
for i := 0; i < 7; i++ {
imgs[i+1].DrawImage(imgs[i], vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
imgs[i+1].DrawImage(imgs[i], vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
}
ResolveStaleImages()
@ -206,10 +205,10 @@ func TestRestoreOverrideSource(t *testing.T) {
fill(img1, clr0.R, clr0.G, clr0.B, clr0.A)
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img2.DrawImage(img1, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img3.DrawImage(img2, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img2.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
img3.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
fill(img0, clr1.R, clr1.G, clr1.B, clr1.A)
img1.DrawImage(img0, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img1.DrawImage(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
ResolveStaleImages()
if err := Restore(); err != nil {
t.Fatal(err)
@ -291,23 +290,23 @@ func TestRestoreComplexGraph(t *testing.T) {
}()
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img3.DrawImage(img0, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img3.DrawImage(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
img3.DrawImage(img1, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img3.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
img4.DrawImage(img1, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img4.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
img4.DrawImage(img2, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img4.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
img5.DrawImage(img3, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img5.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
img6.DrawImage(img3, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img6.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
img6.DrawImage(img4, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img6.DrawImage(img4, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
img7.DrawImage(img2, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img7.DrawImage(img2, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
vs = graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 2, 0, 1, 1, 1, 1)
img7.DrawImage(img3, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img7.DrawImage(img3, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
ResolveStaleImages()
if err := Restore(); err != nil {
t.Fatal(err)
@ -399,8 +398,8 @@ func TestRestoreRecursive(t *testing.T) {
}()
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img1.DrawImage(img0, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, opengl.CompositeModeSourceOver, graphics.FilterNearest)
img1.DrawImage(img0, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeSourceOver, graphics.FilterNearest)
ResolveStaleImages()
if err := Restore(); err != nil {
t.Fatal(err)
@ -487,7 +486,7 @@ func TestDrawImageAndReplacePixels(t *testing.T) {
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img1.DrawImage(img0, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img1.DrawImage(img0, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
img1.ReplacePixels([]byte{0xff, 0xff, 0xff, 0xff}, 1, 0, 1, 1)
ResolveStaleImages()
@ -519,8 +518,8 @@ func TestDispose(t *testing.T) {
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img1.DrawImage(img2, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img1.DrawImage(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
img1.Dispose()
ResolveStaleImages()
@ -547,7 +546,7 @@ func TestDoubleResolve(t *testing.T) {
vs := graphicsutil.QuadVertices(1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img0.DrawImage(img1, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
img0.ReplacePixels([]uint8{0x00, 0xff, 0x00, 0xff}, 1, 1, 1, 1)
// Now img0 is stale.
ResolveStaleImages()

View File

@ -24,7 +24,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
"github.com/hajimehoshi/ebiten/internal/opengl"
"github.com/hajimehoshi/ebiten/internal/packing"
"github.com/hajimehoshi/ebiten/internal/restorable"
)
@ -65,7 +64,7 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
w, h := oldImg.Size()
vs := graphicsutil.QuadVertices(w, h, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
newImg.DrawImage(oldImg, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
newImg.DrawImage(oldImg, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
oldImg.Dispose()
b.restorable = newImg
@ -131,7 +130,7 @@ func (i *Image) ensureNotShared() {
vw, vh := i.backend.restorable.Size()
vs := graphicsutil.QuadVertices(vw, vh, x, y, x+w, y+h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
newImg.DrawImage(i.backend.restorable, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
newImg.DrawImage(i.backend.restorable, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
i.dispose(false)
i.backend = &backend{
@ -204,7 +203,7 @@ func (i *Image) Vertex(dx, dy, sx, sy float32, cr, cg, cb, ca float32) []float32
const MaxCountForShare = 10
func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode opengl.CompositeMode, filter graphics.Filter) {
func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colorm *affine.ColorM, mode graphics.CompositeMode, filter graphics.Filter) {
backendsM.Lock()
defer backendsM.Unlock()

View File

@ -24,7 +24,6 @@ import (
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsutil"
"github.com/hajimehoshi/ebiten/internal/opengl"
. "github.com/hajimehoshi/ebiten/internal/shareable"
"github.com/hajimehoshi/ebiten/internal/testflock"
)
@ -88,7 +87,7 @@ func TestEnsureNotShared(t *testing.T) {
// img4.ensureNotShared() should be called.
vs := img3.QuadVertices(0, 0, size/2, size/2, 1, 0, 0, 1, size/4, size/4, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img4.DrawImage(img3, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img4.DrawImage(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
want := false
if got := img4.IsSharedForTesting(); got != want {
t.Errorf("got: %v, want: %v", got, want)
@ -110,7 +109,7 @@ func TestEnsureNotShared(t *testing.T) {
// Check further drawing doesn't cause panic.
// This bug was fixed by 03dcd948.
img4.DrawImage(img3, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img4.DrawImage(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
}
func Disabled_TestReshared(t *testing.T) {
@ -152,7 +151,7 @@ func Disabled_TestReshared(t *testing.T) {
// Use img1 as a render target.
vs := img2.QuadVertices(0, 0, size, size, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
is := graphicsutil.QuadIndices()
img1.DrawImage(img2, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img1.DrawImage(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
want = false
if got := img1.IsSharedForTesting(); got != want {
t.Errorf("got: %v, want: %v", got, want)
@ -160,7 +159,7 @@ func Disabled_TestReshared(t *testing.T) {
// Use img1 as a render source.
for i := 0; i < MaxCountForShare-1; i++ {
img0.DrawImage(img1, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
want := false
if got := img1.IsSharedForTesting(); got != want {
t.Errorf("got: %v, want: %v", got, want)
@ -177,7 +176,7 @@ func Disabled_TestReshared(t *testing.T) {
}
}
img0.DrawImage(img1, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img1, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
want = true
if got := img1.IsSharedForTesting(); got != want {
t.Errorf("got: %v, want: %v", got, want)
@ -195,7 +194,7 @@ func Disabled_TestReshared(t *testing.T) {
// Use img3 as a render source. img3 never uses a shared texture.
for i := 0; i < MaxCountForShare*2; i++ {
img0.DrawImage(img3, vs, is, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
img0.DrawImage(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest)
want := false
if got := img3.IsSharedForTesting(); got != want {
t.Errorf("got: %v, want: %v", got, want)