[PATCH 3/7] d3dx9: Implement D3DXCheckTextureRequirements.

Philip Nilsson pnilsson at nullref.se
Fri Jul 11 13:22:52 CDT 2008


---
 dlls/d3dx9_36/texture.c |  144 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 143 insertions(+), 1 deletions(-)

diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c
index 7b63d8f..90be065 100644
--- a/dlls/d3dx9_36/texture.c
+++ b/dlls/d3dx9_36/texture.c
@@ -34,8 +34,150 @@ HRESULT WINAPI D3DXCheckTextureRequirements(
     LPDIRECT3DDEVICE9 device, UINT* width, UINT* height, UINT* miplevels,
     DWORD usage, D3DFORMAT* format, D3DPOOL pool)
 {
-    FIXME("(%p, %p, %p, %p, %#x, %p, %#x): stub\n",
+    TRACE("(%p, %p, %p, %p, %#x, %p, %#x)\n",
         device, width, height, miplevels, usage, format, pool);
 
+    if (!device)
+        return D3DERR_INVALIDCALL;
+
+    /* This function does not check if usages and pools are valid combinations. */
+    if (pool != D3DPOOL_DEFAULT && pool != D3DPOOL_MANAGED &&
+        pool != D3DPOOL_SYSTEMMEM && pool != D3DPOOL_SCRATCH)
+        return D3DERR_INVALIDCALL;
+
+    if (usage & (D3DUSAGE_WRITEONLY | D3DUSAGE_DONOTCLIP | D3DUSAGE_POINTS |
+                 D3DUSAGE_RTPATCHES | D3DUSAGE_NPATCHES))
+        return D3DERR_INVALIDCALL;
+
+    /* Workaround until the more advanced solution is implemented below. */
+    if (usage & D3DUSAGE_RENDERTARGET && usage & D3DUSAGE_DEPTHSTENCIL)
+        return D3DERR_NOTAVAILABLE;
+
+    if (format) {
+        IDirect3D9* d3d9 = NULL;
+        D3DDISPLAYMODE d3ddm;
+        HRESULT hr;
+
+        hr = IDirect3DDevice9_GetDirect3D(device, &d3d9);
+        if (hr != D3D_OK || !device)
+            return D3DERR_INVALIDCALL;
+
+        IDirect3D_GetAdapterDisplayMode(d3d9, D3DADAPTER_DEFAULT, &d3ddm);
+
+        /* TODO: Use something more advanced that looks more like what's in MSDN. */
+        hr = IDirect3D9_CheckDeviceFormat(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3ddm.Format, usage, D3DRTYPE_TEXTURE, *format);
+        if (hr != D3D_OK) {
+            if (usage & D3DUSAGE_DEPTHSTENCIL) {
+                switch (*format) {
+                case D3DFMT_D16_LOCKABLE:  *format = D3DFMT_D16; break;
+                case D3DFMT_D32:           *format = D3DFMT_D24X8; break;
+                case D3DFMT_D15S1:         *format = D3DFMT_D24S8; break;
+                case D3DFMT_D24S8:         *format = D3DFMT_D24X4S4; break;
+                case D3DFMT_D24X8:         *format = D3DFMT_D24S8; break;
+                case D3DFMT_D24X4S4:       *format = D3DFMT_D24S8; break;
+                case D3DFMT_D16:           *format = D3DFMT_D24X8; break;
+                case D3DFMT_D32F_LOCKABLE: *format = D3DFMT_D24X8; break;
+                case D3DFMT_D24FS8:        *format = D3DFMT_D24S8; break;
+                default:
+                    IDirect3D9_Release(d3d9);
+                    return D3DERR_NOTAVAILABLE;
+                }
+            } else if (usage & D3DUSAGE_RENDERTARGET) {
+                switch (*format) {
+                case D3DFMT_V8U8:
+                case D3DFMT_L6V5U5:
+                case D3DFMT_X8L8V8U8:
+                case D3DFMT_Q8W8V8U8:
+                case D3DFMT_V16U16:
+                case D3DFMT_A2W10V10U10:
+                case D3DFMT_D16_LOCKABLE:
+                case D3DFMT_D32:
+                case D3DFMT_D15S1:
+                case D3DFMT_D24S8:
+                case D3DFMT_D24X8:
+                case D3DFMT_D24X4S4:
+                case D3DFMT_D16:
+                case D3DFMT_D32F_LOCKABLE:
+                case D3DFMT_D24FS8:
+                case D3DFMT_Q16W16V16U16:
+                case D3DFMT_CxV8U8:
+                    IDirect3D9_Release(d3d9);
+                    return D3DERR_NOTAVAILABLE;
+                case D3DFMT_R8G8B8:   *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_R5G6B5:   *format = D3DFMT_R5G6B5; break;
+                case D3DFMT_X1R5G5B5: *format = D3DFMT_R5G6B5; break;
+                case D3DFMT_R3G3B2:   *format = D3DFMT_R5G6B5; break;
+                case D3DFMT_X4R4G4B4: *format = D3DFMT_R5G6B5; break;
+                case D3DFMT_X8B8G8R8: *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_G16R16:   *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_L8:       *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_L16:      *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_R16F:     *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_G16R16F:  *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_R32F:     *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_G32R32F:  *format = D3DFMT_X8R8G8B8; break;
+                default:
+                    *format = D3DFMT_A8R8G8B8;
+                    break;
+                }
+            } else {
+                switch (*format) {
+                case D3DFMT_R8G8B8:        *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_R3G3B2:        *format = D3DFMT_X4R4G4B4; break;
+                case D3DFMT_X4R4G4B4:      *format = D3DFMT_X1R5G5B5; break;
+                case D3DFMT_A8B8G8R8:      *format = D3DFMT_A8R8G8B8; break;
+                case D3DFMT_X8B8G8R8:      *format = D3DFMT_X8R8G8B8; break;
+                case D3DFMT_A8P8:          *format = D3DFMT_P8; break;
+                case D3DFMT_P8:            *format = D3DFMT_A8R8G8B8; break;
+                case D3DFMT_A4L4:          *format = D3DFMT_A4R4G4B4; break;
+                case D3DFMT_L6V5U5:        *format = D3DFMT_X8L8V8U8; break;
+                case D3DFMT_A2W10V10U10:   *format = D3DFMT_X8L8V8U8; break;
+                case D3DFMT_Q16W16V16U16:  *format = D3DFMT_Q8W8V8U8; break;
+                case D3DFMT_R16F:          *format = D3DFMT_G16R16; break;
+                case D3DFMT_G16R16F:       *format = D3DFMT_G16R16; break;
+                case D3DFMT_R32F:          *format = D3DFMT_G16R16; break;
+                case D3DFMT_G32R32F:       *format = D3DFMT_G16R16; break;
+                case D3DFMT_CxV8U8:        *format = D3DFMT_X8L8V8U8; break;
+                default:
+                    *format = D3DFMT_A8R8G8B8;
+                    break;
+                }
+            }
+        }
+        IDirect3D9_Release(d3d9);
+    }
+
+    if (width && height) {
+        if (*width == D3DX_DEFAULT)
+            *width = *height;
+        else if (*height == D3DX_DEFAULT)
+            *height = *width;
+    }
+
+    if (width && *width == 0)
+        *width = 1;
+    if (height && *height == 0)
+        *height = 1;
+
+    if (width && *width == D3DX_DEFAULT)
+        *width = 256;
+    if (height && *height == D3DX_DEFAULT)
+        *height = 256;
+
+    if (miplevels && (*miplevels == 0 || *miplevels == D3DX_DEFAULT)) {
+        if (!width && !height) {
+            *miplevels = 9;
+        } else {
+            UINT width2 = width ? *width : 0;
+            UINT height2 = height ? *height : 0;
+            UINT temp = width2 > height2 ? width2 : height2;
+            *miplevels = 0;
+            while (temp) {
+                temp = temp >> 1;
+                ++*miplevels;
+            }
+        }
+    }
+
     return D3D_OK;
 }
-- 
1.6.0.2


--ZPt4rx8FFjLCG7dd--



More information about the wine-patches mailing list