ebiten: Add CompositeModeMultiply (#1251)

This change adds a new composite mode called `CompositeModeMultiply`,
which multiplies the source color with the destination color.

This is tested on Linux and Windows only.

Fixes #410
This commit is contained in:
nanoslayer 2020-07-18 08:37:17 -04:00 committed by GitHub
parent 4bd3bc16ac
commit 72babcd420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 1 deletions

View File

@ -85,4 +85,8 @@ const (
// Sum of source and destination (a.k.a. 'plus' or 'additive') // Sum of source and destination (a.k.a. 'plus' or 'additive')
// c_out = c_src + c_dst // c_out = c_src + c_dst
CompositeModeLighter CompositeMode = CompositeMode(driver.CompositeModeLighter) CompositeModeLighter CompositeMode = CompositeMode(driver.CompositeModeLighter)
// The product of source and destination (a.k.a 'multiply blend mode')
// c_out = c_src * c_dst
CompositeModeMultiply CompositeMode = CompositeMode(driver.CompositeModeMultiply)
) )

View File

@ -35,8 +35,9 @@ const (
CompositeModeDestinationAtop CompositeModeDestinationAtop
CompositeModeXor CompositeModeXor
CompositeModeLighter CompositeModeLighter
CompositeModeMultiply
CompositeModeMax = CompositeModeLighter CompositeModeMax = CompositeModeMultiply
) )
type Operation int type Operation int
@ -48,6 +49,7 @@ const (
DstAlpha DstAlpha
OneMinusSrcAlpha OneMinusSrcAlpha
OneMinusDstAlpha OneMinusDstAlpha
DstColor
) )
func (c CompositeMode) Operations() (src Operation, dst Operation) { func (c CompositeMode) Operations() (src Operation, dst Operation) {
@ -78,6 +80,8 @@ func (c CompositeMode) Operations() (src Operation, dst Operation) {
return OneMinusDstAlpha, OneMinusSrcAlpha return OneMinusDstAlpha, OneMinusSrcAlpha
case CompositeModeLighter: case CompositeModeLighter:
return One, One return One, One
case CompositeModeMultiply:
return DstColor, Zero
default: default:
panic(fmt.Sprintf("graphics: invalid composite mode: %d", c)) panic(fmt.Sprintf("graphics: invalid composite mode: %d", c))
} }

View File

@ -36,6 +36,8 @@ func convertOperation(op driver.Operation) operation {
return oneMinusSrcAlpha return oneMinusSrcAlpha
case driver.OneMinusDstAlpha: case driver.OneMinusDstAlpha:
return oneMinusDstAlpha return oneMinusDstAlpha
case driver.DstColor:
return dstColor
default: default:
panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op)) panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op))
} }

View File

@ -93,6 +93,7 @@ const (
dstAlpha = operation(gl.DST_ALPHA) dstAlpha = operation(gl.DST_ALPHA)
oneMinusSrcAlpha = operation(gl.ONE_MINUS_SRC_ALPHA) oneMinusSrcAlpha = operation(gl.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(gl.ONE_MINUS_DST_ALPHA) oneMinusDstAlpha = operation(gl.ONE_MINUS_DST_ALPHA)
dstColor = operation(gl.DST_COLOR)
) )
type contextImpl struct { type contextImpl struct {

View File

@ -90,6 +90,7 @@ var (
dstAlpha operation dstAlpha operation
oneMinusSrcAlpha operation oneMinusSrcAlpha operation
oneMinusDstAlpha operation oneMinusDstAlpha operation
dstColor operation
blend js.Value blend js.Value
clampToEdge js.Value clampToEdge js.Value
@ -144,6 +145,7 @@ func init() {
dstAlpha = operation(contextPrototype.Get("DST_ALPHA").Int()) dstAlpha = operation(contextPrototype.Get("DST_ALPHA").Int())
oneMinusSrcAlpha = operation(contextPrototype.Get("ONE_MINUS_SRC_ALPHA").Int()) oneMinusSrcAlpha = operation(contextPrototype.Get("ONE_MINUS_SRC_ALPHA").Int())
oneMinusDstAlpha = operation(contextPrototype.Get("ONE_MINUS_DST_ALPHA").Int()) oneMinusDstAlpha = operation(contextPrototype.Get("ONE_MINUS_DST_ALPHA").Int())
dstColor = operation(contextPrototype.Get("DST_COLOR").Int())
blend = contextPrototype.Get("BLEND") blend = contextPrototype.Get("BLEND")
clampToEdge = contextPrototype.Get("CLAMP_TO_EDGE") clampToEdge = contextPrototype.Get("CLAMP_TO_EDGE")

View File

@ -91,6 +91,7 @@ const (
dstAlpha = operation(mgl.DST_ALPHA) dstAlpha = operation(mgl.DST_ALPHA)
oneMinusSrcAlpha = operation(mgl.ONE_MINUS_SRC_ALPHA) oneMinusSrcAlpha = operation(mgl.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(mgl.ONE_MINUS_DST_ALPHA) oneMinusDstAlpha = operation(mgl.ONE_MINUS_DST_ALPHA)
dstColor = operation(mgl.DST_COLOR)
) )
type contextImpl struct { type contextImpl struct {

View File

@ -31,6 +31,7 @@ const (
DST_ALPHA = 0x0304 DST_ALPHA = 0x0304
ONE_MINUS_SRC_ALPHA = 0x0303 ONE_MINUS_SRC_ALPHA = 0x0303
ONE_MINUS_DST_ALPHA = 0x0305 ONE_MINUS_DST_ALPHA = 0x0305
DST_COLOR = 0x0306
FALSE = 0 FALSE = 0
TRUE = 1 TRUE = 1