WineD3D: Blitting to offscreen target

Stefan Dösinger stefandoesinger at gmx.at
Wed Mar 14 16:05:47 CDT 2007


-------------- next part --------------
From e77fe55f978e619715ac310d22befbb86735b04f Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Wed, 14 Mar 2007 22:00:31 +0100
Subject: [PATCH] WineD3D: Blitting to offscreen target

This patch fixes the NULL deref that occured when blitting to offscreen
targets and selects the proper gl drawing buffer instead.
---
 dlls/wined3d/device.c  |    2 +-
 dlls/wined3d/surface.c |   20 ++++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 460a255..23e9341 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -690,7 +690,7 @@ static HRESULT  WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
     object->pow2Height = pow2Height;
 
     /* Flags */
-    object->Flags      = 0; /* We start without flags set */
+    object->Flags      = SFLAG_DYNLOCK | 0; /* We start without flags set */
     object->Flags     |= (pow2Width != Width || pow2Height != Height) ? SFLAG_NONPOW2 : 0;
     object->Flags     |= Discard ? SFLAG_DISCARD : 0;
     object->Flags     |= (WINED3DFMT_D16_LOCKABLE == Format) ? SFLAG_LOCKABLE : 0;
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 30ae169..a295bc7 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2637,7 +2637,6 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         DWORD oldCKeyFlags = Src->CKeyFlags;
         DDCOLORKEY oldBltCKey = This->SrcBltCKey;
         RECT SourceRectangle;
-        GLint oldDraw;
 
         TRACE("Blt from surface %p to rendertarget %p\n", Src, This);
 
@@ -2687,11 +2686,17 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         /* Activate the destination context, set it up for blitting */
         ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
 
-        glGetIntegerv(GL_DRAW_BUFFER, &oldDraw);
-        if(This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer) {
+        if(!dstSwapchain) {
+            TRACE("Drawing to offscreen buffer\n");
+            glDrawBuffer(myDevice->offscreenBuffer);
+        } else if(This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer) {
             TRACE("Drawing to front buffer\n");
             glDrawBuffer(GL_FRONT);
             checkGLcall("glDrawBuffer GL_FRONT");
+        } else {
+            TRACE("Drawing to back buffer\n");
+            glDrawBuffer(GL_BACK);
+            checkGLcall("glDrawBuffer GL_BACK");
         }
 
         /* Bind the texture */
@@ -2722,7 +2727,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         }
 
         /* Draw a textured quad
-            */
+         */
         glBegin(GL_QUADS);
 
         glColor3d(1.0f, 1.0f, 1.0f);
@@ -2755,8 +2760,11 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         glBindTexture(GL_TEXTURE_2D, 0);
         checkGLcall("glEnable glBindTexture");
 
-        if(This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer && oldDraw == GL_BACK) {
-            glDrawBuffer(oldDraw);
+        /* The draw buffer should only need to be restored if we were drawing to the front buffer, and there is a back buffer.
+         * otherwise the context manager should choose between GL_BACK / offscreenDrawBuffer
+         */
+        if(dstSwapchain && This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer && dstSwapchain->backBuffer) {
+            glDrawBuffer(GL_BACK);
         }
         /* Restore the color key parameters */
         Src->CKeyFlags = oldCKeyFlags;
-- 
1.4.4.3



More information about the wine-patches mailing list