[856] | 1 | #ifndef __IMDEBUGD3D_H__
|
---|
| 2 | #define __IMDEBUGD3D_H__
|
---|
| 3 |
|
---|
| 4 | #include <imdebug.h>
|
---|
| 5 | #include <d3d9.h>
|
---|
| 6 | #include <string>
|
---|
| 7 |
|
---|
| 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 | string format2string(D3DFORMAT format);
|
---|
| 11 |
|
---|
| 12 | inline HRESULT
|
---|
| 13 | imdebugRenderTarget(IDirect3DSurface9 *pRenderTarget, IDirect3DDevice9 *pd3dDevice, char *argstring = NULL)
|
---|
| 14 | {
|
---|
| 15 | HRESULT hr = S_OK;
|
---|
| 16 | IDirect3DTexture9 *pTempTex;
|
---|
| 17 | IDirect3DSurface9 *pData;
|
---|
| 18 | D3DSURFACE_DESC desc;
|
---|
| 19 | V( pRenderTarget->GetDesc(&desc) );
|
---|
| 20 |
|
---|
| 21 | V( D3DXCreateTexture(pd3dDevice, desc.Width, desc.Height, 0, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pTempTex) );
|
---|
| 22 | V( pTempTex->GetSurfaceLevel(0, &pData) );
|
---|
| 23 | V( pd3dDevice->GetRenderTargetData(pRenderTarget, pData));
|
---|
| 24 |
|
---|
| 25 | D3DLOCKED_RECT lockedRect;
|
---|
| 26 | V( pData->LockRect(&lockedRect, NULL, D3DLOCK_READONLY) );
|
---|
| 27 |
|
---|
| 28 | string s = (NULL == argstring) ? format2string(desc.Format) : argstring;
|
---|
| 29 |
|
---|
| 30 | imdebug(s.append(" w=%d h=%d %p").c_str(), desc.Width, desc.Height, lockedRect.pBits);
|
---|
| 31 |
|
---|
| 32 | pData->UnlockRect();
|
---|
| 33 |
|
---|
| 34 | SAFE_RELEASE(pTempTex);
|
---|
| 35 | SAFE_RELEASE(pData);
|
---|
| 36 |
|
---|
| 37 | return hr;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | inline string format2string(D3DFORMAT format)
|
---|
| 42 | {
|
---|
| 43 | switch(format)
|
---|
| 44 | {
|
---|
| 45 | case D3DFMT_R16F:
|
---|
| 46 | case D3DFMT_R32F:
|
---|
| 47 | return "lum b=32f";
|
---|
| 48 | break;
|
---|
| 49 | case D3DFMT_A8:
|
---|
| 50 | case D3DFMT_P8:
|
---|
| 51 | case D3DFMT_L8:
|
---|
| 52 | case D3DFMT_L16:
|
---|
| 53 | case D3DFMT_D16_LOCKABLE:
|
---|
| 54 | case D3DFMT_D32F_LOCKABLE:
|
---|
| 55 | return "lum";
|
---|
| 56 | break;
|
---|
| 57 | case D3DFMT_G16R16F:
|
---|
| 58 | return "luma b=32f";
|
---|
| 59 | break;
|
---|
| 60 | case D3DFMT_V8U8:
|
---|
| 61 | case D3DFMT_V16U16:
|
---|
| 62 | case D3DFMT_G16R16:
|
---|
| 63 | case D3DFMT_A8P8:
|
---|
| 64 | case D3DFMT_A8L8:
|
---|
| 65 | case D3DFMT_A4L4:
|
---|
| 66 | return "luma";
|
---|
| 67 | break;
|
---|
| 68 | case D3DFMT_R3G3B2:
|
---|
| 69 | case D3DFMT_R5G6B5:
|
---|
| 70 | case D3DFMT_R8G8B8:
|
---|
| 71 | case D3DFMT_CxV8U8:
|
---|
| 72 | case D3DFMT_L6V5U5:
|
---|
| 73 | return "rgb";
|
---|
| 74 | break;
|
---|
| 75 | case D3DFMT_X4R4G4B4:
|
---|
| 76 | case D3DFMT_A8R3G3B2:
|
---|
| 77 | case D3DFMT_A4R4G4B4:
|
---|
| 78 | case D3DFMT_A1R5G5B5:
|
---|
| 79 | case D3DFMT_X1R5G5B5:
|
---|
| 80 | case D3DFMT_X8R8G8B8:
|
---|
| 81 | case D3DFMT_A8R8G8B8:
|
---|
| 82 | case D3DFMT_Q16W16V16U16:
|
---|
| 83 | case D3DFMT_Q8W8V8U8:
|
---|
| 84 | case D3DFMT_A2W10V10U10:
|
---|
| 85 | case D3DFMT_X8L8V8U8:
|
---|
| 86 | return "rgba";
|
---|
| 87 | break;
|
---|
| 88 | case D3DFMT_X8B8G8R8:
|
---|
| 89 | case D3DFMT_A8B8G8R8:
|
---|
| 90 | case D3DFMT_A16B16G16R16:
|
---|
| 91 | case D3DFMT_A2R10G10B10:
|
---|
| 92 | case D3DFMT_A2B10G10R10:
|
---|
| 93 | return "abgr";
|
---|
| 94 | break;
|
---|
| 95 | case D3DFMT_A16B16G16R16F:
|
---|
| 96 | case D3DFMT_A32B32G32R32F:
|
---|
| 97 | return "abgr b=32f";
|
---|
| 98 | break;
|
---|
| 99 | default:
|
---|
| 100 | return "rgba";
|
---|
| 101 | break;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | #endif |
---|