When we use Metal API
drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexCount:indexCount
indexType:MTLIndexTypeUInt32
indexBuffer:indexs
indexBufferOffset:0]
to draw triangles. I have to create a MTLBuffer with uint32_t or uint16_t. When I load an index from a file and save it uint32_t* indices_. I can make sure indices_ have the right values. I try to use
indexs = [_device newBufferWithBytes:indices_
length:SCR_WIDTH*SCR_HEIGHT*6*sizeof(uint32_t)
options:MTLResourceStorageModeShared];
or use
indexs = [_device newBufferWithLength:sizeof(uint32_t)*SCR_WIDTH*SCR_HEIGHT*6 options:MTLResourceStorageModeManaged];
memcpy(indexs.contents, indices_, sizeof(uint32_t) * SCR_WIDTH*SCR_HEIGHT*6);
#if TARGET_OS_OSX
[indexs didModifyRange:NSMakeRange(0, indexs.length)];
#endif
I can not save the index value into the MTLBuffer. I try to debug it, I find that MTLBuffer stores a lot of float value such as 3.0*10-45, and so on. appreciate any comments.