The repository had no licence at all, so every source was all-rights-reserved by default. Add the verbatim MIT text at LICENSE (Copyright (c) 2026 Martino Ferrari) and a two-line SPDX header to each of the 113 first-party sources -- 48 include/plot, 26 src, 10 adapters, 5 examples, 21 tests, 3 tools -- so the grant travels with each file rather than relying on the root document alone. Scripts keep their shebang on line 1; the SPDX lines follow it. Genuinely vendored code is untouched: third_party/stb_truetype.h carries no header of ours. src/render/embedded_mono_font.cpp is generated, so tools/fonts/gen_atlas.py emit() now writes the two lines into its header comment and the file was regenerated -- gen_atlas.py --check passes and the regeneration adds only those comment lines to the previously committed file. README's provenance section now states MIT and links LICENSE. No code, test or public API change.
77 lines
3.1 KiB
C++
77 lines
3.1 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// SPDX-FileCopyrightText: 2026 Martino Ferrari
|
|
|
|
#pragma once
|
|
#include <plot/core/color.hpp>
|
|
#include <plot/core/status.hpp>
|
|
#include <plot/gl/handle.hpp>
|
|
#include <plot/math/vec2.hpp>
|
|
|
|
namespace plot::render {
|
|
|
|
/// Linked line program and its uniform surface.
|
|
///
|
|
/// It owns the `plot::gl::Program` and knows the GLSL pair (shaders.hpp), so no
|
|
/// caller spells out a uniform name that could drift from the shader. Creating
|
|
/// it propagates what the GL layer reports: `ErrorCode::Unsupported` while
|
|
/// `plot::gl::available()` is false, `GLFailure` plus the driver's log when the
|
|
/// GLSL does not compile or link.
|
|
class LineProgram {
|
|
public:
|
|
bool create(Status* st = nullptr) noexcept;
|
|
bool valid() const noexcept { return program_.id() != 0; }
|
|
void bind() const noexcept { program_.use(); }
|
|
|
|
/// `u_scale`: data space to pixels.
|
|
void set_scale(Vec2 data_to_px) const noexcept;
|
|
/// `u_offset`: pixel offset added after `set_scale`.
|
|
void set_offset(Vec2 px) const noexcept;
|
|
/// `u_viewport`: render target size in pixels.
|
|
void set_viewport(Vec2 px) const noexcept;
|
|
/// `u_width`: stroke width in pixels.
|
|
void set_width(f32 px) const noexcept;
|
|
/// `u_dash`: the dash pattern in pixels -- `x` the ink length, `y` the gap, and a
|
|
/// non-positive `y` (the default a caller passes) means **solid**. It is a fragment-shader
|
|
/// discard on the interpolated `v_along`, so it costs no geometry, and it is the one uniform
|
|
/// that distinguishes the crosshair's stroke from every other line in the library.
|
|
void set_dash(Vec2 on_off) const noexcept;
|
|
/// `u_color`: stroke colour, alpha included.
|
|
void set_color(Color color) const noexcept;
|
|
|
|
private:
|
|
gl::Program program_;
|
|
};
|
|
|
|
/// Linked text program and its uniform surface. It fails exactly the way
|
|
/// `LineProgram::create()` does, propagating `Unsupported` and `GLFailure`.
|
|
///
|
|
/// `create()` also points the `u_atlas` sampler at texture unit 0, which is the
|
|
/// unit `plot::gl::Texture::bind()` defaults to, and leaves this program bound.
|
|
/// The atlas itself stays with the caller, who owns its lifetime.
|
|
class TextProgram {
|
|
public:
|
|
bool create(Status* st = nullptr) noexcept;
|
|
bool valid() const noexcept { return program_.id() != 0; }
|
|
void bind() const noexcept { program_.use(); }
|
|
|
|
/// `u_viewport`: render target size in pixels.
|
|
void set_viewport(Vec2 px) const noexcept;
|
|
/// `u_px_range`: the glyph cell's size on screen, in pixels (width and
|
|
/// height -- a cell need not be square).
|
|
void set_px_range(Vec2 px) const noexcept;
|
|
/// `u_glyph_uv`: the glyph cell's size in the atlas, normalised. It is the
|
|
/// rect every staged glyph is read through, so it is one size per draw -- and
|
|
/// it is the *backend's* (`TextBackend::cell_uv`), never a glyph's, because a
|
|
/// draw may stage glyphs whose origins differ even when their size cannot.
|
|
void set_glyph_uv(Vec2 uv) const noexcept;
|
|
/// `u_tex_size`: atlas size in texels.
|
|
void set_texture_size(Vec2 texels) const noexcept;
|
|
/// `u_color`: tint colour, alpha included.
|
|
void set_color(Color color) const noexcept;
|
|
|
|
private:
|
|
gl::Program program_;
|
|
};
|
|
|
|
} // namespace plot::render
|