Page 1 of 1

Need help understanding the engine's texture code

PostPosted: Mon Feb 11, 2019 3:59 pm
by Korshun
We have decided to fork GZDoom 3.7.2 to improve performance in The Forestale by implementing a leaner and faster renderer that doesn't support unneeded features. Its code will, of course, be released along with the game. We have commented out all OpenGL calls in GZDoom except those in FHardwareTexture::CreateTexture.

Unfortunately, there is a bug we can't figure out because of how complex GZDoom's texture system is. There are dozens of texture-related classes and it's mind-boggling, which is understandable, considering how many features the texture system supports, including but not limited to texture composing, HD texture replacements, transparently converting between palletized and truecolor formats, translations, font recoloring. I'd appeciate an explanation of how these classes are structured.

We have a problem with font recoloring. Fonts in The Forestale all have truecolor HD replacements. Untranslated fonts render fine, but all translated colorings of a multi-lump font glyph return the same HD texture with messed up colors. All those colors belong to the palette. Perhaps some GZDoom developer can tell what could cause such a bug. Any help is greatly appreciated.


Menu icons are all in a font with HD replacements. Menu items are single-character strings using that font. The third item's HD replacement has been replaced with a 256x256 horizontal gradient from RGB(0, 0, 0) to RGB(255, 255, 255) for test purposes. Menu items are untranslated by default. The selected menu item is colored green.

Spoiler: GZDoom correctly recoloring menu items and text

Spoiler: Custom renderer receiving translated textures with messed up colors

The following code is used to obtain an OpenGL texture ID from an FTexture. Is it correct?
Spoiler: GetTextureID

And when rendering the text:
Spoiler: Obtaining translation ID from RenderCommand

I'd also like to know what that "int translation" is and if there is more than one way to refer to translations by numbers, whether these translation IDs are global or only relevant to a single font/texture.

Re: Need help understanding the engine's texture code

PostPosted: Mon Feb 11, 2019 4:06 pm
by Graf Zahl
Hard to tell without knowing what you did to the code. Apparently you removed something that's still needed.

Overall, I have my doubts that you can make the renderer really faster. The biggest roadblocks are in code that isn't really optimizable anymore, outside the engine's control in the driver or would be sufficiently detrimental to the engine's features.

Re: Need help understanding the engine's texture code

PostPosted: Mon Feb 11, 2019 5:27 pm
by Korshun
Actually, there is a simpler and more important question: I just plain don't understand what font coloring does to colors. I tried shader-based recolorings and recolorings in Photoshop, and none yield the same beautiful results as GZDoom's text coloring. Even knowing how the recoloring works in the first place would be nice to find the cause of that bug or replicate the recoloring manually.

Re: Need help understanding the engine's texture code

PostPosted: Mon Feb 11, 2019 6:30 pm
by Graf Zahl
The font coloring applies a palette translation, the calculations for that are in v_font.cpp.
So if you have modified anything about translated texture management, that's where to look. And if you changed anything there, best revert it, that stuff has virtually no impact on performance.

Re: Need help understanding the engine's texture code

PostPosted: Tue Feb 12, 2019 3:51 pm
by Korshun
Thanks for pointing at v_font.cpp. Didn't know that the text recoloing system is quite separated from the rest of texture code. That's quite a lot of code and it's hard to understand. But I found out that the text recoloring algorithm is described here: and it doesn't depend on any palette. I still don't understand how the palette figures in all this, but it doesn't matter because I have implemented the same algorithm in a fragment shader with acceptable results.