view clears but the scene does not render

Hey, complete newbie to Metal here.

I've had to use a variety of tutorials to kit together my "hello world" triangle Metal first step app.

but eventually I just sat down and converted the Apple "helloTriangle" app from Cocoa. So some of my understanding is from different sources, which is what I suspect is the issue. Would be nice if Apple would update "helloTriangle" to swift, and MetalKit.


I wound up with an app that has no errors, clears the view to the clearColor, but does not display the triangle. To me that indicates that my number of issues are rather limited.


I have compared my Metal vertex and fragment shaders, my draw method, and my setup code, against Apple's. I do not see any real differences. Apple passes bytes, not buffers... but that would crash the app if it wasn't setup properly.


any hints on where i should be looking? if I had an error, I would have something to check.


attaching my draw method:

func draw(in view: MTKView){
        /
        let commandBuffer = commandQueue!.makeCommandBuffer()
        /
        let renderPassDescriptor = view.currentRenderPassDescriptor!
        /
        let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)
        /
       
        renderEncoder.setRenderPipelineState(renderPipelineState!) /
       
        /
        renderEncoder.setVertexBuffer(posBuffer, offset: 0, at: 0)
        renderEncoder.setVertexBuffer(colorBuffer , offset: 0, at: 1)
        renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3)
       
        /
        renderEncoder.endEncoding()
        /
        let drawable = view.currentDrawable!
        /
        commandBuffer.present(drawable)
        /
        commandBuffer.commit()
    }

Replies

I found a different example that drew. so it's solved, but I did not learn anything.


the code was the same, it was just structured differently with tests for passdescriptor and drawable.