wined3d: Split SetGlTextureDesc() up.

Henri Verbeet hverbeet at codeweavers.com
Wed Sep 24 08:56:47 CDT 2008


This creates a function for setting the texture name and one for setting
the texture target. The idea is that the texture target should get set
right after the surface is created, and won't change, while generating a
texture name can wait.
---
 dlls/wined3d/cubetexture.c       |   13 +++++--
 dlls/wined3d/surface.c           |   64 ++++++++++++++++++++++++++++----------
 dlls/wined3d/surface_gdi.c       |   15 ---------
 dlls/wined3d/texture.c           |   12 +++++--
 dlls/wined3d/wined3d_private.h   |    7 +++-
 include/wine/wined3d_interface.h |    2 -
 6 files changed, 69 insertions(+), 44 deletions(-)

diff --git a/dlls/wined3d/cubetexture.c b/dlls/wined3d/cubetexture.c
index d84dcbc..d670106 100644
--- a/dlls/wined3d/cubetexture.c
+++ b/dlls/wined3d/cubetexture.c
@@ -156,7 +156,8 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
         for (i = 0; i < This->baseTexture.levels; i++) {
             for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
                 IWineD3DSurface_AddDirtyRect(This->surfaces[j][i], NULL);
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], This->baseTexture.textureName, cube_targets[j]);
+                surface_set_texture_name(This->surfaces[j][i], This->baseTexture.textureName);
+                surface_set_texture_target(This->surfaces[j][i], cube_targets[j]);
                 IWineD3DSurface_LoadTexture(This->surfaces[j][i], srgb_mode);
             }
         }
@@ -181,7 +182,8 @@ static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface) {
     for (i = 0; i < This->baseTexture.levels; i++) {
         for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
             IWineD3DSurface_UnLoad(This->surfaces[j][i]);
-            IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], 0, IWineD3DTexture_GetTextureDimensions(iface));
+            surface_set_texture_name(This->surfaces[j][i], 0);
+            surface_set_texture_target(This->surfaces[j][i], IWineD3DTexture_GetTextureDimensions(iface));
         }
     }
 
@@ -245,7 +247,8 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *i
         UINT i, j;
         for (i = 0; i < This->baseTexture.levels; ++i) {
             for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], This->baseTexture.textureName, cube_targets[j]);
+                surface_set_texture_name(This->surfaces[j][i], This->baseTexture.textureName);
+                surface_set_texture_target(This->surfaces[j][i], cube_targets[j]);
             }
         }
     }
@@ -285,8 +288,10 @@ static void WINAPI IWineD3DCubeTextureImpl_Destroy(IWineD3DCubeTexture *iface, D
     for (i = 0; i < This->baseTexture.levels; i++) {
         for (j = 0; j < 6; j++) {
             if (This->surfaces[j][i] != NULL) {
+                IWineD3DSurface *surface = This->surfaces[j][i];
                 /* Clean out the texture name we gave to the surface so that the surface doesn't try and release it */
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], 0, 0);
+                surface_set_texture_name(surface, 0);
+                surface_set_texture_target(surface, 0);
                 /* Cleanup the container */
                 IWineD3DSurface_SetContainer(This->surfaces[j][i], 0);
                 D3DCB_DestroySurface(This->surfaces[j][i]);
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 4c6acc3..4c7e157 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -39,6 +39,53 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES conve
 static inline void clear_unused_channels(IWineD3DSurfaceImpl *This);
 static void surface_remove_pbo(IWineD3DSurfaceImpl *This);
 
+void surface_force_reload(IWineD3DSurface *iface)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    This->Flags &= ~SFLAG_ALLOCATED;
+}
+
+void surface_set_texture_name(IWineD3DSurface *iface, GLuint name)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    TRACE("(%p) : setting texture name %u\n", This, name);
+
+    if (!This->glDescription.textureName && name)
+    {
+        /* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the
+         * surface has no texture name yet. See if we can get rid of this. */
+        if (This->Flags & SFLAG_INTEXTURE)
+            ERR("Surface has SFLAG_INTEXTURE set, but no texture name\n");
+        IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
+    }
+
+    This->glDescription.textureName = name;
+    surface_force_reload(iface);
+}
+
+void surface_set_texture_target(IWineD3DSurface *iface, GLenum target)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    TRACE("(%p) : setting target %#x\n", This, target);
+
+    if (This->glDescription.target != target)
+    {
+        if (target == GL_TEXTURE_RECTANGLE_ARB)
+        {
+            This->Flags &= ~SFLAG_NORMCOORD;
+        }
+        else if (This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB)
+        {
+            This->Flags |= SFLAG_NORMCOORD;
+        }
+    }
+    This->glDescription.target = target;
+    surface_force_reload(iface);
+}
+
 static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This) {
     int active_sampler;
 
@@ -627,22 +674,6 @@ static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface) {
    IWineD3DSurface IWineD3DSurface parts follow
    ****************************************************** */
 
-void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target) {
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    TRACE("(%p) : setting textureName %u, target %#x\n", This, textureName, target);
-    if (This->glDescription.textureName == 0 && textureName != 0) {
-        IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
-    }
-    if(target == GL_TEXTURE_RECTANGLE_ARB && This->glDescription.target != target) {
-        This->Flags &= ~SFLAG_NORMCOORD;
-    } else if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB && target != GL_TEXTURE_RECTANGLE_ARB) {
-        This->Flags |= SFLAG_NORMCOORD;
-    }
-    This->glDescription.textureName = textureName;
-    This->glDescription.target      = target;
-    This->Flags &= ~SFLAG_ALLOCATED;
-}
-
 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     TRACE("(%p) : returning %p\n", This, &This->glDescription);
@@ -4605,7 +4636,6 @@ const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl =
     IWineD3DSurfaceImpl_BindTexture,
     IWineD3DSurfaceImpl_SaveSnapshot,
     IWineD3DSurfaceImpl_SetContainer,
-    IWineD3DSurfaceImpl_SetGlTextureDesc,
     IWineD3DSurfaceImpl_GetGlDesc,
     IWineD3DSurfaceImpl_GetData,
     IWineD3DSurfaceImpl_SetFormat,
diff --git a/dlls/wined3d/surface_gdi.c b/dlls/wined3d/surface_gdi.c
index 05a4a54..6e01534 100644
--- a/dlls/wined3d/surface_gdi.c
+++ b/dlls/wined3d/surface_gdi.c
@@ -534,20 +534,6 @@ IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
     return WINED3D_OK;
 }
 
-void WINAPI IWineGDISurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target) {
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-
-    /* Ignore 0 textureName and target. D3D textures can be created with gdi surfaces as plain
-     * containers, but they're useless until the app creates a d3d device from a d3d point of
-     * view, it's not an implementation limitation. This avoids false warnings when the texture
-     * is destroyed and sets the description back to 0/0
-     */
-    if(textureName != 0 || target != 0) {
-        FIXME("(%p) : Should not be called on a GDI surface. textureName %u, target %i\n", This, textureName, target);
-        DebugBreak();
-    }
-}
-
 void WINAPI IWineGDISurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     FIXME("(%p) : Should not be called on a GDI surface\n", This);
@@ -692,7 +678,6 @@ const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl =
     IWineD3DBaseSurfaceImpl_BindTexture,
     IWineGDISurfaceImpl_SaveSnapshot,
     IWineD3DBaseSurfaceImpl_SetContainer,
-    IWineGDISurfaceImpl_SetGlTextureDesc,
     IWineGDISurfaceImpl_GetGlDesc,
     IWineD3DSurfaceImpl_GetData,
     IWineD3DBaseSurfaceImpl_SetFormat,
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index f138437..8390060 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -138,7 +138,8 @@ static void WINAPI IWineD3DTextureImpl_PreLoad(IWineD3DTexture *iface) {
 
         for (i = 0; i < This->baseTexture.levels; i++) {
             IWineD3DSurface_AddDirtyRect(This->surfaces[i], NULL);
-            IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], This->baseTexture.textureName, IWineD3DTexture_GetTextureDimensions(iface));
+            surface_set_texture_name(This->surfaces[i], This->baseTexture.textureName);
+            surface_set_texture_target(This->surfaces[i], IWineD3DTexture_GetTextureDimensions(iface));
             IWineD3DSurface_LoadTexture(This->surfaces[i], srgb_mode);
         }
     } else {
@@ -162,7 +163,8 @@ static void WINAPI IWineD3DTextureImpl_UnLoad(IWineD3DTexture *iface) {
      */
     for (i = 0; i < This->baseTexture.levels; i++) {
         IWineD3DSurface_UnLoad(This->surfaces[i]);
-        IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], 0, IWineD3DTexture_GetTextureDimensions(iface));
+        surface_set_texture_name(This->surfaces[i], 0);
+        surface_set_texture_target(This->surfaces[i], IWineD3DTexture_GetTextureDimensions(iface));
     }
 
     IWineD3DBaseTextureImpl_UnLoad((IWineD3DBaseTexture *) iface);
@@ -223,7 +225,8 @@ static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface) {
     if (set_gl_texture_desc && SUCCEEDED(hr)) {
         UINT i;
         for (i = 0; i < This->baseTexture.levels; ++i) {
-            IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], This->baseTexture.textureName, IWineD3DTexture_GetTextureDimensions(iface));
+            surface_set_texture_name(This->surfaces[i], This->baseTexture.textureName);
+            surface_set_texture_target(This->surfaces[i], IWineD3DTexture_GetTextureDimensions(iface));
         }
         /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
          * partial driver emulation, we're dealing with a GL_TEXTURE_2D texture which has the address mode set to repeat - something
@@ -284,7 +287,8 @@ static void WINAPI IWineD3DTextureImpl_Destroy(IWineD3DTexture *iface, D3DCB_DES
     for (i = 0; i < This->baseTexture.levels; i++) {
         if (This->surfaces[i] != NULL) {
             /* Clean out the texture name we gave to the surface so that the surface doesn't try and release it */
-            IWineD3DSurface_SetGlTextureDesc(This->surfaces[i], 0, 0);
+            surface_set_texture_name(This->surfaces[i], 0);
+            surface_set_texture_target(This->surfaces[i], 0);
             IWineD3DSurface_SetContainer(This->surfaces[i], 0);
             D3DCB_DestroySurface(This->surfaces[i]);
         }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index b6f3fc6..094bc25 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1907,10 +1907,13 @@ void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCont
 void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
 void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
 
-void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
+void surface_force_reload(IWineD3DSurface *iface);
 GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
-void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
 void surface_load_ds_location(IWineD3DSurface *iface, DWORD location);
+void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
+void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
+void surface_set_texture_name(IWineD3DSurface *iface, GLuint name);
+void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
 
 BOOL getColorBits(WINED3DFORMAT fmt, short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
 BOOL getDepthStencilBits(WINED3DFORMAT fmt, short *depthSize, short *stencilSize);
diff --git a/include/wine/wined3d_interface.h b/include/wine/wined3d_interface.h
index 6ecab39..9a29129 100644
--- a/include/wine/wined3d_interface.h
+++ b/include/wine/wined3d_interface.h
@@ -1157,7 +1157,6 @@ DECLARE_INTERFACE_(IWineD3DSurface,IWineD3DResource)
     STDMETHOD_(void, BindTexture)(THIS) PURE;
     STDMETHOD(SaveSnapshot)(THIS_ const char *filename) PURE;
     STDMETHOD(SetContainer)(THIS_ IWineD3DBase *container) PURE;
-    STDMETHOD_(void,SetGlTextureDesc)(THIS_ UINT textureName, int target) PURE;
     STDMETHOD_(void,GetGlDesc)(THIS_ glDescriptor **glDescription) PURE;
     STDMETHOD_(CONST void *, GetData)(THIS) PURE;
     STDMETHOD(SetFormat)(THIS_ WINED3DFORMAT format) PURE;
@@ -1218,7 +1217,6 @@ DECLARE_INTERFACE_(IWineD3DSurface,IWineD3DResource)
 #define IWineD3DSurface_BindTexture(p)               (p)->lpVtbl->BindTexture(p)
 #define IWineD3DSurface_SaveSnapshot(p,a)            (p)->lpVtbl->SaveSnapshot(p,a)
 #define IWineD3DSurface_SetContainer(p,a)            (p)->lpVtbl->SetContainer(p,a)
-#define IWineD3DSurface_SetGlTextureDesc(p,a,b)      (p)->lpVtbl->SetGlTextureDesc(p,a,b)
 #define IWineD3DSurface_GetGlDesc(p,a)               (p)->lpVtbl->GetGlDesc(p,a)
 #define IWineD3DSurface_GetData(p)                   (p)->lpVtbl->GetData(p)
 #define IWineD3DSurface_SetFormat(p,a)               (p)->lpVtbl->SetFormat(p,a)
-- 
1.5.6.4



--------------010705000109000407040801--



More information about the wine-patches mailing list