Sign In

ID3D11DeviceContext

Overview

The ID3D11DeviceContext interface represents a device context, which is used to issue rendering commands to the GPU. It provides methods for drawing, state management, resource updates, and query handling.

Syntax

interface ID3D11DeviceContext : ID3D11DeviceChild {
    void VSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers);
    void PSSetShaderResources(UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews);
    // ... many more methods ...
}

Methods

MethodDescription
DrawRenders non-indexed, non-instanced primitives.
DrawIndexedRenders indexed primitives.
DrawInstancedRenders instanced primitives.
DrawIndexedInstancedRenders indexed, instanced primitives.
MethodDescription
VSSetShaderSets the vertex shader to the device context.
PSSetShaderSets the pixel shader to the device context.
RSSetViewportsSets the viewports for rasterizer stage.
OMSetRenderTargetsSets render targets and depth-stencil view.
MethodDescription
UpdateSubresourceCopies CPU data to a subresource of a GPU resource.
CopyResourceCopies an entire resource.
CopySubresourceRegionCopies a region of one resource to another.

Properties

  • Device – Retrieves the parent ID3D11Device object.
  • FeatureLevel – Indicates the highest feature level supported.

Remarks

Device contexts are divided into immediate and deferred contexts. The immediate context executes commands as they are issued, while deferred contexts record command lists for later execution on the immediate context.

Example

// Create device and immediate context
ID3D11Device*           gDevice = nullptr;
ID3D11DeviceContext*    gContext = nullptr;
D3D11CreateDevice(
    nullptr,
    D3D_DRIVER_TYPE_HARDWARE,
    nullptr,
    0,
    nullptr,
    0,
    D3D11_SDK_VERSION,
    &gDevice,
    nullptr,
    &gContext);

// Clear render target
float clearColor[4] = {0.1f, 0.2f, 0.3f, 1.0f};
ID3D11RenderTargetView* rtv = nullptr; // Assume created elsewhere
gContext->ClearRenderTargetView(rtv, clearColor);

// Draw a triangle
gContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
gContext->Draw(3, 0);
        

See Also