diff --git a/MaLiang.podspec b/MaLiang.podspec index 4ed7f55..c2e4a19 100644 --- a/MaLiang.podspec +++ b/MaLiang.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'MaLiang' - s.version = '2.0.1-alpha' + s.version = '2.0.0-beta' s.summary = 'MaLiang is a painting Framework based on Metal.' s.description = 'The name of "MaLiang" comes from a boy who had a magical brush in Chinese ancient fairy story.' diff --git a/MaLiang/Classes/Brush.swift b/MaLiang/Classes/Brush.swift index 2c39233..a61375a 100644 --- a/MaLiang/Classes/Brush.swift +++ b/MaLiang/Classes/Brush.swift @@ -81,7 +81,7 @@ open class Brush { let rpd = MTLRenderPipelineDescriptor() rpd.vertexFunction = vertex_func rpd.fragmentFunction = fragment_func - rpd.colorAttachments[0].pixelFormat = target.metalLayer.pixelFormat + rpd.colorAttachments[0].pixelFormat = target.colorPixelFormat setupBlendOptions(for: rpd.colorAttachments[0]!) pipelineState = try! device.makeRenderPipelineState(descriptor: rpd) } diff --git a/MaLiang/Classes/MetalBase/MetalView.swift b/MaLiang/Classes/MetalBase/MetalView.swift index 29a421a..b6687c8 100644 --- a/MaLiang/Classes/MetalBase/MetalView.swift +++ b/MaLiang/Classes/MetalBase/MetalView.swift @@ -50,6 +50,9 @@ open class MetalView: MTKView { } internal func presentRenderTarget() { + + #if !targetEnvironment(simulator) + guard let drawable = metalLayer.nextDrawable(), let texture = renderTarget else { return } @@ -76,6 +79,8 @@ open class MetalView: MTKView { commandEncoder?.endEncoding() commandBuffer?.present(drawable) commandBuffer?.commit() + + #endif } open override var backgroundColor: UIColor? { @@ -96,12 +101,14 @@ open class MetalView: MTKView { setup() } + #if !targetEnvironment(simulator) var metalLayer: CAMetalLayer { guard let layer = layer as? CAMetalLayer else { fatalError("Metal initialize failed!") } return layer } + #endif open func setup() { device = MTLCreateSystemDefaultDevice() @@ -126,7 +133,7 @@ open class MetalView: MTKView { let rpd = MTLRenderPipelineDescriptor() rpd.vertexFunction = vertex_func rpd.fragmentFunction = fragment_func - rpd.colorAttachments[0].pixelFormat = metalLayer.pixelFormat + rpd.colorAttachments[0].pixelFormat = colorPixelFormat rpd.colorAttachments[0].isBlendingEnabled = true rpd.colorAttachments[0].alphaBlendOperation = .add rpd.colorAttachments[0].rgbBlendOperation = .add @@ -160,7 +167,7 @@ open class MetalView: MTKView { // make empty testure internal func makeEmptyTexture() -> MTLTexture? { - let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: metalLayer.pixelFormat, + let textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: colorPixelFormat, width: Int(drawableSize.width), height: Int(drawableSize.height), mipmapped: false)