0
\$\begingroup\$

I am eyeing OpenVG and cairo as rendering libraries for my pet game GUI. You can use both to render either into a texture or issue GL commands to draw directly onto the display. If I would use them directly, there are the following issues:

  • they will mess with GL state, which can be a problem, if it happens every frame,
  • their code will be executed every frame, if the GUI is drawn directly, but the GUI textures would be updated only when game state changes.

For this reasons I think I should be rendering the GUI into texture(s), but I'm asking here just to be sure.

\$\endgroup\$
1
\$\begingroup\$

They have their benefits and drawbacks so you may want to try both to see if performance matters. I was initially going to render everything in but the performance for me on PC platform does not seem to matter.

Keep in mind there is a third option though, you can render your GUI into images within the image itself. So you would draw all the text into the GUI elements when you load up the game. That way you get the flexibility and multilanguage potential without the performance drawback.

To start out I would avoid rendering into the textures, then if you need it either do that or choose the third option.

\$\endgroup\$
1
\$\begingroup\$

A GUI framework should behave efficiently when nothing changes between frames. You can render-to-texture as one way to achieve this, but there are others, like state caching, or keeping the generated rendering commands from the last frame.

The concern about the GUI "messing" with GL state is not really relevant. The state must be restored correctly, no matter how often it is changed, and toggling depth writes and culling is not a performance killer. Switching shaders has some performance impact, but a GUI should use a single shader, so this should be manageable.

The case where I think render-to-texture is justified is where a GUI draw might be expected to take longer than your normal frame budget. In that case, for several frames, you switch into GL GUI state, render a pass to a texture, and switch out of GL GUI state, only showing the result to the user when the expensive draw is complete.

\$\endgroup\$

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.