diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-07-11 12:04:24 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-07-19 07:03:49 +0000 |
commit | 8c54e49e6a0669af1e77525e0e7071b22439d480 (patch) | |
tree | 4395f7c67818266f57c46bd4fee7e3410b33fcc9 /examples/qt3d/compute-particles | |
parent | 7eaf108d53e9d37d214e56218a40220fbca94e43 (diff) |
Compute-Particles: use vec4 in the ParticlesData structure
Since vec3-vec4 padding is not always correctly implemented in all OpenGL GPU
implementations, use vec4 in the struct declaration.
Also slightly improve readibility of the buffer construction code.
Change-Id: I9dfbeb2bcdc0a713e1e0a872f6a5e8cfe50c52a3
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/compute-particles')
-rw-r--r-- | examples/qt3d/compute-particles/ParticlesScene.qml | 9 | ||||
-rw-r--r-- | examples/qt3d/compute-particles/particles.comp | 8 |
2 files changed, 9 insertions, 8 deletions
diff --git a/examples/qt3d/compute-particles/ParticlesScene.qml b/examples/qt3d/compute-particles/ParticlesScene.qml index cbb21f266..e63c6cb91 100644 --- a/examples/qt3d/compute-particles/ParticlesScene.qml +++ b/examples/qt3d/compute-particles/ParticlesScene.qml @@ -94,12 +94,13 @@ Entity { readonly property int floatSize: 4 function buildParticlesBuffer() { - var bufferData = new Float32Array(particlesCount * 4 * 3); + var byteSizeOfParticleData = 12; + var bufferData = new Float32Array(particlesCount * byteSizeOfParticleData); var factor = 500.0; for (var i = 0; i < particlesCount; ++i) { - var positionIdx = i * 12; - var velocityIdx = i * 12 + 4; - var colorIdx = i * 12 + 8; + var positionIdx = i * byteSizeOfParticleData; + var velocityIdx = i * byteSizeOfParticleData + 4; + var colorIdx = i * byteSizeOfParticleData + 8; for (var j = 0; j < 3; ++j) { bufferData[positionIdx + j] = (Math.random() - 0.5) * factor; diff --git a/examples/qt3d/compute-particles/particles.comp b/examples/qt3d/compute-particles/particles.comp index 7feaf5fdd..af993bbe2 100644 --- a/examples/qt3d/compute-particles/particles.comp +++ b/examples/qt3d/compute-particles/particles.comp @@ -7,9 +7,9 @@ layout (local_size_x = 1024) in; struct ParticleData { - vec3 position; - vec3 direction; - vec3 color; + vec4 position; + vec4 direction; + vec4 color; }; // Particles from previouse frame @@ -29,7 +29,7 @@ void main(void) currentParticle.position = currentParticle.position + currentParticle.direction * particleStep; // Make acceleration more or less point toward the center of the scene - vec3 acceleration = normalize(vec3(0.0) - currentParticle.position) * finalCollisionFactor; + vec4 acceleration = normalize(vec4(0.0) - currentParticle.position) * finalCollisionFactor; // New velocity = old velocity + acceleration over step duration currentParticle.direction = currentParticle.direction + acceleration * particleStep; |