4 Replies
      Latest reply on Jan 2, 2020 8:56 AM by Introspector
      dacheng Level 1 Level 1 (0 points)

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

        • Re: Metal Library draw a Rect question
          wcm Apple Staff Apple Staff (335 points)

          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.

          • Re: Metal Library draw a Rect question
            Introspector Level 1 Level 1 (0 points)

            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