Henri Verbeet : wined3d: Split off a function for applying an attachment' s filter states.

Alexandre Julliard julliard at winehq.org
Fri Sep 19 07:14:38 CDT 2008


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

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Thu Sep 18 14:57:53 2008 +0200

wined3d: Split off a function for applying an attachment's filter states.

---

 dlls/wined3d/context.c |  130 ++++++++++++++++++++++--------------------------
 1 files changed, 60 insertions(+), 70 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index b6d8e9b..c3297ac 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -72,55 +72,79 @@ static void context_destroy_fbo(IWineD3DDeviceImpl *This, const GLuint *fbo)
     checkGLcall("glDeleteFramebuffers()");
 }
 
-/* TODO: Handle stencil attachments */
-void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer)
+static void context_apply_attachment_filter_states(IWineD3DDevice *iface, IWineD3DSurface *surface, BOOL force_preload)
 {
-    IWineD3DSurfaceImpl *depth_stencil_impl = (IWineD3DSurfaceImpl *)depth_stencil;
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
+    IWineD3DBaseTextureImpl *texture_impl;
+    BOOL update_minfilter, update_magfilter;
 
-    if (use_render_buffer && depth_stencil_impl->current_renderbuffer)
+    /* Update base texture states array */
+    if (SUCCEEDED(IWineD3DSurface_GetContainer(surface, &IID_IWineD3DBaseTexture, (void **)&texture_impl)))
     {
-        GL_EXTCALL(glFramebufferRenderbufferEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_stencil_impl->current_renderbuffer->id));
-        checkGLcall("glFramebufferRenderbufferEXT()");
-    } else {
-        IWineD3DBaseTextureImpl *texture_impl;
-        GLenum texttarget, target;
-        GLint old_binding = 0;
+        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT)
+        {
+            texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
+            update_minfilter = TRUE;
+        }
+
+        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_POINT)
+        {
+            texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
+            update_magfilter = TRUE;
+        }
+
+        if (texture_impl->baseTexture.bindCount)
+        {
+            WARN("Render targets should not be bound to a sampler\n");
+            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(texture_impl->baseTexture.sampler));
+        }
 
-        texttarget = depth_stencil_impl->glDescription.target;
-        if (texttarget == GL_TEXTURE_2D)
+        IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture_impl);
+    }
+
+    if (update_minfilter || update_magfilter || force_preload)
+    {
+        GLenum target, bind_target;
+        GLint old_binding;
+
+        target = surface_impl->glDescription.target;
+        if (target == GL_TEXTURE_2D)
         {
-            target = GL_TEXTURE_2D;
+            bind_target = GL_TEXTURE_2D;
             glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
-        } else if (texttarget == GL_TEXTURE_RECTANGLE_ARB) {
-            target = GL_TEXTURE_RECTANGLE_ARB;
+        } else if (target == GL_TEXTURE_RECTANGLE_ARB) {
+            bind_target = GL_TEXTURE_RECTANGLE_ARB;
             glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
         } else {
-            target = GL_TEXTURE_CUBE_MAP_ARB;
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
             glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding);
         }
 
-        IWineD3DSurface_PreLoad(depth_stencil);
+        IWineD3DSurface_PreLoad(surface);
 
-        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, old_binding);
+        glBindTexture(bind_target, surface_impl->glDescription.textureName);
+        if (update_minfilter) glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        if (update_magfilter) glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glBindTexture(bind_target, old_binding);
+    }
 
-        /* Update base texture states array */
-        if (SUCCEEDED(IWineD3DSurface_GetContainer(depth_stencil, &IID_IWineD3DBaseTexture, (void **)&texture_impl)))
-        {
-            texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
-            texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
-            if (texture_impl->baseTexture.bindCount)
-            {
-                IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(texture_impl->baseTexture.sampler));
-            }
+    checkGLcall("apply_attachment_filter_states()");
+}
 
-            IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture_impl);
-        }
+/* TODO: Handle stencil attachments */
+void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer)
+{
+    IWineD3DSurfaceImpl *depth_stencil_impl = (IWineD3DSurfaceImpl *)depth_stencil;
+
+    if (use_render_buffer && depth_stencil_impl->current_renderbuffer)
+    {
+        GL_EXTCALL(glFramebufferRenderbufferEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_stencil_impl->current_renderbuffer->id));
+        checkGLcall("glFramebufferRenderbufferEXT()");
+    } else {
+        context_apply_attachment_filter_states((IWineD3DDevice *)This, depth_stencil, TRUE);
 
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, texttarget,
+        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, depth_stencil_impl->glDescription.target,
                     depth_stencil_impl->glDescription.textureName, depth_stencil_impl->glDescription.level));
         checkGLcall("glFramebufferTexture2DEXT()");
     }
@@ -129,44 +153,10 @@ void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_targe
 void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface)
 {
     const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
-    IWineD3DBaseTextureImpl *texture_impl;
-    GLenum texttarget, target;
-    GLint old_binding;
 
-    texttarget = surface_impl->glDescription.target;
-    if (texttarget == GL_TEXTURE_2D)
-    {
-        target = GL_TEXTURE_2D;
-        glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
-    } else if (texttarget == GL_TEXTURE_RECTANGLE_ARB) {
-        target = GL_TEXTURE_RECTANGLE_ARB;
-        glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
-    } else {
-        target = GL_TEXTURE_CUBE_MAP_ARB;
-        glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARB, &old_binding);
-    }
-
-    IWineD3DSurface_PreLoad(surface);
-
-    glBindTexture(target, surface_impl->glDescription.textureName);
-    glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glBindTexture(target, old_binding);
-
-    /* Update base texture states array */
-    if (SUCCEEDED(IWineD3DSurface_GetContainer(surface, &IID_IWineD3DBaseTexture, (void **)&texture_impl)))
-    {
-        texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
-        texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
-        if (texture_impl->baseTexture.bindCount)
-        {
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(texture_impl->baseTexture.sampler));
-        }
-
-        IWineD3DBaseTexture_Release((IWineD3DBaseTexture *)texture_impl);
-    }
+    context_apply_attachment_filter_states((IWineD3DDevice *)This, surface, TRUE);
 
-    GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_COLOR_ATTACHMENT0_EXT + idx, texttarget,
+    GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_COLOR_ATTACHMENT0_EXT + idx, surface_impl->glDescription.target,
             surface_impl->glDescription.textureName, surface_impl->glDescription.level));
 
     checkGLcall("attach_surface_fbo");




More information about the wine-cvs mailing list