From 96acebfe4ff20ff1d949818c39cd37217f5d4fb6 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 31 Oct 2011 21:27:57 +0000 Subject: [PATCH] - Faster BatchNode git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8564 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/BatchNode.java | 165 ++++++++++++------ 1 file changed, 112 insertions(+), 53 deletions(-) diff --git a/engine/src/core/com/jme3/scene/BatchNode.java b/engine/src/core/com/jme3/scene/BatchNode.java index 2581ff513..6b409cbdf 100644 --- a/engine/src/core/com/jme3/scene/BatchNode.java +++ b/engine/src/core/com/jme3/scene/BatchNode.java @@ -80,6 +80,9 @@ public class BatchNode extends Node implements Savable { * used to store transformed vectors before proceeding to a bulk put into the FloatBuffer */ private float[] tmpFloat; + private float[] tmpFloatN; + private float[] tmpFloatT; + /** * Construct a batchNode */ @@ -142,21 +145,23 @@ public class BatchNode extends Node implements Savable { if (batch != null) { Mesh mesh = batch.geometry.getMesh(); - FloatBuffer buf = (FloatBuffer) mesh.getBuffer(VertexBuffer.Type.Position).getData(); - doTransformVerts(buf, bg.startIndex, bg.startIndex + bg.getVertexCount(), buf, bg.cachedOffsetMat); - mesh.getBuffer(VertexBuffer.Type.Position).updateData(buf); - - buf = (FloatBuffer) mesh.getBuffer(VertexBuffer.Type.Normal).getData(); - doTransformNorm(buf, bg.startIndex, bg.startIndex + bg.getVertexCount(), buf, bg.cachedOffsetMat); - mesh.getBuffer(VertexBuffer.Type.Normal).updateData(buf); - + VertexBuffer pvb = mesh.getBuffer(VertexBuffer.Type.Position); + FloatBuffer posBuf = (FloatBuffer) pvb.getData(); + VertexBuffer nvb = mesh.getBuffer(VertexBuffer.Type.Normal); + FloatBuffer normBuf = (FloatBuffer) nvb.getData(); if (mesh.getBuffer(VertexBuffer.Type.Tangent) != null) { - buf = (FloatBuffer) mesh.getBuffer(VertexBuffer.Type.Tangent).getData(); - doTransformNorm(buf, bg.startIndex, bg.startIndex + bg.getVertexCount(), buf, bg.cachedOffsetMat); - mesh.getBuffer(VertexBuffer.Type.Tangent).updateData(buf); + VertexBuffer tvb = mesh.getBuffer(VertexBuffer.Type.Tangent); + FloatBuffer tanBuf = (FloatBuffer) tvb.getData(); + doTransformsTangents(posBuf, normBuf, tanBuf, bg.startIndex, bg.startIndex + bg.getVertexCount(), bg.cachedOffsetMat); + tvb.updateData(tanBuf); + } else { + doTransforms(posBuf, normBuf, bg.startIndex, bg.startIndex + bg.getVertexCount(), bg.cachedOffsetMat); } + pvb.updateData(posBuf); + nvb.updateData(normBuf); + batch.needMeshUpdate = true; } @@ -351,13 +356,16 @@ public class BatchNode extends Node implements Savable { int totalVerts = 0; int totalTris = 0; int totalLodLevels = 0; + int maxVertCount = 0; Mesh.Mode mode = null; - for (Geometry geom : geometries) { + for (Geometry geom : geometries) { totalVerts += geom.getVertexCount(); totalTris += geom.getTriangleCount(); totalLodLevels = Math.min(totalLodLevels, geom.getMesh().getNumLodLevels()); - + if (maxVertCount < geom.getVertexCount()) { + maxVertCount = geom.getVertexCount(); + } Mesh.Mode listMode; int components; switch (geom.getMesh().getMode()) { @@ -403,8 +411,6 @@ public class BatchNode extends Node implements Savable { formatForBuf[VertexBuffer.Type.Index.ordinal()] = VertexBuffer.Format.UnsignedShort; } - int maxElemCount = 0; - int elements = 0; // generate output buffers based on retrieved info for (int i = 0; i < compsForBuf.length; i++) { if (compsForBuf[i] == 0) { @@ -413,16 +419,11 @@ public class BatchNode extends Node implements Savable { Buffer data; if (i == VertexBuffer.Type.Index.ordinal()) { - data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris); - elements = compsForBuf[i]* totalTris; + data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris); } else { - data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalVerts); - elements = compsForBuf[i]* totalVerts; + data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalVerts); } - if(maxElemCount