mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 10:16:01 +08:00
[ios] Fix blending, see #2555
This commit is contained in:
parent
35d76de559
commit
7d6f0f9490
@ -283,21 +283,13 @@ internal final class SpineRenderer: NSObject, MTKViewDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate extension MTLRenderPipelineColorAttachmentDescriptor {
|
|
||||||
|
|
||||||
func apply(blendMode: BlendMode, with premultipliedAlpha: Bool) {
|
|
||||||
isBlendingEnabled = true
|
|
||||||
sourceRGBBlendFactor = blendMode.sourceRGBBlendFactor(premultipliedAlpha: premultipliedAlpha)
|
|
||||||
destinationRGBBlendFactor = blendMode.destinationRGBBlendFactor
|
|
||||||
destinationAlphaBlendFactor = .oneMinusSourceAlpha
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileprivate extension BlendMode {
|
fileprivate extension BlendMode {
|
||||||
func sourceRGBBlendFactor(premultipliedAlpha: Bool) -> MTLBlendFactor {
|
func sourceRGBBlendFactor(premultipliedAlpha: Bool) -> MTLBlendFactor {
|
||||||
switch self {
|
switch self {
|
||||||
case SPINE_BLEND_MODE_NORMAL, SPINE_BLEND_MODE_ADDITIVE:
|
case SPINE_BLEND_MODE_NORMAL:
|
||||||
return premultipliedAlpha ? .one : .sourceAlpha
|
return premultipliedAlpha ? .one : .sourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_ADDITIVE:
|
||||||
|
return .sourceAlpha
|
||||||
case SPINE_BLEND_MODE_MULTIPLY:
|
case SPINE_BLEND_MODE_MULTIPLY:
|
||||||
return .destinationColor
|
return .destinationColor
|
||||||
case SPINE_BLEND_MODE_SCREEN:
|
case SPINE_BLEND_MODE_SCREEN:
|
||||||
@ -307,12 +299,44 @@ fileprivate extension BlendMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sourceAlphaBlendFactor(premultipliedAlpha: Bool) -> MTLBlendFactor {
|
||||||
|
switch self {
|
||||||
|
case SPINE_BLEND_MODE_NORMAL:
|
||||||
|
return premultipliedAlpha ? .one : .sourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_ADDITIVE:
|
||||||
|
return .sourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_MULTIPLY:
|
||||||
|
return .oneMinusSourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_SCREEN:
|
||||||
|
return .oneMinusSourceColor
|
||||||
|
default:
|
||||||
|
return .one // Should never be called
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var destinationRGBBlendFactor: MTLBlendFactor {
|
var destinationRGBBlendFactor: MTLBlendFactor {
|
||||||
switch self {
|
switch self {
|
||||||
case SPINE_BLEND_MODE_NORMAL, SPINE_BLEND_MODE_ADDITIVE:
|
case SPINE_BLEND_MODE_NORMAL:
|
||||||
return .oneMinusSourceAlpha
|
return .oneMinusSourceAlpha
|
||||||
case SPINE_BLEND_MODE_MULTIPLY:
|
case SPINE_BLEND_MODE_ADDITIVE:
|
||||||
return .one
|
return .one
|
||||||
|
case SPINE_BLEND_MODE_MULTIPLY:
|
||||||
|
return .oneMinusSourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_SCREEN:
|
||||||
|
return .oneMinusSourceColor
|
||||||
|
default:
|
||||||
|
return .one // Should never be called
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var destinationAlphaBlendFactor: MTLBlendFactor {
|
||||||
|
switch self {
|
||||||
|
case SPINE_BLEND_MODE_NORMAL:
|
||||||
|
return .oneMinusSourceAlpha
|
||||||
|
case SPINE_BLEND_MODE_ADDITIVE:
|
||||||
|
return .one
|
||||||
|
case SPINE_BLEND_MODE_MULTIPLY:
|
||||||
|
return .oneMinusSourceAlpha
|
||||||
case SPINE_BLEND_MODE_SCREEN:
|
case SPINE_BLEND_MODE_SCREEN:
|
||||||
return .oneMinusSourceColor
|
return .oneMinusSourceColor
|
||||||
default:
|
default:
|
||||||
@ -320,3 +344,14 @@ fileprivate extension BlendMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate extension MTLRenderPipelineColorAttachmentDescriptor {
|
||||||
|
|
||||||
|
func apply(blendMode: BlendMode, with premultipliedAlpha: Bool) {
|
||||||
|
isBlendingEnabled = true
|
||||||
|
sourceRGBBlendFactor = blendMode.sourceRGBBlendFactor(premultipliedAlpha: premultipliedAlpha)
|
||||||
|
sourceAlphaBlendFactor = blendMode.sourceAlphaBlendFactor(premultipliedAlpha: premultipliedAlpha)
|
||||||
|
destinationRGBBlendFactor = blendMode.destinationRGBBlendFactor
|
||||||
|
destinationAlphaBlendFactor = blendMode.destinationAlphaBlendFactor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user