API Reference
The API documentation is automatically generated from the C++ source code using Doxygen and Breathe.
Full API Index
-
class Canvas
- #include <canvas.hpp>
User-facing drawing API.
Canvas provides high-level drawing commands that are recorded through a Device. Use save()/restore() for state management and clipRect() for clipping.
Public Functions
-
explicit Canvas(Device *device)
Construct a Canvas that records into a device.
- Parameters:
device – The device to record drawing commands into.
-
void clipRect(Rect r)
Intersect the current clip with a rectangle.
- Parameters:
r – The clipping rectangle.
Draw an image at the given position (alpha-blended).
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
-
void drawLine(Point p1, Point p2, Color c, f32 width = 1.0f)
Draw a line between two points.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width (default 1.0).
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width = 1.0f)
Draw a connected series of line segments.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width (default 1.0).
-
void drawText(Point p, std::string_view text, Color c)
Draw text at the given position.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
-
void fillRect(Rect r, Color c)
Fill a rectangle with a solid color.
- Parameters:
r – The rectangle to fill.
c – Fill color.
-
void restore()
Restore the most recently saved clip state.
-
void save()
Save the current clip state onto the stack.
Private Functions
-
void applyClip()
-
explicit Canvas(Device *device)
-
struct Color
- #include <types.hpp>
An RGBA color with 8-bit components.
-
struct CompactDrawOp
- #include <recording.hpp>
Compact draw operation structure (28 bytes).
-
union Data
- #include <recording.hpp>
Union of per-operation data variants.
Public Functions
-
inline Data()
Public Members
-
struct ink::CompactDrawOp::Data::[anonymous] clip
SetClip data.
-
struct ink::CompactDrawOp::Data::[anonymous] fill
FillRect data.
-
struct ink::CompactDrawOp::Data::[anonymous] image
DrawImage data.
-
struct ink::CompactDrawOp::Data::[anonymous] line
Line data.
-
struct ink::CompactDrawOp::Data::[anonymous] polyline
Polyline data (arena offset + count).
-
struct ink::CompactDrawOp::Data::[anonymous] stroke
StrokeRect data.
-
struct ink::CompactDrawOp::Data::[anonymous] text
Text data (position + arena offset + length).
-
inline Data()
-
class Device
- #include <device.hpp>
The single recording device.
Device converts Canvas high-level commands into low-level Recording ops. All Surfaces use the same Device — it always records, never draws directly. The actual rendering is done by a Backend that consumes the Recording.
Drawing commands
-
void fillRect(Rect r, Color c)
Fill a rectangle with a solid color.
- Parameters:
r – The rectangle to fill.
c – Fill color.
-
void strokeRect(Rect r, Color c, f32 width = 1.0f)
Stroke a rectangle outline.
- Parameters:
r – The rectangle to stroke.
c – Stroke color.
width – Stroke line width (default 1.0).
-
void drawLine(Point p1, Point p2, Color c, f32 width = 1.0f)
Draw a line between two points.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width (default 1.0).
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width = 1.0f)
Draw a connected series of line segments.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width (default 1.0).
-
void drawText(Point p, std::string_view text, Color c)
Draw text at the given position.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
Draw an image at the given position (alpha-blended).
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
Public Functions
-
Device() = default
-
~Device() = default
-
void beginFrame()
Begin recording a new frame (resets the recorder).
-
void endFrame()
End the current frame recording.
-
std::unique_ptr<Recording> finishRecording()
Finish recording and return the immutable Recording.
- Returns:
Unique pointer to the completed Recording.
-
void resetClip()
Clear the current clip rectangle.
-
void fillRect(Rect r, Color c)
-
struct DrawOp
- #include <recording.hpp>
Draw operation type tag.
Public Types
-
enum class Type : u8
Operation type enumeration.
Values:
-
enumerator FillRect
Fill a rectangle.
-
enumerator StrokeRect
Stroke a rectangle outline.
-
enumerator Line
Draw a line segment.
-
enumerator Polyline
Draw connected line segments.
-
enumerator Text
Draw text.
-
enumerator DrawImage
Draw an image.
-
enumerator SetClip
Set a clip rectangle.
-
enumerator ClearClip
Clear the clip rectangle.
-
enumerator FillRect
-
enum class Type : u8
-
class DrawOpArena
- #include <recording.hpp>
Arena allocator for variable-length DrawOp data (strings, point arrays).
Public Functions
-
explicit DrawOpArena(size_t initialCapacity = 4096)
Construct an arena with the given initial capacity.
- Parameters:
initialCapacity – Initial byte capacity (default 4096).
-
u32 allocate(size_t bytes)
Allocate raw storage.
- Parameters:
bytes – Number of bytes to allocate.
- Returns:
Byte offset into the arena.
-
const Point *getPoints(u32 offset) const
Retrieve stored points by offset.
- Parameters:
offset – Byte offset returned by storePoints().
- Returns:
Pointer to the first Point.
-
const char *getString(u32 offset) const
Retrieve a stored string by offset.
- Parameters:
offset – Byte offset returned by storeString().
- Returns:
Pointer to the null-terminated string.
-
void reset()
Reset the arena, discarding all stored data.
-
explicit DrawOpArena(size_t initialCapacity = 4096)
-
class DrawOpVisitor
- #include <draw_op_visitor.hpp>
Visitor interface for traversing recorded draw operations.
Implement this interface to process drawing commands dispatched by Recording::accept() or Recording::dispatch().
Public Functions
-
virtual ~DrawOpVisitor() = default
-
virtual void visitClearClip() = 0
Visit a clear-clip command (removes current clip).
-
virtual void visitDrawImage(const Image *image, f32 x, f32 y) = 0
Visit an image drawing command.
- Parameters:
image – Pointer to the image to draw.
x – X position to draw at.
y – Y position to draw at.
-
virtual void visitFillRect(Rect rect, Color color) = 0
Visit a filled rectangle command.
- Parameters:
rect – The rectangle to fill.
color – Fill color.
-
virtual void visitLine(Point p1, Point p2, Color color, f32 width) = 0
Visit a line segment command.
- Parameters:
p1 – Start point.
p2 – End point.
color – Line color.
width – Line width.
-
virtual void visitPolyline(const Point *points, i32 count, Color color, f32 width) = 0
Visit a polyline command.
- Parameters:
points – Array of vertices.
count – Number of points.
color – Line color.
width – Line width.
-
virtual void visitSetClip(Rect rect) = 0
Visit a clip rectangle command.
- Parameters:
rect – The clipping rectangle.
-
virtual ~DrawOpVisitor() = default
-
class DrawPass
- #include <draw_pass.hpp>
Sorts recorded draw operations for optimal execution order.
DrawPass reorders operations by clip group, type, and color to minimize state changes in the rendering backend.
Public Functions
-
inline const std::vector<u32> &sortedIndices() const
Get the sorted operation indices.
- Returns:
Indices into Recording::ops() in sorted execution order.
Public Static Functions
-
inline const std::vector<u32> &sortedIndices() const
-
class GlyphCache
- #include <glyph_cache.hpp>
Font rasterization cache backed by a texture atlas.
Rasterizes glyphs on demand using stb_truetype and stores them in a greyscale atlas that can be uploaded to the GPU.
Public Functions
-
~GlyphCache()
-
inline const u8 *atlasData() const
Get the raw atlas pixel data.
- Returns:
Pointer to the greyscale atlas buffer.
-
inline bool atlasDirty() const
Check if the atlas has been modified since last upload.
- Returns:
True if dirty.
-
void drawText(u32 *pixels, i32 stride, i32 bufH, i32 x, i32 y, std::string_view text, Color c)
Rasterize text directly into a pixel buffer (CPU path).
- Parameters:
pixels – Destination pixel buffer (RGBA u32).
stride – Row stride of the destination buffer in pixels.
bufH – Height of the destination buffer in pixels.
x – X position to start drawing.
y – Y position to start drawing.
text – UTF-8 text to rasterize.
c – Text color.
-
const GlyphMetrics *getGlyph(char ch)
Get (or rasterize) metrics for a character.
- Parameters:
ch – The character to look up.
- Returns:
Pointer to the glyph metrics, or nullptr on failure.
-
bool init(const char *fontPath, f32 fontSize)
Initialize with a TrueType font file and pixel size.
- Parameters:
fontPath – Path to the .ttf font file.
fontSize – Desired font size in pixels.
- Returns:
True on success, false if the font could not be loaded.
-
inline i32 lineHeight() const
Get the line height for the loaded font.
- Returns:
Line height in pixels.
-
inline void markClean()
Mark the atlas as clean (after uploading to GPU).
-
i32 measureText(std::string_view text)
Measure the horizontal advance width of a text string.
- Parameters:
text – UTF-8 text to measure.
- Returns:
Width in pixels.
-
void release()
Release all resources.
Private Members
-
bool dirty_ = true
-
void *fontInfo_ = nullptr
-
std::unordered_map<char, GlyphMetrics> glyphs_
-
~GlyphCache()
-
struct GlyphMetrics
- #include <glyph_cache.hpp>
Metrics for a single rasterized glyph.
-
class GpuContext : public ink::Renderer
- #include <gpu_context.hpp>
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.
Friends
- friend class Surface
-
virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) override
-
class Image
- #include <image.hpp>
An immutable snapshot of pixel data.
Images are created from Surfaces via makeSnapshot() and can be drawn onto any Surface via canvas->drawImage(). This is the mechanism for compositing multiple surfaces together.
Public Types
Public Functions
-
inline u64 backendTextureHandle() const
Get the opaque backend texture handle.
- Returns:
Texture handle for GPU-backed images; 0 otherwise.
-
inline PixelFormat format() const
Get pixel format.
- Returns:
The pixel format of this image.
-
inline u32 glTextureId() const
Get the GL texture ID.
- Returns:
OpenGL texture name (truncated from u64 to u32).
-
inline const PixmapInfo &info() const
Get full pixmap info.
- Returns:
Reference to the PixmapInfo descriptor.
-
inline bool isCpuBacked() const
Check if image is CPU-backed.
- Returns:
True if stored as a CPU pixmap.
-
inline bool isGpuBacked() const
Check if image is GPU-backed.
- Returns:
True if stored as a GPU texture.
-
inline const void *pixels() const
Get raw pixel pointer (CPU-backed images only).
- Returns:
Pointer to pixel data, or nullptr for GPU-backed images.
-
inline const u32 *pixels32() const
Get pixel data as 32-bit words.
- Returns:
Pointer to pixel data cast to u32*.
-
inline StorageType storageType() const
Get the storage type.
- Returns:
-
inline u64 uniqueId() const
Get a stable unique identity for backend caches.
- Returns:
Unique image ID.
-
inline bool valid() const
Check if the image contains valid data.
- Returns:
True if dimensions are positive and backing storage is present.
Public Static Functions
Create an image from a backend-specific GPU texture handle.
- Parameters:
textureHandle – Opaque handle (e.g. GLuint for GL, VkImage for Vulkan).
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
Convenience: create from a GL texture ID.
- Parameters:
textureId – OpenGL texture name.
width – Texture width in pixels.
height – Texture height in pixels.
fmt – Pixel format (default RGBA8888).
lifetimeToken – Optional shared_ptr whose destructor releases the texture.
- Returns:
Shared pointer to the new Image.
Private Members
-
PixmapInfo info_
-
const void *pixels_ = nullptr
-
StorageType storageType_ = StorageType::CpuPixmap
-
inline u64 backendTextureHandle() const
-
class Pipeline
- #include <pipeline.hpp>
Abstract base class for rendering pipeline stages.
Each pipeline handles a specific type of draw operations and manages its own vertex accumulation and GPU state. This decouples the rendering backend from specific draw operation types, making it easier to add new operations or backends.
Pipelines are expected to:
Accumulate draw commands via encode()
Submit accumulated work via flush()
Reset state via reset() for the next frame
Public Functions
-
virtual ~Pipeline() = default
-
virtual void encode(const CompactDrawOp &op, const DrawOpArena &arena) = 0
Encode a draw operation into this pipeline’s internal buffers.
The pipeline should determine if the operation belongs to it and either accumulate it or ignore it.
- Parameters:
op – The compact draw operation to encode.
arena – The arena holding variable-length operation data.
-
virtual void flush() = 0
Flush all accumulated draw operations to the GPU.
Called when switching pipelines or at frame end.
-
virtual void reset() = 0
Reset pipeline state for the next frame.
Clears vertex buffers and any cached state.
-
struct PixelData
- #include <pixel_data.hpp>
Non-owning pixel data descriptor for host integration.
Does not own the pixel data — the caller must ensure the pixels remain valid for the lifetime of this descriptor.
Public Functions
-
PixelData() = default
-
inline PixelData(const void *data_, i32 w, i32 h, i32 stride, PixelFormat fmt)
Construct a PixelData descriptor.
- Parameters:
data_ – Pointer to the raw pixel buffer.
w – Width in pixels.
h – Height in pixels.
stride – Bytes per row.
fmt – Pixel format.
-
inline bool isValid() const
Check if the descriptor points to valid pixel data.
- Returns:
True if data is non-null and dimensions are positive.
-
PixelData() = default
-
class Pixmap
- #include <pixmap.hpp>
Owning or non-owning pixel buffer.
Use Alloc() to create an owned buffer, or Wrap() to reference external memory.
Public Functions
-
Pixmap() = default
-
~Pixmap()
-
inline void *addr()
Get raw pixel pointer (mutable).
-
inline const void *addr() const
Get raw pixel pointer (const).
-
inline PixelFormat format() const
Get pixel format.
-
inline const PixmapInfo &info() const
Get the pixmap info descriptor.
-
void reallocate(const PixmapInfo &info)
Reallocate the buffer with new dimensions/format.
- Parameters:
info – New pixmap descriptor.
-
void reset()
Release pixel data and reset to empty state.
-
inline void *rowAddr(i32 y)
Get pointer to the start of a specific row (mutable).
- Parameters:
y – Row index.
-
inline const void *rowAddr(i32 y) const
Get pointer to the start of a specific row (const).
- Parameters:
y – Row index.
-
inline bool valid() const
Check if the pixmap has valid pixel data.
- Returns:
True if pixels are non-null and dimensions are positive.
Public Static Functions
-
static Pixmap Alloc(const PixmapInfo &info)
Allocate a new pixel buffer described by info.
- Parameters:
info – Dimensions, stride, and format of the buffer.
- Returns:
A new Pixmap that owns its pixel data.
-
static Pixmap Wrap(const PixmapInfo &info, void *pixels)
Wrap existing pixel memory (caller keeps ownership).
- Parameters:
info – Dimensions, stride, and format of the buffer.
pixels – Pointer to the external pixel data.
- Returns:
A non-owning Pixmap.
Private Functions
-
Pixmap(const PixmapInfo &info, void *pixels, bool ownsPixels)
-
Pixmap() = default
-
struct PixmapInfo
- #include <pixmap.hpp>
Descriptor for pixel buffer dimensions, stride, and format.
Public Functions
Public Members
-
PixelFormat format = PixelFormat::RGBA8888
Pixel format.
Public Static Functions
-
static inline PixmapInfo Make(i32 w, i32 h, PixelFormat fmt)
Create a PixmapInfo with the given dimensions and format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format.
- Returns:
A new PixmapInfo.
-
static inline PixmapInfo MakeBGRA(i32 w, i32 h)
Create a PixmapInfo with BGRA8888 format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
- Returns:
A new PixmapInfo with BGRA8888 format.
-
static inline PixmapInfo MakeRGBA(i32 w, i32 h)
Create a PixmapInfo with RGBA8888 format.
- Parameters:
w – Width in pixels.
h – Height in pixels.
- Returns:
A new PixmapInfo with RGBA8888 format.
-
PixelFormat format = PixelFormat::RGBA8888
-
struct Point
- #include <types.hpp>
A 2D point with floating-point coordinates.
-
class Recorder
- #include <recording.hpp>
Records draw operations into a compact command buffer.
Call drawing methods to accumulate operations, then finish() to produce an immutable Recording.
Public Functions
-
void clearClip()
Record a clear-clip operation.
Record an image-drawing operation.
- Parameters:
image – Shared pointer to the image.
x – X position.
y – Y position.
-
void drawLine(Point p1, Point p2, Color c, f32 width)
Record a line-drawing operation.
- Parameters:
p1 – Start point.
p2 – End point.
c – Line color.
width – Line width.
-
void drawPolyline(const Point *pts, i32 count, Color c, f32 width)
Record a polyline-drawing operation.
- Parameters:
pts – Array of vertices.
count – Number of points.
c – Line color.
width – Line width.
-
void drawText(Point p, std::string_view text, Color c)
Record a text-drawing operation.
- Parameters:
p – Position of the text baseline.
text – UTF-8 text to draw.
c – Text color.
-
void fillRect(Rect r, Color c)
Record a fill-rectangle operation.
- Parameters:
r – Rectangle to fill.
c – Fill color.
-
std::unique_ptr<Recording> finish()
Finish recording and produce an immutable Recording.
- Returns:
Unique pointer to the completed Recording.
-
void reset()
Reset the recorder, discarding all accumulated operations.
-
void clearClip()
-
class Recording
- #include <recording.hpp>
Immutable command buffer containing recorded draw operations.
Created by Recorder::finish(). Operations can be traversed in original order via accept() or in sorted order via dispatch().
Public Functions
Construct a Recording from operations, arena, and images.
- Parameters:
ops – Vector of compact draw operations.
arena – Arena holding variable-length data.
images – Vector of referenced images.
-
void accept(DrawOpVisitor &visitor) const
Traverse operations in original recording order.
- Parameters:
visitor – The visitor to receive each operation.
-
inline const DrawOpArena &arena() const
Get the data arena.
-
void dispatch(DrawOpVisitor &visitor, const class DrawPass &pass) const
Dispatch operations in sorted order defined by a draw pass.
- Parameters:
visitor – The visitor to receive each operation.
pass – The draw pass defining execution order.
-
const Image *getImage(u32 index) const
Get an image by index.
- Parameters:
index – Index into the images list.
- Returns:
Pointer to the Image, or nullptr if out of range.
-
inline const std::vector<std::shared_ptr<Image>> &images() const
Get the list of referenced images.
-
inline const std::vector<CompactDrawOp> &ops() const
Get the list of recorded operations.
Private Functions
-
void dispatchOp(const CompactDrawOp &op, DrawOpVisitor &visitor) const
-
struct Rect
- #include <types.hpp>
An axis-aligned rectangle defined by position and size.
-
class Renderer
- #include <renderer.hpp>
Abstract rendering interface.
Implemented by CPU and GPU renderers to execute drawing commands. This abstraction allows Surface to work with any rendering backend through a unified interface.
Subclassed by ink::GpuContext
Public Functions
-
virtual ~Renderer() = default
-
virtual void beginFrame(Color clearColor = {0, 0, 0, 255}) = 0
Begin a new frame, clearing the render target.
- Parameters:
clearColor – The color to clear the render target to (default: opaque black).
-
virtual void endFrame() = 0
End the current frame (no GPU submission; see flush()).
-
virtual void execute(const Recording &recording, const DrawPass &pass) = 0
Execute recorded drawing commands in the order defined by a draw pass.
- Parameters:
recording – The recorded drawing commands.
pass – The draw pass defining execution order.
-
virtual std::shared_ptr<Image> makeSnapshot() const = 0
Create an immutable snapshot of the current render target contents.
- Returns:
Shared pointer to the snapshot Image.
-
virtual void resize(i32 w, i32 h) = 0
Resize the render target.
- Parameters:
w – New width in pixels.
h – New height in pixels.
-
inline virtual void setGlyphCache(GlyphCache *cache)
Set the glyph cache used for text rendering.
- Parameters:
cache – Pointer to the glyph cache (may be null to disable text).
-
virtual ~Renderer() = default
-
struct SortKey
- #include <draw_pass.hpp>
64-bit sort key for DrawOp ordering.
Layout: [63:48] clip_id, [47:40] op_type, [39:8] color_hash, [7:0] sequence.
Public Members
-
struct State
-
class Surface
- #include <surface.hpp>
Top-level rendering target.
A Surface owns a Canvas, a Device, and a Renderer. The typical frame cycle is: beginFrame() → draw via canvas() → endFrame() → flush().
Note
The caller must ensure the GL context is current when using a GPU-backed surface.
Public Functions
-
~Surface()
-
void beginFrame(Color clearColor = {0, 0, 0, 255})
Begin a new frame, clearing to the specified color.
- Parameters:
clearColor – The color to clear the render target to (default: opaque black).
-
inline Canvas *canvas() const
Get the Canvas used for drawing on this surface.
- Returns:
Pointer to the Canvas.
-
void endFrame()
End the current frame (finishes recording).
-
void flush()
Execute recorded commands and submit to the backend.
-
PixelData getPixelData() const
Get a non-owning pixel data descriptor for host integration.
- Returns:
A PixelData descriptor.
-
bool isGPU() const
Check if this is a GPU-backed surface.
- Returns:
True if GPU-backed.
-
std::shared_ptr<Image> makeSnapshot() const
Create an immutable snapshot of current surface contents.
- Returns:
Shared pointer to the snapshot Image.
-
Pixmap *peekPixels()
Direct pixel access (raster surfaces only).
- Returns:
Pointer to the underlying Pixmap, or nullptr for GPU/recording surfaces.
-
const Pixmap *peekPixels() const
Direct pixel access (raster surfaces only).
- Returns:
Pointer to the underlying Pixmap, or nullptr for GPU/recording surfaces.
-
void resize(i32 w, i32 h)
Resize the surface to new dimensions.
- Parameters:
w – New width in pixels.
h – New height in pixels.
-
void setGlyphCache(GlyphCache *cache)
Set the glyph cache used for text rendering.
- Parameters:
cache – Pointer to the glyph cache.
Public Static Functions
Create a GPU surface.
Falls back to CPU if context is null or invalid.
- Parameters:
context – Shared pointer to the GPU context.
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format (default BGRA8888).
- Returns:
Unique pointer to the new Surface.
-
static std::unique_ptr<Surface> MakeRaster(i32 w, i32 h, PixelFormat fmt = PixelFormat::BGRA8888)
Create a CPU raster surface that allocates its own pixel buffer.
- Parameters:
w – Width in pixels.
h – Height in pixels.
fmt – Pixel format (default BGRA8888).
- Returns:
Unique pointer to the new Surface.
-
static std::unique_ptr<Surface> MakeRasterDirect(const PixmapInfo &info, void *pixels)
Create a CPU raster surface wrapping a caller-owned pixel buffer (zero-copy).
Private Functions
-
~Surface()
-
namespace ink
Typedefs
-
using f32 = float
32-bit floating point.
-
using f64 = double
64-bit floating point.
-
using i32 = int32_t
Signed 32-bit integer.
-
using u16 = uint16_t
Unsigned 16-bit integer.
-
using u32 = uint32_t
Unsigned 32-bit integer.
-
using u64 = uint64_t
Unsigned 64-bit integer.
-
using u8 = uint8_t
Unsigned 8-bit integer.
Enums
Functions
-
inline const char *version()
Return the library version string (e.g.
“0.1.1”).
- Returns:
Null-terminated version string in “major.minor.patch” format.
-
inline int versionMajor()
Return the major version number.
- Returns:
Major version as an integer.
-
inline int versionMinor()
Return the minor version number.
- Returns:
Minor version as an integer.
-
inline int versionPatch()
Return the patch version number.
- Returns:
Patch version as an integer.
-
using f32 = float
-
namespace GpuContexts
GL-specific GpuContext factory functions.
Vulkan-specific GpuContext factory functions.
Metal-specific GpuContext factory functions.
Usage: #include <ink/gpu/gl/gl_context.hpp> auto ctx = GpuContexts::MakeGL();
Usage: #include <ink/gpu/metal/metal_context.hpp> auto ctx = GpuContexts::MakeMetal();
Usage: #include <ink/gpu/vk/vk_context.hpp> auto ctx = GpuContexts::MakeVulkan();
Functions
-
std::shared_ptr<GpuContext> MakeGL()
Create a GpuContext bound to the currently active OpenGL context.
Host must have created and made current a GL context before calling. Returns nullptr if no GL context is current or GL init fails.
-
std::shared_ptr<GpuContext> MakeMetal()
Create a GpuContext using the default Metal device.
Returns nullptr if no Metal-capable GPU is available or init fails.
-
std::shared_ptr<GpuContext> MakeVulkan()
Create a GpuContext for Vulkan.
Host must have initialized Vulkan before calling. Returns nullptr if Vulkan init fails.
TODO: Implement Vulkan backend
-
std::shared_ptr<GpuContext> MakeGL()
-
namespace std
STL namespace.
- file canvas.hpp
- #include “ink/types.hpp”#include <string_view>#include <vector>#include <memory>
User-facing drawing API with state management.
- file device.hpp
- #include “ink/types.hpp”#include “ink/recording.hpp”#include <memory>
Recording device that converts Canvas commands into low-level draw operations.
- file draw_op_visitor.hpp
- #include “ink/types.hpp”#include <cstdint>#include <memory>
Visitor interface for traversing recorded draw operations.
- file draw_pass.hpp
- #include “ink/types.hpp”#include “ink/recording.hpp”#include <vector>#include <algorithm>
Sort key and draw pass for optimizing draw operation execution order.
- file glyph_cache.hpp
- #include “ink/types.hpp”#include <string_view>#include <unordered_map>#include <vector>#include <string>
Font rasterization cache with texture atlas for text rendering.
- file gl_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file gpu_context.hpp
- #include “ink/renderer.hpp”#include <memory>
GPU rendering context implementing the Renderer interface.
- file metal_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file vk_context.hpp
- #include “ink/gpu/gpu_context.hpp”
- file image.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include <memory>
Immutable image snapshot for compositing and drawing.
- file ink.hpp
- #include “ink/version.hpp”#include “ink/types.hpp”#include “ink/pixmap.hpp”#include “ink/pixel_data.hpp”#include “ink/image.hpp”#include “ink/recording.hpp”#include “ink/draw_op_visitor.hpp”#include “ink/draw_pass.hpp”#include “ink/device.hpp”#include “ink/canvas.hpp”#include “ink/gpu/gpu_context.hpp”#include “ink/pipeline.hpp”#include “ink/surface.hpp”#include “ink/glyph_cache.hpp”
Convenience header that includes the entire ink public API.
Ink - A lightweight 2D rendering library
Usage:
// CPU rendering #include <ink/ink.hpp> auto surface = ink::Surface::MakeRaster(800, 600); surface->canvas()->fillRect({0, 0, 100, 100}, {255, 0, 0, 255}); surface->flush();
// GPU rendering (requires #include <ink/gpu/gl/gl_context.hpp>) auto ctx = ink::GpuContexts::MakeGL(); auto surface = ink::Surface::MakeGpu(ctx, 800, 600); surface->canvas()->fillRect({0, 0, 100, 100}, {255, 0, 0, 255}); surface->flush();
- file pipeline.hpp
- #include “ink/types.hpp”#include “ink/recording.hpp”
Abstract base class for rendering pipeline stages.
- file pixel_data.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include <cstdint>
Non-owning pixel data descriptor for host integration.
- file pixmap.hpp
- #include “ink/types.hpp”#include <cstdlib>#include <cstring>
Pixel format, pixel buffer descriptor, and owning/non-owning pixel buffer.
- file recording.hpp
- #include “ink/types.hpp”#include <string_view>#include <vector>#include <memory>#include <cstring>
Draw operation types, arena allocator, recording, and recorder.
- file renderer.hpp
- #include “ink/types.hpp”#include <memory>
Abstract rendering interface for CPU and GPU backends.
- file surface.hpp
- #include “ink/types.hpp”#include “ink/pixmap.hpp”#include “ink/canvas.hpp”#include “ink/device.hpp”#include “ink/pixel_data.hpp”#include “ink/image.hpp”#include “ink/renderer.hpp”#include <memory>
Top-level rendering target (CPU raster, GPU, or recording-only).
- file types.hpp
- #include <cstdint>
Core type aliases and basic geometric/color types for the ink library.
- file version.hpp
Library version information.
- dir include/ink/gpu/gl
- dir include/ink/gpu
- dir include
- dir include/ink
- dir include/ink/gpu/metal
- dir include/ink/gpu/vk