iphone - What is the equivalent of GL_TRIANGLE_STRIP in Metal for iOS? -


trying draw strip of triangles illustrated here:

gl_triangle_strip

completed objc.io tutorial, draw quad using 2 triangles. triangles disconnected , drawn individually, meaning need specify 6 vertices instead of 4.

// interleaved vertex data x,y,z,w,  r,g,b,a static float vertexdata[] = {     // first triangle: bottom right, clockwise      0.5, -0.5, 0.0, 1.0,     1.0, 0.0, 0.0, 1.0, // bottom right     -0.5, -0.5, 0.0, 1.0,     0.0, 1.0, 0.0, 1.0, // bottom left     -0.5,  0.5, 0.0, 1.0,     0.0, 0.0, 1.0, 1.0, // top left      // second triangle: top right, clockwise      0.5,  0.5, 0.0, 1.0,     1.0, 1.0, 0.0, 1.0, // top right      0.5, -0.5, 0.0, 1.0,     1.0, 0.0, 0.0, 1.0, // bottom right     -0.5,  0.5, 0.0, 1.0,     0.0, 0.0, 1.0, 1.0, // top left }; 

is there way draw strip in opengl es without duplicating vertices?

the short answer this:

renderencoder.drawprimitives(mtlprimitivetype.trianglestrip, vertexstart: 0, vertexcount: 6) 

it's equivalent gl_triangle_strip.

also may want use indexed drawing, load each vertex once, , after need use array of vertex indices specify draw order. way save data not specifying duplicated vertices.

here's call indexed drawing.

renderencoder.drawindexedprimitives(submesh.primitivetype, indexcount: submesh.indexcount, indextype: submesh.indextype, indexbuffer: submesh.indexbuffer.buffer, indexbufferoffset: submesh.indexbuffer.offset) 

cheers!


Comments