From 94cd8656ea123420b31826231a6d8b8ae3347ad5 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 25 Jun 2009 10:24:56 +0200 Subject: [PATCH] wined3d: Make context_resource_released() responsible for activating a different GL context. In case lastActiveRenderTarget is destroyed. --- dlls/wined3d/context.c | 47 ++++++++++++++++++++++++++++++++++++++++++ dlls/wined3d/device.c | 35 ++----------------------------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c index 81bddb18c22..5b3cecb9828 100644 --- a/dlls/wined3d/context.c +++ b/dlls/wined3d/context.c @@ -426,6 +426,53 @@ void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource { case WINED3DRTYPE_SURFACE: { + if ((IWineD3DSurface *)resource == This->lastActiveRenderTarget) + { + IWineD3DSwapChainImpl *swapchain; + + TRACE("Last active render target destroyed.\n"); + + /* Find a replacement surface for the currently active back + * buffer. The context manager does not do NULL checks, so + * switch to a valid target as long as the currently set + * surface is still valid. Use the surface of the implicit + * swpchain. If that is the same as the destroyed surface the + * device is destroyed and the lastActiveRenderTarget member + * shouldn't matter. */ + swapchain = This->swapchains ? (IWineD3DSwapChainImpl *)This->swapchains[0] : NULL; + if (swapchain) + { + if (swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource) + { + TRACE("Activating primary back buffer.\n"); + ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD); + } + else if (!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource) + { + /* Single buffering environment */ + TRACE("Activating primary front buffer.\n"); + + ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD); + } + else + { + /* Implicit render target destroyed, that means the + * device is being destroyed whatever we set here, it + * shouldn't matter. */ + TRACE("Device is being destroyed, setting lastActiveRenderTarget to 0xdeadbabe.\n"); + + This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe; + } + } + else + { + WARN("Render target set, but swapchain does not exist!\n"); + + /* May happen during ddraw uninitialization. */ + This->lastActiveRenderTarget = (IWineD3DSurface *)0xdeadcafe; + } + } + for (i = 0; i < This->numContexts; ++i) { WineD3DContext *context = This->contexts[i]; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 48d49a8ca64..3ad0625df33 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -7327,39 +7327,8 @@ void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resour case WINED3DRTYPE_SURFACE: { unsigned int i; - /* Cleanup any FBO attachments if d3d is enabled */ - if(This->d3d_initialized) { - if((IWineD3DSurface *)resource == This->lastActiveRenderTarget) { - IWineD3DSwapChainImpl *swapchain = This->swapchains ? (IWineD3DSwapChainImpl *) This->swapchains[0] : NULL; - - TRACE("Last active render target destroyed\n"); - /* Find a replacement surface for the currently active back buffer. The context manager does not do NULL - * checks, so switch to a valid target as long as the currently set surface is still valid. Use the - * surface of the implicit swpchain. If that is the same as the destroyed surface the device is destroyed - * and the lastActiveRenderTarget member shouldn't matter - */ - if(swapchain) { - if(swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource) { - TRACE("Activating primary back buffer\n"); - ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD); - } else if(!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource) { - /* Single buffering environment */ - TRACE("Activating primary front buffer\n"); - ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD); - } else { - TRACE("Device is being destroyed, setting lastActiveRenderTarget = 0xdeadbabe\n"); - /* Implicit render target destroyed, that means the device is being destroyed - * whatever we set here, it shouldn't matter - */ - This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe; - } - } else { - /* May happen during ddraw uninitialization */ - TRACE("Render target set, but swapchain does not exist!\n"); - This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadcafe; - } - } - + if (This->d3d_initialized) + { for (i = 0; i < GL_LIMITS(buffers); ++i) { if (This->render_targets[i] == (IWineD3DSurface *)resource) { This->render_targets[i] = NULL;