Hi. I am trying to get access to the depth buffer so I can manipulate its values manually just as I am manipulating back buffer values manually in my drawing routines. Here is what I have in my render ():
D3DLOCKED_RECT LockedRect, LockedRectb;
g_pDevice -> Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB (0, 0, 0), 1.0f, 0);
g_pDevice -> GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, &g_pBackSurf);
g_pDevice -> GetDepthStencilSurface (&pZBuffer);
g_pBackSurf -> LockRect (&LockedRect, NULL, 0);
pZBuffer -> LockRect (&LockedRectb, NULL, 0);
DWORD* pData = (DWORD*)(LockedRect.pBits); //back buffer, works fine
float* dbuff = (float*)(LockedRectb.pBits);
//dbuff [0] = 0.1f;
//When I debug I get an "Error: expression cannot be evaluated" for
//the above line and for LockedRectb.pBits in the line before it.
//Program closes fast whenever I try to manipulate or look at the
//values in the depth buffer.
//GRAPHICS DRAWING HERE
g_pBackSurf -> UnlockRect ();
pZBuffer -> UnlockRect ();
g_pBackSurf -> Release ();
g_pBackSurf = 0;
pZBuffer -> Release ();
pZBuffer = 0;
g_pDevice -> Present (NULL, NULL, NULL, NULL);
render = false;
return S_OK;
Here are my basic D3D settings:
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
HRESULT r = 0;
if (*ppDevice)
(*ppDevice) -> Release ();
ZeroMemory ( &d3dpp, sizeof (D3DPRESENT_PARAMETERS) );
r = pD3D -> GetAdapterDisplayMode (D3DADAPTER_DEFAULT, &d3ddm);
d3dpp.BackBufferWidth = Width;
d3dpp.BackBufferHeight = Height;
d3dpp.BackBufferFormat = bWindowed ? d3ddm.Format : FullScreenFormat;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.hDeviceWindow = hWndTarget;
d3dpp.Windowed = bWindowed;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.FullScreen_RefreshRateInHz = 0;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
r = pD3D -> CreateDevice
(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWndTarget,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
ppDevice
);
g_DeviceHeight = Height;
g_DeviceWidth = Width;
g_SavedPresParams = d3dpp;
return S_OK;
I am making a small renderer in which I basically just want my own back buffer and depth buffer to deal with. I tried making my own array for the depth buffer but it's just too slow since it can't be reset fast enough each time render () is called. What I want to be able to do is look at and manipulate values in the depth buffer and have it cleared by D3D just as the back buffer is cleared. I appreciate any help.