1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "surfaceselectioninstancing_p.h" |
5 | |
6 | SurfaceSelectionInstancing::SurfaceSelectionInstancing() |
7 | { |
8 | } |
9 | |
10 | SurfaceSelectionInstancing::~SurfaceSelectionInstancing() |
11 | { |
12 | } |
13 | |
14 | void SurfaceSelectionInstancing::addPosition(const QVector3D &position) |
15 | { |
16 | m_positions.append(t: position); |
17 | markDirty(); |
18 | m_dirty = true; |
19 | } |
20 | |
21 | void SurfaceSelectionInstancing::resetPositions() |
22 | { |
23 | m_positions.clear(); |
24 | markDirty(); |
25 | m_dirty = true; |
26 | } |
27 | |
28 | QByteArray SurfaceSelectionInstancing::getInstanceBuffer(int *instanceCount) |
29 | { |
30 | if (m_dirty) { |
31 | m_instanceData.resize(size: 0); |
32 | int instanceNumber = 0; |
33 | |
34 | for (auto position : m_positions) { |
35 | auto entry = calculateTableEntry(position, scale: m_scale, eulerRotation: m_rotation, color: m_color); |
36 | m_instanceData.append(s: reinterpret_cast<const char*>(&entry), len: sizeof(entry)); |
37 | instanceNumber++; |
38 | } |
39 | m_instanceCount = instanceNumber; |
40 | m_dirty = false; |
41 | } |
42 | |
43 | if (instanceCount) |
44 | *instanceCount = m_instanceCount; |
45 | |
46 | return m_instanceData; |
47 | } |
48 |