[dx47] debugging aid + lockrect fix

Ann and Jason Edmeades us at the-edmeades.demon.co.uk
Sun Jun 1 06:02:27 CDT 2003


Note this applies on top of dx46 since we both found the same bug.

Changelog

[47] This fixes the glRead call when pRect != NULL, resolves the file
format of the savesnapshot correctly, and adds a debugging aid which can
be compiled in to see the makeup of a single frame.

Jason
-------------- next part --------------
--- dlls/d3d8/device.dx45	2003-06-01 12:34:46.000000000 +0100
+++ dlls/d3d8/device.c	2003-06-01 12:45:17.000000000 +0100
@@ -43,14 +43,24 @@
 /* Some #defines for additional diagnostics */
 #if 0
   /* To avoid having to get gigabytes of trace, the following can be compiled in, and at the start
-     of each frame, a check is made for the existance of C:\D3DTRACE, and if if exists d3d trace
-     is enabled, and if it doesnt exists it is disabled. Adding in the SINGLE_FRAME_DEBUGGING
-     gives a trace of just what makes up a single frame                                           */
+     of each frame, a check is made for the existance of C:\D3DTRACE, and if if exists d3d trace   
+     is enabled, and if it doesnt exists it is disabled.                                           */
 # define FRAME_DEBUGGING
+  /*  Adding in the SINGLE_FRAME_DEBUGGING gives a trace of just what makes up a single frame, before
+      the file is deleted                                                                            */
 # if 1
 #  define SINGLE_FRAME_DEBUGGING
 # endif  
+  /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
+     A check is made for the existence of C:\D3DSHOWFRAME, and if it exists will write the
+     contents of the back buffer into /tmp/backbuffer_* after each primitive array is drawn
+     for a single frame. At the end of the frame, the file is deleted.                         */
+# if 1
+#  define SHOW_FRAME_MAKEUP 1
+# endif  
 static BOOL isOn  = FALSE;
+static BOOL isDumpingFrames  = FALSE;
+static LONG primCounter = 0;
 #endif
 
 /* Per-vertex trace: */
@@ -994,6 +1004,18 @@
     LEAVE_GL();
 
     TRACE("glEnd\n");
+#if defined(SHOW_FRAME_MAKEUP)
+{
+    if (isDumpingFrames == TRUE) {
+      D3DLOCKED_RECT r;
+      char buffer[80];
+      IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->backBuffer, &r, NULL, D3DLOCK_READONLY);
+      sprintf(buffer, "/tmp/backbuffer_%ld.ppm", primCounter++);
+      IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This->backBuffer, buffer);
+      IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->backBuffer);
+    }
+}
+#endif
 }
 
 /* Apply the current values to the specified texture stage */
@@ -1185,8 +1207,21 @@
 
 #if defined(FRAME_DEBUGGING)
 {
-    DWORD res = GetFileAttributesA("C:\\D3DTRACE");
-    if (res != INVALID_FILE_ATTRIBUTES) {
+#if defined(SHOW_FRAME_MAKEUP)
+    primCounter = 0;
+    if (isDumpingFrames == TRUE) {
+        FIXME("Singe Frame snapshots complete\n");
+        DeleteFileA("C:\\D3DSHOWFRAME");
+        isDumpingFrames = FALSE;
+    } else {
+       if (GetFileAttributesA("C:\\D3DSHOWFRAME") != INVALID_FILE_ATTRIBUTES) {
+           FIXME("Singe Frame snapshots Starting\n");
+           isDumpingFrames = TRUE;
+       }
+    }
+#endif
+
+    if (GetFileAttributesA("C:\\D3DTRACE") != INVALID_FILE_ATTRIBUTES) {
         if (!isOn) {
             isOn = TRUE;
             FIXME("Enabling D3D Trace\n");
--- dlls/d3d8/surface.dx46	2003-06-01 12:40:55.000000000 +0100
+++ dlls/d3d8/surface.c	2003-06-01 12:44:44.000000000 +0100
@@ -208,7 +208,7 @@
 			 1,
 			 D3DFmt2GLFmt(This->Device, This->myDesc.Format), 
                          D3DFmt2GLType(This->Device, This->myDesc.Format), 
-                         pLockedRect->pBits + j * pLockedRect->Pitch);
+                         pLockedRect->pBits + (pLockedRect->Pitch * (j-This->lockedRect.top)));
 	    vcheckGLcall("glReadPixels");
 	  }
 	}
@@ -507,7 +507,7 @@
       char buffer[4096];
       ++gen;
       if ((gen % 10) == 0) {
-	snprintf(buffer, sizeof(buffer), "/tmp/surface%u_level%u_%u.png", gl_target, gl_level, gen);
+	snprintf(buffer, sizeof(buffer), "/tmp/surface%u_level%u_%u.ppm", gl_target, gl_level, gen);
 	IDirect3DSurface8Impl_SaveSnapshot((LPDIRECT3DSURFACE8) This, buffer);
       }
     }
@@ -520,7 +520,7 @@
 #include <errno.h>
 HRESULT WINAPI IDirect3DSurface8Impl_SaveSnapshot(LPDIRECT3DSURFACE8 iface, const char* filename) {
   FILE* f = NULL;
-  int i;
+  ULONG i;
   ICOM_THIS(IDirect3DSurface8Impl,iface);
 
   f = fopen(filename, "w+");


More information about the wine-patches mailing list