[PATCH 1/4] d3dx9: Implement D3DXCheckTextureRequirements.

Philip Nilsson pnilsson at nullref.se
Fri Apr 18 12:07:37 CDT 2008


Implements the most used features of D3DXCheckTextureRequirements.

Doesn't do much in the way of format checking or replacing.

---
 dlls/d3dx9_36/Makefile.in   |    3 +-
 dlls/d3dx9_36/d3dx9_36.spec |    2 +-
 dlls/d3dx9_36/texture.c     |  109 +++++++++++++++++++++++++++++++++++++++++++
 include/d3dx9.h             |    2 +
 4 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100644 dlls/d3dx9_36/texture.c

diff --git a/dlls/d3dx9_36/Makefile.in b/dlls/d3dx9_36/Makefile.in
index 2ed85ea..a5c590d 100644
--- a/dlls/d3dx9_36/Makefile.in
+++ b/dlls/d3dx9_36/Makefile.in
@@ -9,7 +9,8 @@ IMPORTS   = d3d9 d3dx8 kernel32
 C_SRCS = \
 	d3dx9_36_main.c \
 	font.c \
-	math.c
+	math.c \
+	texture.c
 
 @MAKE_DLL_RULES@
 
diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec
index e616d23..d4f69f6 100644
--- a/dlls/d3dx9_36/d3dx9_36.spec
+++ b/dlls/d3dx9_36/d3dx9_36.spec
@@ -5,7 +5,7 @@
 @ stub D3DXAssembleShaderFromResourceW
 @ stdcall D3DXBoxBoundProbe(ptr ptr ptr ptr) d3dx8.D3DXBoxBoundProbe
 @ stub D3DXCheckCubeTextureRequirements
-@ stub D3DXCheckTextureRequirements
+@ stdcall D3DXCheckTextureRequirements(ptr ptr ptr ptr long ptr long)
 @ stdcall D3DXCheckVersion(long long)
 @ stub D3DXCheckVolumeTextureRequirements
 @ stub D3DXCleanMesh
diff --git a/dlls/d3dx9_36/texture.c b/dlls/d3dx9_36/texture.c
new file mode 100644
index 0000000..cf47895
--- /dev/null
+++ b/dlls/d3dx9_36/texture.c
@@ -0,0 +1,109 @@
+/*
+ * Surface and texture functions
+ *
+ * Copyright (C) 2008 Philip Nilsson
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include <stdarg.h>
+#define COBJMACROS
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "d3dx9.h"
+#include "wine/debug.h"
+WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
+
+/* TODO: Change formats in some cases. */
+HRESULT WINAPI D3DXCheckTextureRequirements(
+    LPDIRECT3DDEVICE9 device, UINT* width, UINT* height, UINT* miplevels,
+    DWORD usage, D3DFORMAT* format, D3DPOOL pool)
+{
+    TRACE("(%p, %p, %p, %p, %#x, %p, %#x)\n",
+        device, width, height, miplevels, usage, format, pool);
+
+    if (!device)
+        return D3DERR_INVALIDCALL;
+
+    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;
+
+    if (format) {
+        HRESULT ret;
+        D3DDISPLAYMODE displaymode;
+        IDirect3D9* d3d = NULL;
+
+        ret = IDirect3DDevice9_GetDirect3D(device, &d3d);
+        if (ret != D3D_OK)
+            return ret;
+
+        ret = IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &displaymode);
+        if (ret != D3D_OK) {
+            IUnknown_Release(d3d);
+            return ret;
+        }
+
+        ret = IDirect3D9_CheckDeviceFormat(
+            d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+            displaymode.Format, usage, D3DRTYPE_TEXTURE, *format);
+        if (ret != D3D_OK) {
+            IUnknown_Release(d3d);
+            return ret;
+        }
+
+        IUnknown_Release(d3d);
+    }
+
+    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;
+}
diff --git a/include/d3dx9.h b/include/d3dx9.h
index 50b1b5a..3fc7fb2 100644
--- a/include/d3dx9.h
+++ b/include/d3dx9.h
@@ -29,6 +29,8 @@
 #define _FACDD 0x876
 #define MAKE_DDHRESULT(code) MAKE_HRESULT(1, _FACDD, code)
 
+#define D3DX_DEFAULT ((UINT) -1)
+
 enum _D3DXERR {
     D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900),
     D3DXERR_INVALIDMESH             = MAKE_DDHRESULT(2901),
-- 
1.5.5




More information about the wine-patches mailing list