mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
parent
e42ee8c506
commit
272d0c6a3f
@ -40,49 +40,49 @@ const (
|
||||
CompositeModeMax = CompositeModeMultiply
|
||||
)
|
||||
|
||||
type Operation int
|
||||
type BlendFactor int
|
||||
|
||||
const (
|
||||
Zero Operation = iota
|
||||
One
|
||||
SrcAlpha
|
||||
DstAlpha
|
||||
OneMinusSrcAlpha
|
||||
OneMinusDstAlpha
|
||||
DstColor
|
||||
BlendFactorZero BlendFactor = iota
|
||||
BlendFactorOne
|
||||
BlendFactorSrcAlpha
|
||||
BlendFactorDstAlpha
|
||||
BlendFactorOneMinusSrcAlpha
|
||||
BlendFactorOneMinusDstAlpha
|
||||
BlendFactorDstColor
|
||||
)
|
||||
|
||||
func (c CompositeMode) Operations() (src Operation, dst Operation) {
|
||||
func (c CompositeMode) BlendFactors() (src BlendFactor, dst BlendFactor) {
|
||||
switch c {
|
||||
case CompositeModeSourceOver:
|
||||
return One, OneMinusSrcAlpha
|
||||
return BlendFactorOne, BlendFactorOneMinusSrcAlpha
|
||||
case CompositeModeClear:
|
||||
return Zero, Zero
|
||||
return BlendFactorZero, BlendFactorZero
|
||||
case CompositeModeCopy:
|
||||
return One, Zero
|
||||
return BlendFactorOne, BlendFactorZero
|
||||
case CompositeModeDestination:
|
||||
return Zero, One
|
||||
return BlendFactorZero, BlendFactorOne
|
||||
case CompositeModeDestinationOver:
|
||||
return OneMinusDstAlpha, One
|
||||
return BlendFactorOneMinusDstAlpha, BlendFactorOne
|
||||
case CompositeModeSourceIn:
|
||||
return DstAlpha, Zero
|
||||
return BlendFactorDstAlpha, BlendFactorZero
|
||||
case CompositeModeDestinationIn:
|
||||
return Zero, SrcAlpha
|
||||
return BlendFactorZero, BlendFactorSrcAlpha
|
||||
case CompositeModeSourceOut:
|
||||
return OneMinusDstAlpha, Zero
|
||||
return BlendFactorOneMinusDstAlpha, BlendFactorZero
|
||||
case CompositeModeDestinationOut:
|
||||
return Zero, OneMinusSrcAlpha
|
||||
return BlendFactorZero, BlendFactorOneMinusSrcAlpha
|
||||
case CompositeModeSourceAtop:
|
||||
return DstAlpha, OneMinusSrcAlpha
|
||||
return BlendFactorDstAlpha, BlendFactorOneMinusSrcAlpha
|
||||
case CompositeModeDestinationAtop:
|
||||
return OneMinusDstAlpha, SrcAlpha
|
||||
return BlendFactorOneMinusDstAlpha, BlendFactorSrcAlpha
|
||||
case CompositeModeXor:
|
||||
return OneMinusDstAlpha, OneMinusSrcAlpha
|
||||
return BlendFactorOneMinusDstAlpha, BlendFactorOneMinusSrcAlpha
|
||||
case CompositeModeLighter:
|
||||
return One, One
|
||||
return BlendFactorOne, BlendFactorOne
|
||||
case CompositeModeMultiply:
|
||||
return DstColor, Zero
|
||||
return BlendFactorDstColor, BlendFactorZero
|
||||
default:
|
||||
panic(fmt.Sprintf("graphics: invalid composite mode: %d", c))
|
||||
panic(fmt.Sprintf("graphicsdriver: invalid composite mode: %d", c))
|
||||
}
|
||||
}
|
||||
|
@ -25,27 +25,27 @@ import (
|
||||
|
||||
const numDescriptorsPerFrame = 32
|
||||
|
||||
func operationToBlend(c graphicsdriver.Operation, alpha bool) _D3D12_BLEND {
|
||||
func blendFactorToBlend(c graphicsdriver.BlendFactor, alpha bool) _D3D12_BLEND {
|
||||
switch c {
|
||||
case graphicsdriver.Zero:
|
||||
case graphicsdriver.BlendFactorZero:
|
||||
return _D3D12_BLEND_ZERO
|
||||
case graphicsdriver.One:
|
||||
case graphicsdriver.BlendFactorOne:
|
||||
return _D3D12_BLEND_ONE
|
||||
case graphicsdriver.SrcAlpha:
|
||||
case graphicsdriver.BlendFactorSrcAlpha:
|
||||
return _D3D12_BLEND_SRC_ALPHA
|
||||
case graphicsdriver.DstAlpha:
|
||||
case graphicsdriver.BlendFactorDstAlpha:
|
||||
return _D3D12_BLEND_DEST_ALPHA
|
||||
case graphicsdriver.OneMinusSrcAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusSrcAlpha:
|
||||
return _D3D12_BLEND_INV_SRC_ALPHA
|
||||
case graphicsdriver.OneMinusDstAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusDstAlpha:
|
||||
return _D3D12_BLEND_INV_DEST_ALPHA
|
||||
case graphicsdriver.DstColor:
|
||||
case graphicsdriver.BlendFactorDstColor:
|
||||
if alpha {
|
||||
return _D3D12_BLEND_DEST_ALPHA
|
||||
}
|
||||
return _D3D12_BLEND_DEST_COLOR
|
||||
default:
|
||||
panic(fmt.Sprintf("directx: invalid operation: %d", c))
|
||||
panic(fmt.Sprintf("directx: invalid blend factor: %d", c))
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,7 +391,7 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
|
||||
}
|
||||
|
||||
// Create a pipeline state.
|
||||
srcOp, dstOp := compositeMode.Operations()
|
||||
srcOp, dstOp := compositeMode.BlendFactors()
|
||||
psoDesc := _D3D12_GRAPHICS_PIPELINE_STATE_DESC{
|
||||
pRootSignature: rootSignature,
|
||||
VS: _D3D12_SHADER_BYTECODE{
|
||||
@ -409,11 +409,11 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
|
||||
{
|
||||
BlendEnable: 1,
|
||||
LogicOpEnable: 0,
|
||||
SrcBlend: operationToBlend(srcOp, false),
|
||||
DestBlend: operationToBlend(dstOp, false),
|
||||
SrcBlend: blendFactorToBlend(srcOp, false),
|
||||
DestBlend: blendFactorToBlend(dstOp, false),
|
||||
BlendOp: _D3D12_BLEND_OP_ADD,
|
||||
SrcBlendAlpha: operationToBlend(srcOp, true),
|
||||
DestBlendAlpha: operationToBlend(dstOp, true),
|
||||
SrcBlendAlpha: blendFactorToBlend(srcOp, true),
|
||||
DestBlendAlpha: blendFactorToBlend(dstOp, true),
|
||||
BlendOpAlpha: _D3D12_BLEND_OP_ADD,
|
||||
LogicOp: _D3D12_LOGIC_OP_NOOP,
|
||||
RenderTargetWriteMask: writeMask,
|
||||
|
@ -300,21 +300,21 @@ func (g *Graphics) SetTransparent(transparent bool) {
|
||||
g.transparent = transparent
|
||||
}
|
||||
|
||||
func operationToBlendFactor(c graphicsdriver.Operation) mtl.BlendFactor {
|
||||
func blendFactorToMetalBlendFactor(c graphicsdriver.BlendFactor) mtl.BlendFactor {
|
||||
switch c {
|
||||
case graphicsdriver.Zero:
|
||||
case graphicsdriver.BlendFactorZero:
|
||||
return mtl.BlendFactorZero
|
||||
case graphicsdriver.One:
|
||||
case graphicsdriver.BlendFactorOne:
|
||||
return mtl.BlendFactorOne
|
||||
case graphicsdriver.SrcAlpha:
|
||||
case graphicsdriver.BlendFactorSrcAlpha:
|
||||
return mtl.BlendFactorSourceAlpha
|
||||
case graphicsdriver.DstAlpha:
|
||||
case graphicsdriver.BlendFactorDstAlpha:
|
||||
return mtl.BlendFactorDestinationAlpha
|
||||
case graphicsdriver.OneMinusSrcAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusSrcAlpha:
|
||||
return mtl.BlendFactorOneMinusSourceAlpha
|
||||
case graphicsdriver.OneMinusDstAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusDstAlpha:
|
||||
return mtl.BlendFactorOneMinusDestinationAlpha
|
||||
case graphicsdriver.DstColor:
|
||||
case graphicsdriver.BlendFactorDstColor:
|
||||
return mtl.BlendFactorDestinationColor
|
||||
default:
|
||||
panic(fmt.Sprintf("metal: invalid operation: %d", c))
|
||||
|
@ -112,11 +112,11 @@ func (s *Shader) RenderPipelineState(view *view, compositeMode graphicsdriver.Co
|
||||
rpld.ColorAttachments[0].PixelFormat = pix
|
||||
rpld.ColorAttachments[0].BlendingEnabled = true
|
||||
|
||||
src, dst := compositeMode.Operations()
|
||||
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = operationToBlendFactor(dst)
|
||||
rpld.ColorAttachments[0].DestinationRGBBlendFactor = operationToBlendFactor(dst)
|
||||
rpld.ColorAttachments[0].SourceAlphaBlendFactor = operationToBlendFactor(src)
|
||||
rpld.ColorAttachments[0].SourceRGBBlendFactor = operationToBlendFactor(src)
|
||||
src, dst := compositeMode.BlendFactors()
|
||||
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = blendFactorToMetalBlendFactor(dst)
|
||||
rpld.ColorAttachments[0].DestinationRGBBlendFactor = blendFactorToMetalBlendFactor(dst)
|
||||
rpld.ColorAttachments[0].SourceAlphaBlendFactor = blendFactorToMetalBlendFactor(src)
|
||||
rpld.ColorAttachments[0].SourceRGBBlendFactor = blendFactorToMetalBlendFactor(src)
|
||||
if stencilMode == prepareStencil {
|
||||
rpld.ColorAttachments[0].WriteMask = mtl.ColorWriteMaskNone
|
||||
} else {
|
||||
|
@ -21,26 +21,26 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
type operation int
|
||||
type blendFactor int
|
||||
|
||||
func convertOperation(op graphicsdriver.Operation) operation {
|
||||
func convertBlendFactor(op graphicsdriver.BlendFactor) blendFactor {
|
||||
switch op {
|
||||
case graphicsdriver.Zero:
|
||||
case graphicsdriver.BlendFactorZero:
|
||||
return zero
|
||||
case graphicsdriver.One:
|
||||
case graphicsdriver.BlendFactorOne:
|
||||
return one
|
||||
case graphicsdriver.SrcAlpha:
|
||||
case graphicsdriver.BlendFactorSrcAlpha:
|
||||
return srcAlpha
|
||||
case graphicsdriver.DstAlpha:
|
||||
case graphicsdriver.BlendFactorDstAlpha:
|
||||
return dstAlpha
|
||||
case graphicsdriver.OneMinusSrcAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusSrcAlpha:
|
||||
return oneMinusSrcAlpha
|
||||
case graphicsdriver.OneMinusDstAlpha:
|
||||
case graphicsdriver.BlendFactorOneMinusDstAlpha:
|
||||
return oneMinusDstAlpha
|
||||
case graphicsdriver.DstColor:
|
||||
case graphicsdriver.BlendFactorDstColor:
|
||||
return dstColor
|
||||
default:
|
||||
panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op))
|
||||
panic(fmt.Sprintf("opengl: invalid blend factor %d at convertBlendFactor", op))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,13 +83,13 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
zero = operation(gl.ZERO)
|
||||
one = operation(gl.ONE)
|
||||
srcAlpha = operation(gl.SRC_ALPHA)
|
||||
dstAlpha = operation(gl.DST_ALPHA)
|
||||
oneMinusSrcAlpha = operation(gl.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = operation(gl.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = operation(gl.DST_COLOR)
|
||||
zero = blendFactor(gl.ZERO)
|
||||
one = blendFactor(gl.ONE)
|
||||
srcAlpha = blendFactor(gl.SRC_ALPHA)
|
||||
dstAlpha = blendFactor(gl.DST_ALPHA)
|
||||
oneMinusSrcAlpha = blendFactor(gl.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = blendFactor(gl.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = blendFactor(gl.DST_COLOR)
|
||||
)
|
||||
|
||||
type contextImpl struct {
|
||||
@ -127,8 +127,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
return
|
||||
}
|
||||
c.lastCompositeMode = mode
|
||||
s, d := mode.Operations()
|
||||
s2, d2 := convertOperation(s), convertOperation(d)
|
||||
s, d := mode.BlendFactors()
|
||||
s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
|
||||
gl.BlendFunc(uint32(s2), uint32(d2))
|
||||
}
|
||||
|
||||
|
@ -83,13 +83,13 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
srcAlpha = operation(gles.SRC_ALPHA)
|
||||
dstAlpha = operation(gles.DST_ALPHA)
|
||||
oneMinusSrcAlpha = operation(gles.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = operation(gles.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = operation(gles.DST_COLOR)
|
||||
zero = blendFactor(gles.ZERO)
|
||||
one = blendFactor(gles.ONE)
|
||||
srcAlpha = blendFactor(gles.SRC_ALPHA)
|
||||
dstAlpha = blendFactor(gles.DST_ALPHA)
|
||||
oneMinusSrcAlpha = blendFactor(gles.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = blendFactor(gles.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = blendFactor(gles.DST_COLOR)
|
||||
)
|
||||
|
||||
type contextImpl struct {
|
||||
@ -118,8 +118,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
return
|
||||
}
|
||||
c.lastCompositeMode = mode
|
||||
s, d := mode.Operations()
|
||||
s2, d2 := convertOperation(s), convertOperation(d)
|
||||
s, d := mode.BlendFactors()
|
||||
s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
|
||||
c.ctx.BlendFunc(uint32(s2), uint32(d2))
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ func getProgramID(p program) programID {
|
||||
}
|
||||
|
||||
const (
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
srcAlpha = operation(gles.SRC_ALPHA)
|
||||
dstAlpha = operation(gles.DST_ALPHA)
|
||||
oneMinusSrcAlpha = operation(gles.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = operation(gles.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = operation(gles.DST_COLOR)
|
||||
zero = blendFactor(gles.ZERO)
|
||||
one = blendFactor(gles.ONE)
|
||||
srcAlpha = blendFactor(gles.SRC_ALPHA)
|
||||
dstAlpha = blendFactor(gles.DST_ALPHA)
|
||||
oneMinusSrcAlpha = blendFactor(gles.ONE_MINUS_SRC_ALPHA)
|
||||
oneMinusDstAlpha = blendFactor(gles.ONE_MINUS_DST_ALPHA)
|
||||
dstColor = blendFactor(gles.DST_COLOR)
|
||||
)
|
||||
|
||||
type webGLVersion int
|
||||
@ -200,8 +200,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
|
||||
return
|
||||
}
|
||||
c.lastCompositeMode = mode
|
||||
s, d := mode.Operations()
|
||||
s2, d2 := convertOperation(s), convertOperation(d)
|
||||
s, d := mode.BlendFactors()
|
||||
s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
|
||||
gl := c.gl
|
||||
gl.blendFunc.Invoke(int(s2), int(d2))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user