Changed: Implement getZBuffer for Direct3D driver

This commit is contained in:
kervala 2010-11-04 22:19:57 +01:00
parent 19191f88f4
commit 9c9fc9375c
2 changed files with 62 additions and 33 deletions

View file

@ -3763,51 +3763,81 @@ bool CDriverD3D::clipRect(NLMISC::CRect &rect)
return rect.Width>0 && rect.Height>0; return rect.Width>0 && rect.Height>0;
} }
void CDriverD3D::getZBufferPart (std::vector<float> &/* zbuffer */, NLMISC::CRect &/* rect */) void CDriverD3D::getZBuffer(std::vector<float> &zbuffer)
{
H_AUTO_D3D(CDriverD3D_getZBuffer);
CRect rect(0, 0);
getWindowSize(rect.Width, rect.Height);
getZBufferPart(zbuffer, rect);
}
void CDriverD3D::getZBufferPart (std::vector<float> &zbuffer, NLMISC::CRect &rect)
{ {
/* ace: currently not working
zbuffer.clear(); zbuffer.clear();
if(clipRect(rect)) IDirect3DSurface9 *surface;
if (SUCCEEDED(_DeviceInterface->GetDepthStencilSurface(&surface)))
{ {
IDirect3DSurface9 *surface; if (clipRect(rect))
if(_DeviceInterface->GetDepthStencilSurface(&surface)== D3D_OK)
{ {
// Surface desc RECT winRect;
D3DSURFACE_DESC desc; winRect.left = rect.left();
if (surface->GetDesc(&desc) == D3D_OK) winRect.right = rect.right();
winRect.top = rect.top();
winRect.bottom = rect.bottom();
// Lock the surface
D3DLOCKED_RECT lock;
if (SUCCEEDED(surface->LockRect (&lock, &winRect, D3DLOCK_READONLY)))
{ {
// 32 bits format supported zbuffer.resize(rect.Width*rect.Height);
if (desc.Format == D3DFMT_D24S8)
// Surface desc
D3DSURFACE_DESC desc;
if (SUCCEEDED(surface->GetDesc(&desc)))
{ {
// Lock the surface const uint8* pBits = (uint8*)lock.pBits;
D3DLOCKED_RECT lock;
::RECT winRect; for(uint y=0; y<rect.Height; ++y)
winRect.left = rect.left();
winRect.right = rect.right();
winRect.top = rect.top();
winRect.bottom = rect.bottom();
const uint lineCount = rect.Height;
const uint width = rect.Width;
HRESULT hr = surface->LockRect (&lock, &winRect, D3DLOCK_READONLY);
if (hr == D3D_OK)
{ {
zbuffer.resize(rect.Width*rect.Height); uint offset = y*rect.Width;
// Line count uint end = offset + rect.Width;
float *dest = &(zbuffer[0]);
uint i; // 32 bits format supported
for (i=0; i<lineCount; i++) if (desc.Format == D3DFMT_D32F_LOCKABLE)
{ {
memcpy (dest+(4*i*width), ((uint8*)lock.pBits)+(i*lock.Pitch), width*4); const float *src = (float*)(pBits + lock.Pitch * y);
float *dst = &zbuffer[offset];
memcpy(dst, src, rect.Width * sizeof(float));
}
else if (desc.Format == D3DFMT_D24S8)
{
uint32* pRow = (uint32*)(pBits + lock.Pitch * y);
while(offset != end)
{
uint32 value = *pRow++;
zbuffer[offset++] = (float)value / (float)std::numeric_limits<uint32>::max();
}
}
else if (desc.Format == D3DFMT_D16_LOCKABLE)
{
uint16* pRow = (uint16*)(pBits + lock.Pitch * y);
while(offset != end)
{
uint16 value = *pRow++;
zbuffer[offset++] = (float)value / (float)std::numeric_limits<uint16>::max();
}
} }
surface->UnlockRect ();
} }
} }
surface->UnlockRect ();
} }
surface->Release();
} }
surface->Release();
} }
*/
} }

View file

@ -822,9 +822,8 @@ public:
virtual void setDepthRange(float znear, float zfar); virtual void setDepthRange(float znear, float zfar);
virtual void getDepthRange(float &znear, float &zfar) const; virtual void getDepthRange(float &znear, float &zfar) const;
// todo hulud d3d buffers virtual void getZBuffer (std::vector<float> &zbuffer);
virtual void getZBuffer (std::vector<float> &/* zbuffer */) {} virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect);
virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect); // Only 32 bits back buffer supported
// return true if driver support Bloom effect. // return true if driver support Bloom effect.
virtual bool supportBloomEffect() const; virtual bool supportBloomEffect() const;