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-examples/src/main/java/com/ardor3d | |
parent | 8908ac9904c3acc8bd40b4c16b13d0934ca81ee5 (diff) |
Switched more code to using more efficient index buffers.
Diffstat (limited to 'ardor3d-examples/src/main/java/com/ardor3d')
3 files changed, 29 insertions, 27 deletions
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ExportImportExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ExportImportExample.java index c6f3872..11fe9f4 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ExportImportExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/pipeline/ExportImportExample.java @@ -13,7 +13,6 @@ package com.ardor3d.example.pipeline; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -25,6 +24,7 @@ import com.ardor3d.math.Vector3; import com.ardor3d.renderer.IndexMode;
import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.WireframeState;
+import com.ardor3d.scenegraph.IndexBufferData;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.MeshData;
import com.ardor3d.scenegraph.Node;
@@ -177,20 +177,20 @@ public class ExportImportExample extends ExampleBase { meshData.setVertexBuffer(vertexBuffer);
- final IntBuffer indexBuffer = BufferUtils.createIntBuffer(18);
+ final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(18, vertexBuffer.capacity() - 1);
// Strips
- indexBuffer.put(0).put(3).put(1).put(2);
- indexBuffer.put(4).put(7).put(5).put(6);
+ indices.put(0).put(3).put(1).put(2);
+ indices.put(4).put(7).put(5).put(6);
// Quad
- indexBuffer.put(8).put(9).put(10).put(11);
+ indices.put(8).put(9).put(10).put(11);
// Triangles
- indexBuffer.put(12).put(13).put(15);
- indexBuffer.put(13).put(15).put(14);
+ indices.put(12).put(13).put(15);
+ indices.put(13).put(15).put(14);
- meshData.setIndexBuffer(indexBuffer);
+ meshData.setIndices(indices);
// Setting sub primitive data
final int[] indexLengths = new int[] { 4, 4, 4, 6 };
diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DegenerateTrianglesExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DegenerateTrianglesExample.java index 361c39c..c9a859d 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DegenerateTrianglesExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/DegenerateTrianglesExample.java @@ -11,7 +11,6 @@ package com.ardor3d.example.renderer; import java.nio.FloatBuffer; -import java.nio.IntBuffer; import com.ardor3d.example.ExampleBase; import com.ardor3d.example.Purpose; @@ -28,6 +27,7 @@ import com.ardor3d.math.Vector3; import com.ardor3d.renderer.IndexMode; import com.ardor3d.renderer.queue.RenderBucketType; import com.ardor3d.renderer.state.TextureState; +import com.ardor3d.scenegraph.IndexBufferData; import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.MeshData; import com.ardor3d.scenegraph.hint.CullHint; @@ -128,7 +128,8 @@ public class DegenerateTrianglesExample extends ExampleBase { final FloatBuffer normalBuffer = BufferUtils.createVector3Buffer(totalSize); final FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(totalSize); - final IntBuffer indexBuffer = BufferUtils.createIntBuffer((ySize - 1) * xSize * 2); + final IndexBufferData<?> indices = BufferUtils.createIndexBufferData((ySize - 1) * xSize * 2, + vertexBuffer.capacity() - 1); final int[] indexLengths = new int[ySize - 1]; for (int y = 0; y < ySize; y++) { @@ -142,8 +143,8 @@ public class DegenerateTrianglesExample extends ExampleBase { for (int y = 0; y < ySize - 1; y++) { for (int x = 0; x < xSize; x++) { final int index = y * xSize + x; - indexBuffer.put(index); - indexBuffer.put(index + xSize); + indices.put(index); + indices.put(index + xSize); } indexLengths[y] = xSize * 2; } @@ -152,7 +153,7 @@ public class DegenerateTrianglesExample extends ExampleBase { meshData.setNormalBuffer(normalBuffer); meshData.setTextureBuffer(textureBuffer, 0); - meshData.setIndexBuffer(indexBuffer); + meshData.setIndices(indices); meshData.setIndexLengths(indexLengths); meshData.setIndexMode(IndexMode.TriangleStrip); @@ -167,7 +168,8 @@ public class DegenerateTrianglesExample extends ExampleBase { final FloatBuffer normalBuffer = BufferUtils.createVector3Buffer(totalSize); final FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(totalSize); - final IntBuffer indexBuffer = BufferUtils.createIntBuffer((ySize - 1) * xSize * 2 + (ySize - 1) * 2); + final IndexBufferData<?> indices = BufferUtils.createIndexBufferData((ySize - 1) * xSize * 2 + (ySize - 1) * 2, + vertexBuffer.capacity() - 1); for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { @@ -180,20 +182,20 @@ public class DegenerateTrianglesExample extends ExampleBase { for (int y = 0; y < ySize - 1; y++) { for (int x = 0; x < xSize; x++) { final int index = y * xSize + x; - indexBuffer.put(index); - indexBuffer.put(index + xSize); + indices.put(index); + indices.put(index + xSize); } final int index = (y + 1) * xSize; - indexBuffer.put(index + xSize - 1); - indexBuffer.put(index); + indices.put(index + xSize - 1); + indices.put(index); } meshData.setVertexBuffer(vertexBuffer); meshData.setNormalBuffer(normalBuffer); meshData.setTextureBuffer(textureBuffer, 0); - meshData.setIndexBuffer(indexBuffer); + meshData.setIndices(indices); meshData.setIndexMode(IndexMode.TriangleStrip); return mesh; diff --git a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MultiStripExample.java b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MultiStripExample.java index 310e39d..35486ce 100644 --- a/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MultiStripExample.java +++ b/ardor3d-examples/src/main/java/com/ardor3d/example/renderer/MultiStripExample.java @@ -11,7 +11,6 @@ package com.ardor3d.example.renderer;
import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
@@ -19,6 +18,7 @@ import com.ardor3d.intersection.PickData; import com.ardor3d.intersection.PrimitivePickResults;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.IndexMode;
+import com.ardor3d.scenegraph.IndexBufferData;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.MeshData;
import com.ardor3d.util.geom.BufferUtils;
@@ -91,20 +91,20 @@ public class MultiStripExample extends ExampleBase { meshData.setVertexBuffer(vertexBuffer);
- final IntBuffer indexBuffer = BufferUtils.createIntBuffer(18);
+ final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(18, vertexBuffer.capacity() - 1);
// Strips
- indexBuffer.put(0).put(3).put(1).put(2);
- indexBuffer.put(4).put(7).put(5).put(6);
+ indices.put(0).put(3).put(1).put(2);
+ indices.put(4).put(7).put(5).put(6);
// Quad
- indexBuffer.put(8).put(9).put(10).put(11);
+ indices.put(8).put(9).put(10).put(11);
// Triangles
- indexBuffer.put(12).put(13).put(15);
- indexBuffer.put(13).put(14).put(15);
+ indices.put(12).put(13).put(15);
+ indices.put(13).put(14).put(15);
- meshData.setIndexBuffer(indexBuffer);
+ meshData.setIndices(indices);
// Setting sub primitive data
final int[] indexLengths = new int[] { 4, 4, 4, 6 };
|