mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphics: CompositionMode -> CompositeMode (#170)
This commit is contained in:
parent
1eb623cf16
commit
c6fc5ab865
@ -43,7 +43,7 @@ func update(screen *ebiten.Image) error {
|
||||
screen.DrawImage(ebitenImage, op)
|
||||
op = &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(ox+float64(w), oy)
|
||||
op.CompositionMode = ebiten.CompositionModeLighter
|
||||
op.CompositeMode = ebiten.CompositeModeLighter
|
||||
screen.DrawImage(ebitenImage, op)
|
||||
return nil
|
||||
}
|
||||
@ -54,7 +54,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Composition Mode (Ebiten Demo)"); err != nil {
|
||||
if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Composite Mode (Ebiten Demo)"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
op = &ebiten.DrawImageOptions{}
|
||||
op.CompositionMode = ebiten.CompositionModeSourceOut
|
||||
op.CompositeMode = ebiten.CompositeModeSourceOut
|
||||
if err := maskImage.DrawImage(fiveyearsImage, op); err != nil {
|
||||
return err
|
||||
}
|
||||
|
28
graphics.go
28
graphics.go
@ -36,22 +36,22 @@ func glFilter(c *opengl.Context, filter Filter) opengl.Filter {
|
||||
panic("not reach")
|
||||
}
|
||||
|
||||
// CompositionMode represents Porter-Duff composition mode.
|
||||
type CompositionMode int
|
||||
// CompositeMode represents Porter-Duff composition mode.
|
||||
type CompositeMode int
|
||||
|
||||
// Note: This name convention follow CSS compositing: https://drafts.fxtf.org/compositing-2/
|
||||
|
||||
const (
|
||||
CompositionModeSourceOver CompositionMode = CompositionMode(opengl.CompositionModeSourceOver) // regular alpha blending
|
||||
CompositionModeClear = CompositionMode(opengl.CompositionModeClear)
|
||||
CompositionModeCopy = CompositionMode(opengl.CompositionModeCopy)
|
||||
CompositionModeDestination = CompositionMode(opengl.CompositionModeDestination)
|
||||
CompositionModeSourceIn = CompositionMode(opengl.CompositionModeSourceIn)
|
||||
CompositionModeDestinationIn = CompositionMode(opengl.CompositionModeDestinationIn)
|
||||
CompositionModeSourceOut = CompositionMode(opengl.CompositionModeSourceOut)
|
||||
CompositionModeDestinationOut = CompositionMode(opengl.CompositionModeDestinationOut)
|
||||
CompositionModeSourceAtop = CompositionMode(opengl.CompositionModeSourceAtop)
|
||||
CompositionModeDestinationAtop = CompositionMode(opengl.CompositionModeDestinationAtop)
|
||||
CompositionModeXor = CompositionMode(opengl.CompositionModeXor)
|
||||
CompositionModeLighter = CompositionMode(opengl.CompositionModeLighter) // sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
CompositeModeSourceOver CompositeMode = CompositeMode(opengl.CompositeModeSourceOver) // regular alpha blending
|
||||
CompositeModeClear = CompositeMode(opengl.CompositeModeClear)
|
||||
CompositeModeCopy = CompositeMode(opengl.CompositeModeCopy)
|
||||
CompositeModeDestination = CompositeMode(opengl.CompositeModeDestination)
|
||||
CompositeModeSourceIn = CompositeMode(opengl.CompositeModeSourceIn)
|
||||
CompositeModeDestinationIn = CompositeMode(opengl.CompositeModeDestinationIn)
|
||||
CompositeModeSourceOut = CompositeMode(opengl.CompositeModeSourceOut)
|
||||
CompositeModeDestinationOut = CompositeMode(opengl.CompositeModeDestinationOut)
|
||||
CompositeModeSourceAtop = CompositeMode(opengl.CompositeModeSourceAtop)
|
||||
CompositeModeDestinationAtop = CompositeMode(opengl.CompositeModeDestinationAtop)
|
||||
CompositeModeXor = CompositeMode(opengl.CompositeModeXor)
|
||||
CompositeModeLighter = CompositeMode(opengl.CompositeModeLighter) // sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
)
|
||||
|
10
image.go
10
image.go
@ -99,7 +99,7 @@ func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error) {
|
||||
}
|
||||
w, h := image.Size()
|
||||
quads := &textureQuads{parts: parts, width: w, height: h}
|
||||
m := opengl.CompositionMode(options.CompositionMode)
|
||||
m := opengl.CompositeMode(options.CompositeMode)
|
||||
return i.framebuffer.DrawTexture(glContext, image.texture, quads, &options.GeoM, &options.ColorM, m)
|
||||
}
|
||||
|
||||
@ -184,10 +184,10 @@ func (i *Image) ReplacePixels(p []uint8) error {
|
||||
|
||||
// A DrawImageOptions represents options to render an image on an image.
|
||||
type DrawImageOptions struct {
|
||||
ImageParts ImageParts
|
||||
GeoM GeoM
|
||||
ColorM ColorM
|
||||
CompositionMode CompositionMode
|
||||
ImageParts ImageParts
|
||||
GeoM GeoM
|
||||
ColorM ColorM
|
||||
CompositeMode CompositeMode
|
||||
|
||||
// Deprecated (as of 1.1.0-alpha): Use ImageParts instead.
|
||||
Parts []ImagePart
|
||||
|
@ -246,7 +246,7 @@ func min(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
func TestImageCompositionModeLighter(t *testing.T) {
|
||||
func TestImageCompositeModeLighter(t *testing.T) {
|
||||
img0, _, err := openEbitenImage("testdata/ebiten.png")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -261,7 +261,7 @@ func TestImageCompositionModeLighter(t *testing.T) {
|
||||
}
|
||||
img1.Fill(color.RGBA{0x01, 0x02, 0x03, 0x04})
|
||||
op := &DrawImageOptions{}
|
||||
op.CompositionMode = CompositionModeLighter
|
||||
op.CompositeMode = CompositeModeLighter
|
||||
img1.DrawImage(img0, op)
|
||||
for j := 0; j < img1.Bounds().Size().Y; j++ {
|
||||
for i := 0; i < img1.Bounds().Size().X; i++ {
|
||||
|
@ -37,7 +37,7 @@ var vertices = make([]int16, 16*quadsMaxNum)
|
||||
|
||||
var shadersInitialized = false
|
||||
|
||||
func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix, mode opengl.CompositionMode) error {
|
||||
func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix, mode opengl.CompositeMode) error {
|
||||
c.BlendFunc(mode)
|
||||
|
||||
// NOTE: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far.
|
||||
|
@ -116,7 +116,7 @@ func (f *Framebuffer) Fill(c *opengl.Context, clr color.Color) error {
|
||||
return c.FillFramebuffer(r, g, b, a)
|
||||
}
|
||||
|
||||
func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQuads, geo, clr Matrix, mode opengl.CompositionMode) error {
|
||||
func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQuads, geo, clr Matrix, mode opengl.CompositeMode) error {
|
||||
if err := f.setAsViewport(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ func (p Program) id() programID {
|
||||
}
|
||||
|
||||
type context struct {
|
||||
locationCache *locationCache
|
||||
funcs chan func()
|
||||
lastCompositionMode CompositionMode
|
||||
locationCache *locationCache
|
||||
funcs chan func()
|
||||
lastCompositeMode CompositeMode
|
||||
}
|
||||
|
||||
func NewContext() *Context {
|
||||
@ -73,7 +73,7 @@ func NewContext() *Context {
|
||||
}
|
||||
c.locationCache = newLocationCache()
|
||||
c.funcs = make(chan func())
|
||||
c.lastCompositionMode = CompositionModeUnknown
|
||||
c.lastCompositeMode = CompositeModeUnknown
|
||||
return c
|
||||
}
|
||||
|
||||
@ -107,15 +107,15 @@ func (c *Context) Init() {
|
||||
// Textures' pixel formats are alpha premultiplied.
|
||||
gl.Enable(gl.BLEND)
|
||||
})
|
||||
c.BlendFunc(CompositionModeSourceOver)
|
||||
c.BlendFunc(CompositeModeSourceOver)
|
||||
}
|
||||
|
||||
func (c *Context) BlendFunc(mode CompositionMode) {
|
||||
func (c *Context) BlendFunc(mode CompositeMode) {
|
||||
c.RunOnContextThread(func() {
|
||||
if c.lastCompositionMode == mode {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
c.lastCompositionMode = mode
|
||||
c.lastCompositeMode = mode
|
||||
s, d := c.operations(mode)
|
||||
gl.BlendFunc(uint32(s), uint32(d))
|
||||
})
|
||||
|
@ -63,11 +63,11 @@ func (p Program) id() programID {
|
||||
}
|
||||
|
||||
type context struct {
|
||||
gl *webgl.Context
|
||||
lastFramebuffer Framebuffer
|
||||
locationCache *locationCache
|
||||
lastProgramID programID
|
||||
lastCompositionMode CompositionMode
|
||||
gl *webgl.Context
|
||||
lastFramebuffer Framebuffer
|
||||
locationCache *locationCache
|
||||
lastProgramID programID
|
||||
lastCompositeMode CompositeMode
|
||||
}
|
||||
|
||||
func NewContext() *Context {
|
||||
@ -115,7 +115,7 @@ func NewContext() *Context {
|
||||
}
|
||||
c.gl = gl
|
||||
c.locationCache = newLocationCache()
|
||||
c.lastCompositionMode = CompositionModeUnknown
|
||||
c.lastCompositeMode = CompositeModeUnknown
|
||||
c.init()
|
||||
return c
|
||||
}
|
||||
@ -125,14 +125,14 @@ func (c *Context) init() {
|
||||
// Textures' pixel formats are alpha premultiplied.
|
||||
gl.Enable(gl.BLEND)
|
||||
//gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
|
||||
c.BlendFunc(CompositionModeSourceOver)
|
||||
c.BlendFunc(CompositeModeSourceOver)
|
||||
}
|
||||
|
||||
func (c *Context) BlendFunc(mode CompositionMode) {
|
||||
if c.lastCompositionMode == mode {
|
||||
func (c *Context) BlendFunc(mode CompositeMode) {
|
||||
if c.lastCompositeMode == mode {
|
||||
return
|
||||
}
|
||||
c.lastCompositionMode = mode
|
||||
c.lastCompositeMode = mode
|
||||
s, d := c.operations(mode)
|
||||
gl := c.gl
|
||||
gl.BlendFunc(int(s), int(d))
|
||||
|
@ -41,52 +41,52 @@ type Context struct {
|
||||
context
|
||||
}
|
||||
|
||||
type CompositionMode int
|
||||
type CompositeMode int
|
||||
|
||||
const (
|
||||
CompositionModeSourceOver CompositionMode = iota // This value must be 0 (= initial value)
|
||||
CompositionModeClear
|
||||
CompositionModeCopy
|
||||
CompositionModeDestination
|
||||
CompositionModeDestinationOver
|
||||
CompositionModeSourceIn
|
||||
CompositionModeDestinationIn
|
||||
CompositionModeSourceOut
|
||||
CompositionModeDestinationOut
|
||||
CompositionModeSourceAtop
|
||||
CompositionModeDestinationAtop
|
||||
CompositionModeXor
|
||||
CompositionModeLighter
|
||||
CompositionModeUnknown
|
||||
CompositeModeSourceOver CompositeMode = iota // This value must be 0 (= initial value)
|
||||
CompositeModeClear
|
||||
CompositeModeCopy
|
||||
CompositeModeDestination
|
||||
CompositeModeDestinationOver
|
||||
CompositeModeSourceIn
|
||||
CompositeModeDestinationIn
|
||||
CompositeModeSourceOut
|
||||
CompositeModeDestinationOut
|
||||
CompositeModeSourceAtop
|
||||
CompositeModeDestinationAtop
|
||||
CompositeModeXor
|
||||
CompositeModeLighter
|
||||
CompositeModeUnknown
|
||||
)
|
||||
|
||||
func (c *Context) operations(mode CompositionMode) (src operation, dst operation) {
|
||||
func (c *Context) operations(mode CompositeMode) (src operation, dst operation) {
|
||||
switch mode {
|
||||
case CompositionModeSourceOver:
|
||||
case CompositeModeSourceOver:
|
||||
return c.one, c.oneMinusSrcAlpha
|
||||
case CompositionModeClear:
|
||||
case CompositeModeClear:
|
||||
return c.zero, c.zero
|
||||
case CompositionModeCopy:
|
||||
case CompositeModeCopy:
|
||||
return c.one, c.zero
|
||||
case CompositionModeDestination:
|
||||
case CompositeModeDestination:
|
||||
return c.zero, c.one
|
||||
case CompositionModeDestinationOver:
|
||||
case CompositeModeDestinationOver:
|
||||
return c.oneMinusDstAlpha, c.one
|
||||
case CompositionModeSourceIn:
|
||||
case CompositeModeSourceIn:
|
||||
return c.dstAlpha, c.zero
|
||||
case CompositionModeDestinationIn:
|
||||
case CompositeModeDestinationIn:
|
||||
return c.zero, c.srcAlpha
|
||||
case CompositionModeSourceOut:
|
||||
case CompositeModeSourceOut:
|
||||
return c.oneMinusDstAlpha, c.zero
|
||||
case CompositionModeDestinationOut:
|
||||
case CompositeModeDestinationOut:
|
||||
return c.zero, c.oneMinusSrcAlpha
|
||||
case CompositionModeSourceAtop:
|
||||
case CompositeModeSourceAtop:
|
||||
return c.dstAlpha, c.oneMinusSrcAlpha
|
||||
case CompositionModeDestinationAtop:
|
||||
case CompositeModeDestinationAtop:
|
||||
return c.oneMinusDstAlpha, c.srcAlpha
|
||||
case CompositionModeXor:
|
||||
case CompositeModeXor:
|
||||
return c.oneMinusDstAlpha, c.oneMinusSrcAlpha
|
||||
case CompositionModeLighter:
|
||||
case CompositeModeLighter:
|
||||
return c.one, c.one
|
||||
default:
|
||||
panic("not reach")
|
||||
|
Loading…
Reference in New Issue
Block a user