Search in sources :

Example 96 with DoubleBuffer

use of java.nio.DoubleBuffer in project robovm by robovm.

the class MachineSizedFloatPtr method set.

/**
     * Copies {@code count} floats from {@code src} starting at offset {@code offset}
     * to the memory pointed to by this {@link MachineSizedFloatPtr}. Does  
     * {@code float} to {@code double} conversion if running on a 64-bit 
     * platform.
     * 
     * @param src the source.
     * @param offset the offset within the source array to start copying from.
     * @param count the number of elements to copy.
     */
public void set(float[] src, int offset, int count) {
    if (_sizeOf() == 4) {
        asFloatBuffer(count).put(src, offset, count);
    } else {
        Arrays.checkOffsetAndCount(src.length, offset, count);
        DoubleBuffer buf = asDoubleBuffer(count);
        for (int i = 0; i < count; i++) {
            buf.put(src[i + offset]);
        }
    }
}
Also used : DoubleBuffer(java.nio.DoubleBuffer)

Example 97 with DoubleBuffer

use of java.nio.DoubleBuffer in project spaceships-demo by puniverse.

the class VAO method setVertex.

public void setVertex(GL3 gl, String attributeName, VBO vbo) {
    vbo.bind(gl);
    final int location = getLocation(gl, attributeName);
    gl.glEnableVertexAttribArray(location);
    if (vbo.getBuffer() instanceof FloatBuffer)
        gl.glVertexAttribPointer(location, vbo.getComponents(), vbo.getComponentType(), vbo.isNormalized(), vbo.getStride(), 0);
    else if (vbo.getBuffer() instanceof IntBuffer)
        gl.glVertexAttribIPointer(location, vbo.getComponents(), vbo.getComponentType(), vbo.getStride(), 0);
    else if (vbo.getBuffer() instanceof DoubleBuffer)
        gl.glVertexAttribPointer(location, vbo.getComponents(), vbo.getComponentType(), false, vbo.getStride(), 0);
    else
        throw new GLException("Unrecognized buffer type: " + vbo.getBuffer().getClass().getName());
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) IntBuffer(java.nio.IntBuffer) GLException(javax.media.opengl.GLException) FloatBuffer(java.nio.FloatBuffer)

Example 98 with DoubleBuffer

use of java.nio.DoubleBuffer in project playn by threerings.

the class JavaGL20 method glBufferData.

@Override
public void glBufferData(int target, int size, Buffer data, int usage) {
    if (data == null) {
        GL15.glBufferData(target, size, usage);
        return;
    }
    // Limit the buffer to the given size, restoring it afterwards
    int oldLimit = data.limit();
    if (data instanceof ByteBuffer) {
        ByteBuffer subData = (ByteBuffer) data;
        subData.limit(subData.position() + size);
        GL15.glBufferData(target, subData, usage);
    } else if (data instanceof IntBuffer) {
        IntBuffer subData = (IntBuffer) data;
        subData.limit(subData.position() + size / 4);
        GL15.glBufferData(target, subData, usage);
    } else if (data instanceof FloatBuffer) {
        FloatBuffer subData = (FloatBuffer) data;
        subData.limit(subData.position() + size / 4);
        GL15.glBufferData(target, subData, usage);
    } else if (data instanceof DoubleBuffer) {
        DoubleBuffer subData = (DoubleBuffer) data;
        subData.limit(subData.position() + size / 8);
        GL15.glBufferData(target, subData, usage);
    } else if (data instanceof ShortBuffer) {
        ShortBuffer subData = (ShortBuffer) data;
        subData.limit(subData.position() + size / 2);
        GL15.glBufferData(target, subData, usage);
    }
    data.limit(oldLimit);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 99 with DoubleBuffer

use of java.nio.DoubleBuffer in project playn by threerings.

the class JavaGL20 method glBufferSubData.

@Override
public void glBufferSubData(int target, int offset, int size, Buffer data) {
    // Limit the buffer to the given size, restoring it afterwards
    int oldLimit = data.limit();
    if (data instanceof ByteBuffer) {
        ByteBuffer subData = (ByteBuffer) data;
        subData.limit(subData.position() + size);
        GL15.glBufferSubData(target, offset, subData);
    } else if (data instanceof IntBuffer) {
        IntBuffer subData = (IntBuffer) data;
        subData.limit(subData.position() + size / 4);
        GL15.glBufferSubData(target, offset, subData);
    } else if (data instanceof FloatBuffer) {
        FloatBuffer subData = (FloatBuffer) data;
        subData.limit(subData.position() + size / 4);
        GL15.glBufferSubData(target, offset, subData);
    } else if (data instanceof DoubleBuffer) {
        DoubleBuffer subData = (DoubleBuffer) data;
        subData.limit(subData.position() + size / 8);
        GL15.glBufferSubData(target, offset, subData);
    } else if (data instanceof ShortBuffer) {
        ShortBuffer subData = (ShortBuffer) data;
        subData.limit(subData.position() + size / 2);
        GL15.glBufferSubData(target, offset, subData);
    }
    data.limit(oldLimit);
}
Also used : DoubleBuffer(java.nio.DoubleBuffer) IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 100 with DoubleBuffer

use of java.nio.DoubleBuffer in project android_frameworks_base by ParanoidAndroid.

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)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)162 ByteBuffer (java.nio.ByteBuffer)39 FloatBuffer (java.nio.FloatBuffer)26 IntBuffer (java.nio.IntBuffer)25 ShortBuffer (java.nio.ShortBuffer)22 LongBuffer (java.nio.LongBuffer)14 CharBuffer (java.nio.CharBuffer)11 BufferOverflowException (java.nio.BufferOverflowException)8 IOException (java.io.IOException)5 BufferUnderflowException (java.nio.BufferUnderflowException)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ServerDenseDoubleRow (com.tencent.angel.ps.impl.matrix.ServerDenseDoubleRow)4 Test (org.junit.Test)4 InvalidMarkException (java.nio.InvalidMarkException)3 Random (java.util.Random)3 BytePointer (org.bytedeco.javacpp.BytePointer)3 DoublePointer (org.bytedeco.javacpp.DoublePointer)3 FloatPointer (org.bytedeco.javacpp.FloatPointer)3 IntPointer (org.bytedeco.javacpp.IntPointer)3