Files
plotter/src/render/program.cpp
T

53 lines
1.9 KiB
C++

#include <plot/render/program.hpp>
#include <plot/render/shaders.hpp>
namespace plot::render {
bool LineProgram::create(Status* st) noexcept {
// plot::gl::Program::from_source() reports Unsupported while
// plot::gl::available() is false and GLFailure when the driver rejects the
// GLSL. Propagating it is the whole point of returning a bool here: the
// caller must not end up drawing with a program that never linked.
program_ = gl::Program::from_source(kLineVS, kLineFS, st);
return program_.id() != 0;
}
void LineProgram::set_scale(Vec2 data_to_px) const noexcept {
program_.set_uniform("u_scale", data_to_px);
}
void LineProgram::set_offset(Vec2 px) const noexcept { program_.set_uniform("u_offset", px); }
void LineProgram::set_viewport(Vec2 px) const noexcept { program_.set_uniform("u_viewport", px); }
void LineProgram::set_width(f32 px) const noexcept { program_.set_uniform("u_width", px); }
void LineProgram::set_color(Color color) const noexcept { program_.set_uniform("u_color", color); }
bool TextProgram::create(Status* st) noexcept {
program_ = gl::Program::from_source(kTextVS, kTextFS, st);
if (program_.id() == 0) {
return false;
}
// The atlas is bound to texture unit 0 by plot::gl::Texture::bind(), so the
// sampler has to point there. It is set once, here, not per frame.
program_.use();
program_.set_uniform_int("u_atlas", 0);
return true;
}
void TextProgram::set_viewport(Vec2 px) const noexcept { program_.set_uniform("u_viewport", px); }
void TextProgram::set_px_range(Vec2 px) const noexcept { program_.set_uniform("u_px_range", px); }
void TextProgram::set_glyph_uv(Vec2 uv) const noexcept { program_.set_uniform("u_glyph_uv", uv); }
void TextProgram::set_texture_size(Vec2 texels) const noexcept {
program_.set_uniform("u_tex_size", texels);
}
void TextProgram::set_color(Color color) const noexcept { program_.set_uniform("u_color", color); }
} // namespace plot::render