[Chapter 4] Is this code incorrect?

I am not getting the expected output due to these changes at this location.

Does author should be creating device.makeBuffer and then setVertexStride here?
There seem to be duplicate code.
Screen Shot 2022-02-21 at 8.09.58 PM

Is it intentional? I am kind of confused here. Could you please explain?
My code is not showing any dots after adding these lines as suggested. Or can you suggest what I might be doing wrong?

Why creating device.makeBuffer is not required for matrix? How can the matrix data be accessed in shader without creating buffer?

If you’re only sending a small amount of data (less than 4kb) to the GPU, setVertexBytes(_:length:index:) is an alternative to setting up an MTLBuffer.

Metal will set up an ad-hoc buffer for this data, and on the GPU-side you treat it as a buffer.

For the two renderEncoder.setVertexBytes(...), you have two draw calls. You set the matrix for the first point, do a draw call, then set the matrix for the second point and do a draw call.

I’m not sure what you’re doing wrong - I just went through the chapter up to this point, and my code works.
I’ll attach the playground up to this point.

I hope you saw that Apple has changed how you make the library. In Utility.swift, you should have

 library = device.makeDefaultLibrary()!

3DTransforms.playground.zip (17.2 KB)


Now I understand why its used twice. (for original point and then transformed point).
Ok. Thanks for sharing the reference code. I compared my code side by side.
There was some sequence issue in my code.

Thank you very much!

1 Like