]> git.cworth.org Git - apitrace/blobdiff - helpers/d3dsize.hpp
Fix volume locked size computation.
[apitrace] / helpers / d3dsize.hpp
index 31fcd740a95c55d2bc645e6d58191f984821c891..9a1102ae9034bb8a10d31f454030dd9cd38f7477 100644 (file)
@@ -139,17 +139,24 @@ _getLockSize(D3DFORMAT Format, UINT Width, UINT Height, INT RowPitch, UINT Depth
     case D3DFMT_DXT3:
     case D3DFMT_DXT4:
     case D3DFMT_DXT5:
-    case D3DFMT_ATI1:
-    case D3DFMT_ATI2:
-        Width /= 4;
-        Height /= 4;
+        Width  = (Width  + 3) / 4;
+        Height = (Height + 3) / 4;
+        break;
+
+    case D3DFMT_ATI1N:
+    case D3DFMT_ATI2N:
+        /*
+         * Because these are unsupported formats, RowPitch is not set to the
+         * number of bytes between row of blocks, but instead in such way that
+         * Height * RowPitch will match the expected size.
+         */
         break;
 
     case D3DFMT_UYVY:
     case D3DFMT_R8G8_B8G8:
     case D3DFMT_YUY2:
     case D3DFMT_G8R8_G8B8:
-        Width /= 2;
+        Width = (Width + 1) / 2;
         break;
 
     case D3DFMT_NV12:
@@ -285,7 +292,7 @@ _getLockSize(IDirect3DCubeTexture9 *pTexture, D3DCUBEMAP_FACES FaceType, UINT Le
 
 
 static inline size_t
-_getLockSize(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedBox, const D3DBOX *pBox) {
+_getLockSize(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox) {
     HRESULT hr;
 
     D3DVOLUME_DESC Desc;
@@ -307,12 +314,12 @@ _getLockSize(IDirect3DVolume9 *pVolume, const D3DLOCKED_BOX *pLockedBox, const D
         Depth  = Desc.Depth;
     }
 
-    return _getLockSize(Desc.Format, Width, Height, pLockedBox->RowPitch, Depth, pLockedBox->SlicePitch);
+    return _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
 }
 
 
 static inline size_t
-_getLockSize(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedBox, const D3DBOX *pBox) {
+_getLockSize(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox) {
     HRESULT hr;
 
     D3DVOLUME_DESC Desc;
@@ -334,7 +341,7 @@ _getLockSize(IDirect3DVolumeTexture9 *pTexture, UINT Level, const D3DLOCKED_BOX
         Depth  = Desc.Depth;
     }
 
-    return _getLockSize(Desc.Format, Width, Height, pLockedBox->RowPitch, Depth, pLockedBox->SlicePitch);
+    return _getLockSize(Desc.Format, Width, Height, pLockedVolume->RowPitch, Depth, pLockedVolume->SlicePitch);
 }