после выноса всех инициализаций из основного цикла отрисовки в примитивы, отрисовка пропала не смотря на все вызовы дроуколов
Так выглядит цикл сейчас:
```
//update
scene.update()
guard let drawable = view.currentDrawable else {
return
}
let commandBuffer = metalCommandQueue.makeCommandBuffer()
let renderPassDescriptor = view.currentRenderPassDescriptor
renderPassDescriptor?.colorAttachments[0].clearColor = MTLClearColorMake(0, 0.5, 0.5, 1.0)
renderPassDescriptor?.colorAttachments[0].loadAction = .clear
renderPassDescriptor?.colorAttachments[0].storeAction = .store
var renderEncoder = commandBuffer?.makeRenderCommandEncoder(descriptor: renderPassDescriptor!)
renderEncoder?.setDepthStencilState(depthStencilState)
let t = Triangle(Utils(metalDevice: metalDevice))
t.draw(&renderEncoder, cameraData)
renderEncoder?.endEncoding()
commandBuffer?.present(drawable)
commandBuffer?.commit()
```
Так выглядит тело draw у triangle:
```
override func draw(_ encoder: inout MTLRenderCommandEncoder!, _ camera: CameraParameters) -> Void {
encoder.setRenderPipelineState(pipelineState)
var model: matrix_float4x4 = Matrix44.create_from_rotation(eulers: transform.eulers)
model = Matrix44.create_from_translation(translation: transform.position) * model
encoder.setVertexBytes(&model, length: MemoryLayout<matrix_float4x4>.stride, index: 3)
var localCamera = camera
encoder.setVertexBuffer(buffer.vertexBuffer, offset: 0, index: 0)
encoder.setVertexBuffer(buffer.colorBuffer, offset: 0, index: 1)
encoder.setVertexBuffer(buffer.textureBuffer, offset: 0, index: 2)
encoder.setVertexBytes(&model, length: MemoryLayout<matrix_float4x4>.stride, index: 3)
encoder.setVertexBytes(&localCamera, length: MemoryLayout<CameraParameters>.stride, index: 4)
encoder.setFragmentTexture(material.texture, index: 0)
encoder.setFragmentSamplerState(material.sampler, index: 0)
encoder.drawIndexedPrimitives(type: .triangle, indexCount: 3, indexType: .uint32, indexBuffer: buffer.indexBuffer, indexBufferOffset: 0)
}
```
Так код лучше читается) https://codeshare.io/6pPA8k
Обсуждают сегодня