Ok, thank you and Roderick for useful info. I figure that my previous patch wasn't ideal, unfortunately it introduced one more of such recursive ENTERGL / ActivateContext situations. I'll try to improve that and send another patch.
Regarding moving code around - I wish I was so competent in Direct3D and OpenGL to freely move code around in wined3d etc :). Hopefully, wine hacking may improve my grasp on it, but at the moment that's probably over my head. If you don't object, I'll do basic stuff, like putting additional LEAVE_GL/ENTER_GL in my own recent change to _BltOverride and wherever else I find similar problem, and maybe I'll look into possible redundance of glDrawBuffer call Roderick mentioned.
Also may be worth to think if it's reasonable to put a substantial amount of effort into eliminating a few redundant gl* calls or a LEAVE_GL/ENTER_GL block now (then possibly also hunting regressions), when there are major problems like crashes etc. Say, to use Aliens vs Predator 2 game as an illustration - despite now one can at least get into the game proper (i.e. load a level), it's still largerly unusable because of a dinput bug and terrible performance (some fog-related software emulation fixme - I'll probably submit this to bugzilla).
Stefan Dösinger wrote:
Am Montag, 10. Dezember 2007 18:39:49 schrieb Alexander Dorofeyev:
Hello.
I was recently experimenting with a fix that involved ActivateContext and needed to figure out whether it is ok if ActivateContext is called inside ENTER_GL()... LEAVE_GL() (also if recursive ENTER_GL is ok). At first I tried to look for example code in wined3d/surface.c, which seemed to indicate this is ok, because it obviously seems to happen in one or few places. Then I found this
ActivateContext inside ENTER_GL() and LEAVE_GL() is *not* ok, but it happens in quite a few places unfortunately. The problem this causes is stated in this bugreport. ActivateContext can call GDI calls, and they can deadlock if called between ENTER_GL and LEAVE_GL.
The example with BindTexture you gave is the main problem indeed, patches like that are a way forward. However, instead of just adding a LEAVE_GL() and ENTER_GL() it should be checked if this can be avoided by moving code around a bit. Be warned that there are a few other troubles with ActivateContext and gl calls as well, for example fbo setup vs ActivateContext