-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoped_line.cpp
61 lines (52 loc) · 1.44 KB
/
scoped_line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2023 Michel de Boer
// License: GPLv3
#include "scoped_line.h"
namespace SpiralFun {
void Line::setNodeMaterial(QSGGeometryNode* node)
{
// There seems to be an GL bug that causes the line width from one line to
// be used for drawing another line if they had the same color.
// By creating a unique material type for each line this bug is avoided as
// for each unique material a shader will be created.
if (mMaterial)
{
// Subsequent nodes will point to the material owned by the first node.
node->setMaterial(mMaterial);
node->setFlag(QSGNode::OwnsMaterial, false);
}
else
{
// The first node will own the material.
mMaterial = new LineMaterial;
mMaterial->setColor(mColor);
mMaterial->setFlag(QSGMaterial::Blending);
node->setMaterial(mMaterial);
node->setFlag(QSGNode::OwnsMaterial, true);
}
}
ScopedLine::ScopedLine(Line* line, const std::function<void()>& cleanup) :
mLine(line),
mCleanup(cleanup)
{
}
ScopedLine::~ScopedLine()
{
if (mCleanup)
mCleanup();
}
ScopedLine::ScopedLine(ScopedLine&& other)
{
mLine = other.mLine;
mCleanup = std::move(other.mCleanup);
other.mCleanup = nullptr;
}
ScopedLine& ScopedLine::operator=(ScopedLine&& rhs)
{
if (mCleanup)
mCleanup();
mLine = rhs.mLine;
mCleanup = std::move(rhs.mCleanup);
rhs.mCleanup = nullptr;
return *this;
}
}