nCine::RHI::D3D11::D3D11Device class

Pipeline-state and draw-call facade of the Direct3D 11 backend (aliased as RHI::Device).

Exposes the OpenGL device's surface (blending, depth, cull, scissor, viewport, clear and the draw calls) so the backend-neutral render pipeline drives it unchanged.

The device also owns the real ID3D11Device, immediate ID3D11DeviceContext and the DXGI IDXGISwapChain created from the SDL window (via CreateSwapchain(), called by the SDL window backend). PresentFrame() blits the rendered scene into the back-buffer and presents it (the buffer-swap equivalent).

Public types

struct ScissorState
struct BlendingState
struct DepthTestState
struct CullFaceState

Public static functions

static void SetBlendingEnabled(bool enabled)
static void SetBlendingFactors(nCine::BlendingFactor srcRgb, nCine::BlendingFactor dstRgb, nCine::BlendingFactor srcAlpha, nCine::BlendingFactor dstAlpha)
static auto GetBlendingState() -> BlendingState
static void SetBlendingState(const BlendingState& state)
static void SetDepthTestEnabled(bool enabled)
static void SetDepthMaskEnabled(bool enabled)
static auto GetDepthTestState() -> DepthTestState
static void SetDepthTestState(const DepthTestState& state)
static void SetCullFaceEnabled(bool enabled)
static auto GetCullFaceState() -> CullFaceState
static void SetCullFaceState(const CullFaceState& state)
static auto GetScissorState() -> ScissorState
static void SetScissorState(const ScissorState& state)
static void SetScissor(const Recti& rect)
static void SetScissorTestEnabled(bool enabled)
static auto GetViewport() -> Recti
static void SetViewport(const Recti& rect)
static void InitViewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
static auto GetClearColor() -> Colorf
static void SetClearColor(const Colorf& color)
static void Clear(ClearFlags flags)
static void DrawArrays(PrimitiveType primitive, std::int32_t firstVertex, std::int32_t numVertices)
static void DrawArraysInstanced(PrimitiveType primitive, std::int32_t firstVertex, std::int32_t numVertices, std::int32_t numInstances)
static void DrawElements(PrimitiveType primitive, std::uint32_t numIndices, IndexFormat indexFormat, std::uintptr_t indexOffset, std::int32_t baseVertex)
static void DrawElements(PrimitiveType primitive, std::uint32_t numIndices, std::uintptr_t indexOffset, std::int32_t baseVertex)
static void DrawElementsInstanced(PrimitiveType primitive, std::uint32_t numIndices, IndexFormat indexFormat, std::uintptr_t indexOffset, std::int32_t numInstances, std::int32_t baseVertex)
static void DrawElementsInstanced(PrimitiveType primitive, std::uint32_t numIndices, std::uintptr_t indexOffset, std::int32_t numInstances, std::int32_t baseVertex)
static auto InsertFence() -> FenceHandle
static void DeleteFence(FenceHandle& fence)
static auto ClientWaitFence(FenceHandle fence, std::uint64_t timeoutNs) -> bool
static void SetupInitialState()
static void BindProgram(D3D11ShaderProgram* program)
Records the currently bound shader program.
static auto CurrentProgram() -> D3D11ShaderProgram*
Returns the currently bound shader program.
static void BindTexture(std::uint32_t unit, const D3D11Texture* texture)
Records the texture bound to a texture unit.
static void UnbindTexture(const D3D11Texture* texture)
Clears a texture from every unit it is bound to (called from ~D3D11Texture to avoid a dangling pointer).
static auto GetBoundTexture(std::uint32_t unit) -> const D3D11Texture*
Returns the texture bound to a texture unit.
static void BindUniformRange(std::uint32_t index, const std::uint8_t* data, std::uint32_t size)
Records the host data range bound to a uniform binding point.
static void UnbindRenderTarget(const D3D11RenderTarget* renderTarget)
Clears a render target from the device if it is the current one (called from ~D3D11RenderTarget).
static void OnRtvReleased(const ID3D11RenderTargetView* rtv)
Scrubs a released render target view from the last-bound shadow so a recycled pointer can't be mistaken for still bound (called by D3D11RenderTarget whenever it releases an RTV).
static void SetRenderTarget(D3D11RenderTarget* renderTarget)
Records the current draw render target (its bound color attachments receive the pixels).
static void OnProgramDestroyed(const D3D11ShaderProgram* program)
Clears a destroyed program from the device's current-program and shadow-state tracking (called from ~D3D11ShaderProgram).
static auto CreateSwapchain(void* windowHandle, std::int32_t width, std::int32_t height, bool vsync) -> bool
Creates the D3D11 device, immediate context and DXGI swap chain for the given native window.
static void DestroySwapchain()
Releases the swap chain, context and device.
static void ResizeSwapchain(std::int32_t width, std::int32_t height)
Resizes the swap-chain back-buffer (releases and recreates the back-buffer RTV around ResizeBuffers).
static void PresentFrame()
Blits the rendered scene into the back-buffer and presents it (the buffer-swap equivalent).
static auto GetD3DDevice() -> ID3D11Device*
Returns the D3D11 device (for resource creation), or nullptr before creation.
static auto GetD3DContext() -> ID3D11DeviceContext*
Returns the D3D11 immediate context, or nullptr before creation.
static auto GetMaxTextureDimension() -> std::int32_t
Returns the largest supported 2D texture dimension of the obtained feature level (16384 on 11_0, 8192 on 10.x; consumed by GfxCapabilities).

Constructors, destructors, conversion operators

D3D11Device() deleted
~D3D11Device() deleted

Function documentation

static bool nCine::RHI::D3D11::D3D11Device::CreateSwapchain(void* windowHandle, std::int32_t width, std::int32_t height, bool vsync)

Creates the D3D11 device, immediate context and DXGI swap chain for the given native window.

Parameters
windowHandle Native HWND (desktop) or CoreWindow IUnknown* (UWP), passed as a void* so the window backend does not need the D3D11/DXGI headers
width Back-buffer width in pixels
height Back-buffer height in pixels
vsync Whether PresentFrame() presents with vertical sync
Returns true if the device and swap chain were created

Two window kinds are supported, selected at compile time by DEATH_TARGET_WINDOWS_RT:

  • Desktop (SDL2): windowHandle is a native HWND; a windowed bitblt swap chain is created via D3D11CreateDeviceAndSwapChain.
  • UWP (Windows Store / Xbox): windowHandle is the CoreWindow as an opaque IUnknown*; a flip-model swap chain is created via IDXGIFactory2::CreateSwapChainForCoreWindow (UWP forbids the desktop bitblt swap chain).