Skip to content

Commit

Permalink
fix build issues on simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Harley-xk committed Apr 7, 2019
1 parent a92c315 commit 1cec189
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MaLiang.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

Expand Down
2 changes: 1 addition & 1 deletion MaLiang/Classes/Brush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 9 additions & 2 deletions MaLiang/Classes/MetalBase/MetalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ open class MetalView: MTKView {
}

internal func presentRenderTarget() {

#if !targetEnvironment(simulator)

guard let drawable = metalLayer.nextDrawable(), let texture = renderTarget else {
return
}
Expand All @@ -76,6 +79,8 @@ open class MetalView: MTKView {
commandEncoder?.endEncoding()
commandBuffer?.present(drawable)
commandBuffer?.commit()

#endif
}

open override var backgroundColor: UIColor? {
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1cec189

Please sign in to comment.