Skip to main content
gamedev.net
🔒 Locked

Z-buffer creation error

Started by Kjell Andersson 0 replies 1.3k views
Original Post
Kjell Andersson
Kjell Andersson
I am trying to port an application from DX3 to DX7 and can''t seem to be able to create the z-buffers as I used to. I found out that the creation procedure had changed and that the dwZBufferBitDepth was no longer directly under DDSURFACEDESC. Ok, so I changed my code and now use DDSURFACEDESC2 and DDSD_PIXELFORMAT instead. The problem is that my creation now fails. What have I done wrong? The z-buffer is used as a stand alone surface that I later use to copy to the screen-attached z-buffer. Here is the code I use now that does not work: DDSURFACEDESC2 ddsd; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH / DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; ddsd.dwHeight = 128; ddsd.dwWidth = 128; ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER; ddsd.ddpfPixelFormat.dwZBufferBitDepth = 16; d3dapp->m_pDD->CreateSurface(&ddsd, &m_lpDDSz, NULL);
ckillpack
ckillpack
quote:
Original post by Kjell Andersson

The problem is that my creation now fails. What have I done wrong?

Here is the code I use now that does not work:

DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH / DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
ddsd.dwHeight = 128;
ddsd.dwWidth = 128;
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
ddsd.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
ddsd.ddpfPixelFormat.dwZBufferBitDepth = 16;
d3dapp->m_pDD->CreateSurface(&ddsd, &m_lpDDSz, NULL);



Hi Kjell,

First I think you have a typo in the ddsd.dwFlags line. It should read

ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH / DDSD_PIXELFORMAT;

If you make this change the call fails but this time because the ddsd.ddpfPixelFormat structure is wrong. The best to accurately fill this out (in fact this is what D3D recommends, and I do) is prior to creating your ZBuffer you enumerate the card''s zbuffer formats.

Here is some sample code

DDPIXELFORMAT g_MyZBufferPF;

// This is a very simple callback - we will just use the
// first 16-bit z-buffer format that we find.
HRESULT CALLBACK EnumZBufferPFCallback( LPDDPIXELFORMAT lpDDPixFmt , LPVOID lpContext )
{
if (lpDDPixFmt->dwZBufferBitDepth == 16)
{
g_MyZBufferPF = *lpDDPixFmt;
return D3DENUMRET_CANCEL;
}

return D3DENUMRET_OK;
}

...

// Z-Buffer creation code

// Enumerate Z-Buffer formats
// Substitute the correct D3D GUID in, e.g. if you
// don''t have a TnL device then you would want to use
// IID_IDirect3DHALDevice.


HRESULT hr;
hr = m_pD3D7->EnumZBufferFormats( IID_IDirect3DTnLHalDevice , EnumZBufferPFCallback );
if (FAILED( hr ))
// Error: do something

// And then your code with a slight modification.
DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH / DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
ddsd.dwHeight = 128;
ddsd.dwWidth = 128;

Here is the change, we just copy our z-buffer pixel format
of choice into the ddsd.ddpfPixelFormat field...

ddsd.ddpfPixelFormat = g_MyZBufferPF;
d3dapp->m_pDD->CreateSurface(&ddsd, &m_lpDDSz, NULL);

I have tested this code on my GeForce it works absolutely fine.

HTH

Chris

Chris Killpack : ckillpack@eaeurope.com
Technology Group : Bullfrog Productions Ltd
Chris Killpack : ckillpack@eaeurope.comTechnology Group : Bullfrog Productions Ltd

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.