* Particle meshes now call updateCounts() when number of particles changes. This might fix native crashes in some cases.

* Removed completely useless merge sort on the entire particle array from ParticleTriMesh ...
 * Added a small note in the javadoc of VertexBuffer.updateData() regarding bizarre issues

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9380 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Sha..rd 13 years ago
parent 30dfa52f51
commit 4fc046a0e1
  1. 20
      engine/src/core/com/jme3/effect/ParticlePointMesh.java
  2. 40
      engine/src/core/com/jme3/effect/ParticleTriMesh.java
  3. 4
      engine/src/core/com/jme3/scene/VertexBuffer.java

@ -62,53 +62,55 @@ public class ParticlePointMesh extends ParticleMesh {
// set positions // set positions
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles); FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles);
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
//if the buffer is already set only update the data //if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) { if (buf != null) {
buf.updateData(pb); buf.updateData(pb);
} else { } else {
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
setBuffer(pvb); setBuffer(pvb);
} }
// set colors // set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4); ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4);
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
buf = getBuffer(VertexBuffer.Type.Color); buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) { if (buf != null) {
buf.updateData(cb); buf.updateData(cb);
} else { } else {
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
setBuffer(cvb); setBuffer(cvb);
} }
// set sizes // set sizes
FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles); FloatBuffer sb = BufferUtils.createFloatBuffer(numParticles);
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
svb.setupData(Usage.Stream, 1, Format.Float, sb);
buf = getBuffer(VertexBuffer.Type.Size); buf = getBuffer(VertexBuffer.Type.Size);
if (buf != null) { if (buf != null) {
buf.updateData(sb); buf.updateData(sb);
} else { } else {
VertexBuffer svb = new VertexBuffer(VertexBuffer.Type.Size);
svb.setupData(Usage.Stream, 1, Format.Float, sb);
setBuffer(svb); setBuffer(svb);
} }
// set UV-scale // set UV-scale
FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4); FloatBuffer tb = BufferUtils.createFloatBuffer(numParticles*4);
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
buf = getBuffer(VertexBuffer.Type.TexCoord); buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) { if (buf != null) {
buf.updateData(tb); buf.updateData(tb);
} else { } else {
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Stream, 4, Format.Float, tb);
setBuffer(tvb); setBuffer(tvb);
} }
updateCounts();
} }
@Override @Override

@ -40,7 +40,6 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Format; import com.jme3.scene.VertexBuffer.Format;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import com.jme3.util.SortUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
@ -50,9 +49,9 @@ public class ParticleTriMesh extends ParticleMesh {
private int imagesX = 1; private int imagesX = 1;
private int imagesY = 1; private int imagesY = 1;
private boolean uniqueTexCoords = false; private boolean uniqueTexCoords = false;
private ParticleComparator comparator = new ParticleComparator(); // private ParticleComparator comparator = new ParticleComparator();
private ParticleEmitter emitter; private ParticleEmitter emitter;
private Particle[] particlesCopy; // private Particle[] particlesCopy;
@Override @Override
public void initParticleData(ParticleEmitter emitter, int numParticles) { public void initParticleData(ParticleEmitter emitter, int numParticles) {
@ -60,38 +59,34 @@ public class ParticleTriMesh extends ParticleMesh {
this.emitter = emitter; this.emitter = emitter;
particlesCopy = new Particle[numParticles]; // particlesCopy = new Particle[numParticles];
// set positions // set positions
FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4); FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position); // if the buffer is already set only update the data
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
//if the buffer is already set only update the data
VertexBuffer buf = getBuffer(VertexBuffer.Type.Position); VertexBuffer buf = getBuffer(VertexBuffer.Type.Position);
if (buf != null) { if (buf != null) {
buf.updateData(pb); buf.updateData(pb);
} else { } else {
VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
pvb.setupData(Usage.Stream, 3, Format.Float, pb);
setBuffer(pvb); setBuffer(pvb);
} }
// set colors // set colors
ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4); ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
buf = getBuffer(VertexBuffer.Type.Color); buf = getBuffer(VertexBuffer.Type.Color);
if (buf != null) { if (buf != null) {
buf.updateData(cb); buf.updateData(cb);
} else { } else {
VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
cvb.setNormalized(true);
setBuffer(cvb); setBuffer(cvb);
} }
// set texcoords // set texcoords
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4); FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4);
uniqueTexCoords = false; uniqueTexCoords = false;
for (int i = 0; i < numParticles; i++){ for (int i = 0; i < numParticles; i++){
tb.put(0f).put(1f); tb.put(0f).put(1f);
@ -100,12 +95,13 @@ public class ParticleTriMesh extends ParticleMesh {
tb.put(1f).put(0f); tb.put(1f).put(0f);
} }
tb.flip(); tb.flip();
tvb.setupData(Usage.Static, 2, Format.Float, tb);
buf = getBuffer(VertexBuffer.Type.TexCoord); buf = getBuffer(VertexBuffer.Type.TexCoord);
if (buf != null) { if (buf != null) {
buf.updateData(tb); buf.updateData(tb);
} else { } else {
VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
tvb.setupData(Usage.Static, 2, Format.Float, tb);
setBuffer(tvb); setBuffer(tvb);
} }
@ -126,16 +122,16 @@ public class ParticleTriMesh extends ParticleMesh {
} }
ib.flip(); ib.flip();
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
buf = getBuffer(VertexBuffer.Type.Index); buf = getBuffer(VertexBuffer.Type.Index);
if (buf != null) { if (buf != null) {
buf.updateData(ib); buf.updateData(ib);
} else { } else {
VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
setBuffer(ivb); setBuffer(ivb);
} }
updateCounts();
} }
@Override @Override
@ -150,12 +146,12 @@ public class ParticleTriMesh extends ParticleMesh {
@Override @Override
public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) { public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) {
System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length); // System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length);
comparator.setCamera(cam); // comparator.setCamera(cam);
// Arrays.sort(particlesCopy, comparator); // Arrays.sort(particlesCopy, comparator);
// SortUtil.qsort(particlesCopy, comparator); // SortUtil.qsort(particlesCopy, comparator);
SortUtil.msort(particles, particlesCopy, comparator); // SortUtil.msort(particles, particlesCopy, comparator);
particles = particlesCopy; // particles = particlesCopy;
VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position); VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position);
FloatBuffer positions = (FloatBuffer) pvb.getData(); FloatBuffer positions = (FloatBuffer) pvb.getData();

@ -542,8 +542,10 @@ public class VertexBuffer extends NativeObject implements Savable, Cloneable {
* data already set, e.g. vb.updateData(vb.getData()), this will just * data already set, e.g. vb.updateData(vb.getData()), this will just
* set the proper update flag indicating the data should be sent to the GPU * set the proper update flag indicating the data should be sent to the GPU
* again. * again.
* <p>
* It is allowed to specify a buffer with different capacity than the * It is allowed to specify a buffer with different capacity than the
* originally set buffer. * originally set buffer, HOWEVER, if you do so, you must
* call Mesh.updateCounts() otherwise bizarre errors can occur.
* *
* @param data The data buffer to set * @param data The data buffer to set
*/ */

Loading…
Cancel
Save