Few months ago, I got annoy that we had some code that translate API independent enumerations to OpenGL enumerations, back and forth, with basically no consideration at what happens when we add a new enumeration value in the API independent enumerations and no consideration of how this translation would perform within the rendering loop, where performance is critical and it's typically going to be called. Considering the high number of translations per frame, probably it starts to matter.
Well, we know how things rise... It turns out as this 27 pages article that I called Robust and efficient translations in C++ using tables with zero-based enumerations which is nothing revolutionnary but maybe somewhat useful.
It's pretty common to read some stipulations about how the compilers are supposed to optimize the code. On cross-compiler environments, the following charts from the article are wishing us good luck with such ideas! The four implementation methods are described in the full article.
X: number values per enumeration ; Y: ms.
For the once who doesn't want to go through the 27 pages, here is the base solution we propose for enumeration translations.
This template can be extended in many ways to better fit the need of the scenarios where it used as described in the full article.
Enjoy!
Thanks to Stephanie Hurlburt for the review.