[8/8] WineD3D: Use the source surface's texture for writing the backup

Stefan Dösinger stefan at codeweavers.com
Wed Feb 28 10:24:09 CST 2007


-------------- next part --------------
From 288f1b00b55a6427eaa9be53ab2a659a7ae6c5f4 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Wed, 28 Feb 2007 14:05:45 +0100
Subject: [PATCH] WineD3D: Use the source surface's texture for writing the backup

The hwstretch blit code creates a new texture each time it is called to back up the back buffer and
releases it afterwards. It is more efficient to keep the texture and release it with the surface. This
patch uses the source surface's texture to do the job. Because the source surface is an active render
target its texture is either only needed for blitting(onscreen target) or will be completely overwritten
on the next render target change(offscreen target).

The surface destroy code will release the opengl texture
---
 dlls/wined3d/surface.c |   34 +++++++++++++++-------------------
 1 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 8e5bd88..db0bd8f 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2251,7 +2251,7 @@ static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3D
 
 /* Uses the hardware to stretch and flip the image */
 static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWineD3DSurface *SrcSurface, IWineD3DSwapChainImpl *swapchain, WINED3DRECT *srect, WINED3DRECT *drect, BOOL upsidedown) {
-    GLuint backup, src;
+    GLuint src;
     IWineD3DDeviceImpl *myDevice = This->resource.wineD3DDevice;
     IWineD3DSurfaceImpl *Src = (IWineD3DSurfaceImpl *) SrcSurface;
     float left, right, top, bottom; /* Texture coordinates */
@@ -2266,20 +2266,18 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
     /* Backup the back buffer and copy the source buffer into a texture to draw an upside down stretched quad. If
      * we are reading from the back buffer, the backup can be used as source texture
      */
-    glGenTextures(1, &backup);
-    checkGLcall("glGenTextures(1, &backup)");
-    glBindTexture(GL_TEXTURE_2D, backup);
-    checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
+    if(Src->glDescription.textureName == 0) {
+        /* Get it a description */
+        IWineD3DSurface_PreLoad(SrcSurface);
+    }
+    glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
+    checkGLcall("glBindTexture(Src->glDescription.target, Src->glDescription.textureName)");
 
     glReadBuffer(GL_BACK);
     checkGLcall("glReadBuffer(GL_BACK)");
 
     /* TODO: Only back up the part that will be overwritten */
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Src->pow2Width, Src->pow2Height, 0,
-                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-    checkGLcall("glTexImage2D");
-
-    glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+    glCopyTexSubImage2D(Src->glDescription.target, 0,
                         0, 0 /* read offsets */,
                         0, 0,
                         fbwidth,
@@ -2287,13 +2285,13 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
 
     checkGLcall("glCopyTexSubImage2D");
 
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    glTexParameteri(Src->glDescription.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     checkGLcall("glTexParameteri");
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(Src->glDescription.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     checkGLcall("glTexParameteri");
 
-    if(!swapchain || (IWineD3DSurface *) This == swapchain->backBuffer[0]) {
-        src = backup;
+    if(!swapchain || (IWineD3DSurface *) Src == swapchain->backBuffer[0]) {
+        src = Src->glDescription.textureName;
     } else {
         glReadBuffer(GL_FRONT);
         checkGLcall("glReadBuffer(GL_FRONT)");
@@ -2370,8 +2368,8 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
     checkGLcall("glCopyTexSubImage2D");
 
     /* Write the back buffer backup back */
-    glBindTexture(GL_TEXTURE_2D, backup);
-    checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
+    glBindTexture(GL_TEXTURE_2D, Src->glDescription.textureName);
+    checkGLcall("glBindTexture(GL_TEXTURE_2D, Src->glDescription.textureName)");
 
     glBegin(GL_QUADS);
         /* top left */
@@ -2392,12 +2390,10 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
     glEnd();
 
     /* Cleanup */
-    if(src != backup) {
+    if(src != Src->glDescription.textureName) {
         glDeleteTextures(1, &src);
         checkGLcall("glDeleteTextures(1, &src)");
     }
-    glDeleteTextures(1, &backup);
-    checkGLcall("glDeleteTextures(1, &backup)");
     LEAVE_GL();
 }
 
-- 
1.4.4.3



More information about the wine-patches mailing list