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,52 +3763,82 @@ bool CDriverD3D::clipRect(NLMISC::CRect &rect)
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();
IDirect3DSurface9 *surface;
if (SUCCEEDED(_DeviceInterface->GetDepthStencilSurface(&surface)))
{
if (clipRect(rect))
{
IDirect3DSurface9 *surface;
if(_DeviceInterface->GetDepthStencilSurface(&surface)== D3D_OK)
{
// Surface desc
D3DSURFACE_DESC desc;
if (surface->GetDesc(&desc) == D3D_OK)
{
// 32 bits format supported
if (desc.Format == D3DFMT_D24S8)
{
// Lock the surface
D3DLOCKED_RECT lock;
::RECT winRect;
RECT winRect;
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)
// Lock the surface
D3DLOCKED_RECT lock;
if (SUCCEEDED(surface->LockRect (&lock, &winRect, D3DLOCK_READONLY)))
{
zbuffer.resize(rect.Width*rect.Height);
// Line count
float *dest = &(zbuffer[0]);
uint i;
for (i=0; i<lineCount; i++)
// Surface desc
D3DSURFACE_DESC desc;
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->Release();
}
}
*/
}
void CDriverD3D::findNearestFullscreenVideoMode()

View file

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