Metal Library draw a Rect question

Why Draw a square in metal, need six vertexes but in OPenGL only need four vertexes . I want to know the principle

Answered by wcm in 171038022

OpenGL has a "quad" primitive that gets turned into a pair of triangles behind the scenes. Metal has no quad primitive. If you're drawing a single quad, you can use a triangle strip to draw it with only four vertices, achieving the same effect. If you're drawing a mesh composed of quads that share some vertices, the easiest approach is probably to use indexed drawing to draw two triangles per quad face, or triangle strips if the topology of the mesh is agreeable to being represented as strips.

Accepted Answer

OpenGL has a "quad" primitive that gets turned into a pair of triangles behind the scenes. Metal has no quad primitive. If you're drawing a single quad, you can use a triangle strip to draw it with only four vertices, achieving the same effect. If you're drawing a mesh composed of quads that share some vertices, the easiest approach is probably to use indexed drawing to draw two triangles per quad face, or triangle strips if the topology of the mesh is agreeable to being represented as strips.

So I draw a cube, I need to use the eight vertices or more. is that right?

Yes, you can draw a cube with eight vertices by using indexed drawing.

Here's how to do it... Set to triangleStrip


let texSize:Float = 0.5;

let vertexData:[Float] = [

-texSize, texSize, 0.0, //topLeft

-texSize, -texSize, 0.0, //botLeft

texSize, texSize, 0.0, //topRight

texSize, -texSize, 0.0 //botRight

]

Metal Library draw a Rect question
 
 
Q