From a883ea07772c7e56fa0b99b9bc949f40b246beec Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 4 Nov 2010 22:19:57 +0100 Subject: [PATCH] Changed: Implement getZBuffer for Direct3D driver --- .../3d/driver/direct3d/driver_direct3d.cpp | 90 ++++++++++++------- .../src/3d/driver/direct3d/driver_direct3d.h | 5 +- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 8388651c8..098e7d1df 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -3763,51 +3763,81 @@ bool CDriverD3D::clipRect(NLMISC::CRect &rect) return rect.Width>0 && rect.Height>0; } -void CDriverD3D::getZBufferPart (std::vector &/* zbuffer */, NLMISC::CRect &/* rect */) +void CDriverD3D::getZBuffer(std::vector &zbuffer) +{ + H_AUTO_D3D(CDriverD3D_getZBuffer); + + CRect rect(0, 0); + getWindowSize(rect.Width, rect.Height); + getZBufferPart(zbuffer, rect); +} + +void CDriverD3D::getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect) { -/* ace: currently not working zbuffer.clear(); - if(clipRect(rect)) + IDirect3DSurface9 *surface; + if (SUCCEEDED(_DeviceInterface->GetDepthStencilSurface(&surface))) { - IDirect3DSurface9 *surface; - if(_DeviceInterface->GetDepthStencilSurface(&surface)== D3D_OK) + if (clipRect(rect)) { - // Surface desc - D3DSURFACE_DESC desc; - if (surface->GetDesc(&desc) == D3D_OK) + RECT winRect; + winRect.left = rect.left(); + 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 - if (desc.Format == D3DFMT_D24S8) + zbuffer.resize(rect.Width*rect.Height); + + // Surface desc + D3DSURFACE_DESC desc; + if (SUCCEEDED(surface->GetDesc(&desc))) { - // Lock the surface - D3DLOCKED_RECT lock; - ::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) + const uint8* pBits = (uint8*)lock.pBits; + + for(uint y=0; y::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::max(); + } } - surface->UnlockRect (); } } + + surface->UnlockRect (); } - surface->Release(); } + + surface->Release(); } -*/ } diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 5f2857de1..f17531520 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -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 &/* zbuffer */) {} - virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect); // Only 32 bits back buffer supported + virtual void getZBuffer (std::vector &zbuffer); + virtual void getBufferPart (CBitmap &bitmap, NLMISC::CRect &rect); // return true if driver support Bloom effect. virtual bool supportBloomEffect() const;