MCPcopy Create free account
hub / github.com/davideberly/GeometricTools / Particles

Method Particles

GTE/Graphics/Particles.cpp:14–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace gte;
13
14Particles::Particles(std::vector<Vector4<float>> const& positionSize,
15 float sizeAdjust, VertexFormat const& vformat)
16 :
17 mPositionSize(positionSize),
18 mSizeAdjust(sizeAdjust),
19 mNumActive(static_cast<uint32_t>(positionSize.size()))
20{
21 uint32_t texOffset = IsValid(vformat);
22 if (texOffset == std::numeric_limits<uint32_t>::max())
23 {
24 // IsValid(...) will generate logging messages depending on the
25 // specific failure condition.
26 return;
27 }
28
29 uint32_t numParticles = mNumActive;
30 uint32_t numVertices = 4 * numParticles;
31 mVBuffer = std::make_shared<VertexBuffer>(vformat, numVertices);
32 mVBuffer->SetUsage(Resource::Usage::DYNAMIC_UPDATE);
33 uint32_t vertexSize = vformat.GetVertexSize();
34 int32_t index = vformat.GetIndex(VASemantic::TEXCOORD, 0);
35 uint32_t offset = vformat.GetOffset(index);
36 char* tcoords = mVBuffer->GetData() + offset;
37 std::array<Vector2<float>, 4> commonTCD =
38 {
39 Vector2<float>{ 0.0f, 0.0f },
40 Vector2<float>{ 1.0f, 0.0f },
41 Vector2<float>{ 1.0f, 1.0f },
42 Vector2<float>{ 0.0f, 1.0f }
43 };
44 for (uint32_t i = 0; i < numParticles; ++i)
45 {
46 for (uint32_t j = 0; j < 4; ++j)
47 {
48 Vector2<float>& tcoord = *reinterpret_cast<Vector2<float>*>(tcoords);
49 tcoord = commonTCD[j];
50 tcoords += vertexSize;
51 }
52 }
53
54 mIBuffer = std::make_shared<IndexBuffer>(IP_TRIMESH, 2 * numParticles, sizeof(uint32_t));
55 auto* indices = mIBuffer->Get<uint32_t>();
56 for (uint32_t i = 0; i < numParticles; ++i)
57 {
58 uint32_t iFI = 4 * i;
59 uint32_t iFIp1 = iFI + 1;
60 uint32_t iFIp2 = iFI + 2;
61 uint32_t iFIp3 = iFI + 3;
62 *indices++ = iFI;
63 *indices++ = iFIp1;
64 *indices++ = iFIp2;
65 *indices++ = iFI;
66 *indices++ = iFIp2;
67 *indices++ = iFIp3;
68 }
69
70 UpdateModelBound();
71}

Callers

nothing calls this directly

Calls 5

SetUsageMethod · 0.80
GetVertexSizeMethod · 0.80
GetIndexMethod · 0.45
GetOffsetMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected