[2/2] wined3d: Use GL_EXT_framebuffer_blit for framebuffer->texture blits in BltOverride

Fabian Bieler der.fabe at gmx.net
Thu Apr 5 15:52:57 CDT 2007


-------------- next part --------------
From b369a9384beb831dfae6460418d861f30a9cef3e Mon Sep 17 00:00:00 2001
From: Fabian Bieler <der.fabe at gmx.net>
Date: Thu, 5 Apr 2007 21:52:44 +0200
Subject: [PATCH] wined3d: Use GL_EXT_framebuffer_blit for framebuffer->texture blits in BltOverride

---
 dlls/wined3d/surface.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 21ac153..9566aad 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2265,6 +2265,43 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_Flip(IWineD3DSurface *iface, IWineD3DS
     return IWineD3DDevice_Present(D3D, NULL, NULL, 0, NULL);
 }
 
+/* Does a frame buffer -> texture blit. */
+static inline void fb_copy_to_texture_framebuffer_blit(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface,
+        IWineD3DSwapChainImpl *swapchain, WINED3DRECT *srect, WINED3DRECT *drect, BOOL upsidedown) {
+    static GLuint tmp_fbo = 0;
+    GLint old_binding;
+
+    ENTER_GL();
+
+    if(!tmp_fbo)
+        glGenFramebuffersEXT(1, &tmp_fbo);
+
+    glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &old_binding);
+    GL_EXTCALL(glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, tmp_fbo));
+    checkGLcall("glBindFramebuffer()");
+    GL_EXTCALL(glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D,
+               This->glDescription.textureName, 0));
+    checkGLcall("glFramebufferTexture2D()");
+
+    if(upsidedown) {
+        GL_EXTCALL(glBlitFramebufferEXT(srect->x1, srect->y1, srect->x2, srect->y2,
+                                        drect->x1, drect->y1, drect->x2, drect->y2,
+                                        GL_COLOR_BUFFER_BIT, GL_NEAREST));
+    } else {
+        GL_EXTCALL(glBlitFramebufferEXT(srect->x1, srect->y1, srect->x2, srect->y2,
+                                        drect->x1, drect->y2, drect->x2, drect->y1,
+                                        GL_COLOR_BUFFER_BIT, GL_NEAREST));
+    }
+    checkGLcall("glBlitFramebuffer()");
+
+    GL_EXTCALL(glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0));
+    checkGLcall("glFramebufferTexture2D()");
+    GL_EXTCALL(glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, old_binding));
+    checkGLcall("glBindFramebuffer()");
+
+    LEAVE_GL();
+}
+
 /* Does a direct frame buffer -> texture copy. Stretching is done
  * with single pixel copy calls
  */
@@ -2693,8 +2730,7 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         }
 
         /* Blt is a pretty powerful call, while glCopyTexSubImage2D is not. glCopyTexSubImage cannot
-         * flip the image nor scale it. If GL_EXT_framebuffer_blit is available it can be used(hopefully,
-         * not implemented by now). Otherwise:
+         * flip the image nor scale it. If GL_EXT_framebuffer_blit is available it can be used. Otherwise:
          *
          * -> If the app asks for a unscaled, upside down copy, just perform one glCopyTexSubImage2D call
          * -> If the app wants a image width an unscaled width, copy it line per line
@@ -2704,8 +2740,9 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
          * -> If the app wants a scaled image with a dest rect that is bigger than the fb, it has to be copied
          *    pixel by pixel
          */
-        if(FALSE /* GL_SUPPORT(EXT_FRAMEBUFFER_BLIT) */) {
+        if(GL_SUPPORT(EXT_FRAMEBUFFER_BLIT)) {
             TRACE("Using GL_EXT_framebuffer_blit for copying\n");
+            fb_copy_to_texture_framebuffer_blit(This, SrcSurface, srcSwapchain, &srect, &rect, upsideDown);
         } else if((!stretchx) || rect.x2 - rect.x1 > Src->currentDesc.Width ||
                                     rect.y2 - rect.y1 > Src->currentDesc.Height) {
             TRACE("No stretching in x direction, using direct framebuffer -> texture copy\n");
-- 
1.4.4.1



More information about the wine-patches mailing list