I meet a problem when I want to lock a back buffer under DXUT framework.
I do change the present parameter flag to D3DPRESENTFLAG_LOCKABLE_BACKBUFFER,
and in OnD3D9FrameRender I call :
[source lang = "c"]
// test to modify the backbuffer
IDirect3DSurface9* pSurface;
V(pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&pSurface));
D3DLOCKED_RECT lockedRect;
D3DSURFACE_DESC sd;
pSurface->GetDesc(&sd);
pSurface->LockRect(&lockedRect,NULL,D3DLOCK_DISCARD);
int pitch = lockedRect.Pitch;
DWORD* pBits = reinterpret_cast<DWORD*>(lockedRect.pBits);
for (int i = 0; i < 1; ++i)
{
int x = rand() % sd.Height;
int y = rand() % sd.Width;
*(pBits + y + x * pitch) = D3DCOLOR_XRGB(rand()%256,rand()%256,rand()%256);
}
pSurface->UnlockRect();
SAFE_RELEASE(pSurface);
when debuging, i check the sd(surface_desc),all data are all right. But the data pSurface pointing to are mistake:
- pSurface 0x001ebee0 {Name=0x00000016 <Bad Ptr> Width=1 Height=67108865 ...} IDirect3DSurface9 *
+ IDirect3DResource9 {...} IDirect3DResource9
+ Name 0x00000016 <Bad Ptr> const wchar_t *
Width 1 unsigned int
Height 67108865 unsigned int
Usage 4 unsigned long
Format D3DFMT_UNKNOWN _D3DFORMAT
Pool D3DPOOL_DEFAULT _D3DPOOL
MultiSampleType 640 _D3DMULTISAMPLE_TYPE
MultiSampleQuality 480 unsigned long
Priority 0 unsigned long
LockCount 22 unsigned int
DCCount 0 unsigned int
+ CreationCallStack 0x00000007 <Bad Ptr> const wchar_t *
I think the value of width and height replace the value of MultiSampleType and MultiSampleQuality... Why there is an offset?
and when i write the back buffer, it's overflow and the shutdown.
Need help ,thx.