Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgrenderparticles.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#include <QtQuick3DRuntimeRender/private/qssgrenderparticles_p.h>
7#include <cmath>
8
10
11static int divisibleBy(int a, int b)
12{
13 return (a % b) ? a + b - (a % b) : a;
14}
15static int ceilDivide(int a, int b)
16{
17 int x = a / b;
18 int y = (a % b) ? 1 : 0;
19 return x + y;
20}
21
22void QSSGParticleBuffer::resize(int particleCount, int particleSize)
23{
24 if (particleCount == 0) {
25 m_particlesPerSlice = 0;
26 m_particleCount = 0;
27 m_sliceStride = 0;
28 m_size = QSize();
29 m_particleBuffer.resize(0);
30 return;
31 }
32 int vec4PerParticle = ceilDivide(particleSize, 16);
33 int vec4s = particleCount * vec4PerParticle;
34 int width = divisibleBy(std::sqrt(vec4s), vec4PerParticle);
35 int height = ceilDivide(vec4s, width);
36 m_particlesPerSlice = width / vec4PerParticle;
37 m_particleCount = particleCount;
38 width = divisibleBy(width, 4);
39 height = divisibleBy(height, 4);
40 m_sliceStride = width * 16;
41 m_size = QSize(width, height);
42 m_particleBuffer.resize(m_sliceStride * height);
43}
44
45void QSSGParticleBuffer::resizeLine(int particleCount, int segmentCount)
46{
47 m_segments = segmentCount;
48 resize(particleCount * segmentCount, sizeof(QSSGLineParticle));
49}
50
51void QSSGParticleBuffer::setBounds(const QSSGBounds3& bounds)
52{
53 m_bounds = bounds;
54 m_serial++;
55}
56
57char *QSSGParticleBuffer::pointer()
58{
59 return m_particleBuffer.data();
60}
61
62const char *QSSGParticleBuffer::pointer() const
63{
64 return m_particleBuffer.constData();
65}
66
67int QSSGParticleBuffer::particlesPerSlice() const
68{
69 return m_particlesPerSlice;
70}
71
72int QSSGParticleBuffer::sliceStride() const
73{
74 return m_sliceStride;
75}
76
77int QSSGParticleBuffer::particleCount() const
78{
79 return m_particleCount;
80}
81
82QSize QSSGParticleBuffer::size() const
83{
84 return m_size;
85}
86
87int QSSGParticleBuffer::sliceCount() const
88{
89 return m_size.height();
90}
91
92QByteArray QSSGParticleBuffer::data() const
93{
94 return m_particleBuffer;
95}
96
97int QSSGParticleBuffer::bufferSize() const
98{
99 return m_particleBuffer.size();
100}
101
102int QSSGParticleBuffer::serial() const
103{
104 return m_serial;
105}
106
107int QSSGParticleBuffer::segments() const
108{
109 return m_segments;
110}
111
112QSSGBounds3 QSSGParticleBuffer::bounds() const
113{
114 return m_bounds;
115}
116
117QSSGRenderParticles::QSSGRenderParticles()
118 : QSSGRenderNode(QSSGRenderGraphObject::Type::Particles)
119{
120
121}
122
123QT_END_NAMESPACE
static int ceilDivide(int a, int b)
static QT_BEGIN_NAMESPACE int divisibleBy(int a, int b)