DirectX9 - Depth Stencil as Texture

Started by
1 comment, last by martinperry 12 years, 11 months ago
I am trying to bind depth stencil to texture. I have GeForce 7900 GTX, so according to Nvidia documentation i use FOURCC RAWZ

if (this->stencilEnabled)
{
return;
}

IDirect3D9 * d3d;
HRESULT hr = this->device->GetDirect3D(&d3d);
if (FAILED(hr))
{
printf("Can not obtain D3D");
return;
}

D3DFORMAT format;
bool formatSet = false;

D3DDISPLAYMODE mode;
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode);

hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE,
ATI_DS_HACK);
if (SUCCEEDED(hr))
{
format = ATI_DS_HACK;
formatSet = true;
}

hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE,
NVIDIA_DS_HACK_8);
if (SUCCEEDED(hr))
{
format = NVIDIA_DS_HACK_8;
formatSet = true;
}

hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_TEXTURE,
NVIDIA_DS_HACK_6_7);
if (SUCCEEDED(hr))
{
format = NVIDIA_DS_HACK_6_7;
formatSet = true;
}

if (!formatSet)
{
printf("Depth stencil as texture not supported\n");
return;
}

hr = D3DXCreateTexture(this->device,
this->texWidth,
this->texHeight,
1,
D3DUSAGE_DEPTHSTENCIL,
format,
D3DPOOL_DEFAULT,
&this->stencilTexture);

if (FAILED(hr))
{
printf("Creating depth stencil failed\n");
return;
}

this->stencilTexture->GetSurfaceLevel(0, &this->stencil);



this->stencilEnabled = true;


My code set format = NVIDIA_DS_HACK_6_7; correctly from CheckDeviceCaps... but CreateTexture function than failed with HRESULT = -2005530518
What is wrong with my code ?
Advertisement
I'm not sure if you can use D3DXCreateTexture for this...it changes the parameters. You just want to use IDirect3DDevice9::CreateTexture.

Also, you can use DXGetErrorString and DXGetErrorDescription to get the name and description for an HRESULT, since the raw integer value is useless on its own.
Error from D3DErrorLokkup says:

HRESULT: 0x8876086a (2289436778)
Name: D3DERR_NOTAVAILABLE
Description: Not available
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x086a (2154)

This topic is closed to new replies.

Advertisement