Jump to content
  • Advertisement
Sign in to follow this  
martinperry

DirectX9 - Depth Stencil as Texture

This topic is 2608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!