1

I'd like to implement a level of detail algorithm for my polygons into my 3d engine. What I got is the following:

1. An entity with multiple amounts of polygons, e.g.:

House: 

1. -Entity1:   10000 polygons            viewrange[0,100]
2. -Entity1:   5000  polygons            viewrange[100,300]
3. -Entity1:   800   polygons            viewrange[300,1000]
4. -Entity1:   100   polygons            viewrange[1000,infinity]

Usually, I would create a new VAO including the VBO's for each Entity but is there a smarter way of implementing this? Could I use only one single VAO and adjust the level of detail by changing the indices buffer?

I created an example. I am dealing with terrain grids at the moment and need to apply LoD to them:

Example for different indices buffer, but how would I swap them? Is that efficient?

What is the best way for implementing LoD in OpenGL? Do I need multiple VAO's or is one VAO enough?

Luecx
  • 160
  • 1
  • 12

1 Answers1

2

You can store both, the data and the indexing information in one VAO. If you add together all the indices in one buffer, you can adjust which level you want to draw by specifying the start index and the amount of indices in the draw command.

For your example, you would create a index buffer with 30 indices, where index 0-5 is for level 1, 6-29 for level 2. You can then draw level 1 by calling:

glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

and level 2 by calling:

glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, (void*)(6 * sizeof(GLuint)));

Note, that this method requires you to have all the levels in storage at all time. This might, depending on your needs, not be what you want.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • That sounds good. But what method would be more efficient if I have terrain grids where the highest LOD is at around 256x256 vertices? Would you still store all of them in one buffer or start using multiple VAOs? – Luecx Jul 16 '17 at 09:52
  • 1
    If I have a terrain consisting of a regular grid, then I would go for dynamic tessellation by using a tessellation shader. Especially for a terrain, you'll need more details closer to the camera anyway. About multiple VAOs: In the end it boils down to: Do you want to load all data in the beginning or do you want to load and delete levels from memory when they are not necessary. – BDL Jul 16 '17 at 09:56
  • I might generate the terrain procedural. But I am not sure about that yet. Would it make a big difference? – Luecx Jul 16 '17 at 09:59
  • It depends :). If your terrain generation algorithm is fast enough to generate it on the fly -> tessellation shader and implement it there. If it is too slow -> generate a heightmap offline and use that. If terrain cannot be represented by heightmap (which I doubt because that would require something more complex than a regular grid as basis) -> tile it up and stream tiles from HD (or main memory). – BDL Jul 16 '17 at 10:03
  • Next time try to ask the real question in first place. "How can I handle level-of-detail for a procedural terrain?" is quite different from "Do I need multiple VAOs to store multiple levels?". – BDL Jul 16 '17 at 10:04
  • Why would I use a height map? Why not apply the height map to the grid before loading it into my VAO? Yeah you are right, sorry for that :) – Luecx Jul 16 '17 at 10:04