Changed: Implement getZBuffer for Direct3D driver

This commit is contained in:
kervala 2010-11-04 22:19:57 +01:00
parent 24b19f3077
commit a883ea0777
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; IDirect3DSurface9 *surface;
if(_DeviceInterface->GetDepthStencilSurface(&surface)== D3D_OK) if (SUCCEEDED(_DeviceInterface->GetDepthStencilSurface(&surface)))
{ {
// Surface desc if (clipRect(rect))
D3DSURFACE_DESC desc;
if (surface->GetDesc(&desc) == D3D_OK)
{ {
// 32 bits format supported RECT winRect;
if (desc.Format == D3DFMT_D24S8)
{
// Lock the surface
D3DLOCKED_RECT lock;
::RECT winRect;
winRect.left = rect.left(); winRect.left = rect.left();
winRect.right = rect.right(); winRect.right = rect.right();
winRect.top = rect.top(); winRect.top = rect.top();
winRect.bottom = rect.bottom(); winRect.bottom = rect.bottom();
const uint lineCount = rect.Height;
const uint width = rect.Width; // Lock the surface
HRESULT hr = surface->LockRect (&lock, &winRect, D3DLOCK_READONLY); D3DLOCKED_RECT lock;
if (hr == D3D_OK) if (SUCCEEDED(surface->LockRect (&lock, &winRect, D3DLOCK_READONLY)))
{ {
zbuffer.resize(rect.Width*rect.Height); zbuffer.resize(rect.Width*rect.Height);
// Line count
float *dest = &(zbuffer[0]); // Surface desc
uint i; D3DSURFACE_DESC desc;
for (i=0; i<lineCount; i++) if (SUCCEEDED(surface->GetDesc(&desc)))
{ {
memcpy (dest+(4*i*width), ((uint8*)lock.pBits)+(i*lock.Pitch), width*4); const uint8* pBits = (uint8*)lock.pBits;
for(uint y=0; y<rect.Height; ++y)
{
uint offset = y*rect.Width;
uint end = offset + rect.Width;
// 32 bits format supported
if (desc.Format == D3DFMT_D32F_LOCKABLE)
{
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;