Stefan Dösinger : wined3d: De-Statify depth blit opengl resources.

Alexandre Julliard julliard at winehq.org
Tue Feb 5 06:34:56 CST 2008


Module: wine
Branch: master
Commit: 3d2aa7afa064595e9481b0cdf10c42b51b700f2f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3d2aa7afa064595e9481b0cdf10c42b51b700f2f

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Sun Jan 27 14:32:40 2008 +0100

wined3d: De-Statify depth blit opengl resources.

---

 dlls/wined3d/arb_program_shader.c |   25 +++++++++++++++++++------
 dlls/wined3d/baseshader.c         |    2 ++
 dlls/wined3d/device.c             |   10 +++++++++-
 dlls/wined3d/drawprim.c           |    9 ++++-----
 dlls/wined3d/glsl_shader.c        |   20 +++++++++++++++-----
 dlls/wined3d/wined3d_private.h    |    5 +++++
 6 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 2117d13..84516c3 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -1713,18 +1713,30 @@ static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
 static void shader_arb_select_depth_blt(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
-    static GLuint vprogram_id = 0;
-    static GLuint fprogram_id = 0;
 
-    if (!vprogram_id) vprogram_id = create_arb_blt_vertex_program(gl_info);
-    GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vprogram_id));
+    if (!This->depth_blt_vprogram_id) This->depth_blt_vprogram_id = create_arb_blt_vertex_program(gl_info);
+    GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, This->depth_blt_vprogram_id));
     glEnable(GL_VERTEX_PROGRAM_ARB);
 
-    if (!fprogram_id) fprogram_id = create_arb_blt_fragment_program(gl_info);
-    GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fprogram_id));
+    if (!This->depth_blt_fprogram_id) This->depth_blt_fprogram_id = create_arb_blt_fragment_program(gl_info);
+    GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, This->depth_blt_fprogram_id));
     glEnable(GL_FRAGMENT_PROGRAM_ARB);
 }
 
+static void shader_arb_destroy_depth_blt(IWineD3DDevice *iface) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+
+    if(This->depth_blt_vprogram_id) {
+        GL_EXTCALL(glDeleteProgramsARB(1, &This->depth_blt_vprogram_id));
+        This->depth_blt_vprogram_id = 0;
+    }
+    if(This->depth_blt_fprogram_id) {
+        GL_EXTCALL(glDeleteProgramsARB(1, &This->depth_blt_fprogram_id));
+        This->depth_blt_fprogram_id = 0;
+    }
+}
+
 static void shader_arb_cleanup(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
@@ -1747,6 +1759,7 @@ static void shader_arb_destroy(IWineD3DBaseShader *iface) {
 const shader_backend_t arb_program_shader_backend = {
     &shader_arb_select,
     &shader_arb_select_depth_blt,
+    &shader_arb_destroy_depth_blt,
     &shader_arb_load_constants,
     &shader_arb_cleanup,
     &shader_arb_color_correction,
diff --git a/dlls/wined3d/baseshader.c b/dlls/wined3d/baseshader.c
index f4c101f..e06d7f7 100644
--- a/dlls/wined3d/baseshader.c
+++ b/dlls/wined3d/baseshader.c
@@ -1098,6 +1098,7 @@ void shader_trace_init(
 
 static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
 static void shader_none_select_depth_blt(IWineD3DDevice *iface) {}
+static void shader_none_destroy_depth_blt(IWineD3DDevice *iface) {}
 static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
 static void shader_none_cleanup(IWineD3DDevice *iface) {}
 static void shader_none_color_correction(SHADER_OPCODE_ARG* arg) {}
@@ -1106,6 +1107,7 @@ static void shader_none_destroy(IWineD3DBaseShader *iface) {}
 const shader_backend_t none_shader_backend = {
     &shader_none_select,
     &shader_none_select_depth_blt,
+    &shader_none_destroy_depth_blt,
     &shader_none_load_constants,
     &shader_none_cleanup,
     &shader_none_color_correction,
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index a2509a7..f0bac3e 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -6897,7 +6897,15 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Reset(IWineD3DDevice* iface, WINED3DPRE
         This->shader_backend->shader_destroy((IWineD3DBaseShader *) shader);
     }
 
-    if(pPresentationParameters->Windowed) {
+    if(This->depth_blt_texture) {
+        ENTER_GL();
+        glDeleteTextures(1, &This->depth_blt_texture);
+        LEAVE_GL();
+        This->depth_blt_texture = 0;
+    }
+    This->shader_backend->shader_destroy_depth_blt(iface);
+
+     if(pPresentationParameters->Windowed) {
         mode.Width = swapchain->orig_width;
         mode.Height = swapchain->orig_height;
         mode.RefreshRate = 0;
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 5d4d536..70a8c46 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -773,20 +773,19 @@ static void depth_copy(IWineD3DDevice *iface) {
     }
 
     if (This->render_offscreen) {
-        static GLuint tmp_texture = 0;
         GLint old_binding = 0;
 
         TRACE("Copying onscreen depth buffer to offscreen surface\n");
 
-        if (!tmp_texture) {
-            glGenTextures(1, &tmp_texture);
+        if (!This->depth_blt_texture) {
+            glGenTextures(1, &This->depth_blt_texture);
         }
 
         /* 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);
+        glBindTexture(GL_TEXTURE_2D, This->depth_blt_texture);
         glCopyTexImage2D(depth_stencil->glDescription.target,
                 depth_stencil->glDescription.level,
                 depth_stencil->glDescription.glFormatInternal,
@@ -802,7 +801,7 @@ static void depth_copy(IWineD3DDevice *iface) {
 
         GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, This->fbo));
         checkGLcall("glBindFramebuffer()");
-        depth_blt(iface, tmp_texture);
+        depth_blt(iface, This->depth_blt_texture);
         checkGLcall("depth_blt");
     } else {
         TRACE("Copying offscreen surface to onscreen depth buffer\n");
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 64ca8b1..5572231 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -3229,18 +3229,27 @@ static void shader_glsl_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
 static void shader_glsl_select_depth_blt(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
-    static GLhandleARB program_id = 0;
     static GLhandleARB loc = -1;
 
-    if (!program_id) {
-        program_id = create_glsl_blt_shader(gl_info);
-        loc = GL_EXTCALL(glGetUniformLocationARB(program_id, "sampler"));
+    if (!This->depth_blt_glsl_program_id) {
+        This->depth_blt_glsl_program_id = create_glsl_blt_shader(gl_info);
+        loc = GL_EXTCALL(glGetUniformLocationARB(This->depth_blt_glsl_program_id, "sampler"));
     }
 
-    GL_EXTCALL(glUseProgramObjectARB(program_id));
+    GL_EXTCALL(glUseProgramObjectARB(This->depth_blt_glsl_program_id));
     GL_EXTCALL(glUniform1iARB(loc, 0));
 }
 
+static void shader_glsl_destroy_depth_blt(IWineD3DDevice *iface) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+
+    if(This->depth_blt_glsl_program_id) {
+        GL_EXTCALL(glDeleteObjectARB(This->depth_blt_glsl_program_id));
+        This->depth_blt_glsl_program_id = 0;
+    }
+}
+
 static void shader_glsl_cleanup(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
@@ -3285,6 +3294,7 @@ static void shader_glsl_destroy(IWineD3DBaseShader *iface) {
 const shader_backend_t glsl_shader_backend = {
     &shader_glsl_select,
     &shader_glsl_select_depth_blt,
+    &shader_glsl_destroy_depth_blt,
     &shader_glsl_load_constants,
     &shader_glsl_cleanup,
     &shader_glsl_color_correction,
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index bb99148..27b1dc1 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -196,6 +196,7 @@ struct SHADER_OPCODE_ARG;
 typedef struct {
     void (*shader_select)(IWineD3DDevice *iface, BOOL usePS, BOOL useVS);
     void (*shader_select_depth_blt)(IWineD3DDevice *iface);
+    void (*shader_destroy_depth_blt)(IWineD3DDevice *iface);
     void (*shader_load_constants)(IWineD3DDevice *iface, char usePS, char useVS);
     void (*shader_cleanup)(IWineD3DDevice *iface);
     void (*shader_color_correction)(struct SHADER_OPCODE_ARG *arg);
@@ -701,6 +702,10 @@ struct IWineD3DDeviceImpl
     GLuint                  src_fbo;
     GLuint                  dst_fbo;
     GLenum                  *draw_buffers;
+    GLuint                  depth_blt_texture;
+    GLuint                  depth_blt_vprogram_id;
+    GLuint                  depth_blt_fprogram_id;
+    GLhandleARB             depth_blt_glsl_program_id;
 
     /* Cursor management */
     BOOL                    bCursorVisible;




More information about the wine-cvs mailing list