use of java.nio.ShortBuffer in project android_frameworks_base by ResurrectionRemix.
the class DhcpPacket method checksum.
/**
* Performs an IP checksum (used in IP header and across UDP
* payload) on the specified portion of a ByteBuffer. The seed
* allows the checksum to commence with a specified value.
*/
private int checksum(ByteBuffer buf, int seed, int start, int end) {
int sum = seed;
int bufPosition = buf.position();
// set position of original ByteBuffer, so that the ShortBuffer
// will be correctly initialized
buf.position(start);
ShortBuffer shortBuf = buf.asShortBuffer();
// re-set ByteBuffer position
buf.position(bufPosition);
short[] shortArray = new short[(end - start) / 2];
shortBuf.get(shortArray);
for (short s : shortArray) {
sum += intAbs(s);
}
start += shortArray.length * 2;
// see if a singleton byte remains
if (end != start) {
short b = buf.get(start);
// make it unsigned
if (b < 0) {
b += 256;
}
sum += b * 256;
}
sum = ((sum >> 16) & 0xFFFF) + (sum & 0xFFFF);
sum = ((sum + ((sum >> 16) & 0xFFFF)) & 0xFFFF);
int negated = ~sum;
return intAbs((short) negated);
}
use of java.nio.ShortBuffer in project XobotOS by xamarin.
the class GLLogWrapper method doArrayElement.
private void doArrayElement(StringBuilder builder, boolean enabled, String name, PointerInfo pointer, int index) {
if (!enabled) {
return;
}
builder.append(" ");
builder.append(name + ":{");
if (pointer == null || pointer.mTempByteBuffer == null) {
builder.append("undefined }");
return;
}
if (pointer.mStride < 0) {
builder.append("invalid stride");
return;
}
int stride = pointer.getStride();
ByteBuffer byteBuffer = pointer.mTempByteBuffer;
int size = pointer.mSize;
int type = pointer.mType;
int sizeofType = pointer.sizeof(type);
int byteOffset = stride * index;
for (int i = 0; i < size; i++) {
if (i > 0) {
builder.append(", ");
}
switch(type) {
case GL_BYTE:
{
byte d = byteBuffer.get(byteOffset);
builder.append(Integer.toString(d));
}
break;
case GL_UNSIGNED_BYTE:
{
byte d = byteBuffer.get(byteOffset);
builder.append(Integer.toString(0xff & d));
}
break;
case GL_SHORT:
{
ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
short d = shortBuffer.get(byteOffset / 2);
builder.append(Integer.toString(d));
}
break;
case GL_FIXED:
{
IntBuffer intBuffer = byteBuffer.asIntBuffer();
int d = intBuffer.get(byteOffset / 4);
builder.append(Integer.toString(d));
}
break;
case GL_FLOAT:
{
FloatBuffer intBuffer = byteBuffer.asFloatBuffer();
float d = intBuffer.get(byteOffset / 4);
builder.append(Float.toString(d));
}
break;
default:
builder.append("?");
break;
}
byteOffset += sizeofType;
}
builder.append("}");
}
use of java.nio.ShortBuffer in project XobotOS by xamarin.
the class GLLogWrapper method toByteBuffer.
private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
ByteBuffer result = null;
boolean convertWholeBuffer = (byteCount < 0);
if (input instanceof ByteBuffer) {
ByteBuffer input2 = (ByteBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = input2.limit() - position;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
for (int i = 0; i < byteCount; i++) {
result.put(input2.get());
}
input2.position(position);
} else if (input instanceof CharBuffer) {
CharBuffer input2 = (CharBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
CharBuffer result2 = result.asCharBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof ShortBuffer) {
ShortBuffer input2 = (ShortBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
ShortBuffer result2 = result.asShortBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof IntBuffer) {
IntBuffer input2 = (IntBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
IntBuffer result2 = result.asIntBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof FloatBuffer) {
FloatBuffer input2 = (FloatBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
FloatBuffer result2 = result.asFloatBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof DoubleBuffer) {
DoubleBuffer input2 = (DoubleBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
DoubleBuffer result2 = result.asDoubleBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof LongBuffer) {
LongBuffer input2 = (LongBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
LongBuffer result2 = result.asLongBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else {
throw new RuntimeException("Unimplemented Buffer subclass.");
}
result.rewind();
// The OpenGL API will interpret the result in hardware byte order,
// so we better do that as well:
result.order(ByteOrder.nativeOrder());
return result;
}
use of java.nio.ShortBuffer in project XobotOS by xamarin.
the class Group method draw.
public void draw(GL10 gl) {
gl.glDisableClientState(gl.GL_COLOR_ARRAY);
gl.glVertexPointer(3, gl.GL_FIXED, 0, parent.getVertexBuffer());
gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
gl.glNormalPointer(gl.GL_FIXED, 0, parent.getNormalBuffer());
gl.glEnableClientState(gl.GL_NORMAL_ARRAY);
if (parent.hasTexcoords()) {
gl.glTexCoordPointer(2, gl.GL_FIXED, 0, parent.getTexcoordBuffer());
gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
gl.glEnable(gl.GL_TEXTURE_2D);
} else {
gl.glDisable(gl.GL_TEXTURE_2D);
}
Iterator<MaterialIndices> iter = materialIndices.iterator();
while (iter.hasNext()) {
MaterialIndices matIdx = iter.next();
ShortBuffer indexBuffer = matIdx.getIndexBuffer();
Material mat = matIdx.getMaterial();
mat.setMaterialParameters(gl);
if (parent.hasTexcoords() && mat.getMap_Kd().length() > 0) {
Texture texture = parent.getTexture(mat.getMap_Kd());
texture.setTextureParameters(gl);
}
gl.glDrawElements(gl.GL_TRIANGLES, indexBuffer.capacity(), gl.GL_UNSIGNED_SHORT, indexBuffer);
}
}
use of java.nio.ShortBuffer in project XobotOS by xamarin.
the class Group method getNumTriangles.
public int getNumTriangles() {
int numTriangles = 0;
Iterator<MaterialIndices> iter = materialIndices.iterator();
while (iter.hasNext()) {
MaterialIndices matIdx = iter.next();
ShortBuffer indexBuffer = matIdx.getIndexBuffer();
numTriangles += indexBuffer.capacity() / 3;
}
return numTriangles;
}
Aggregations