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')
// c_out = c_src + c_dst
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
CompositeModeXor
CompositeModeLighter
CompositeModeMultiply
CompositeModeMax = CompositeModeLighter
CompositeModeMax = CompositeModeMultiply
)
type Operation int
@ -48,6 +49,7 @@ const (
DstAlpha
OneMinusSrcAlpha
OneMinusDstAlpha
DstColor
)
func (c CompositeMode) Operations() (src Operation, dst Operation) {
@ -78,6 +80,8 @@ func (c CompositeMode) Operations() (src Operation, dst Operation) {
return OneMinusDstAlpha, OneMinusSrcAlpha
case CompositeModeLighter:
return One, One
case CompositeModeMultiply:
return DstColor, Zero
default:
panic(fmt.Sprintf("graphics: invalid composite mode: %d", c))
}

View File

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

View File

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

View File

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

View File

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

View File

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