1
\$\begingroup\$

I have terrain separated by chunks and I would like to put environment (For example, rocks, trees, etc..) in each chunk randomly.

My question is related to how to implement such system in OpenGL.

What I have tried:

  1. Solution: Draw the environment with instancing once for all the terrain (not a specific chunk)

    Problem: I except the chunk to sometimes take a bit to load and because I am using threads the environment will appear as floating.

  2. Solution: Draw the environment with instancing for each chunk.

    Problem: To draw each chunk, I will need to bind the VBO for the chunk, draw the chunk, bind the VBO for the environment (and the VAO probably) and draw it.

    I don't want to put so many glBindBuffer functions because I heard it is slow (Please correct me if I am wrong)

  3. (Not tried) Solution: Somehow merge the vertices of the terrain with its environment and draw them together.

    Problem: My terrain is drawn with GL_TRIANGLE_STRIP so this is a first problem, the second problem(?) is that I don't know how well it will function (talking speed).

I tried looking up solutions on the internet but didn't seem to find any that relate to chunks.

Anyone know how other games that uses chunks do that? Is there a way to do it without causing a lot of speed decrease?

\$\endgroup\$
  • 4
    \$\begingroup\$ "I heard it is slow" is usually not a great guide for optimization. To make good decisions and not prematurely optimize, we need to know how slow. The best way to learn that is to set up a simple test and profile it. You may find it's slow in the sense of "avoid doing this thousands of times" rather than "avoid doing this even twice" ;) \$\endgroup\$ – DMGregory Apr 16 '17 at 13:29
  • \$\begingroup\$ "I will need to bind the VBO for the chunk, draw the chunk, bind the VBO for the environment (and the VAO probably)" If you have a VAO, you don't need to bind any VBO to draw it. \$\endgroup\$ – HolyBlackCat Apr 17 '17 at 17:38
  • \$\begingroup\$ @HolyBlackCat I do need to bind the VBO, because each chunk as it's own environment VBO. \$\endgroup\$ – JohnMiz Apr 18 '17 at 10:13
  • \$\begingroup\$ Pardon me, I assumed that you have a single VBO per VAO. If not, then you have to rebind proper VBOs indeed. \$\endgroup\$ – HolyBlackCat Apr 18 '17 at 17:17
1
\$\begingroup\$

The correct answer depends on the amount of chunks you have. If you have very few of them, the overhead of multiple drawing calls will be negigible and you should opt for better design instead. Otherwise, you could use the single call solution, maybe adding a sync point that would ensure no assets flying in the final rendering. The sweet spot where the amount of chunks is favourable to a specific solution is only known with proper profiling.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You said that if I have few chunks it would be negligible so why do I need to find better design? What do you mean by single draw call? (Do you mean single draw call every chunk which bundles the terrain and the environment?) And what do you mean by sync point? I didn't really get that. \$\endgroup\$ – JohnMiz Apr 18 '17 at 10:30
  • 1
    \$\begingroup\$ I said that you should go for the option with the best design when optimization is not worth it. That is a general rule of thumb in programming, since optimization is usually related with less manageable code. Both per chunk or global single call solutions have the drawback of coupling the environment with the terrain. You should only opt for these if the performance benefit surpass the work of maintaining these strucutres. The sync that I mentioned is a technique for thead sync, such as locks or atomic operations. \$\endgroup\$ – dsilva.vinicius Apr 18 '17 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.