Gpu Context

class GpuContext : public ink::Renderer

GPU rendering context.

Implements the Renderer interface for GPU rendering. Create via backend-specific factory functions:

Renderer interface

virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) override

Begin a new frame, clearing the render target.

Parameters:

clearColor – The color to clear the render target to (default: opaque black).

virtual void endFrame() override

End the current frame.

virtual void execute(const Recording &recording, const DrawPass &pass) override

Execute recorded drawing commands.

Parameters:
  • recording – The recorded drawing commands.

  • pass – The draw pass defining execution order.

virtual void resize(i32 w, i32 h) override

Resize the render target.

Parameters:
  • w – New width in pixels.

  • h – New height in pixels.

virtual std::shared_ptr<Image> makeSnapshot() const override

Create an immutable snapshot of the current render target.

Returns:

Shared pointer to the snapshot Image.

virtual void setGlyphCache(GlyphCache *cache) override

Set the glyph cache used for text rendering.

Parameters:

cache – Pointer to the glyph cache.

GPU-specific operations

void readPixels(void *dst, i32 x, i32 y, i32 w, i32 h) const

Read pixels from the GPU framebuffer into a buffer.

Parameters:
  • dst – Destination buffer (must be large enough for w×h×4 bytes).

  • x – X offset in the framebuffer.

  • y – Y offset in the framebuffer.

  • w – Width of the region to read.

  • h – Height of the region to read.

unsigned int textureId() const

Get the GL texture ID of the offscreen color attachment.

Returns:

OpenGL texture name.

unsigned int fboId() const

Get the GL framebuffer object ID.

Returns:

OpenGL FBO name.

Public Functions

~GpuContext() override
bool valid() const

Check if the underlying GPU implementation is valid.

Returns:

True if the GPU backend was initialized successfully.