From a6b44658eb1c55295f132a36233a11aa2bd8f9cf Mon Sep 17 00:00:00 2001 From: Scott Barta Date: Fri, 9 Mar 2012 13:52:20 -0800 Subject: New drop of the jmonkeyengine library A new drop of the jmonkeyengine library sources, based on a 2012-03-05 snapshot. Fixes a few unnecessary memory allocations in the main rendering loop. Change-Id: I51ac0942fe87204df102cfdce746b59a5cb5ff85 --- .../jme3tools/optimize/GeometryBatchFactory.java | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java') diff --git a/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java b/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java index ae6ad8c..121d75c 100644 --- a/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java +++ b/engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java @@ -62,26 +62,27 @@ public class GeometryBatchFactory { } } - private static void doTransformTangents(FloatBuffer inBuf, int offset, FloatBuffer outBuf, Matrix4f transform) { + private static void doTransformTangents(FloatBuffer inBuf, int offset, int components, FloatBuffer outBuf, Matrix4f transform) { Vector3f tan = new Vector3f(); - float handedness = 0; + // offset is given in element units // convert to be in component units - offset *= 4; + offset *= components; - for (int i = 0; i < inBuf.capacity() / 4; i++) { - tan.x = inBuf.get(i * 4 + 0); - tan.y = inBuf.get(i * 4 + 1); - tan.z = inBuf.get(i * 4 + 2); - handedness = inBuf.get(i * 4 + 3); + for (int i = 0; i < inBuf.capacity() / components; i++) { + tan.x = inBuf.get(i * components + 0); + tan.y = inBuf.get(i * components + 1); + tan.z = inBuf.get(i * components + 2); transform.multNormal(tan, tan); - outBuf.put(offset + i * 4 + 0, tan.x); - outBuf.put(offset + i * 4 + 1, tan.y); - outBuf.put(offset + i * 4 + 2, tan.z); - outBuf.put(offset + i * 4 + 3, handedness); - + outBuf.put(offset + i * components + 0, tan.x); + outBuf.put(offset + i * components + 1, tan.y); + outBuf.put(offset + i * components + 2, tan.z); + + if (components == 4){ + outBuf.put(offset + i * components + 3, inBuf.get(i * components + 3)); + } } } @@ -129,9 +130,9 @@ public class GeometryBatchFactory { throw new UnsupportedOperationException(); } - for (Entry entry : geom.getMesh().getBuffers()) { - compsForBuf[entry.getKey()] = entry.getValue().getNumComponents(); - formatForBuf[entry.getKey()] = entry.getValue().getFormat(); + for (VertexBuffer vb : geom.getMesh().getBufferList().getArray()){ + compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); + formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); } if (mode != null && mode != listMode) { @@ -208,10 +209,11 @@ public class GeometryBatchFactory { FloatBuffer inPos = (FloatBuffer) inBuf.getDataReadOnly(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); doTransformNorms(inPos, globalVertIndex, outPos, worldMatrix); - }else if(Type.Tangent.ordinal() == bufType){ + }else if(Type.Tangent.ordinal() == bufType){ FloatBuffer inPos = (FloatBuffer) inBuf.getDataReadOnly(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); - doTransformTangents(inPos, globalVertIndex, outPos, worldMatrix); + int components = inBuf.getNumComponents(); + doTransformTangents(inPos, globalVertIndex, components, outPos, worldMatrix); } else { inBuf.copyElements(0, outBuf, globalVertIndex, geomVertCount); } -- cgit v1.2.3