[2/2] wined3d: Restore texture bindings in the FBO code

H. Verbeet hverbeet at gmail.com
Mon Dec 25 10:12:50 CST 2006


Previously all textures were (re)bound each DrawPrimitive call. With
the new state management only dirty textures are bound, so we need to
restore the texture binding if we change it.

Changelog:
  - Restore texture bindings in the FBO code
-------------- next part --------------
---

 dlls/wined3d/device.c   |    8 ++++++--
 dlls/wined3d/drawprim.c |    7 +++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 1c1abab..3ff851a 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -5840,16 +5840,18 @@ static void set_depth_stencil_fbo(IWineD
 
     if (depth_stencil_impl) {
         GLenum texttarget, target;
+        GLint old_binding = 0;
 
         IWineD3DSurface_PreLoad(depth_stencil);
         texttarget = depth_stencil_impl->glDescription.target;
         target = texttarget == GL_TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP_ARB;
 
+        glGetIntegerv(texttarget == GL_TEXTURE_2D ? GL_TEXTURE_BINDING_2D : GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding);
         glBindTexture(target, depth_stencil_impl->glDescription.textureName);
         glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
-        glBindTexture(target, 0);
+        glBindTexture(target, old_binding);
 
         GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, texttarget, depth_stencil_impl->glDescription.textureName, 0));
         checkGLcall("glFramebufferTexture2DEXT()");
@@ -5876,15 +5878,17 @@ static void set_render_target_fbo(IWineD
 
     if (rtimpl) {
         GLenum texttarget, target;
+        GLint old_binding = 0;
 
         IWineD3DSurface_PreLoad(render_target);
         texttarget = rtimpl->glDescription.target;
         target = texttarget == GL_TEXTURE_2D ? GL_TEXTURE_2D : GL_TEXTURE_CUBE_MAP_ARB;
 
+        glGetIntegerv(texttarget == GL_TEXTURE_2D ? GL_TEXTURE_BINDING_2D : GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding);
         glBindTexture(target, rtimpl->glDescription.textureName);
         glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
         glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-        glBindTexture(target, 0);
+        glBindTexture(target, old_binding);
 
         GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + idx, texttarget, rtimpl->glDescription.textureName, 0));
         checkGLcall("glFramebufferTexture2DEXT()");
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index a1992c4..7e897f1 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -1849,6 +1849,7 @@ static void check_fbo_status(IWineD3DDev
 
 static void depth_blt(IWineD3DDevice *iface, GLuint texture) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    GLint old_binding = 0;
 
     glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT);
 
@@ -1860,6 +1861,7 @@ static void depth_blt(IWineD3DDevice *if
     glDepthFunc(GL_ALWAYS);
 
     GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
+    glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
     glBindTexture(GL_TEXTURE_2D, texture);
     glEnable(GL_TEXTURE_2D);
 
@@ -1872,6 +1874,8 @@ static void depth_blt(IWineD3DDevice *if
     glVertex2f(1.0f, 1.0f);
     glEnd();
 
+    glBindTexture(GL_TEXTURE_2D, old_binding);
+
     glPopAttrib();
 }
 
@@ -1887,6 +1891,7 @@ static void depth_copy(IWineD3DDevice *i
 
     if (This->render_offscreen) {
         static GLuint tmp_texture = 0;
+        GLint old_binding = 0;
 
         TRACE("Copying onscreen depth buffer to offscreen surface\n");
 
@@ -1897,6 +1902,7 @@ static void depth_copy(IWineD3DDevice *i
         /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
          * directly on the FBO texture. That's because we need to flip. */
         GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
+        glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
         glBindTexture(GL_TEXTURE_2D, tmp_texture);
         glCopyTexImage2D(depth_stencil->glDescription.target,
                 depth_stencil->glDescription.level,
@@ -1909,6 +1915,7 @@ static void depth_copy(IWineD3DDevice *i
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
+        glBindTexture(GL_TEXTURE_2D, old_binding);
 
         GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, This->fbo));
         checkGLcall("glBindFramebuffer()");


More information about the wine-patches mailing list