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 = -2005530518What is wrong with my code ?