internal/graphicsdriver: rename Operator -> BlendFactor

Updates #2382
This commit is contained in:
Hajime Hoshi 2022-10-15 17:27:29 +09:00
parent e42ee8c506
commit 272d0c6a3f
8 changed files with 88 additions and 88 deletions

View File

@ -40,49 +40,49 @@ const (
CompositeModeMax = CompositeModeMultiply CompositeModeMax = CompositeModeMultiply
) )
type Operation int type BlendFactor int
const ( const (
Zero Operation = iota BlendFactorZero BlendFactor = iota
One BlendFactorOne
SrcAlpha BlendFactorSrcAlpha
DstAlpha BlendFactorDstAlpha
OneMinusSrcAlpha BlendFactorOneMinusSrcAlpha
OneMinusDstAlpha BlendFactorOneMinusDstAlpha
DstColor BlendFactorDstColor
) )
func (c CompositeMode) Operations() (src Operation, dst Operation) { func (c CompositeMode) BlendFactors() (src BlendFactor, dst BlendFactor) {
switch c { switch c {
case CompositeModeSourceOver: case CompositeModeSourceOver:
return One, OneMinusSrcAlpha return BlendFactorOne, BlendFactorOneMinusSrcAlpha
case CompositeModeClear: case CompositeModeClear:
return Zero, Zero return BlendFactorZero, BlendFactorZero
case CompositeModeCopy: case CompositeModeCopy:
return One, Zero return BlendFactorOne, BlendFactorZero
case CompositeModeDestination: case CompositeModeDestination:
return Zero, One return BlendFactorZero, BlendFactorOne
case CompositeModeDestinationOver: case CompositeModeDestinationOver:
return OneMinusDstAlpha, One return BlendFactorOneMinusDstAlpha, BlendFactorOne
case CompositeModeSourceIn: case CompositeModeSourceIn:
return DstAlpha, Zero return BlendFactorDstAlpha, BlendFactorZero
case CompositeModeDestinationIn: case CompositeModeDestinationIn:
return Zero, SrcAlpha return BlendFactorZero, BlendFactorSrcAlpha
case CompositeModeSourceOut: case CompositeModeSourceOut:
return OneMinusDstAlpha, Zero return BlendFactorOneMinusDstAlpha, BlendFactorZero
case CompositeModeDestinationOut: case CompositeModeDestinationOut:
return Zero, OneMinusSrcAlpha return BlendFactorZero, BlendFactorOneMinusSrcAlpha
case CompositeModeSourceAtop: case CompositeModeSourceAtop:
return DstAlpha, OneMinusSrcAlpha return BlendFactorDstAlpha, BlendFactorOneMinusSrcAlpha
case CompositeModeDestinationAtop: case CompositeModeDestinationAtop:
return OneMinusDstAlpha, SrcAlpha return BlendFactorOneMinusDstAlpha, BlendFactorSrcAlpha
case CompositeModeXor: case CompositeModeXor:
return OneMinusDstAlpha, OneMinusSrcAlpha return BlendFactorOneMinusDstAlpha, BlendFactorOneMinusSrcAlpha
case CompositeModeLighter: case CompositeModeLighter:
return One, One return BlendFactorOne, BlendFactorOne
case CompositeModeMultiply: case CompositeModeMultiply:
return DstColor, Zero return BlendFactorDstColor, BlendFactorZero
default: default:
panic(fmt.Sprintf("graphics: invalid composite mode: %d", c)) panic(fmt.Sprintf("graphicsdriver: invalid composite mode: %d", c))
} }
} }

View File

@ -25,27 +25,27 @@ import (
const numDescriptorsPerFrame = 32 const numDescriptorsPerFrame = 32
func operationToBlend(c graphicsdriver.Operation, alpha bool) _D3D12_BLEND { func blendFactorToBlend(c graphicsdriver.BlendFactor, alpha bool) _D3D12_BLEND {
switch c { switch c {
case graphicsdriver.Zero: case graphicsdriver.BlendFactorZero:
return _D3D12_BLEND_ZERO return _D3D12_BLEND_ZERO
case graphicsdriver.One: case graphicsdriver.BlendFactorOne:
return _D3D12_BLEND_ONE return _D3D12_BLEND_ONE
case graphicsdriver.SrcAlpha: case graphicsdriver.BlendFactorSrcAlpha:
return _D3D12_BLEND_SRC_ALPHA return _D3D12_BLEND_SRC_ALPHA
case graphicsdriver.DstAlpha: case graphicsdriver.BlendFactorDstAlpha:
return _D3D12_BLEND_DEST_ALPHA return _D3D12_BLEND_DEST_ALPHA
case graphicsdriver.OneMinusSrcAlpha: case graphicsdriver.BlendFactorOneMinusSrcAlpha:
return _D3D12_BLEND_INV_SRC_ALPHA return _D3D12_BLEND_INV_SRC_ALPHA
case graphicsdriver.OneMinusDstAlpha: case graphicsdriver.BlendFactorOneMinusDstAlpha:
return _D3D12_BLEND_INV_DEST_ALPHA return _D3D12_BLEND_INV_DEST_ALPHA
case graphicsdriver.DstColor: case graphicsdriver.BlendFactorDstColor:
if alpha { if alpha {
return _D3D12_BLEND_DEST_ALPHA return _D3D12_BLEND_DEST_ALPHA
} }
return _D3D12_BLEND_DEST_COLOR return _D3D12_BLEND_DEST_COLOR
default: 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. // Create a pipeline state.
srcOp, dstOp := compositeMode.Operations() srcOp, dstOp := compositeMode.BlendFactors()
psoDesc := _D3D12_GRAPHICS_PIPELINE_STATE_DESC{ psoDesc := _D3D12_GRAPHICS_PIPELINE_STATE_DESC{
pRootSignature: rootSignature, pRootSignature: rootSignature,
VS: _D3D12_SHADER_BYTECODE{ VS: _D3D12_SHADER_BYTECODE{
@ -409,11 +409,11 @@ func (p *pipelineStates) newPipelineState(device *_ID3D12Device, vsh, psh *_ID3D
{ {
BlendEnable: 1, BlendEnable: 1,
LogicOpEnable: 0, LogicOpEnable: 0,
SrcBlend: operationToBlend(srcOp, false), SrcBlend: blendFactorToBlend(srcOp, false),
DestBlend: operationToBlend(dstOp, false), DestBlend: blendFactorToBlend(dstOp, false),
BlendOp: _D3D12_BLEND_OP_ADD, BlendOp: _D3D12_BLEND_OP_ADD,
SrcBlendAlpha: operationToBlend(srcOp, true), SrcBlendAlpha: blendFactorToBlend(srcOp, true),
DestBlendAlpha: operationToBlend(dstOp, true), DestBlendAlpha: blendFactorToBlend(dstOp, true),
BlendOpAlpha: _D3D12_BLEND_OP_ADD, BlendOpAlpha: _D3D12_BLEND_OP_ADD,
LogicOp: _D3D12_LOGIC_OP_NOOP, LogicOp: _D3D12_LOGIC_OP_NOOP,
RenderTargetWriteMask: writeMask, RenderTargetWriteMask: writeMask,

View File

@ -300,21 +300,21 @@ func (g *Graphics) SetTransparent(transparent bool) {
g.transparent = transparent g.transparent = transparent
} }
func operationToBlendFactor(c graphicsdriver.Operation) mtl.BlendFactor { func blendFactorToMetalBlendFactor(c graphicsdriver.BlendFactor) mtl.BlendFactor {
switch c { switch c {
case graphicsdriver.Zero: case graphicsdriver.BlendFactorZero:
return mtl.BlendFactorZero return mtl.BlendFactorZero
case graphicsdriver.One: case graphicsdriver.BlendFactorOne:
return mtl.BlendFactorOne return mtl.BlendFactorOne
case graphicsdriver.SrcAlpha: case graphicsdriver.BlendFactorSrcAlpha:
return mtl.BlendFactorSourceAlpha return mtl.BlendFactorSourceAlpha
case graphicsdriver.DstAlpha: case graphicsdriver.BlendFactorDstAlpha:
return mtl.BlendFactorDestinationAlpha return mtl.BlendFactorDestinationAlpha
case graphicsdriver.OneMinusSrcAlpha: case graphicsdriver.BlendFactorOneMinusSrcAlpha:
return mtl.BlendFactorOneMinusSourceAlpha return mtl.BlendFactorOneMinusSourceAlpha
case graphicsdriver.OneMinusDstAlpha: case graphicsdriver.BlendFactorOneMinusDstAlpha:
return mtl.BlendFactorOneMinusDestinationAlpha return mtl.BlendFactorOneMinusDestinationAlpha
case graphicsdriver.DstColor: case graphicsdriver.BlendFactorDstColor:
return mtl.BlendFactorDestinationColor return mtl.BlendFactorDestinationColor
default: default:
panic(fmt.Sprintf("metal: invalid operation: %d", c)) panic(fmt.Sprintf("metal: invalid operation: %d", c))

View File

@ -112,11 +112,11 @@ func (s *Shader) RenderPipelineState(view *view, compositeMode graphicsdriver.Co
rpld.ColorAttachments[0].PixelFormat = pix rpld.ColorAttachments[0].PixelFormat = pix
rpld.ColorAttachments[0].BlendingEnabled = true rpld.ColorAttachments[0].BlendingEnabled = true
src, dst := compositeMode.Operations() src, dst := compositeMode.BlendFactors()
rpld.ColorAttachments[0].DestinationAlphaBlendFactor = operationToBlendFactor(dst) rpld.ColorAttachments[0].DestinationAlphaBlendFactor = blendFactorToMetalBlendFactor(dst)
rpld.ColorAttachments[0].DestinationRGBBlendFactor = operationToBlendFactor(dst) rpld.ColorAttachments[0].DestinationRGBBlendFactor = blendFactorToMetalBlendFactor(dst)
rpld.ColorAttachments[0].SourceAlphaBlendFactor = operationToBlendFactor(src) rpld.ColorAttachments[0].SourceAlphaBlendFactor = blendFactorToMetalBlendFactor(src)
rpld.ColorAttachments[0].SourceRGBBlendFactor = operationToBlendFactor(src) rpld.ColorAttachments[0].SourceRGBBlendFactor = blendFactorToMetalBlendFactor(src)
if stencilMode == prepareStencil { if stencilMode == prepareStencil {
rpld.ColorAttachments[0].WriteMask = mtl.ColorWriteMaskNone rpld.ColorAttachments[0].WriteMask = mtl.ColorWriteMaskNone
} else { } else {

View File

@ -21,26 +21,26 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" "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 { switch op {
case graphicsdriver.Zero: case graphicsdriver.BlendFactorZero:
return zero return zero
case graphicsdriver.One: case graphicsdriver.BlendFactorOne:
return one return one
case graphicsdriver.SrcAlpha: case graphicsdriver.BlendFactorSrcAlpha:
return srcAlpha return srcAlpha
case graphicsdriver.DstAlpha: case graphicsdriver.BlendFactorDstAlpha:
return dstAlpha return dstAlpha
case graphicsdriver.OneMinusSrcAlpha: case graphicsdriver.BlendFactorOneMinusSrcAlpha:
return oneMinusSrcAlpha return oneMinusSrcAlpha
case graphicsdriver.OneMinusDstAlpha: case graphicsdriver.BlendFactorOneMinusDstAlpha:
return oneMinusDstAlpha return oneMinusDstAlpha
case graphicsdriver.DstColor: case graphicsdriver.BlendFactorDstColor:
return dstColor return dstColor
default: default:
panic(fmt.Sprintf("opengl: invalid operation %d at convertOperation", op)) panic(fmt.Sprintf("opengl: invalid blend factor %d at convertBlendFactor", op))
} }
} }

View File

@ -83,13 +83,13 @@ func getProgramID(p program) programID {
} }
const ( const (
zero = operation(gl.ZERO) zero = blendFactor(gl.ZERO)
one = operation(gl.ONE) one = blendFactor(gl.ONE)
srcAlpha = operation(gl.SRC_ALPHA) srcAlpha = blendFactor(gl.SRC_ALPHA)
dstAlpha = operation(gl.DST_ALPHA) dstAlpha = blendFactor(gl.DST_ALPHA)
oneMinusSrcAlpha = operation(gl.ONE_MINUS_SRC_ALPHA) oneMinusSrcAlpha = blendFactor(gl.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(gl.ONE_MINUS_DST_ALPHA) oneMinusDstAlpha = blendFactor(gl.ONE_MINUS_DST_ALPHA)
dstColor = operation(gl.DST_COLOR) dstColor = blendFactor(gl.DST_COLOR)
) )
type contextImpl struct { type contextImpl struct {
@ -127,8 +127,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
return return
} }
c.lastCompositeMode = mode c.lastCompositeMode = mode
s, d := mode.Operations() s, d := mode.BlendFactors()
s2, d2 := convertOperation(s), convertOperation(d) s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
gl.BlendFunc(uint32(s2), uint32(d2)) gl.BlendFunc(uint32(s2), uint32(d2))
} }

View File

@ -83,13 +83,13 @@ func getProgramID(p program) programID {
} }
const ( const (
zero = operation(gles.ZERO) zero = blendFactor(gles.ZERO)
one = operation(gles.ONE) one = blendFactor(gles.ONE)
srcAlpha = operation(gles.SRC_ALPHA) srcAlpha = blendFactor(gles.SRC_ALPHA)
dstAlpha = operation(gles.DST_ALPHA) dstAlpha = blendFactor(gles.DST_ALPHA)
oneMinusSrcAlpha = operation(gles.ONE_MINUS_SRC_ALPHA) oneMinusSrcAlpha = blendFactor(gles.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(gles.ONE_MINUS_DST_ALPHA) oneMinusDstAlpha = blendFactor(gles.ONE_MINUS_DST_ALPHA)
dstColor = operation(gles.DST_COLOR) dstColor = blendFactor(gles.DST_COLOR)
) )
type contextImpl struct { type contextImpl struct {
@ -118,8 +118,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
return return
} }
c.lastCompositeMode = mode c.lastCompositeMode = mode
s, d := mode.Operations() s, d := mode.BlendFactors()
s2, d2 := convertOperation(s), convertOperation(d) s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
c.ctx.BlendFunc(uint32(s2), uint32(d2)) c.ctx.BlendFunc(uint32(s2), uint32(d2))
} }

View File

@ -80,13 +80,13 @@ func getProgramID(p program) programID {
} }
const ( const (
zero = operation(gles.ZERO) zero = blendFactor(gles.ZERO)
one = operation(gles.ONE) one = blendFactor(gles.ONE)
srcAlpha = operation(gles.SRC_ALPHA) srcAlpha = blendFactor(gles.SRC_ALPHA)
dstAlpha = operation(gles.DST_ALPHA) dstAlpha = blendFactor(gles.DST_ALPHA)
oneMinusSrcAlpha = operation(gles.ONE_MINUS_SRC_ALPHA) oneMinusSrcAlpha = blendFactor(gles.ONE_MINUS_SRC_ALPHA)
oneMinusDstAlpha = operation(gles.ONE_MINUS_DST_ALPHA) oneMinusDstAlpha = blendFactor(gles.ONE_MINUS_DST_ALPHA)
dstColor = operation(gles.DST_COLOR) dstColor = blendFactor(gles.DST_COLOR)
) )
type webGLVersion int type webGLVersion int
@ -200,8 +200,8 @@ func (c *context) blendFunc(mode graphicsdriver.CompositeMode) {
return return
} }
c.lastCompositeMode = mode c.lastCompositeMode = mode
s, d := mode.Operations() s, d := mode.BlendFactors()
s2, d2 := convertOperation(s), convertOperation(d) s2, d2 := convertBlendFactor(s), convertBlendFactor(d)
gl := c.gl gl := c.gl
gl.blendFunc.Invoke(int(s2), int(d2)) gl.blendFunc.Invoke(int(s2), int(d2))
} }