Hello. I've got a problem with swapping shaders in one render. I am rendering HUD (2d user inteface over previously rendered 3d scene). The structure is not complex, tree-like: there are multiple movable windows containing texture background and optinally some textboxes, buttons, radiobuttons and statictexts (each widget type having own dedicated shader). The gui windows may overlap eachother (one used last should be on top of previous).
So the rendering works like this - interate over the list of windows (which are sorted from back to front) and render each. Rendering single window - use button shader, set uniforms, render all buttons, then use textbox shader, set uniforms, render all texboxes, use statictext shader, set uniforms render all etc...
As you can see i am rebinding the same shader multiple multiple times during one render. But i kind of have to? I cannot find another solution. If i render all buttons first and then for example textboxes, the textbox from window behind can overwrite previously draw button from front window. The depth test is obviously disabled for HUD rendering (what i draw last is on front). Actually maybe that's the solution to use depth buffer in some tricky way (bumped onto it while writin the post)?
Thanks for all suggestions