iOS10 - can't render Sprite Kit scene within SceneKit with openGL

拥有回忆 提交于 2019-12-06 22:32:26

问题


Since I've updated to iOS 10, I'm not able anymore to render a Sprite Kit scene to a Scene Node while using openGL for rendering. Things work fine with Metal. The error logs: "Failed to create IOSurface image (texture)"

I used to be able to do something like:

class ViewController: UIViewController {
  @IBOutlet weak var scnView: SCNView!

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    scnView.showsStatistics = true
    scnView.allowsCameraControl = true

    let scnScene = SCNScene()
    scnView.scene = scnScene

    print("scnView renderingAPI is metal", scnView.renderingAPI == SCNRenderingAPI.metal)
    print("scnView renderingAPI is opengl", scnView.renderingAPI == SCNRenderingAPI.openGLES2)

    // setup SceneKit scene
    let cameraNode = SCNNode()
    cameraNode.camera = SCNCamera()
    cameraNode.position = SCNVector3(x: 0.0, y: 0.0, z: 25.0)
    scnScene.rootNode.addChildNode(cameraNode)

    let cubeNode = SCNNode()
    cubeNode.geometry = SCNBox(width: 5.0, height: 5.0, length: 5.0, chamferRadius: 0.0)
    scnScene.rootNode.addChildNode(cubeNode)

    // setup SpriteKit Scene
    let skScene = SKScene()
    skScene.backgroundColor = UIColor.black
    skScene.size = CGSize(width: 100, height: 100)

    let skNode = SKShapeNode(rect: CGRect(x: 0.0, y: 0.0, width: 10.0, height: 10.0))
    skNode.fillColor = UIColor.green
    skNode.position = CGPoint(x: 5.0, y: 5.0)
    skScene.addChild(skNode)

    cubeNode.geometry?.firstMaterial?.diffuse.contents = skScene
  }
}

(here is a repo to reproduce this: https://github.com/gsabran/iOS10-OpenGLRenderingBug)

来源:https://stackoverflow.com/questions/39521210/ios10-cant-render-sprite-kit-scene-within-scenekit-with-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!