diff options
author | renanse <[email protected]> | 2013-01-20 00:51:00 -0600 |
---|---|---|
committer | renanse <[email protected]> | 2013-01-20 00:51:00 -0600 |
commit | be8f02e0593bf0f0a86082b3bdfc2c5805a57e59 (patch) | |
tree | 011383de3e280f1a960b17f818dfad2e012a31c1 /ardor3d-core/src/main/java | |
parent | 8908ac9904c3acc8bd40b4c16b13d0934ca81ee5 (diff) |
Switched more code to using more efficient index buffers.
Diffstat (limited to 'ardor3d-core/src/main/java')
9 files changed, 105 insertions, 13 deletions
diff --git a/ardor3d-core/src/main/java/com/ardor3d/renderer/effect/EffectManager.java b/ardor3d-core/src/main/java/com/ardor3d/renderer/effect/EffectManager.java index 8299c14..c5780bd 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/renderer/effect/EffectManager.java +++ b/ardor3d-core/src/main/java/com/ardor3d/renderer/effect/EffectManager.java @@ -18,11 +18,11 @@ import com.ardor3d.framework.DisplaySettings; import com.ardor3d.image.TextureStoreFormat; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.Camera; -import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.Camera.ProjectionMode; +import com.ardor3d.renderer.Renderer; import com.ardor3d.renderer.state.RenderState; -import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.renderer.state.RenderState.StateType; +import com.ardor3d.renderer.state.ZBufferState; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.hint.CullHint; import com.ardor3d.scenegraph.hint.LightCombineMode; @@ -139,7 +139,7 @@ public class EffectManager { _fsq = new Mesh("fsq"); _fsq.getMeshData().setVertexBuffer(BufferUtils.createFloatBuffer(-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1)); _fsq.getMeshData().setTextureBuffer(BufferUtils.createFloatBuffer(0, 0, 1, 0, 1, 1, 0, 1), 0); - _fsq.getMeshData().setIndexBuffer(BufferUtils.createIntBuffer(0, 1, 3, 1, 2, 3)); + _fsq.getMeshData().setIndices(BufferUtils.createIndexBufferData(new int[] { 0, 1, 3, 1, 2, 3 }, 3)); _fsq.getSceneHints().setCullHint(CullHint.Never); _fsq.getSceneHints().setLightCombineMode(LightCombineMode.Off); diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ByteBufferData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ByteBufferData.java index 89d516e..4091e06 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ByteBufferData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ByteBufferData.java @@ -106,6 +106,20 @@ public class ByteBufferData extends IndexBufferData<ByteBuffer> implements Savab } @Override + public void put(final int[] array) { + for (int i = 0; i < array.length; i++) { + put(array[i]); + } + } + + @Override + public void put(final int[] array, final int offset, final int length) { + for (int i = offset, max = offset + length; i < max; i++) { + put(array[i]); + } + } + + @Override public int getByteCount() { return 1; } diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IndexBufferData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IndexBufferData.java index 9c39fae..4ca77b5 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IndexBufferData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IndexBufferData.java @@ -66,6 +66,26 @@ public abstract class IndexBufferData<T extends Buffer> extends AbstractBufferDa public abstract void put(IndexBufferData<?> buf); /** + * Write the contents of the given int array into this IndexBufferData. Note that data conversion is handled using + * the get/put methods in IndexBufferData. + * + * @param array + * the source int array. + */ + public abstract void put(int[] array); + + /** + * Write the contents of the given int array into this IndexBufferData. Note that data conversion is handled using + * the get/put methods in IndexBufferData. + * + * @param array + * the source int array. + * @param offset + * @param length + */ + public abstract void put(int[] array, int offset, int length); + + /** * Get the underlying nio buffer. */ @Override @@ -121,6 +141,20 @@ public abstract class IndexBufferData<T extends Buffer> extends AbstractBufferDa } /** + * @see Buffer#flip(); + */ + public void flip() { + getBuffer().flip(); + } + + /** + * @see Buffer#clear(); + */ + public void clear() { + getBuffer().clear(); + } + + /** * @see Buffer#reset(); */ public void reset() { diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IntBufferData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IntBufferData.java index 4e4cf04..219a729 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IntBufferData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/IntBufferData.java @@ -105,6 +105,16 @@ public class IntBufferData extends IndexBufferData<IntBuffer> implements Savable } @Override + public void put(final int[] array) { + _buffer.put(array); + } + + @Override + public void put(final int[] array, final int offset, final int length) { + _buffer.put(array, offset, length); + } + + @Override public int getByteCount() { return 4; } diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/Mesh.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/Mesh.java index d97c844..b81eb1c 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/Mesh.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/Mesh.java @@ -336,7 +336,7 @@ public class Mesh extends Spatial implements Renderable, Pickable { } renderer.setupVertexData(meshData.getVertexCoords()); - if (meshData.getIndexBuffer() != null) { + if (meshData.getIndices() != null) { renderer.drawElements(meshData.getIndices(), meshData.getIndexLengths(), meshData.getIndexModes(), primcount); } else { @@ -390,7 +390,7 @@ public class Mesh extends Spatial implements Renderable, Pickable { renderer.setupVertexDataVBO(meshData.getVertexCoords()); } - if (meshData.getIndexBuffer() != null) { + if (meshData.getIndices() != null) { // TODO: Maybe ask for the IndexBuffer's dynamic/static type and fall back to arrays for indices? renderer.drawElementsVBO(meshData.getIndices(), meshData.getIndexLengths(), meshData.getIndexModes(), primcount); diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java index 8516f48..90a5a8b 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/MeshData.java @@ -794,7 +794,7 @@ public class MeshData implements Savable { } for (int i = 0; i < rSize; i++) { - if (getIndexBuffer() != null) { + if (getIndices() != null) { result[i] = getIndices().get(getVertexIndex(primitiveIndex, i, section)); } else { result[i] = getVertexIndex(primitiveIndex, i, section); @@ -833,7 +833,7 @@ public class MeshData implements Savable { if (result[i] == null) { result[i] = new Vector3(); } - if (getIndexBuffer() != null) { + if (getIndices() != null) { // indexed geometry BufferUtils.populateFromBuffer(result[i], getVertexBuffer(), getIndices().get(getVertexIndex(primitiveIndex, i, section))); @@ -960,7 +960,7 @@ public class MeshData implements Savable { // Now, based on IndexMode, pick a point on that primitive final IndexMode mode = getIndexMode(section); - final boolean hasIndices = getIndexBuffer() != null; + final boolean hasIndices = getIndices() != null; switch (mode) { case Triangles: case TriangleFan: diff --git a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ShortBufferData.java b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ShortBufferData.java index 95016bf..5d8f8f8 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ShortBufferData.java +++ b/ardor3d-core/src/main/java/com/ardor3d/scenegraph/ShortBufferData.java @@ -106,6 +106,20 @@ public class ShortBufferData extends IndexBufferData<ShortBuffer> implements Sav } @Override + public void put(final int[] array) { + for (int i = 0; i < array.length; i++) { + put(array[i]); + } + } + + @Override + public void put(final int[] array, final int offset, final int length) { + for (int i = offset, max = offset + length; i < max; i++) { + put(array[i]); + } + } + + @Override public int getByteCount() { return 2; } diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/geom/BufferUtils.java b/ardor3d-core/src/main/java/com/ardor3d/util/geom/BufferUtils.java index 6017a8b..a0a3478 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/util/geom/BufferUtils.java +++ b/ardor3d-core/src/main/java/com/ardor3d/util/geom/BufferUtils.java @@ -1552,6 +1552,31 @@ public final class BufferUtils { } /** + * Create a new IndexBufferData large enough to fit the contents of the given array. The specific implementation + * will be chosen based on the max value you need to store in your buffer. If that value is less than 2^8, a + * ByteBufferData is used. If it is less than 2^16, a ShortBufferData is used. Otherwise an IntBufferData is used. + * + * @param contents + * an array of index values to store in your newly created IndexBufferData. + * @param maxValue + * the largest value you will need to store in your buffer. Often this is equal to + * ("size of vertex buffer" - 1). + * @return the new IndexBufferData + */ + public static IndexBufferData<?> createIndexBufferData(final int[] contents, final int maxValue) { + final IndexBufferData<?> buffer; + if (maxValue < 256) { // 2^8 + buffer = createIndexBufferData(contents.length, ByteBufferData.class); + } else if (maxValue < 65536) { // 2^16 + buffer = createIndexBufferData(contents.length, ShortBufferData.class); + } else { + buffer = createIndexBufferData(contents.length, IntBufferData.class); + } + buffer.put(contents); + return buffer; + } + + /** * Create a new IndexBufferData of the specified size and class. * * @param size diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/stat/graph/TimedAreaGrapher.java b/ardor3d-core/src/main/java/com/ardor3d/util/stat/graph/TimedAreaGrapher.java index 4b0e5d2..73637b8 100644 --- a/ardor3d-core/src/main/java/com/ardor3d/util/stat/graph/TimedAreaGrapher.java +++ b/ardor3d-core/src/main/java/com/ardor3d/util/stat/graph/TimedAreaGrapher.java @@ -272,11 +272,6 @@ public class TimedAreaGrapher extends AbstractStatGrapher implements TableLinkab area = new Mesh("a"); area.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(maxSamples * 2)); - area.getMeshData().setIndexBuffer(BufferUtils.createIntBuffer(maxSamples * 2)); - for (int i = 0; i < maxSamples * 2; i++) { - area.getMeshData().getIndices().put(i); - } - area.getMeshData().getIndexBuffer().rewind(); area.getSceneHints().setRenderBucketType(RenderBucketType.Ortho); area.getMeshData().setIndexMode(IndexMode.LineStrip); |