WineD3D: Implement depth copy from onscreen to offscreen surface when depth fixup is used

Frank Richter frank.richter at gmail.com
Wed Mar 5 17:33:36 CST 2008


---
 dlls/wined3d/device.c          |    5 +++-
 dlls/wined3d/drawprim.c        |   43 +++++++++++++++++++++++++++++----------
 dlls/wined3d/wined3d_private.h |    1 +
 3 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 3f2d57e..4e8461a 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -172,6 +172,9 @@ static ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) {
         if (This->dst_fbo) {
             GL_EXTCALL(glDeleteFramebuffersEXT(1, &This->dst_fbo));
         }
+        if (This->depth_copy_fbo) {
+            GL_EXTCALL(glDeleteFramebuffersEXT(1, &This->depth_copy_fbo));
+        }
 
         This->shader_backend->shader_free_private(iface);
 
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 2ece349..79d1bf5 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -767,11 +767,6 @@ void depth_copy(IWineD3DDevice *iface) {
     /* TODO: Make this work for modes other than FBO */
     if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return;
 
-    if (depth_stencil->current_renderbuffer) {
-        FIXME("Not supported with fixed up depth stencil\n");
-        return;
-    }
-
     if (This->render_offscreen) {
         GLint old_binding = 0;
 
@@ -783,7 +778,8 @@ void depth_copy(IWineD3DDevice *iface) {
 
         /* 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));
+        if (!depth_stencil->current_renderbuffer)
+            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
         glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
         glBindTexture(GL_TEXTURE_2D, This->depth_blt_texture);
         glCopyTexImage2D(depth_stencil->glDescription.target,
@@ -799,11 +795,36 @@ void depth_copy(IWineD3DDevice *iface) {
         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()");
-        depth_blt(iface, This->depth_blt_texture);
-        checkGLcall("depth_blt");
+        if (depth_stencil->current_renderbuffer)
+        {
+            /* Set up an FBO with the actual depth render target attached */
+            if (!This->depth_copy_fbo)
+                GL_EXTCALL(glGenFramebuffersEXT(1, &This->depth_copy_fbo));
+            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, This->depth_copy_fbo));
+            checkGLcall("glBindFramebuffer()");
+	    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, depth_stencil->glDescription.target, depth_stencil->glDescription.textureName, depth_stencil->glDescription.level));
+            checkGLcall("glFramebufferTexture2DEXT()");
+            glDrawBuffer(GL_NONE);
+            glReadBuffer(GL_NONE);
+	    depth_blt(iface, This->depth_blt_texture);
+	    checkGLcall("depth_blt");
+	    /* Restore actual FBO */
+            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, This->fbo));
+            checkGLcall("glBindFramebuffer()");
+        }
+        else
+        {
+            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, This->fbo));
+            checkGLcall("glBindFramebuffer()");
+	    depth_blt(iface, This->depth_blt_texture);
+	    checkGLcall("depth_blt");
+        }
     } else {
+	if (depth_stencil->current_renderbuffer) {
+	    FIXME("Not supported with fixed up depth stencil\n");
+	    return;
+	}
+
         TRACE("Copying offscreen surface to onscreen depth buffer\n");
 
         GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 8084d83..f0b8c1c 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -779,6 +779,7 @@ struct IWineD3DDeviceImpl
     GLuint                  dst_fbo;
     GLenum                  *draw_buffers;
     GLuint                  depth_blt_texture;
+    GLuint                  depth_copy_fbo;
 
     /* Cursor management */
     BOOL                    bCursorVisible;
-- 
1.5.2.5


--------------070002040800080407090601--



More information about the wine-patches mailing list