elba_gfx.h
Joins elba to a gfx device: a desc on the gfx worker pool and a streamed surface that uploads only the dirty rect. Render thread only.
#include "elba/elba_gfx.h". The guide starts at Vector engine (elba).
Surface
Explained in Vector engine (elba).
elba_gfx_descelba_gfx_surfaceelba_gfx_surface_createelba_gfx_surface_destroyelba_gfx_surface_imageelba_gfx_surface_resizeelba_gfx_renderExample
dial.cpp
#include "isolenui/app/app.h"
#include "elba/elba_gfx.h"
#include "isolenui/ui/ui.h"
// a retained context on the gfx cpu pool renders into a streamed image,
// and only the rows the scene touched go up each frame
struct dial {
elba_context* ctx;
elba_gfx_surface* surface;
elba_scene* scene;
elba_path* arc;
};
static bool dial_open(dial* d, gfx_device* dev)
{
elba_desc desc = elba_gfx_desc();
desc.policy = elba_policy_retained;
d->ctx = elba_context_create(&desc);
d->surface = d->ctx ? elba_gfx_surface_create(d->ctx, dev, 256u, 256u) : nullptr;
d->scene = elba_scene_create();
d->arc = elba_path_create();
return d->surface && d->scene && d->arc;
}
static void dial_frame(ui::ctx* u, dial* d, float value)
{
elba_path_reset(d->arc);
elba_arc(d->arc, 128.0f, 128.0f, 100.0f, 100.0f, 0.0f, -2.4f, 4.8f * value);
elba_stroke_style s = elba_stroke_default();
s.width = 18.0f;
s.cap = elba_cap_round;
const elba_paint ink = elba_solid(elba_rgba8(0xffe5648au));
elba_scene_reset(d->scene);
elba_stroke(d->scene, d->arc, nullptr, &s, &ink);
if (elba_gfx_render(d->surface, d->scene, nullptr) == elba_ok) {
ui::image(u, elba_gfx_surface_image(d->surface), ui::row().width(128.0f).height(128.0f));
}
}
static void dial_close(dial* d)
{
elba_path_destroy(d->arc);
elba_scene_destroy(d->scene);
elba_gfx_surface_destroy(d->surface);
elba_context_destroy(d->ctx);
}