forked from gongjianbo/MyTestCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyBlenderItem.cpp
73 lines (62 loc) · 1.78 KB
/
MyBlenderItem.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
62
63
64
65
66
67
68
69
70
71
72
#include "MyBlenderItem.h"
#include <QSGGeometryNode>
#include <QSGGeometry>
#include <QSGMaterial>
#include <QSGTextureProvider>
#include <QSGTextureMaterial>
#include "MyXorNode.h"
MyBlenderItem::MyBlenderItem(QQuickItem *parent)
: QQuickItem(parent)
{
setFlag(ItemHasContents, true);
}
void MyBlenderItem::setSource1(QQuickItem *item)
{
if(source1 == item)
return;
source1 = item;
source1Change = true;
emit source1Changed();
update();
}
void MyBlenderItem::setSource2(QQuickItem *item)
{
if(source2 == item)
return;
source2 = item;
source2Change = true;
emit source2Changed();
update();
}
QSGNode *MyBlenderItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData)
{
Q_UNUSED(updatePaintNodeData)
// Check if our input is valid and abort if not, deleting the old node.
bool abort = false;
if (!source1 || !source1->isTextureProvider()) {
qDebug() << "source1 is missing or not a texture provider";
abort = true;
}
if (!source2 || !source2->isTextureProvider()) {
qDebug() << "source2 is missing or not a texture provider";
abort = true;
}
if (abort) {
delete oldNode;
return nullptr;
}
XorNode *node = static_cast<XorNode *>(oldNode);
// If the sources have changed, recreate the nodes
if (source1Change || source2Change) {
delete node;
node = nullptr;
source1Change = false;
source2Change = false;
}
// Create a new XorNode for us to render with.
if (!node)
node = new XorNode(source1->textureProvider(), source2->textureProvider());
// Update the geometry of the node to match the new bounding rect
node->setRect(boundingRect());
return node;
}