mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
parent
e03825bf08
commit
180e456a8e
102
blend.go
102
blend.go
@ -24,20 +24,20 @@ import (
|
|||||||
//
|
//
|
||||||
// The default (zero) value is source-over (regular alpha blending).
|
// The default (zero) value is source-over (regular alpha blending).
|
||||||
type Blend struct {
|
type Blend struct {
|
||||||
// BlendFactorSourceColor is a factor for source RGB values.
|
// BlendFactorSourceRGB is a factor for source RGB values.
|
||||||
BlendFactorSourceColor BlendFactor
|
BlendFactorSourceRGB BlendFactor
|
||||||
|
|
||||||
// BlendFactorSourceAlpha is a factor for source alpha values.
|
// BlendFactorSourceAlpha is a factor for source alpha values.
|
||||||
BlendFactorSourceAlpha BlendFactor
|
BlendFactorSourceAlpha BlendFactor
|
||||||
|
|
||||||
// BlendFactorDestinationColor is a factor for destination RGB values.
|
// BlendFactorDestinationRGB is a factor for destination RGB values.
|
||||||
BlendFactorDestinationColor BlendFactor
|
BlendFactorDestinationRGB BlendFactor
|
||||||
|
|
||||||
// BlendFactorDestinationAlpha is a factor for destination apha values.
|
// BlendFactorDestinationAlpha is a factor for destination apha values.
|
||||||
BlendFactorDestinationAlpha BlendFactor
|
BlendFactorDestinationAlpha BlendFactor
|
||||||
|
|
||||||
// BlendOperationColor is an operation for source and destination RGB values.
|
// BlendOperationRGB is an operation for source and destination RGB values.
|
||||||
BlendOperationColor BlendOperation
|
BlendOperationRGB BlendOperation
|
||||||
|
|
||||||
// BlendOperationAlpha is an operation for source and destination alpha values.
|
// BlendOperationAlpha is an operation for source and destination alpha values.
|
||||||
BlendOperationAlpha BlendOperation
|
BlendOperationAlpha BlendOperation
|
||||||
@ -45,11 +45,11 @@ type Blend struct {
|
|||||||
|
|
||||||
func (b Blend) internalBlend() graphicsdriver.Blend {
|
func (b Blend) internalBlend() graphicsdriver.Blend {
|
||||||
return graphicsdriver.Blend{
|
return graphicsdriver.Blend{
|
||||||
BlendFactorSourceColor: b.BlendFactorSourceColor.internalBlendFactor(true),
|
BlendFactorSourceRGB: b.BlendFactorSourceRGB.internalBlendFactor(true),
|
||||||
BlendFactorSourceAlpha: b.BlendFactorSourceAlpha.internalBlendFactor(true),
|
BlendFactorSourceAlpha: b.BlendFactorSourceAlpha.internalBlendFactor(true),
|
||||||
BlendFactorDestinationColor: b.BlendFactorDestinationColor.internalBlendFactor(false),
|
BlendFactorDestinationRGB: b.BlendFactorDestinationRGB.internalBlendFactor(false),
|
||||||
BlendFactorDestinationAlpha: b.BlendFactorDestinationAlpha.internalBlendFactor(false),
|
BlendFactorDestinationAlpha: b.BlendFactorDestinationAlpha.internalBlendFactor(false),
|
||||||
BlendOperationColor: b.BlendOperationColor.internalBlendOperation(),
|
BlendOperationRGB: b.BlendOperationRGB.internalBlendOperation(),
|
||||||
BlendOperationAlpha: b.BlendOperationAlpha.internalBlendOperation(),
|
BlendOperationAlpha: b.BlendOperationAlpha.internalBlendOperation(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ const (
|
|||||||
BlendFactorDestinationAlpha
|
BlendFactorDestinationAlpha
|
||||||
BlendFactorOneMinusSourceAlpha
|
BlendFactorOneMinusSourceAlpha
|
||||||
BlendFactorOneMinusDestinationAlpha
|
BlendFactorOneMinusDestinationAlpha
|
||||||
BlendFactorDestinationColor
|
BlendFactorDestinationRGB
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b BlendFactor) internalBlendFactor(source bool) graphicsdriver.BlendFactor {
|
func (b BlendFactor) internalBlendFactor(source bool) graphicsdriver.BlendFactor {
|
||||||
@ -90,8 +90,8 @@ func (b BlendFactor) internalBlendFactor(source bool) graphicsdriver.BlendFactor
|
|||||||
return graphicsdriver.BlendFactorOneMinusSourceAlpha
|
return graphicsdriver.BlendFactorOneMinusSourceAlpha
|
||||||
case BlendFactorOneMinusDestinationAlpha:
|
case BlendFactorOneMinusDestinationAlpha:
|
||||||
return graphicsdriver.BlendFactorOneMinusDestinationAlpha
|
return graphicsdriver.BlendFactorOneMinusDestinationAlpha
|
||||||
case BlendFactorDestinationColor:
|
case BlendFactorDestinationRGB:
|
||||||
return graphicsdriver.BlendFactorDestinationColor
|
return graphicsdriver.BlendFactorDestinationRGB
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("ebiten: invalid blend factor: %d", b))
|
panic(fmt.Sprintf("ebiten: invalid blend factor: %d", b))
|
||||||
}
|
}
|
||||||
@ -135,132 +135,132 @@ var (
|
|||||||
// BlendSourceOver represents the regular alpha blending.
|
// BlendSourceOver represents the regular alpha blending.
|
||||||
// c_out = c_src + c_dst × (1 - α_src)
|
// c_out = c_src + c_dst × (1 - α_src)
|
||||||
BlendSourceOver = Blend{
|
BlendSourceOver = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOne,
|
BlendFactorSourceRGB: BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: BlendFactorOne,
|
BlendFactorSourceAlpha: BlendFactorOne,
|
||||||
BlendFactorDestinationColor: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = 0
|
// c_out = 0
|
||||||
BlendClear = Blend{
|
BlendClear = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorZero,
|
BlendFactorSourceRGB: BlendFactorZero,
|
||||||
BlendFactorSourceAlpha: BlendFactorZero,
|
BlendFactorSourceAlpha: BlendFactorZero,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src
|
// c_out = c_src
|
||||||
BlendCopy = Blend{
|
BlendCopy = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOne,
|
BlendFactorSourceRGB: BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: BlendFactorOne,
|
BlendFactorSourceAlpha: BlendFactorOne,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_dst
|
// c_out = c_dst
|
||||||
BlendDestination = Blend{
|
BlendDestination = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorZero,
|
BlendFactorSourceRGB: BlendFactorZero,
|
||||||
BlendFactorSourceAlpha: BlendFactorZero,
|
BlendFactorSourceAlpha: BlendFactorZero,
|
||||||
BlendFactorDestinationColor: BlendFactorOne,
|
BlendFactorDestinationRGB: BlendFactorOne,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOne,
|
BlendFactorDestinationAlpha: BlendFactorOne,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × (1 - α_dst) + c_dst
|
// c_out = c_src × (1 - α_dst) + c_dst
|
||||||
BlendDestinationOver = Blend{
|
BlendDestinationOver = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorOne,
|
BlendFactorDestinationRGB: BlendFactorOne,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOne,
|
BlendFactorDestinationAlpha: BlendFactorOne,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × α_dst
|
// c_out = c_src × α_dst
|
||||||
BlendSourceIn = Blend{
|
BlendSourceIn = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_dst × α_src
|
// c_out = c_dst × α_src
|
||||||
BlendDestinationIn = Blend{
|
BlendDestinationIn = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorZero,
|
BlendFactorSourceRGB: BlendFactorZero,
|
||||||
BlendFactorSourceAlpha: BlendFactorZero,
|
BlendFactorSourceAlpha: BlendFactorZero,
|
||||||
BlendFactorDestinationColor: BlendFactorSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × (1 - α_dst)
|
// c_out = c_src × (1 - α_dst)
|
||||||
BlendSourceOut = Blend{
|
BlendSourceOut = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_dst × (1 - α_src)
|
// c_out = c_dst × (1 - α_src)
|
||||||
BlendDestinationOut = Blend{
|
BlendDestinationOut = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × α_dst + c_dst × (1 - α_src)
|
// c_out = c_src × α_dst + c_dst × (1 - α_src)
|
||||||
BlendSourceAtop = Blend{
|
BlendSourceAtop = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × (1 - α_dst) + c_dst × α_src
|
// c_out = c_src × (1 - α_dst) + c_dst × α_src
|
||||||
BlendDestinationAtop = Blend{
|
BlendDestinationAtop = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
||||||
BlendXor = Blend{
|
BlendXor = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceRGB: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
BlendFactorSourceAlpha: BlendFactorOneMinusDestinationAlpha,
|
||||||
BlendFactorDestinationColor: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
BlendLighter = Blend{
|
BlendLighter = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOne,
|
BlendFactorSourceRGB: BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: BlendFactorOne,
|
BlendFactorSourceAlpha: BlendFactorOne,
|
||||||
BlendFactorDestinationColor: BlendFactorOne,
|
BlendFactorDestinationRGB: BlendFactorOne,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOne,
|
BlendFactorDestinationAlpha: BlendFactorOne,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
10
graphics.go
10
graphics.go
@ -80,7 +80,7 @@ const (
|
|||||||
// Deprecated: as of v2.5. Use BlendLighter instead.
|
// Deprecated: as of v2.5. Use BlendLighter instead.
|
||||||
CompositeModeLighter
|
CompositeModeLighter
|
||||||
|
|
||||||
// Deprecated: as of v2.5. Use Blend with BlendFactorDestinationColor and BlendFactorZero instead.
|
// Deprecated: as of v2.5. Use Blend with BlendFactorDestinationRGB and BlendFactorZero instead.
|
||||||
CompositeModeMultiply
|
CompositeModeMultiply
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -114,11 +114,11 @@ func (c CompositeMode) blend() Blend {
|
|||||||
return BlendLighter
|
return BlendLighter
|
||||||
case CompositeModeMultiply:
|
case CompositeModeMultiply:
|
||||||
return Blend{
|
return Blend{
|
||||||
BlendFactorSourceColor: BlendFactorDestinationColor,
|
BlendFactorSourceRGB: BlendFactorDestinationRGB,
|
||||||
BlendFactorSourceAlpha: BlendFactorDestinationColor,
|
BlendFactorSourceAlpha: BlendFactorDestinationRGB,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -3607,11 +3607,11 @@ func TestImageBlendOperation(t *testing.T) {
|
|||||||
dst.WritePixels(dstPix)
|
dst.WritePixels(dstPix)
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.Blend = ebiten.Blend{
|
op.Blend = ebiten.Blend{
|
||||||
BlendFactorSourceColor: ebiten.BlendFactorOne,
|
BlendFactorSourceRGB: ebiten.BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: ebiten.BlendFactorOne,
|
BlendFactorSourceAlpha: ebiten.BlendFactorOne,
|
||||||
BlendFactorDestinationColor: ebiten.BlendFactorOne,
|
BlendFactorDestinationRGB: ebiten.BlendFactorOne,
|
||||||
BlendFactorDestinationAlpha: ebiten.BlendFactorOne,
|
BlendFactorDestinationAlpha: ebiten.BlendFactorOne,
|
||||||
BlendOperationColor: cop,
|
BlendOperationRGB: cop,
|
||||||
BlendOperationAlpha: aop,
|
BlendOperationAlpha: aop,
|
||||||
}
|
}
|
||||||
dst.DrawImage(src, op)
|
dst.DrawImage(src, op)
|
||||||
|
@ -277,11 +277,11 @@ type drawTrianglesCommand struct {
|
|||||||
func (c *drawTrianglesCommand) String() string {
|
func (c *drawTrianglesCommand) String() string {
|
||||||
// TODO: Improve readability
|
// TODO: Improve readability
|
||||||
blend := fmt.Sprintf("{src-color: %d, src-alpha: %d, dst-color: %d, dst-alpha: %d, op-color: %d, op-alpha: %d}",
|
blend := fmt.Sprintf("{src-color: %d, src-alpha: %d, dst-color: %d, dst-alpha: %d, op-color: %d, op-alpha: %d}",
|
||||||
c.blend.BlendFactorSourceColor,
|
c.blend.BlendFactorSourceRGB,
|
||||||
c.blend.BlendFactorSourceAlpha,
|
c.blend.BlendFactorSourceAlpha,
|
||||||
c.blend.BlendFactorDestinationColor,
|
c.blend.BlendFactorDestinationRGB,
|
||||||
c.blend.BlendFactorDestinationAlpha,
|
c.blend.BlendFactorDestinationAlpha,
|
||||||
c.blend.BlendOperationColor,
|
c.blend.BlendOperationRGB,
|
||||||
c.blend.BlendOperationAlpha)
|
c.blend.BlendOperationAlpha)
|
||||||
|
|
||||||
dst := fmt.Sprintf("%d", c.dst.id)
|
dst := fmt.Sprintf("%d", c.dst.id)
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
package graphicsdriver
|
package graphicsdriver
|
||||||
|
|
||||||
type Blend struct {
|
type Blend struct {
|
||||||
BlendFactorSourceColor BlendFactor
|
BlendFactorSourceRGB BlendFactor
|
||||||
BlendFactorSourceAlpha BlendFactor
|
BlendFactorSourceAlpha BlendFactor
|
||||||
BlendFactorDestinationColor BlendFactor
|
BlendFactorDestinationRGB BlendFactor
|
||||||
BlendFactorDestinationAlpha BlendFactor
|
BlendFactorDestinationAlpha BlendFactor
|
||||||
BlendOperationColor BlendOperation
|
BlendOperationRGB BlendOperation
|
||||||
BlendOperationAlpha BlendOperation
|
BlendOperationAlpha BlendOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ const (
|
|||||||
BlendFactorDestinationAlpha
|
BlendFactorDestinationAlpha
|
||||||
BlendFactorOneMinusSourceAlpha
|
BlendFactorOneMinusSourceAlpha
|
||||||
BlendFactorOneMinusDestinationAlpha
|
BlendFactorOneMinusDestinationAlpha
|
||||||
BlendFactorDestinationColor
|
BlendFactorDestinationRGB
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlendOperation byte
|
type BlendOperation byte
|
||||||
@ -44,28 +44,28 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var BlendSourceOver = Blend{
|
var BlendSourceOver = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOne,
|
BlendFactorSourceRGB: BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: BlendFactorOne,
|
BlendFactorSourceAlpha: BlendFactorOne,
|
||||||
BlendFactorDestinationColor: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationRGB: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
BlendFactorDestinationAlpha: BlendFactorOneMinusSourceAlpha,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
var BlendClear = Blend{
|
var BlendClear = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorZero,
|
BlendFactorSourceRGB: BlendFactorZero,
|
||||||
BlendFactorSourceAlpha: BlendFactorZero,
|
BlendFactorSourceAlpha: BlendFactorZero,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
|
||||||
var BlendCopy = Blend{
|
var BlendCopy = Blend{
|
||||||
BlendFactorSourceColor: BlendFactorOne,
|
BlendFactorSourceRGB: BlendFactorOne,
|
||||||
BlendFactorSourceAlpha: BlendFactorOne,
|
BlendFactorSourceAlpha: BlendFactorOne,
|
||||||
BlendFactorDestinationColor: BlendFactorZero,
|
BlendFactorDestinationRGB: BlendFactorZero,
|
||||||
BlendFactorDestinationAlpha: BlendFactorZero,
|
BlendFactorDestinationAlpha: BlendFactorZero,
|
||||||
BlendOperationColor: BlendOperationAdd,
|
BlendOperationRGB: BlendOperationAdd,
|
||||||
BlendOperationAlpha: BlendOperationAdd,
|
BlendOperationAlpha: BlendOperationAdd,
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func blendFactorToBlend(f graphicsdriver.BlendFactor, alpha bool) _D3D12_BLEND {
|
|||||||
return _D3D12_BLEND_INV_SRC_ALPHA
|
return _D3D12_BLEND_INV_SRC_ALPHA
|
||||||
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
||||||
return _D3D12_BLEND_INV_DEST_ALPHA
|
return _D3D12_BLEND_INV_DEST_ALPHA
|
||||||
case graphicsdriver.BlendFactorDestinationColor:
|
case graphicsdriver.BlendFactorDestinationRGB:
|
||||||
// D3D12_RENDER_TARGET_BLEND_DESC's *BlendAlpha members don't allow *_COLOR values.
|
// D3D12_RENDER_TARGET_BLEND_DESC's *BlendAlpha members don't allow *_COLOR values.
|
||||||
// See https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_render_target_blend_desc.
|
// See https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_render_target_blend_desc.
|
||||||
if alpha {
|
if alpha {
|
||||||
@ -423,9 +423,9 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
|
|||||||
{
|
{
|
||||||
BlendEnable: 1,
|
BlendEnable: 1,
|
||||||
LogicOpEnable: 0,
|
LogicOpEnable: 0,
|
||||||
SrcBlend: blendFactorToBlend(blend.BlendFactorSourceColor, false),
|
SrcBlend: blendFactorToBlend(blend.BlendFactorSourceRGB, false),
|
||||||
DestBlend: blendFactorToBlend(blend.BlendFactorDestinationColor, false),
|
DestBlend: blendFactorToBlend(blend.BlendFactorDestinationRGB, false),
|
||||||
BlendOp: blendOperationToBlendOp(blend.BlendOperationColor),
|
BlendOp: blendOperationToBlendOp(blend.BlendOperationRGB),
|
||||||
SrcBlendAlpha: blendFactorToBlend(blend.BlendFactorSourceAlpha, true),
|
SrcBlendAlpha: blendFactorToBlend(blend.BlendFactorSourceAlpha, true),
|
||||||
DestBlendAlpha: blendFactorToBlend(blend.BlendFactorDestinationAlpha, true),
|
DestBlendAlpha: blendFactorToBlend(blend.BlendFactorDestinationAlpha, true),
|
||||||
BlendOpAlpha: blendOperationToBlendOp(blend.BlendOperationAlpha),
|
BlendOpAlpha: blendOperationToBlendOp(blend.BlendOperationAlpha),
|
||||||
|
@ -314,8 +314,8 @@ func blendFactorToMetalBlendFactor(c graphicsdriver.BlendFactor) mtl.BlendFactor
|
|||||||
return mtl.BlendFactorOneMinusSourceAlpha
|
return mtl.BlendFactorOneMinusSourceAlpha
|
||||||
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
||||||
return mtl.BlendFactorOneMinusDestinationAlpha
|
return mtl.BlendFactorOneMinusDestinationAlpha
|
||||||
case graphicsdriver.BlendFactorDestinationColor:
|
case graphicsdriver.BlendFactorDestinationRGB:
|
||||||
return mtl.BlendFactorDestinationColor
|
return mtl.BlendFactorDestinationRGB
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("metal: invalid blend factor: %d", c))
|
panic(fmt.Sprintf("metal: invalid blend factor: %d", c))
|
||||||
}
|
}
|
||||||
|
@ -271,11 +271,11 @@ type BlendFactor uint8
|
|||||||
const (
|
const (
|
||||||
BlendFactorZero BlendFactor = 0
|
BlendFactorZero BlendFactor = 0
|
||||||
BlendFactorOne BlendFactor = 1
|
BlendFactorOne BlendFactor = 1
|
||||||
BlendFactorSourceColor BlendFactor = 2
|
BlendFactorSourceRGB BlendFactor = 2
|
||||||
BlendFactorOneMinusSourceColor BlendFactor = 3
|
BlendFactorOneMinusSourceColor BlendFactor = 3
|
||||||
BlendFactorSourceAlpha BlendFactor = 4
|
BlendFactorSourceAlpha BlendFactor = 4
|
||||||
BlendFactorOneMinusSourceAlpha BlendFactor = 5
|
BlendFactorOneMinusSourceAlpha BlendFactor = 5
|
||||||
BlendFactorDestinationColor BlendFactor = 6
|
BlendFactorDestinationRGB BlendFactor = 6
|
||||||
BlendFactorOneMinusDestinationColor BlendFactor = 7
|
BlendFactorOneMinusDestinationColor BlendFactor = 7
|
||||||
BlendFactorDestinationAlpha BlendFactor = 8
|
BlendFactorDestinationAlpha BlendFactor = 8
|
||||||
BlendFactorOneMinusDestinationAlpha BlendFactor = 9
|
BlendFactorOneMinusDestinationAlpha BlendFactor = 9
|
||||||
|
@ -113,11 +113,11 @@ func (s *Shader) RenderPipelineState(view *view, blend graphicsdriver.Blend, ste
|
|||||||
rpld.ColorAttachments[0].BlendingEnabled = true
|
rpld.ColorAttachments[0].BlendingEnabled = true
|
||||||
|
|
||||||
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorDestinationAlpha)
|
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorDestinationAlpha)
|
||||||
rpld.ColorAttachments[0].DestinationRGBBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorDestinationColor)
|
rpld.ColorAttachments[0].DestinationRGBBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorDestinationRGB)
|
||||||
rpld.ColorAttachments[0].SourceAlphaBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorSourceAlpha)
|
rpld.ColorAttachments[0].SourceAlphaBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorSourceAlpha)
|
||||||
rpld.ColorAttachments[0].SourceRGBBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorSourceColor)
|
rpld.ColorAttachments[0].SourceRGBBlendFactor = blendFactorToMetalBlendFactor(blend.BlendFactorSourceRGB)
|
||||||
rpld.ColorAttachments[0].AlphaBlendOperation = blendOperationToMetalBlendOperation(blend.BlendOperationAlpha)
|
rpld.ColorAttachments[0].AlphaBlendOperation = blendOperationToMetalBlendOperation(blend.BlendOperationAlpha)
|
||||||
rpld.ColorAttachments[0].RGBBlendOperation = blendOperationToMetalBlendOperation(blend.BlendOperationColor)
|
rpld.ColorAttachments[0].RGBBlendOperation = blendOperationToMetalBlendOperation(blend.BlendOperationRGB)
|
||||||
|
|
||||||
if stencilMode == prepareStencil {
|
if stencilMode == prepareStencil {
|
||||||
rpld.ColorAttachments[0].WriteMask = mtl.ColorWriteMaskNone
|
rpld.ColorAttachments[0].WriteMask = mtl.ColorWriteMaskNone
|
||||||
|
@ -55,7 +55,7 @@ func convertBlendFactor(f graphicsdriver.BlendFactor) blendFactor {
|
|||||||
return glOneMinusSrcAlpha
|
return glOneMinusSrcAlpha
|
||||||
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
case graphicsdriver.BlendFactorOneMinusDestinationAlpha:
|
||||||
return glOneMinusDstAlpha
|
return glOneMinusDstAlpha
|
||||||
case graphicsdriver.BlendFactorDestinationColor:
|
case graphicsdriver.BlendFactorDestinationRGB:
|
||||||
return glDstColor
|
return glDstColor
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("opengl: invalid blend factor %d", f))
|
panic(fmt.Sprintf("opengl: invalid blend factor %d", f))
|
||||||
|
@ -119,13 +119,13 @@ func (c *context) blend(blend graphicsdriver.Blend) {
|
|||||||
}
|
}
|
||||||
c.lastBlend = blend
|
c.lastBlend = blend
|
||||||
gl.BlendFuncSeparate(
|
gl.BlendFuncSeparate(
|
||||||
uint32(convertBlendFactor(blend.BlendFactorSourceColor)),
|
uint32(convertBlendFactor(blend.BlendFactorSourceRGB)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorDestinationColor)),
|
uint32(convertBlendFactor(blend.BlendFactorDestinationRGB)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
uint32(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
uint32(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
||||||
)
|
)
|
||||||
gl.BlendEquationSeparate(
|
gl.BlendEquationSeparate(
|
||||||
uint32(convertBlendOperation(blend.BlendOperationColor)),
|
uint32(convertBlendOperation(blend.BlendOperationRGB)),
|
||||||
uint32(convertBlendOperation(blend.BlendOperationAlpha)),
|
uint32(convertBlendOperation(blend.BlendOperationAlpha)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -109,13 +109,13 @@ func (c *context) blend(blend graphicsdriver.Blend) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.ctx.BlendFuncSeparate(
|
c.ctx.BlendFuncSeparate(
|
||||||
uint32(convertBlendFactor(blend.BlendFactorSourceColor)),
|
uint32(convertBlendFactor(blend.BlendFactorSourceRGB)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorDestinationColor)),
|
uint32(convertBlendFactor(blend.BlendFactorDestinationRGB)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
uint32(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
||||||
uint32(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
uint32(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
||||||
)
|
)
|
||||||
c.ctx.BlendEquationSeparate(
|
c.ctx.BlendEquationSeparate(
|
||||||
uint32(convertBlendOperation(blend.BlendOperationColor)),
|
uint32(convertBlendOperation(blend.BlendOperationRGB)),
|
||||||
uint32(convertBlendOperation(blend.BlendOperationAlpha)),
|
uint32(convertBlendOperation(blend.BlendOperationAlpha)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -192,13 +192,13 @@ func (c *context) blend(blend graphicsdriver.Blend) {
|
|||||||
c.lastBlend = blend
|
c.lastBlend = blend
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.blendFuncSeparate.Invoke(
|
gl.blendFuncSeparate.Invoke(
|
||||||
int(convertBlendFactor(blend.BlendFactorSourceColor)),
|
int(convertBlendFactor(blend.BlendFactorSourceRGB)),
|
||||||
int(convertBlendFactor(blend.BlendFactorDestinationColor)),
|
int(convertBlendFactor(blend.BlendFactorDestinationRGB)),
|
||||||
int(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
int(convertBlendFactor(blend.BlendFactorSourceAlpha)),
|
||||||
int(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
int(convertBlendFactor(blend.BlendFactorDestinationAlpha)),
|
||||||
)
|
)
|
||||||
gl.blendEquationSeparate.Invoke(
|
gl.blendEquationSeparate.Invoke(
|
||||||
int(convertBlendOperation(blend.BlendOperationColor)),
|
int(convertBlendOperation(blend.BlendOperationRGB)),
|
||||||
int(convertBlendOperation(blend.BlendOperationAlpha)),
|
int(convertBlendOperation(blend.BlendOperationAlpha)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user