abx_pradB
abx_pradB

Reputation: 1

DirectX 3d 11 after using the Depth Stencil view in OMSetRenderTarget nothing is rendering at alllll

I HAVE been trying this for hours now. I have no clue why the triangle is not rendering on the screen.

    D3D11_DEPTH_STENCIL_DESC dsDesc = {};
    dsDesc.DepthEnable = true;
    dsDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    dsDesc.DepthFunc = D3D11_COMPARISON_LESS;

    if (FAILED(pDevice->CreateDepthStencilState(&dsDesc, &pDSState)))
    {
        this->Release();
        return false;
    }

    pDeviceContext->OMSetDepthStencilState(pDSState, 1u);
    

    D3D11_TEXTURE2D_DESC descDepth = {};
    descDepth.Width = 800u;
    descDepth.Height = 600u;
    descDepth.MipLevels = 1u;
    descDepth.ArraySize = 1u;
    descDepth.Format = DXGI_FORMAT_D32_FLOAT;
    descDepth.SampleDesc.Count = 1u;
    descDepth.SampleDesc.Quality = 0u;
    descDepth.Usage = D3D11_USAGE_DEFAULT;
    descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
    descDepth.CPUAccessFlags = 0;
    descDepth.MiscFlags = 0;

    if (FAILED(pDevice->CreateTexture2D(&descDepth,NULL,&pDepthStencil)))
    {
        this->Release();
        return false;
    }

    D3D11_DEPTH_STENCIL_VIEW_DESC descDSV = {};
    descDSV.Format = DXGI_FORMAT_D32_FLOAT;
    descDSV.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
    descDSV.Texture2D.MipSlice = 0u;
    if (FAILED(pDevice->CreateDepthStencilView(pDepthStencil, &descDSV,&pDSV)))
    {
        this->Release();
        return false;
    }
    

    pDeviceContext->OMSetRenderTargets(1u, &pTarget,pDSV);

If I don't put the pDSV value and put NULL in its place, at the end of the above code snippet I do see a triangle.

AND I am most definitely am clearing the buffer by also clearing the depth stencil as below

    const float color[] = { r,g,b,1 };
    this->pDeviceContext->ClearRenderTargetView(this->pTarget, color);
    this->pDeviceContext->ClearDepthStencilView(this->pDSV, D3D11_CLEAR_DEPTH, 1.0f, 0u);

AND you might say that no man you are not setting up the view port BUT I AM setting it up also.

    D3D11_VIEWPORT vp;
    vp.Width = 800;
    vp.Height = 600;
    vp.MinDepth = 0.0f;
    vp.MaxDepth = 1.0f;
    vp.TopLeftX = 0;
    vp.TopLeftY = 0;
    graphics->pDeviceContext->RSSetViewports(1u, &vp);

now for the love of god can any one tell me why MY EYES not see the triangle on the screen. WHERE AM I DOING THIS WRONG? is it the hardware requirements or is it some setting somewhere I have no IDEA of. AND no I am not using multiple samples and I also have no idea about that.

I just want to enable the depth buffer also. I tried to read the documentation also tried to see videos also searched methods to debug graphics. in visual studio 2019 through frame capture . but I am not getting where I am going wrong.

this is the link to my github repo containing all the code files

Upvotes: 0

Views: 100

Answers (1)

abx_pradB
abx_pradB

Reputation: 1

OK I found the problem. The truth was I was ignoring the debugger what it has to say. But this was a wierd error. the debugger said

The RenderTargetView at slot 0 is not compatible with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:804,h:604,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:800,h:600,as:1), while the Resource is a Texture2D with (mc:1,mq:0). [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW]

I don't know why it create the RenderTargetView are 804 / 604 .I just forced it to have 800 / 600 dimensions by editing the swap chain descriptor. The debugger was also throwing an exception which I thought was something weird with the IDE(visual studio 2019). I might want to know why did it create the renderTarget with a wierdly different dimentions in the first place. does is have to do with the window styling or somehing I think it is But I would like to know WHY If anyone can tell weather it was because of window styling or I don't know.

Upvotes: 0

Related Questions