DirectX 11 | C++ | Depth/ Stencil system not working correctly

Started by
3 comments, last by Mate 9 years, 4 months ago

Hello,

I'm new to this board, so I'm sorry if I break any topic rules.

First of all I want to say, that I am programming a 3d game in C++ with DirectX 11.

Now I have an issue, that I can't fix after 10 times of reading the whole code.

So I'll copy the realative code somewhere here below.

I located the error, or some relative part of it in the line, where it says "devcon->OMSetRenderTargets(1, &backbuffer, depthStencilView);".

The issue is from the, like the title says, depth view. Before I wrote this, the programm worked perfectly and when I set the render target WITHOUT the depth implementaion, it is working.

CODE:

... (THIS IS FROM THE INITIALIZATION PART)

D3D11_TEXTURE2D_DESC depthStencilDesc;

depthStencilDesc.Width = windowSizeX;
depthStencilDesc.Height = windowSizeY;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 4;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;

hResult = dev->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
if (FAILED(hResult))
exit(hResult);

D3D11_DEPTH_STENCIL_VIEW_DESC descDSV;
ZeroMemory(&descDSV, sizeof(descDSV));

descDSV.Format = depthStencilDesc.Format;
descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
descDSV.Texture2D.MipSlice = 0;;

hResult = dev->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView);
if (FAILED(hResult))
exit(hResult);

devcon->OMSetRenderTargets(1, &backbuffer, depthStencilView);

D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = windowSizeX;
viewport.Height = windowSizeY;
viewport.MinDepth = 0.0F;
viewport.MaxDepth = 1.0F;

devcon->RSSetViewports(1, &viewport);

...

... (THIS IS FROM THE MAIN LOOP)

devcon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0.0f);

...

So the COM-objects are released and thats it.

I'm also sorry for syntax mistakes in this text. They are because english is not my motherlanguage.

Please help with that.

Domenik Papst

Advertisement
What outputs are the debug layer giving you? It will generally spit out a description of what is thinks is wrong.

It also helps if you tell us what error or unexpected result you're getting, with or without the debug layer (but do it with). smile.png

(You are using the debug layer, right? And regularly testing with Microsoft's Graphics Debugger built into Visual Studio 2012 and newer, right?)

Sean Middleditch – Game Systems Engineer – Join my team!

What outputs are the debug layer giving you? It will generally spit out a description of what is thinks is wrong.

It also helps if you tell us what error or unexpected result you're getting, with or without the debug layer (but do it with). smile.png

(You are using the debug layer, right? And regularly testing with Microsoft's Graphics Debugger built into Visual Studio 2012 and newer, right?)

First of all thank for the awnser !

Now I forgot to say what the actually problem is biggrin.png : I've got no errors, but my rectangle isn't showing anymore on the screen. After applying the depth view to the OM stage of the rendering pipeline.

Now as I sayed, that I have no errors, you might know, that the debug console is not saying anything about that. It says that there is no problem.

I also checked the shaders, but there is like I expected no mistake ...

EDIT : I figured out the problem on my self :). The problem was that I just had a different amount of buffers in the back-buffer-description and the depth-description.

I'm new to DirectX. I came from Java+OpenGL and moved to C++ and DirectX. Now I don't really know what the buffer sampling quality changes ? I mean yeah .. the quality, but what exectly ? the performence ? The color/ pixel smoothing ?

And the last one, I swear, when I use windowed fullscreen, the edges are smooth, but when I change to fullscreen state, the resolution seems to get bad ... :S ?


when I use windowed fullscreen, the edges are smooth, but when I change to fullscreen state, the resolution seems to get bad

Just a guess, but you need to reset the size of the backbuffer(s) when the size of the window changes. And don't forget to change the aspect ratio of your projection at the same time.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.


when I use windowed fullscreen, the edges are smooth, but when I change to fullscreen state, the resolution seems to get bad

Just a guess, but you need to reset the size of the backbuffer(s) when the size of the window changes. And don't forget to change the aspect ratio of your projection at the same time.

Hm .. actually a good one :) I will do this in a few moments. I really like this community, so I decided to stay. If you want to, I'll tell you if it's working.

This topic is closed to new replies.

Advertisement