Re: Complex Surfaces patch

Marius Grigoriu <[email protected]> Thu, 12 Aug 2004 00:39:38 -0400
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
Marius Grigoriu wrote:

>>		/* FIXME: Adding more than 6 surfaces seems to break things, regardless
>>		 * of original size so we deviate a little from what windows does
>>		 */
>>    
>>
Disregard that whole thing about crashing when we have more surfaces. 
The whole problem was sound related and it must have been bad luck that 
almost everytime I decreased the number I had an easier time getting 
into the game. I realized that it was a sound problem becuase the freeze 
would always happen just as the loading music was supposed to come on. I 
also had some screaching issues randomly. Then I noticed that the 
cvscedega script generates the config file defaulting to the alsa sound 
driver. I switched to OSS and everything is great now.

Here is the new patch that follows the windows behavior. X11 licensed.
complex_mipmap_v2.patch (text/x-patch, 1.8 KB)
? complex_mipmap_v2.patch
Index: main.c
===================================================================
RCS file: /cvsroot/winex/dlls/ddraw/ddraw/main.c,v
retrieving revision 1.77
diff -u -r1.77 main.c
--- main.c	18 Feb 2004 22:27:36 -0000	1.77
+++ main.c	12 Aug 2004 04:32:41 -0000
@@ -323,20 +323,37 @@
 {
     DWORD mipmap_level = 0;
     HRESULT hr;
+	DWORD max;
+	DDSURFACEDESC2 mipmap_surface_desc;
+
+	mipmap_surface_desc = *pDDSD;
+
+	/* A somewhat undocumented feature, if DDSCAPS_COMPLEX is set,
+	 * "It is permissible to omit the number of mipmaps levels, in which case
+	 * CreateSurface() will create a chain of surfaces each a power of two
+	 * smaller than the previous one down to the smallest possible size."
+	 */
+	if(!(mipmap_surface_desc.dwFlags & DDSD_MIPMAPCOUNT) &&
+		(mipmap_surface_desc.ddsCaps.dwCaps & DDSCAPS_COMPLEX) &&
+		(mipmap_surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)){
+		DDRAW_dump_surface_desc(pDDSD);
+		max = (mipmap_surface_desc.dwWidth > mipmap_surface_desc.dwHeight) ? 
+			mipmap_surface_desc.dwWidth : mipmap_surface_desc.dwHeight;
+		mipmap_surface_desc.u2.dwMipMapCount = log(max)/log(2) + 2;
+		mipmap_surface_desc.dwFlags |= DDSD_MIPMAPCOUNT;
+	}
 
-    hr = This->create_texture(This, pDDSD, ppSurf, pUnkOuter, mipmap_level);
+    hr = This->create_texture(This, &mipmap_surface_desc, ppSurf, pUnkOuter, mipmap_level);
     if (FAILED(hr)) return hr;
 
     /* Create attached mipmaps if required. */
-    if (more_mipmaps(pDDSD))
+    if (more_mipmaps(&mipmap_surface_desc))
     {
 	LPDIRECTDRAWSURFACE7 mipmap;
 	LPDIRECTDRAWSURFACE7 prev_mipmap;
-	DDSURFACEDESC2 mipmap_surface_desc;
 
 	prev_mipmap = *ppSurf;
 	IDirectDrawSurface7_AddRef(prev_mipmap);
-	mipmap_surface_desc = *pDDSD;
 	mipmap_surface_desc.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
 
 	while (more_mipmaps(&mipmap_surface_desc))