nCine::RHI::Software::SwDevice class

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

Mirrors the OpenGL device's surface (blending, depth, cull, scissor, viewport, clear and the draw calls) but instead of talking to a GPU it is a small immediate-mode state machine: Bind* calls record the current program, textures and uniform ranges, Set* calls record blend/scissor/viewport state, and each Draw* call gathers all of it and runs the hand-written C++ effect selected by the bound program, rasterizing into the current render target's color texture with SwRaster. Depth is a no-op (the renderer is 2D) and fences signal immediately.

The blend factors on this API are the pipeline-neutral nCine::BlendingFactor (fully qualified so they are never shadowed by the rasterizer's identically-named mirror enum).

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 auto CreateSwapchain(void* windowHandle, std::int32_t width, std::int32_t height, bool vsync) -> bool
No-op (the window backend owns the presentation path).
static void DestroySwapchain()
No-op.
static void ResizeSwapchain(std::int32_t width, std::int32_t height)
No-op (the CPU screen buffer is sized by ResizeScreenFramebuffer() from the render pipeline, not by the window).
static void PresentFrame()
No-op (the window backend blits GetScreenFramebuffer() itself).
static void BindProgram(SwShaderProgram* program)
Records the currently bound shader program.
static auto CurrentProgram() -> SwShaderProgram*
Returns the currently bound shader program.
static void BindTexture(std::uint32_t unit, const SwTexture* texture)
Records the texture bound to a texture unit.
static void UnbindTexture(const SwTexture* texture)
Clears a texture from every unit it is bound to (called from ~SwTexture to avoid a dangling pointer).
static auto GetBoundTexture(std::uint32_t unit) -> const SwTexture*
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 SetRenderTarget(SwRenderTarget* renderTarget)
Records the current draw render target (its color attachment 0 receives the pixels).
static void UnbindRenderTarget(const SwRenderTarget* renderTarget)
Clears a render target from the device if it is the current one (called from ~SwRenderTarget).
static void SetDefaultFramebuffer(const Framebuffer& framebuffer)
Sets the framebuffer used when no render target is bound (present/back-buffer path).
static void ResizeScreenFramebuffer(std::int32_t width, std::int32_t height)
Resizes the owned screen back-buffer to the window size and installs it as the default framebuffer.
static auto GetScreenFramebuffer() -> Framebuffer
Returns the owned screen back-buffer (pixels/size/stride) for the window backend to present.
static void FlushSoftwareRenderer()
Renders any draws the tile renderer has deferred into the current color buffer.
static void EndFrame()
Ends the presented frame, dropping any per-frame device state.
static void SetPendingSoftwareLighting(const float* lightmap, std::int32_t lmW, std::int32_t lmH, std::int32_t scale, std::int32_t vpX, std::int32_t vpY, std::int32_t vpW, std::int32_t vpH, float ambR, float ambG, float ambB, bool waterActive = false, float waterLevelPx = 0.0f, float waterTime = 0.0f, float waterCamY = 0.0f)
Queues a dynamic lightmap to be composited over a viewport during the next matching Combine draw.

Constructors, destructors, conversion operators

SwDevice() deleted
~SwDevice() deleted

Function documentation

static void nCine::RHI::Software::SwDevice::ResizeScreenFramebuffer(std::int32_t width, std::int32_t height)

Resizes the owned screen back-buffer to the window size and installs it as the default framebuffer.

The root screen viewport binds no render target, so its clears and draws land in the default framebuffer. On desktop the window backend calls this once at window creation and on every resize to give that framebuffer a CPU surface sized to the drawable, then reads it back each frame with GetScreenFramebuffer() to present it (the software counterpart of the GL default framebuffer + buffer swap). The backend owns the pixel memory; it stays valid until the next resize.

static void nCine::RHI::Software::SwDevice::FlushSoftwareRenderer()

Renders any draws the tile renderer has deferred into the current color buffer.

The window backend calls this before reading GetScreenFramebuffer() to present, so every queued draw has landed in the screen buffer. Forwards to the rasterizer's deferred-layer flush, which waits for all worker threads to finish; a no-op when nothing is queued.

static void nCine::RHI::Software::SwDevice::EndFrame()

Ends the presented frame, dropping any per-frame device state.

The window backend calls this after presenting. Discards software-lighting entries left in the queue (their Combine draw was culled or never dispatched, e.g. an off-screen viewport): without this the leftovers would survive into later frames, permanently shifting the viewport-to-lightmap pairing in splitscreen — and their caller-owned lightmap pointers would dangle past the compositor's frame.

static void nCine::RHI::Software::SwDevice::SetPendingSoftwareLighting(const float* lightmap, std::int32_t lmW, std::int32_t lmH, std::int32_t scale, std::int32_t vpX, std::int32_t vpY, std::int32_t vpW, std::int32_t vpH, float ambR, float ambG, float ambB, bool waterActive = false, float waterLevelPx = 0.0f, float waterTime = 0.0f, float waterCamY = 0.0f)

Queues a dynamic lightmap to be composited over a viewport during the next matching Combine draw.

Parameters
lightmap Half-resolution accumulation buffer, 2 floats per texel (R = intensity incl. the ambient base, G = brightness core), row-major. Caller-owned; must stay valid until the matching Combine draw is dispatched (the compositor keeps it in a per-viewport member).
lmW Lightmap width in texels
lmH Lightmap height in texels
scale Lightmap-to-screen downscale factor (a screen pixel samples texel pixel / scale)
vpX Viewport left in screen-buffer pixels
vpY Viewport top in screen-buffer pixels
vpW Viewport width in screen-buffer pixels (clamped against the buffer at apply time)
vpH Viewport height in screen-buffer pixels (clamped against the buffer at apply time)
ambR Ambient colour red the unlit scene is blended toward
ambG Ambient colour green the unlit scene is blended toward
ambB Ambient colour blue the unlit scene is blended toward
waterActive Whether the waterline is inside this viewport - enables the lightweight per-row water effect (the CPU replacement of the CombineWithWater shader variants). With water active, lightmap may be nullptr for a water-only combine (fully lit scene).
waterLevelPx Waterline position in viewport-local pixels from the TOP edge (the shader path's viewWaterLevel); may be negative when the whole viewport is underwater
waterTime Wave animation time, the shader path's uTime (elapsed frames * 0.0018)
waterCamY Camera world-space Y, anchors the per-row wave phase to the world while scrolling

Software-lighting entry point used by the viewport compositor (Jazz2::Rendering::CombineRenderer). The scene renders straight to the screen buffer with no shader post-processing, so the dynamic lighting is applied on the CPU here instead: the compositor builds the half-resolution lightmap in the Visit (queue-building) phase and calls this, then the Combine draw it queues is intercepted in Dispatch() during the later Draw phase - after the scene has been rasterized into the screen buffer and before the HUD - where the map is blended in place over the viewport rectangle. Entries are consumed first-in-first-out, one per Combine draw, so splitscreen viewports each receive their own map in submission order.