📄 twiddle.c
字号:
psSrcRect->left,
psSrcRect->top,
psDestRect->right - psDestRect->left,
psDestRect->bottom - psDestRect->top,
ui32Stride);
ui32Log2Width = AsPowerOfTwo(psDest->sDescription.sTexture.dwScaledWidth);
ui32Log2Height = AsPowerOfTwo(psDest->sDescription.sTexture.dwScaledHeight);
/* Twiddle to dest from memory region */
pfnSubTextureTwiddle((IMG_VOID *) ((DWORD) (psDest->psMemInfo->pvLinAddr) + psDest->sDescription.sTexture.dwLevelOffset),
pvBuffer,
ui32Log2Width,
ui32Log2Height,
psDestRect->left,
psDestRect->top,
psDestRect->right - psDestRect->left,
psDestRect->bottom - psDestRect->top,
ui32Stride);
D3DMFree(pvBuffer);
}
/***********************************************************************************
Function Name : UnTwiddleRegionToBuffer
Inputs :
Outputs :
Returns : -
Description : UnTwiddleRegion a texture region to a mem buffer
************************************************************************************/
IMG_VOID UnTwiddleRegionToBuffer(LPD3DM_SURFACE psSource,
VOID *pvDest,
DWORD dwDestStrideByte,
DWORD dwDestBytesPerPixel,
PRECT psSrcRect)
{
IMG_UINT32 ui32Log2Width, ui32Log2Height, ui32Stride;
ui32Stride = dwDestStrideByte / dwDestBytesPerPixel;
ui32Log2Width = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledWidth);
ui32Log2Height = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledHeight);
switch(dwDestBytesPerPixel)
{
case 1:
{
pfnReadBackData = ReadBackTwiddle8bpp;
break;
}
case 2:
{
pfnReadBackData = ReadBackTwiddle16bpp;
break;
}
case 4:
{
pfnReadBackData = ReadBackTwiddle32bpp;
break;
}
}
pfnReadBackData(pvDest,
(IMG_VOID *) ((DWORD) (psSource->psMemInfo->pvLinAddr) + psSource->sDescription.sTexture.dwLevelOffset),
ui32Log2Width,
ui32Log2Height,
psSrcRect->left,
psSrcRect->top,
psSrcRect->right - psSrcRect->left,
psSrcRect->bottom - psSrcRect->top,
ui32Stride);
}
/***********************************************************************************
Function Name : UnTwiddleRegion
Inputs :
Outputs :
Returns : -
Description : UnTwiddleRegion a texture region
************************************************************************************/
IMG_VOID UnTwiddleRegion(LPD3DM_SURFACE psSource,
LPD3DM_SURFACE psDest,
PRECT psSrcRect,
PRECT psDestRect)
{
IMG_UINT32 ui32Log2Width, ui32Log2Height, ui32Stride;
IMG_VOID *pvDest = (IMG_VOID *) ((DWORD) (psDest->psMemInfo->pvLinAddr) +
psDest->sDescription.sTexture.dwLevelOffset +
(psDestRect->top * psDest->dwStrideByte) +
(psDestRect->left * (psDest->dwBpp / 8)));
ui32Stride = psDest->dwStrideByte / (psDest->dwBpp / 8);
ui32Log2Width = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledWidth);
ui32Log2Height = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledHeight);
switch(psDest->dwBpp)
{
case 8:
{
pfnReadBackData = ReadBackTwiddle8bpp;
break;
}
case 16:
{
pfnReadBackData = ReadBackTwiddle16bpp;
break;
}
case 32:
{
pfnReadBackData = ReadBackTwiddle32bpp;
break;
}
}
pfnReadBackData(pvDest,
(IMG_VOID *) ((DWORD) (psSource->psMemInfo->pvLinAddr) + psSource->sDescription.sTexture.dwLevelOffset),
ui32Log2Width,
ui32Log2Height,
psSrcRect->left,
psSrcRect->top,
psDestRect->right - psDestRect->left,
psDestRect->bottom - psDestRect->top,
ui32Stride);
}
/***********************************************************************************
Function Name : UnTwiddleToSurface
Inputs :
Outputs :
Returns : -
Description : UnTwiddles a texture surface to another surface
************************************************************************************/
IMG_VOID UnTwiddleToSurface(LPD3DM_SURFACE psSource,
LPD3DM_SURFACE psDest,
PRECT psSrcRect,
PRECT psDestRect)
{
IMG_UINT32 ui32Log2Width, ui32Log2Height, ui32Stride;
ui32Stride = psDest->dwStrideByte / (psDest->dwBpp / 8);
ui32Log2Width = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledWidth);
ui32Log2Height = AsPowerOfTwo(psSource->sDescription.sTexture.dwScaledHeight);
switch(psSource->dwBpp)
{
case 8:
{
pfnReadBackData = ReadBackTwiddle8bpp;
break;
}
case 16:
{
pfnReadBackData = ReadBackTwiddle16bpp;
break;
}
case 32:
{
pfnReadBackData = ReadBackTwiddle32bpp;
break;
}
}
pfnReadBackData((IMG_VOID *) ((DWORD) (psDest->psMemInfo->pvLinAddr) + psDest->sDescription.sTexture.dwLevelOffset),
(IMG_VOID *) ((DWORD) (psSource->psMemInfo->pvLinAddr) + psSource->sDescription.sTexture.dwLevelOffset),
ui32Log2Width,
ui32Log2Height,
psDestRect->left,
psDestRect->top,
psDestRect->right - psDestRect->left,
psDestRect->bottom - psDestRect->top,
ui32Stride);
}
/***********************************************************************************
Function Name : UnTwiddleSurface
Inputs :
Outputs :
Returns : -
Description : UnTwiddles a texture surface
************************************************************************************/
IMG_VOID UnTwiddleSurface(LPD3DM_SURFACE psSurf)
{
IMG_UINT32 ui32Log2Width, ui32Log2Height, ui32Stride, ui32AllocSize;
IMG_VOID *pvBuffer;
ui32AllocSize = (psSurf->dwStrideByte * psSurf->sDescription.sTexture.dwScaledHeight);
ui32Stride = psSurf->dwStrideByte / (psSurf->dwBpp / 8);
ui32Log2Width = AsPowerOfTwo(psSurf->sDescription.sTexture.dwScaledWidth);
ui32Log2Height = AsPowerOfTwo(psSurf->sDescription.sTexture.dwScaledHeight);
pvBuffer = D3DMAllocate(ui32AllocSize);
switch(psSurf->dwBpp)
{
case 8:
{
pfnReadBackData = ReadBackTwiddle8bpp;
break;
}
case 16:
{
pfnReadBackData = ReadBackTwiddle16bpp;
break;
}
case 32:
{
pfnReadBackData = ReadBackTwiddle32bpp;
break;
}
}
pfnReadBackData(pvBuffer,
(IMG_VOID *) ((DWORD) (psSurf->psMemInfo->pvLinAddr) + psSurf->sDescription.sTexture.dwLevelOffset),
ui32Log2Width,
ui32Log2Height,
0,
0,
psSurf->sDescription.sTexture.dwScaledWidth,
psSurf->sDescription.sTexture.dwScaledHeight,
ui32Stride);
/* Copy converted buffer */
memcpy((IMG_VOID *) ((DWORD) (psSurf->psMemInfo->pvLinAddr) + psSurf->sDescription.sTexture.dwLevelOffset),
pvBuffer,
ui32AllocSize);
psSurf->dwFlags &= ~D3DM_SURFACE_FLAGS_TWIDDLED;
D3DMFree(pvBuffer);
}
/***********************************************************************************
Function Name : Twiddle
Inputs :
Outputs :
Returns : -
Description : Decides what action to take when copying between surfaces
************************************************************************************/
IMG_BOOL Twiddle(LPD3DM_SURFACE psSrcData,
LPD3DM_SURFACE psDestData,
PRECT psSrcRect,
PRECT psDestRect)
{
if(psSrcData->psContext->sRegData.dwIFlags & D3DMREGI_NOTWIDDLEDTEXTURES)
{
return IMG_FALSE;
}
/* We currently can't twiddle between distinct formats */
if(psSrcData->eFormat != psDestData->eFormat)
{
if(psSrcData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED)
{
/* We need to untwiddle the surface */
UnTwiddleSurface(psSrcData);
}
if(psDestData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED)
{
/* Does Dest rect cover entire surface? */
if((psDestRect->right - psDestRect->left) == psDestData->sDescription.sTexture.dwScaledWidth &&
(psDestRect->bottom - psDestRect->top) == psDestData->sDescription.sTexture.dwScaledHeight)
{
/* Copy will overwrite all twiddled data */
psDestData->dwFlags &= ~D3DM_SURFACE_FLAGS_TWIDDLED;
}
else
{
/* We need to untwiddle the dest surface */
UnTwiddleSurface(psDestData);
}
}
return IMG_FALSE;
}
/* We need to decide if we can twiddle, or if not what we need to do */
if(!(psSrcData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED) &&
!(psDestData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED))
{
/* Strided to Strided */
if(psDestData->eSurfaceType == D3DMRTYPE_TEXTURE)
{
/* Does Dest rect cover entire surface? */
if((psDestRect->right - psDestRect->left) == psDestData->sDescription.sTexture.dwScaledWidth &&
(psDestRect->bottom - psDestRect->top) == psDestData->sDescription.sTexture.dwScaledHeight)
{
/* Twiddle all data to target */
TwiddleSurface(psSrcData, psDestData, psSrcRect, psDestRect);
psDestData->dwFlags |= D3DM_SURFACE_FLAGS_TWIDDLED;
}
else return IMG_FALSE;
}
else return IMG_FALSE;
}
else if(!(psSrcData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED) &&
(psDestData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED))
{
/* Twiddle to target */
TwiddleSurface(psSrcData, psDestData, psSrcRect, psDestRect);
}
else if((psSrcData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED) &&
!(psDestData->dwFlags & D3DM_SURFACE_FLAGS_TWIDDLED))
{
/* Twiddled to Strided. Does Dest rect cover entire surface? */
if((psDestRect->right - psDestRect->left) == psDestData->sDescription.sTexture.dwScaledWidth &&
(psDestRect->bottom - psDestRect->top) == psDestData->sDescription.sTexture.dwScaledHeight)
{
if(psDestData->eSurfaceType == D3DMRTYPE_TEXTURE)
{
/* Direct Copy of pre-twiddled data */
TwiddleCopy(psSrcData, psDestData);
}
else
{
/* Untwiddle entire source surface to dest surface */
UnTwiddleToSurface(psSrcData,
psDestData,
psSrcRect,
psDestRect);
}
}
else
{
/* De-twiddle sub region to dest */
UnTwiddleRegion(psSrcData,
psDestData,
psSrcRect,
psDestRect);
}
}
else
{
/* Twiddled to Twiddled - Does Dest rect cover entire surface? */
if((psDestRect->right - psDestRect->left) == psDestData->sDescription.sTexture.dwScaledWidth &&
(psDestRect->bottom - psDestRect->top) == psDestData->sDescription.sTexture.dwScaledHeight)
{
/* Direct Copy of pre-twiddled data */
TwiddleCopy(psSrcData, psDestData);
}
else
{
/* De-twiddle to temp - twiddle to target */
TwiddleRegionFromTwiddled(psSrcData,
psDestData,
psSrcRect,
psDestRect);
}
}
return IMG_TRUE;
}
/*****************************************************************************
End of file (TWIDDLE.C)
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -