下面列出了java.nio.IntBuffer#position ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public IntBuffer getIndexIntBuffer(
final int size ,
final byte[] buffer ,
final int start ,
final int length ,
final ByteOrder order ) throws IOException {
IReadSupporter wrapBuffer =
ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for ( int i = 0 ; i < size ; i++ ) {
result.put( NumberToBinaryUtils.getUnsignedShortToInt( wrapBuffer.getShort() ) );
}
result.position( 0 );
return result;
}
@Override
public IntBuffer getIndexIntBuffer(
final byte[] buffer ,
final int start ,
final int length ,
final ByteOrder order ) throws IOException {
int size = length / Byte.BYTES;
IReadSupporter wrapBuffer =
ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for ( int i = 0 ; i < size ; i++ ) {
result.put( NumberToBinaryUtils.getUnsignedByteToInt( wrapBuffer.getByte() ) );
}
result.position( 0 );
return result;
}
public static void copy(IntBuffer srcBuf, int srcStep, IntBuffer dstBuf, int dstStep) {
int w = Math.min(srcStep, dstStep);
int srcLine = srcBuf.position();
int dstLine = dstBuf.position();
while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) {
srcBuf.position(srcLine);
dstBuf.position(dstLine);
w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining());
for (int x = 0; x < w; x++) {
int in = srcBuf.get();
int out = in;
dstBuf.put(out);
}
srcLine += srcStep;
dstLine += dstStep;
}
}
@Override
public void alcGetInteger(int param, IntBuffer buffer, int size) {
if (buffer.position() != 0) throw new AssertionError();
if (buffer.limit() != size) throw new AssertionError();
ALCcontext context = ALC10.alcGetCurrentContext();
ALCdevice device = ALC10.alcGetContextsDevice(context);
ALC10.alcGetInteger(device, param, buffer);
}
private static int[] getGlyphs(GlyphSequence gs) {
IntBuffer gb = gs.getGlyphs();
gb.rewind();
int[] glyphs = new int[gb.limit() - gb.position()];
for (int i = 0; gb.position() < gb.limit(); ) {
glyphs[i++] = gb.get();
}
return glyphs;
}
public void glMultMatrixx(IntBuffer m) {
int position = m.position();
mCurrent.glMultMatrixx(m);
m.position(position);
mgl.glMultMatrixx(m);
if ( _check) check();
}
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length ) throws IOException{
int size = length / Short.BYTES;
ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer , start , length );
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( (int)( wrapBuffer.getShort() ) );
}
result.position( 0 );
return result;
}
@Override
public IntBuffer getIndexIntBuffer( final int size , final ByteBuffer wrapBuffer ) throws IOException{
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( wrapBuffer.getInt() );
}
result.position( 0 );
return result;
}
private int[] getInts(int offset, int count) {
int[] ints = new int[count];
if (count <= 16) {
for(int i = 0; i < count; offset += 4, ++i) {
ints[i] = bytes.getInt(offset);
}
} else {
IntBuffer temp = bytes.asIntBuffer();
temp.position(offset / 4);
temp.get(ints);
}
return ints;
}
private int[] getInts(int offset, int count) {
int[] ints = new int[count];
if (count <= 16) {
for(int i = 0; i < count; offset += 4, ++i) {
ints[i] = bytes.getInt(offset);
}
} else {
IntBuffer temp = bytes.asIntBuffer();
temp.position(offset / 4);
temp.get(ints);
}
return ints;
}
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length , ByteOrder order ) throws IOException{
int size = length / Integer.BYTES;
IReadSupporter wrapBuffer = ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( wrapBuffer.getInt() );
}
result.position( 0 );
return result;
}
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length , ByteOrder order ) throws IOException{
int size = length / Integer.BYTES;
IReadSupporter wrapBuffer = ByteBufferSupporterFactory.createReadSupporter( buffer , start , length , order );
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( wrapBuffer.getInt() );
}
result.position( 0 );
return result;
}
@Override
public IntBuffer getIndexIntBuffer( final byte[] buffer , final int start , final int length ) throws IOException{
int size = length / Short.BYTES;
ByteBuffer wrapBuffer = ByteBuffer.wrap( buffer , start , length );
IntBuffer result = IntBuffer.allocate( size );
for( int i = 0 ; i < size ; i++ ){
result.put( (int)( wrapBuffer.getShort() ) );
}
result.position( 0 );
return result;
}
/** Locates metadata related to the passed id (converted into a byte
* array). Returns either a bytebuffer with the position set to the
* start of the metadata or null. */
private ByteBuffer findMetadataFor (byte[] id) throws IOException {
System.err.println("FindMetadataFor " + new String(id));
long result = -1;
//Get a buffer clone so we don't have threading problems - never
//use the master buffer
ByteBuffer buf = getMetaBuffer().asReadOnlyBuffer();
IntBuffer ibuf = buf.asIntBuffer();
do {
//First, see if the ID (image filename) length matches the ID
//we received - if it doesn't, no need to examine the record
int thisIdLength = ibuf.get();
System.err.println("pos:" + ibuf.position() + " idLen: " + thisIdLength + " looking for len: " + id.length);
if (thisIdLength == id.length) {
//Mark the start of this metadata record and position to
//the start of the ID entry
System.err.println("Length match. Putting mark at " + (buf.position()) + " and moving to " + (buf.position() + ID_OFFSET) + " to check data");
buf.mark().position (buf.position() + ID_OFFSET);
byte[] chars = new byte[id.length];
//Fetch the ID into the array, and reset the buffer position
//for either returning or skipping to the next record
buf.get(chars).reset();
System.err.println(" id from metadata: " + new String(chars));
//Compare it with the id we were passed
if (Arrays.equals(chars, id)) {
System.err.println(" MATCHED - position: " + buf.position());
return buf;
}
}
//Skip ahead to the next record
buf.position(buf.position() + METAENTRY_LENGTH);
ibuf.position(buf.position() / 4);
System.err.println("Buffer pos: " + buf.position() + " ibuf: " + ibuf.position());
} while (buf.position() <= buf.limit() - METAENTRY_LENGTH);
return null;
}
@Override
public void alGenEffects(final int numEffects, final IntBuffer buffers) {
if (buffers.position() != 0) throw new AssertionError();
if (buffers.limit() != numEffects) throw new AssertionError();
EXTEfx.alGenEffects(buffers);
}
@Override
public void alGenAuxiliaryEffectSlots(int numSlots, IntBuffer buffers) {
if (buffers.position() != 0) throw new AssertionError();
if (buffers.limit() != numSlots) throw new AssertionError();
EFX10.alGenAuxiliaryEffectSlots(buffers);
}
@Override
public void alDeleteBuffers(final int numBuffers, final IntBuffer buffers) {
if (buffers.position() != 0) throw new AssertionError();
if (buffers.limit() != numBuffers) throw new AssertionError();
AL10.alDeleteBuffers(buffers);
}
@Override
public void alGenEffects(int numEffects, IntBuffer buffers) {
if (buffers.position() != 0) throw new AssertionError();
if (buffers.limit() != numEffects) throw new AssertionError();
EFX10.alGenEffects(buffers);
}
@Override
public void drawFrame() {
if(frameBuffer == null) {
if(getWidth() != 0 && getHeight() != 0) {
initFBO();
} else {
return;
}
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
super.drawFrame();
int[] pixels = new int[getWidth()*getHeight()];
IntBuffer intBuffer = IntBuffer.wrap(pixels);
intBuffer.position(0);
GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
for(int i = 0; i < pixels.length; i++) {
pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000); //swap red and blue to translate back to bitmap rgb style
}
Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
callback.bitmapCreated(image);
}
@Override
public void drawFrame() {
if(frameBuffer == null) {
if(getWidth() != 0 && getHeight() != 0) {
initFBO();
} else {
return;
}
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
super.drawFrame();
int[] pixels = new int[getWidth()*getHeight()];
IntBuffer intBuffer = IntBuffer.wrap(pixels);
intBuffer.position(0);
GLES20.glReadPixels(0, 0, getWidth(), getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, intBuffer);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
for(int i = 0; i < pixels.length; i++) {
pixels[i] = (pixels[i] & (0xFF00FF00)) | ((pixels[i] >> 16) & 0x000000FF) | ((pixels[i] << 16) & 0x00FF0000); //swap red and blue to translate back to bitmap rgb style
}
Bitmap image = Bitmap.createBitmap(pixels, getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
callback.bitmapCreated(image);
}