c++sfmlvertex-array

Combining Primitives in SFML Vertex Arrays


The documentation for SFML states that you can combine primitives to create vertex arrays. I think what they are referring to is the fact that multiple Triangles can be grouped into a TriangleFan or TriangleStrip.

I'm wondering whether there is a way to combine two existing primitive types in a single vertex array. For example, could I define a bunch of vertices as a TriangleFan and then switch over to a LineStrip ? Or would this require two separate arrays?


Solution

  • No, you can only use one primitive type per vertex array.

    With the following draw function you could theoretically use one array/vector (not sf::VertexArray and provide different offsets and sizes to draw different parts of the array with different primitive types, but that's effectively the same thing as using two different arrays and thus you'll need to ask yourself what the gain is in mixing these vertices together.

    void draw(const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default)