Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: 2 questions about VertexArray / VertexBuffer  (Read 396 times)

0 Members and 1 Guest are viewing this topic.

Nafffen

  • Newbie
  • *
  • Posts: 18
    • View Profile
2 questions about VertexArray / VertexBuffer
« on: December 21, 2023, 11:13:40 am »
1. With Primitives Triangles, is there a way to specify all points then specify index of points used for each triangles ? Or the API just allows passing triangles directly by coords ?

2. With other than Triangles, is there a way to "reset" the primitive, for example with sf::TriangleFan, start a new TriangleFan in another location, but they will be drawn from the same VertexArray

Thank you

Garwin

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: 2 questions about VertexArray / VertexBuffer
« Reply #1 on: December 21, 2023, 02:34:17 pm »
You can both, look at the documentation.
void    draw (const Vertex *vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates &states=RenderStates::Default)

So you can use any container/build in array of sf::Vertex that uses continuous memory.  Just pass to draw call the pointer to the first Vertex, number of vertices, and primitive type.

But as for each PrimitiveType you need a separate draw call, it does not bring the advantage of limiting draw calls.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: 2 questions about VertexArray / VertexBuffer
« Reply #2 on: December 21, 2023, 04:58:58 pm »
1) No, I don't think SFML provides an interface for indexed vertices. You can, however, use raw OpenGL directly alongside your SFML if you really need indexing.

2) No. The primitive is set per draw call so the only ways to do that is to draw multiple (separate) triangle fans or to convert the triangle fans into triangles first.

Actually, thinking about that answer to part 2, I've just remembered that I've created an automatic function to do just that and it's on the SFML wiki here:
https://github.com/SFML/SFML/wiki/Source%3A-Triangles-Extractor

There's some extra information on an SFML thread post about it here too:
https://en.sfml-dev.org/forums/index.php?topic=29292
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: 2 questions about VertexArray / VertexBuffer
« Reply #3 on: December 25, 2023, 09:30:59 pm »
As Hapax said, we're currently not supporting indexed vertices and you can't change primitive types on the go.

With the removal of sf::Quads this causes even more pain, if you have to use sf::Triangles and duplicate vertices more than necessary, so eventually we might add indexed vertices.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything