Search in sources :

Example 81 with IntBuffer

use of java.nio.IntBuffer in project android_frameworks_base by ResurrectionRemix.

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("}");
}
Also used : IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 82 with IntBuffer

use of java.nio.IntBuffer in project android_frameworks_base by ResurrectionRemix.

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;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 83 with IntBuffer

use of java.nio.IntBuffer 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("}");
}
Also used : IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 84 with IntBuffer

use of java.nio.IntBuffer 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;
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) LongBuffer(java.nio.LongBuffer) IntBuffer(java.nio.IntBuffer) CharBuffer(java.nio.CharBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 85 with IntBuffer

use of java.nio.IntBuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglContext method querySupportedFormats.

@Override
public ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type) {
    long memFlags = Utils.getMemoryAccessFlags(access);
    int typeFlag = LwjglImage.decodeImageType(type);
    Utils.tempBuffers[0].b16i.rewind();
    //query count
    int ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, null, Utils.tempBuffers[0].b16i);
    Utils.checkError(ret, "clGetSupportedImageFormats");
    int count = Utils.tempBuffers[0].b16i.get(0);
    if (count == 0) {
        return new ImageFormat[0];
    }
    //get formats
    CLImageFormat.Buffer formatsB = new CLImageFormat.Buffer(BufferUtils.createByteBuffer(count * CLImageFormat.SIZEOF));
    ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, formatsB, (IntBuffer) null);
    Utils.checkError(ret, "clGetSupportedImageFormats");
    //convert formats
    ImageFormat[] formats = new ImageFormat[count];
    for (int i = 0; i < count; ++i) {
        CLImageFormat f = formatsB.get();
        Image.ImageChannelOrder channelOrder = LwjglImage.encodeImageChannelOrder(f.image_channel_order());
        Image.ImageChannelType channelType = LwjglImage.encodeImageChannelType(f.image_channel_data_type());
        formats[i] = new ImageFormat(channelOrder, channelType);
    }
    return formats;
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FrameBuffer(com.jme3.texture.FrameBuffer) ByteBuffer(java.nio.ByteBuffer) IntBuffer(java.nio.IntBuffer) IntBuffer(java.nio.IntBuffer) ImageFormat(com.jme3.opencl.Image.ImageFormat)

Aggregations

IntBuffer (java.nio.IntBuffer)286 ByteBuffer (java.nio.ByteBuffer)97 FloatBuffer (java.nio.FloatBuffer)47 ShortBuffer (java.nio.ShortBuffer)36 Test (org.junit.Test)35 Bitmap (android.graphics.Bitmap)18 DoubleBuffer (java.nio.DoubleBuffer)18 IOException (java.io.IOException)14 BaseTest (org.apache.jena.atlas.junit.BaseTest)14 FileOutputStream (java.io.FileOutputStream)13 CharBuffer (java.nio.CharBuffer)11 LongBuffer (java.nio.LongBuffer)11 UTF8CodePointDecoder (org.antlr.v4.runtime.UTF8CodePointDecoder)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 Buffer (java.nio.Buffer)9 VertexBuffer (com.jme3.scene.VertexBuffer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 BufferOverflowException (java.nio.BufferOverflowException)6 FileChannel (java.nio.channels.FileChannel)6