Skip to content

Commit

Permalink
prepare path and object id access in brush-nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Bies committed Feb 7, 2022
1 parent afe9ebc commit f16c7b4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/objects/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,25 +667,26 @@ void Object::draw_object(Painter& renderer,
const Style& style,
const PainterOptions& options) const
{
options.object_id = id();
if (QPainter* painter = renderer.painter; painter != nullptr && is_active()) {
const auto& path_vector = this->path_vector();
const auto faces = path_vector.faces();
const auto& outline = path_vector.outline();
if (!faces.empty() || !outline.isEmpty()) {
renderer.set_style(style, *this, options);
auto& painter = *renderer.painter;

for (const auto& face : faces) {
painter.save();
painter.setPen(Qt::NoPen);
painter.drawPath(face);
painter.restore();

for (std::size_t f = 0; f < faces.size(); ++f) {
options.path_id = f;
renderer.set_style(style, *this, options);
painter->save();
painter->setPen(Qt::NoPen);
painter->drawPath(faces.at(f));
painter->restore();
}

painter.save();
painter->save();
renderer.painter->setBrush(Qt::NoBrush);
painter.drawPath(outline);
painter.restore();
painter->drawPath(outline);
painter->restore();

const auto marker_color = style.property(Style::PEN_COLOR_KEY)->value<Color>();
const auto width = style.property(Style::PEN_WIDTH_KEY)->value<double>();
Expand Down
14 changes: 14 additions & 0 deletions src/renderers/offscreenrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ const std::vector<OffscreenRenderer::ShaderInput> OffscreenRenderer::fragment_sh
QT_TRANSLATE_NOOP("OffscreenRenderer", "view_pos"),
ShaderInput::Kind::Varying,
},
{
Type::Integer,
QT_TRANSLATE_NOOP("OffscreenRenderer", "object_id"),
ShaderInput::Kind::Uniform,
},
{
Type::Integer,
QT_TRANSLATE_NOOP("OffscreenRenderer", "path_id"),
ShaderInput::Kind::Uniform,
},
};

QString OffscreenRenderer::ShaderInput::tr_name() const
Expand Down Expand Up @@ -70,6 +80,8 @@ uniform mat3 view_transform;
uniform vec2 view_size;
uniform vec2 roi_tl;
uniform vec2 roi_br;
uniform int object_id;
uniform int path_id;
vec2 unc(vec2 centered) {
return (centered + vec2(1.0, 1.0)) / 2.0;
Expand Down Expand Up @@ -311,6 +323,8 @@ Texture OffscreenRenderer::render(const Object& object,
::set_uniform(*this, "view_size", Vec2f(options.device.width(), options.device.height()));
::set_uniform(*this, "roi_tl", Vec2f(roi.topLeft()));
::set_uniform(*this, "roi_br", Vec2f(roi.bottomRight()));
::set_uniform(*this, "object_id", options.object_id);
::set_uniform(*this, "path_id", options.path_id);

m_vertices.bind();

Expand Down
4 changes: 3 additions & 1 deletion src/renderers/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void Painter::toast(const Vec2f& pos, const QString& text) const
}

QBrush
Painter::make_brush(const Style& style, const Object& object, const PainterOptions& options)
Painter::make_brush(const Style& style,
const Object& object,
const PainterOptions& options)
{
if (style.property(omm::Style::BRUSH_IS_ACTIVE_KEY)->value<bool>()) {
if (style.property("gl-brush")->value<bool>()) {
Expand Down
4 changes: 3 additions & 1 deletion src/renderers/painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class Painter

void toast(const Vec2f& pos, const QString& text) const;

static QBrush make_brush(const Style& style, const Object& object, const PainterOptions& options);
static QBrush make_brush(const Style& style,
const Object& object,
const PainterOptions& options);
static QPen make_pen(const Style& style, const Object& object);

static QBrush make_simple_brush(const Style& style);
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/painteroptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct PainterOptions
const Style* default_style = nullptr;
const bool device_is_viewport;
const QPaintDevice& device;
mutable std::size_t object_id;
mutable std::size_t path_id = 0;
};

} // namespace omm

0 comments on commit f16c7b4

Please sign in to comment.