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?
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.