Game Development Reference
In-Depth Information
Note If you rebuild the shared libraries on the command line, Eclipse and the ADT plug-in won't
pick up the new shared libraries themselves. If you run your app immediately after compiling the
shared libraries, it will still use the old shared libraries! To fix this, select your Android project in the
Package Explorer view in Eclipse and press F5.
Now that we fixed the location of the JniUtils class, we can modify the Vertices and Vertices3
classes. Both have a field called vertices of type IntBuffer . We now can modify those fields
to be ByteBuffer instances instead. We can also get rid of the tmpBuffer field in both classes,
because we no longer have to convert anything. All we need to do is modify the constructors
so that they compile again and modify the setVertices() methods so that they use our native
method. Listing 13-7 and Listing 13-8 show the parts that changed in Vertices and Vertices3 ,
respectively.
Listing 13-7. Excerpt of Vertices.java, Using JniUtils
public class Vertices {
final GLGraphics glGraphics;
final boolean hasColor;
final boolean hasTexCoords;
final int vertexSize;
final ByteBuffer vertices;
final ShortBuffer indices;
public Vertices(GLGraphics glGraphics, int maxVertices, int maxIndices, boolean hasColor,
boolean hasTexCoords) {
this .glGraphics = glGraphics;
this .hasColor = hasColor;
this .hasTexCoords = hasTexCoords;
this .vertexSize = (2 + (hasColor?4:0) + (hasTexCoords?2:0)) * 4;
this .vertices = ByteBuffer.allocateDirect(maxVertices * vertexSize);
this .vertices.order(ByteOrder.nativeOrder());
if if(maxIndices > 0) {
ByteBuffer buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
buffer.order(ByteOrder.nativeOrder());
this. indices = buffer.asShortBuffer();
} else {
this .indices = null;
}
}
public void setVertices( float[] vertices, int offset, int length) {
this .vertices.clear();
JniUtils.copy( this .vertices, vertices, offset, length);
this .vertices.position(length * 4);
}
Search WWH ::




Custom Search