Hi,
Just looking at Chapter 5 starter project and I am at the point where I am adding a vertex descriptor attribute for normals on page 120. The code is as follows:
vertexDescriptor.attributes[1] =
MDLVertexAttribute(name: MDLVertexAttributeNormal,
format: .float3, offset: 12, bufferIndex: 0)
I am a little bit confused by setting the offset for normals. Why is it set to 12? I know the book says that is the length of the position attribute, but should not it be rather set to
MemoryLayout<float3>.stride
since position is of format .float3?
I am confused as to why is it hardcoded like that? Since in the examples before when setting the MTLVertexDescriptor the MemoryLayout was always used for strides.
Then later it says to set the layout to 24.
vertexDescriptor.layouts[0] = MDLVertexBufferLayout(stride: 24)
but would it not be better to do :
vertexDescriptor.layouts[0] = MDLVertexBufferLayout(stride: MemoryLayout<float3>.stride + MemoryLayout<float3>stride)
since position and normal attributes are both of float3 format?
Cheers