c++directx-11

Understanding ID3D11Device and ID3D11DeviceContext


I have some problems understanding the difference between ID3D11Device and ID3D11DeviceContext.


Solution

  • The ID3D11Device is used for creating resources, for example, the many shaders in the pipeline.

    The ID3D11DeviceContext is used for binding those resources to the pipeline, for example, the many shaders.

    device->CreatePixelShader(/*arguments*/);
    context->PSSetShader(/*pass shader created with 'device'*/);
    

    But why you need then two objects?

    So that you don't have 1 "God" object that does everything (that's a guess :)).

    Which object send the final Image to the backbuffer.

    The ID3D11DeviceContext does. I guess with "Image" you mean a texture, if yes, the image doesn't get "sent", it gets copied to the back buffer, using the method Draw.

    The backbuffer is in the ID3D11RenderTargetView object, isn't it?

    Yes, in form of a ID3D11Resource, which would be the back buffer "texture" (The Draw calls draw into that "texture").

    And which objects are connect with the SwapChain and why exactly?

    That's a bit broad. The swap chain stores the back buffer textures, and many other informations such as how to flip the buffers, which window is associated with it, ... This gets used when you Draw something.

    So, I guess the ID3D11Resources are "conntected" with the swap chain, as they store the back buffer textures used by it.