Created
March 3, 2024 20:14
-
-
Save patskovn/44d17ee06b6de046d57571f6156ba2b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func draw(in view: MTKView) { | |
| guard let drawable = view.currentDrawable else { return } | |
| let renderPassDescriptor = MTLRenderPassDescriptor() | |
| renderPassDescriptor.colorAttachments[0].texture = drawable.texture | |
| renderPassDescriptor.colorAttachments[0].loadAction = .clear | |
| renderPassDescriptor.colorAttachments[0].storeAction = .store | |
| renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 1.0) | |
| let commandBuffer = commandQueue.makeCommandBuffer()! | |
| let commandEncoder = commandBuffer. | |
| makeRenderCommandEncoder(descriptor: renderPassDescriptor)! | |
| commandEncoder.setRenderPipelineState(pipelineState) | |
| commandEncoder.setVertexBuffer(node.buffer, offset: 0, index: 0) | |
| commandEncoder.drawPrimitives(type: .triangleStrip vertexStart: 0, vertexCount: node.vertexCount) | |
| commandEncoder.endEncoding() | |
| commandBuffer.present(drawable) | |
| commandBuffer.commit() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment