Tidy texture/mip copy code
- Rename and comment variables for clarity - Remove unused 'dwSrcSlicePitch' - Remove 'dwCubeFaceSize' calculations since we can get this from 'dwSlicePitch'
This commit is contained in:
parent
2e27e0d4b5
commit
516457c89c
|
@ -6019,10 +6019,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
return;
|
||||
}
|
||||
|
||||
DWORD D3DLockFlags = D3DLOCK_NOSYSLOCK;
|
||||
|
||||
DWORD dwCubeFaceOffset = 0;
|
||||
DWORD dwCubeFaceSize = 0;
|
||||
D3DCUBEMAP_FACES last_face = (bCubemap) ? D3DCUBEMAP_FACE_NEGATIVE_Z : D3DCUBEMAP_FACE_POSITIVE_X;
|
||||
|
||||
// Block size only applies to compressed DXT formats
|
||||
|
@ -6036,11 +6033,10 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
for (int face = D3DCUBEMAP_FACE_POSITIVE_X; face <= last_face; face++) {
|
||||
// As we iterate through mipmap levels, we'll adjust the source resource offset
|
||||
DWORD dwMipOffset = 0;
|
||||
DWORD pxMipWidth = xboxWidth;
|
||||
DWORD pxMipHeight = xboxHeight;
|
||||
DWORD pxMipDepth = dwDepth;
|
||||
DWORD dwMipRowPitch = dwRowPitch;
|
||||
DWORD dwSrcSlicePitch = dwMipRowPitch * pxMipHeight; // TODO
|
||||
DWORD pxMipWidth = xboxWidth; // the current mip width in pixels
|
||||
DWORD pxMipHeight = xboxHeight; // the current mip height in pixels
|
||||
DWORD pxMipDepth = dwDepth; // the current mip depth in pixels
|
||||
DWORD dwMipRowPitch = dwRowPitch; // bytes to the next row of pixels (or DXT blocks)
|
||||
|
||||
for (unsigned int mipmap_level = 0; mipmap_level < dwMipMapLevels; mipmap_level++) {
|
||||
|
||||
|
@ -6048,16 +6044,18 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
DWORD numRows = pxMipHeight;
|
||||
|
||||
if (bCompressed) {
|
||||
// Each row contains a 4x4 pixel blocks, instead of single pixels
|
||||
// Each row contains a 4x4 pixel DXT blocks, instead of single pixels
|
||||
// So divide by 4 to get the number of rows
|
||||
numRows = (numRows + 3) / 4;
|
||||
}
|
||||
|
||||
DWORD dwMipSize = dwMipRowPitch * numRows;
|
||||
DWORD mip2dSize = dwMipRowPitch * numRows; // the size of one layer of the mip slice
|
||||
DWORD mipSlicePitch = mip2dSize * pxMipDepth; // the total size of the mip slice (depth is only > 1 for volume textures)
|
||||
|
||||
// Lock the host resource
|
||||
D3DLOCKED_RECT LockedRect = {};
|
||||
D3DLOCKED_BOX LockedBox = {};
|
||||
DWORD D3DLockFlags = D3DLOCK_NOSYSLOCK;
|
||||
|
||||
switch (XboxResourceType) {
|
||||
case xbox::X_D3DRTYPE_SURFACE:
|
||||
|
@ -6123,7 +6121,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
if (!skipDueToNoPalette) {
|
||||
if (!ConvertD3DTextureToARGBBuffer(
|
||||
X_Format,
|
||||
pSrc, pxMipWidth, pxMipHeight, dwMipRowPitch, dwMipSize,//use dwMipSize instead of dwSrcSlicePitch here, because the mipSize changed in 3D mip map.
|
||||
pSrc, pxMipWidth, pxMipHeight, dwMipRowPitch, mip2dSize,
|
||||
pDst, dwDstRowPitch, dwDstSlicePitch,
|
||||
pxMipDepth,//used pxMipDepth here because in 3D mip map the 3rd dimension also shrinked to 1/2 at each mip level.
|
||||
iTextureStage)) {
|
||||
|
@ -6140,7 +6138,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
);
|
||||
}
|
||||
else if (bCompressed) {
|
||||
memcpy(pDst, pSrc, dwMipSize);
|
||||
memcpy(pDst, pSrc, mip2dSize);
|
||||
}
|
||||
else {
|
||||
/* TODO : // Let DirectX convert the surface (including palette formats) :
|
||||
|
@ -6159,7 +6157,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
} else {
|
||||
*/
|
||||
if ((dwDstRowPitch == dwMipRowPitch) && (dwMipRowPitch == pxMipWidth * dwBPP)) {
|
||||
memcpy(pDst, pSrc, dwMipSize);
|
||||
memcpy(pDst, pSrc, mip2dSize);
|
||||
}
|
||||
else {
|
||||
for (DWORD v = 0; v < pxMipHeight; v++) {
|
||||
|
@ -6195,12 +6193,8 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
EmuLog(LOG_LEVEL::WARNING, "Unlocking host %s failed!", ResourceTypeName);
|
||||
}
|
||||
|
||||
if (face == D3DCUBEMAP_FACE_POSITIVE_X) {
|
||||
dwCubeFaceSize += pxMipDepth * dwMipSize;
|
||||
}
|
||||
|
||||
// Calculate the next mipmap level dimensions
|
||||
dwMipOffset += pxMipDepth * dwMipSize;//for 3D volumeTexture, the dwDepth >1 in mip_level 0, pxMipDepth must be multiplied.
|
||||
dwMipOffset += mipSlicePitch;
|
||||
if (pxMipWidth > 1) {
|
||||
pxMipWidth /= 2;
|
||||
|
||||
|
@ -6222,11 +6216,7 @@ void CreateHostResource(xbox::X_D3DResource *pResource, DWORD D3DUsage, int iTex
|
|||
}
|
||||
} // for mipmap levels
|
||||
|
||||
if (face == D3DCUBEMAP_FACE_POSITIVE_X) {
|
||||
dwCubeFaceSize = ROUND_UP(dwCubeFaceSize, X_D3DTEXTURE_CUBEFACE_ALIGNMENT);
|
||||
}
|
||||
|
||||
dwCubeFaceOffset += dwCubeFaceSize;
|
||||
dwCubeFaceOffset += dwSlicePitch;
|
||||
} // for cube faces
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue