java.nio.ShortBuffer Java Examples

The following examples show how to use java.nio.ShortBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoundBuffer.java    From lwjglbook with Apache License 2.0 6 votes vote down vote up
private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        vorbis = Utils.ioResourceToByteBuffer(resource, bufferSize);
        IntBuffer error = stack.mallocInt(1);
        long decoder = stb_vorbis_open_memory(vorbis, error, null);
        if (decoder == NULL) {
            throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
        }

        stb_vorbis_get_info(decoder, info);

        int channels = info.channels();

        int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);

        pcm = MemoryUtil.memAllocShort(lengthSamples);

        pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
        stb_vorbis_close(decoder);

        return pcm;
    }
}
 
Example #2
Source File: ChannelHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * ByteChannelからshort配列を読み込む
 * @param channel
 * @return
 * @throws IOException
 */
public static short[] readShortArray(@NonNull final ByteChannel channel)
	throws IOException {
	
	final int n = readInt(channel);
	final ByteBuffer buf = ByteBuffer.allocate(n * 2).order(ByteOrder.BIG_ENDIAN);
	final int readBytes = channel.read(buf);
	if (readBytes != n * 2) throw new IOException();
	buf.clear();
	final ShortBuffer result = buf.asShortBuffer();
	if (result.hasArray()) {
		return result.array();
	}  else {
		final short[] b = new short[n];
		result.get(b);
		return b;
	}
}
 
Example #3
Source File: AudioChannel.java    From EZFilter with MIT License 6 votes vote down vote up
private long drainOverflow(final ShortBuffer outBuff) {
    final ShortBuffer overflowBuff = mOverflowBuffer.data;
    final int overflowLimit = overflowBuff.limit();
    final int overflowSize = overflowBuff.remaining();

    final long beginPresentationTimeUs = mOverflowBuffer.presentationTimeUs + sampleCountToDurationUs(overflowBuff.position(), mInputSampleRate,
            mOutputChannelCount);

    outBuff.clear();
    // Limit overflowBuff to outBuff's capacity
    overflowBuff.limit(outBuff.capacity());
    // Load overflowBuff onto outBuff
    outBuff.put(overflowBuff);

    if (overflowSize >= outBuff.capacity()) {
        // Overflow fully consumed - Reset
        overflowBuff.clear().limit(0);
    } else {
        // Only partially consumed - Keep position & restore previous limit
        overflowBuff.limit(overflowLimit);
    }

    return beginPresentationTimeUs;
}
 
Example #4
Source File: ArrayUtils.java    From icafe with Eclipse Public License 1.0 6 votes vote down vote up
public static byte[] toByteArray(short[] data, boolean bigEndian) {
	
	ByteBuffer byteBuffer = ByteBuffer.allocate(data.length * 2);
	
	if (bigEndian) {
		byteBuffer.order(ByteOrder.BIG_ENDIAN);
	} else {
		byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
	}
       
	ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
       shortBuffer.put(data);

       byte[] array = byteBuffer.array();

	return array;
}
 
Example #5
Source File: OpusEncoder.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
/**
 * Encode the input buffer to output.
 * @param directInput Input sample buffer
 * @param frameSize Number of samples per channel
 * @param directOutput Output byte buffer
 * @return Number of bytes written to the output
 */
public int encode(ShortBuffer directInput, int frameSize, ByteBuffer directOutput) {
  checkNotReleased();

  if (!directInput.isDirect() || !directOutput.isDirect()) {
    throw new IllegalArgumentException("Arguments must be direct buffers.");
  }

  directOutput.clear();
  int result = library.encode(instance, directInput, frameSize, directOutput, directOutput.capacity());

  if (result < 0) {
    throw new IllegalStateException("Encoding failed with error " + result);
  }

  directOutput.position(result);
  directOutput.flip();

  return result;
}
 
Example #6
Source File: BufferUtils.java    From jogl-samples with MIT License 6 votes vote down vote up
private static boolean isDirect(Buffer buf) {
    if (buf instanceof FloatBuffer) {
        return ((FloatBuffer) buf).isDirect();
    }
    if (buf instanceof IntBuffer) {
        return ((IntBuffer) buf).isDirect();
    }
    if (buf instanceof ShortBuffer) {
        return ((ShortBuffer) buf).isDirect();
    }
    if (buf instanceof ByteBuffer) {
        return ((ByteBuffer) buf).isDirect();
    }
    if (buf instanceof DoubleBuffer) {
        return ((DoubleBuffer) buf).isDirect();
    }
    if (buf instanceof LongBuffer) {
        return ((LongBuffer) buf).isDirect();
    }
    throw new UnsupportedOperationException(" BufferUtils.isDirect was called on " + buf.getClass().getName());
}
 
Example #7
Source File: LandscapeTileIndices.java    From tribaltrouble with GNU General Public License v2.0 6 votes vote down vote up
public final void fillCoverIndices(ShortBuffer buffer, int lod, int border_set, int start_x, int start_y, int end_x, int end_y) {
	border_set = adjustBorderSet(lod, border_set);
	int num_quads_exp = getNumQuadsExp(lod);
	int quad_size_exp = patch_exp - num_quads_exp;
	int quad_size = 1 << quad_size_exp;
	int start_quad_x = start_x>>quad_size_exp;
	int start_quad_y = start_y>>quad_size_exp;
	int end_quad_x = end_x>>quad_size_exp;
	int end_quad_y = end_y>>quad_size_exp;
	LandscapeTileTriangle[][] quads = quad_to_planes[lod];
	for (int x = start_quad_x; x <= end_quad_x; x++)
		for (int y = start_quad_y; y <= end_quad_y; y++) {
			LandscapeTileTriangle[] quad = quads[getQuadIndex(num_quads_exp, x, y)];
			LandscapeTileTriangle north = quad[LandscapeTileTriangle.NORTH_EXP];
			LandscapeTileTriangle south = quad[LandscapeTileTriangle.SOUTH_EXP];
			LandscapeTileTriangle east = quad[LandscapeTileTriangle.EAST_EXP];
			LandscapeTileTriangle west = quad[LandscapeTileTriangle.WEST_EXP];
			north.addIndices(buffer, border_set);
			south.addIndices(buffer, border_set);
			if (east != north && east != south) {
				east.addIndices(buffer, border_set);
				west.addIndices(buffer, border_set);
			}
		}
}
 
Example #8
Source File: HelloGlobe.java    From hello-triangle with MIT License 6 votes vote down vote up
private ShortBuffer getElementBuffer(float radius, short rings, short sectors) {

        float R = 1f / (float) (rings - 1);
        float S = 1f / (float) (sectors - 1);
        short r, s;
        float x, y, z;

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(rings * sectors * 6);

        for (r = 0; r < rings - 1; r++) {

            for (s = 0; s < sectors - 1; s++) {

                elementBuffer.put((short) (r * sectors + s));
                elementBuffer.put((short) (r * sectors + (s + 1)));
                elementBuffer.put((short) ((r + 1) * sectors + (s + 1)));
                elementBuffer.put((short) ((r + 1) * sectors + (s + 1)));
                elementBuffer.put((short) (r * sectors + s));
//                elementBuffer.put((short) (r * sectors + (s + 1)));
                elementBuffer.put((short) ((r + 1) * sectors + s));
            }
        }
        elementBuffer.position(0);

        return elementBuffer;
    }
 
Example #9
Source File: Gl_400_fbo_layered.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl4.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl4.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return checkError(gl4, "initBuffer");
    }
 
Example #10
Source File: BufferUtils.java    From Ultraino with MIT License 6 votes vote down vote up
/**
 * Creates a new ShortBuffer with the same contents as the given
 * ShortBuffer. The new ShortBuffer is separate from the old one and changes
 * are not reflected across. If you want to reflect changes, consider using
 * Buffer.duplicate().
 *
 * @param buf
 *            the ShortBuffer to copy
 * @return the copy
 */
public static ShortBuffer clone(ShortBuffer buf) {
    if (buf == null) {
        return null;
    }
    buf.rewind();

    ShortBuffer copy;
    if (isDirect(buf)) {
        copy = createShortBuffer(buf.limit());
    } else {
        copy = ShortBuffer.allocate(buf.limit());
    }
    copy.put(buf);

    return copy;
}
 
Example #11
Source File: GLMeshTest.java    From WraithEngine with Apache License 2.0 6 votes vote down vote up
@Test
public void createData()
{
    IOpenGL opengl = opengl();
    OpenGLRenderingEngine renderingEngine = new OpenGLRenderingEngine(opengl);
    renderingEngine.init();

    IMesh mesh = renderingEngine.createMesh();
    mesh.update(vertexData());

    verify(opengl, times(1)).generateVertexArray();
    verify(opengl, times(2)).generateBuffer();

    verify(opengl, times(1)).uploadBufferData((FloatBuffer) any());
    verify(opengl, times(1)).uploadBufferData((ShortBuffer) any());
}
 
Example #12
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 6 votes vote down vote up
public ShortBuffer getIndexBuffer() {
	short[] iarray = new short[sides * 3];
	ByteBuffer ibb = ByteBuffer.allocateDirect(sides * 3 * 2);
	ibb.order(ByteOrder.nativeOrder());
	ShortBuffer mIndexBuffer = ibb.asShortBuffer();
	for (int i = 0; i < sides; i++) {
		short index1 = 0;
		short index2 = (short) (i + 1);
		short index3 = (short) (i + 2);
		if (index3 == sides + 1) {
			index3 = 1;
		}
		mIndexBuffer.put(index1);
		mIndexBuffer.put(index2);
		mIndexBuffer.put(index3);

		iarray[i * 3 + 0] = index1;
		iarray[i * 3 + 1] = index2;
		iarray[i * 3 + 2] = index3;
	}
	//this.printShortArray(iarray, "index array");
	return mIndexBuffer;
}
 
Example #13
Source File: Gl_320_fbo_srgb_decode_ext.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset);
        int uniformBlockSize = Math.max(Mat4.SIZE, uniformBufferOffset.get(0));

        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return true;
    }
 
Example #14
Source File: LODGeomap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {
    FloatBuffer pb = writeVertexArray(null, scale, center);
    FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);
    FloatBuffer nb = writeNormalArray(null, scale);
    IndexBuffer ib = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize);
    FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    writeTangentArray(nb, tanb, bb, texb, scale);
    Mesh m = new Mesh();
    m.setMode(Mode.TriangleStrip);
    m.setBuffer(Type.Position, 3, pb);
    m.setBuffer(Type.Normal, 3, nb);
    m.setBuffer(Type.Tangent, 3, tanb);
    m.setBuffer(Type.Binormal, 3, bb);
    m.setBuffer(Type.TexCoord, 2, texb);
    switch (ib.getFormat()) {
        case UnsignedInt:
            m.setBuffer(Type.Index, 3, (IntBuffer) ib.getBuffer());
            break;
        case UnsignedShort:
            m.setBuffer(Type.Index, 3, (ShortBuffer) ib.getBuffer());
            break;
        case UnsignedByte:
            m.setBuffer(Type.Index, 3, (ByteBuffer) ib.getBuffer());
            break;
    }
    m.setStatic();
    m.updateBound();
    return m;
}
 
Example #15
Source File: LineTexBucket.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public static void init() {

            shader = new Shader("linetex_layer_tex");
            //shader = new Shader("linetex_layer");

            int[] vboIds = GLUtils.glGenBuffers(1);
            mVertexFlipID = vboIds[0];

            /* bytes: 0, 1, 0, 1, 0, ... */
            byte[] flip = new byte[MapRenderer.MAX_QUADS * 4];
            for (int i = 0; i < flip.length; i++)
                flip[i] = (byte) (i % 2);

            ByteBuffer buf = ByteBuffer.allocateDirect(flip.length)
                    .order(ByteOrder.nativeOrder());
            buf.put(flip);
            buf.flip();

            ShortBuffer sbuf = buf.asShortBuffer();

            //GL.bindBuffer(GL20.ARRAY_BUFFER, mVertexFlipID);
            GLState.bindVertexBuffer(mVertexFlipID);
            gl.bufferData(GL.ARRAY_BUFFER, flip.length, sbuf,
                    GL.STATIC_DRAW);
            GLState.bindVertexBuffer(GLState.UNBIND);

            //    mTexID = new int[10];
            //    byte[] stipple = new byte[40];
            //    stipple[0] = 32;
            //    stipple[1] = 32;
            //    mTexID[0] = loadStippleTexture(stipple);

            //tex = new TextureItem(CanvasAdapter.getBitmapAsset("patterns/arrow.png"));
            //tex.mipmap = true;
        }
 
Example #16
Source File: AudioChannelWithSP.java    From Mp4Composer-android with MIT License 5 votes vote down vote up
private void writeToSonicSteam(final ShortBuffer data) {

        short[] temBuff = new short[data.capacity()];
        data.get(temBuff);
        data.rewind();
        stream.writeShortToStream(temBuff, temBuff.length / outputChannelCount);
    }
 
Example #17
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static ShortBuffer createShortBuffer(short... data) {
    if (data == null) {
        return null;
    }
    ShortBuffer buff = createShortBuffer(data.length);
    buff.clear();
    buff.put(data);
    buff.flip();
    return buff;
}
 
Example #18
Source File: PrimitiveShortArraySerializationProvider.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public short[] readField(final byte[] fieldData) {
  if ((fieldData == null) || (fieldData.length < 2)) {
    return null;
  }
  final ShortBuffer buff = ByteBuffer.wrap(fieldData).asShortBuffer();
  final short[] result = new short[buff.remaining()];
  buff.get(result);
  return result;
}
 
Example #19
Source File: ShortPointer.java    From tapir with MIT License 5 votes vote down vote up
/**
 * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers
 * backed with an array, allocates enough memory for the array and copies it.
 *
 * @param buffer the Buffer to reference or copy
 * @see #put(short[])
 */
public ShortPointer(ShortBuffer buffer) {
    super(buffer);
    if (buffer != null && buffer.hasArray()) {
        short[] array = buffer.array();
        allocateArray(array.length);
        put(array);
        position(buffer.position());
        limit(buffer.limit());
    }
}
 
Example #20
Source File: BufferUtils.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) {
	if (buffer == null || (buffer.remaining() < required)) {
		int position = (buffer != null ? buffer.position() : 0);
		ShortBuffer newVerts = createShortBuffer(position + required);
		if (buffer != null) {
			buffer.rewind();
			newVerts.put(buffer);
			newVerts.position(position);
		}
		buffer = newVerts;
	}
	return buffer;
}
 
Example #21
Source File: TrueTypeFont.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {

    if (ulSize == 0f && ulPos == 0f) {

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
            if (upem < 16 || upem > 16384) {
                upem = 2048;
            }
        }

        ByteBuffer os2_Table = getTableBuffer(os_2Tag);
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
    }

    metrics[offset] = stPos * pointSize;
    metrics[offset+1] = stSize * pointSize;

    metrics[offset+2] = ulPos * pointSize;
    metrics[offset+3] = ulSize * pointSize;
}
 
Example #22
Source File: IndexBuffer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static IndexBuffer wrapIndexBuffer(Buffer buf) {
    if (buf instanceof ByteBuffer) {
        return new IndexByteBuffer((ByteBuffer) buf);
    } else if (buf instanceof ShortBuffer) {
        return new IndexShortBuffer((ShortBuffer) buf);
    } else if (buf instanceof IntBuffer) {
        return new IndexIntBuffer((IntBuffer) buf);
    } else {
        throw new UnsupportedOperationException("Index buffer type unsupported: "+ buf.getClass());
    }
}
 
Example #23
Source File: VolumePostProcessor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public void process(long timecode, ShortBuffer buffer) throws InterruptedException {
  int currentVolume = context.playerOptions.volumeLevel.get();

  if (currentVolume != volumeProcessor.getLastVolume()) {
    AudioFrameVolumeChanger.apply(context);
  }

  // Volume 0 is stored in the frame with volume 100 buffer
  if (currentVolume != 0) {
    volumeProcessor.applyVolume(100, currentVolume, buffer);
  } else {
    volumeProcessor.setLastVolume(0);
  }
}
 
Example #24
Source File: Quad.java    From ShapesInOpenGLES2.0 with MIT License 5 votes vote down vote up
/**
 * creates buffers for Quad shape object
 * @param pos
 * @param widths
 */
public void createBuffers( float[] pos, float[] widths) {
    createVertexData(pos, widths);

    final FloatBuffer heightMapVertexDataBuffer = ByteBuffer
            .allocateDirect(aQuadVertexData.length * BYTES_PER_FLOAT).order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    heightMapVertexDataBuffer.put(aQuadVertexData).position(0);

    final ShortBuffer heightMapIndexDataBuffer = ByteBuffer
            .allocateDirect(aQuadIndexData.length * BYTES_PER_SHORT).order(ByteOrder.nativeOrder())
            .asShortBuffer();
    heightMapIndexDataBuffer.put(aQuadIndexData).position(0);

    if (qvbo[0] > 0 && qibo[0] > 0) {
        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, qvbo[0]);
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, heightMapVertexDataBuffer.capacity() * BYTES_PER_FLOAT,
                heightMapVertexDataBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, qibo[0]);
        GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, heightMapIndexDataBuffer.capacity()
                * BYTES_PER_SHORT, heightMapIndexDataBuffer, GLES20.GL_STATIC_DRAW);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    } else {
        GlUtil.checkGlError("glGenBuffers");
    }
}
 
Example #25
Source File: Gl_320_fbo_shadow.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        ShortBuffer elementBuffer = GLBuffers.newDirectShortBuffer(elementData);
        ByteBuffer vertexBuffer = GLBuffers.newDirectByteBuffer(vertexSize);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
        gl3.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementSize, elementBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        for (int i = 0; i < vertexCount; i++) {
            vertexData[i].toBb(vertexBuffer, i);
        }
        vertexBuffer.rewind();
        gl3.glBufferData(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL_STATIC_DRAW);
        gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

        int[] uniformBufferOffset = {0};
        gl3.glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, uniformBufferOffset, 0);
        int uniformBlockSize = Math.max(Mat4.SIZE * 3, uniformBufferOffset[0]);

        gl3.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl3.glBufferData(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_DYNAMIC_DRAW);
        gl3.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(vertexBuffer);

        return true;
    }
 
Example #26
Source File: TrueTypeFont.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
    if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
        stSize = .05f;
        stPos = -.4f;
        return;
    }
    ShortBuffer sb = os_2Table.asShortBuffer();
    stSize = sb.get(13) / (float)upem;
    stPos = -sb.get(14) / (float)upem;
}
 
Example #27
Source File: MonocleRobot.java    From Monocle with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Color getPixelColor(double x, double y) {
    Application.checkEventThread();
    NativeScreen screen = NativePlatformFactory.getNativePlatform().getScreen();
    final int byteDepth = screen.getDepth() >>> 3;
    final int bwidth = screen.getWidth();
    final int bheight = screen.getHeight();

    if (x < 0 || x > bwidth || y < 0 || y > bheight) {
        return GlassRobot.convertFromIntArgb(0);
    }

    synchronized (NativeScreen.framebufferSwapLock) {

        ByteBuffer buffer = screen.getScreenCapture();

        if (byteDepth == 2) {
            ShortBuffer shortbuf = buffer.asShortBuffer();

            int v = shortbuf.get((int) (y * bwidth) + (int) x);
            int red = (v & 0xF800) >> 11 << 3;
            int green = (v & 0x7E0) >> 5 << 2;
            int blue = (v & 0x1F) << 3;

            int p = (0xff000000
                    | (red << 16)
                    | (green << 8)
                    | blue);
            return GlassRobot.convertFromIntArgb(p);
        } else if (byteDepth >= 4) {
            IntBuffer intbuf = buffer.asIntBuffer();
            return GlassRobot.convertFromIntArgb(intbuf.get((int) (y * bwidth) + (int) x));
        } else {
            throw new RuntimeException("Unknown bit depth: " + byteDepth);
        }
    }
}
 
Example #28
Source File: TrueTypeFont.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void setStrikethroughMetrics(ByteBuffer os_2Table, int upem) {
    if (os_2Table == null || os_2Table.capacity() < 30 || upem < 0) {
        stSize = .05f;
        stPos = -.4f;
        return;
    }
    ShortBuffer sb = os_2Table.asShortBuffer();
    stSize = sb.get(13) / (float)upem;
    stPos = -sb.get(14) / (float)upem;
}
 
Example #29
Source File: TypedArrayFunctions.java    From es6draft with MIT License 5 votes vote down vote up
private static final ShortBuffer asShortBuffer(TypedArrayObject typedArray) {
    ByteBuffer data = byteBuffer(typedArray);
    int byteOffset = byteOffset(typedArray);
    int byteLength = byteLength(typedArray);

    data.limit(byteOffset + byteLength).position(byteOffset);
    ShortBuffer view = data.asShortBuffer();
    data.clear();
    return view;
}
 
Example #30
Source File: TrueTypeFont.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getStyleMetrics(float pointSize, float[] metrics, int offset) {

    if (ulSize == 0f && ulPos == 0f) {

        ByteBuffer head_Table = getTableBuffer(headTag);
        int upem = -1;
        if (head_Table != null && head_Table.capacity() >= 18) {
            ShortBuffer sb = head_Table.asShortBuffer();
            upem = sb.get(9) & 0xffff;
            if (upem < 16 || upem > 16384) {
                upem = 2048;
            }
        }

        ByteBuffer os2_Table = getTableBuffer(os_2Tag);
        setStrikethroughMetrics(os2_Table, upem);

        ByteBuffer post_Table = getTableBuffer(postTag);
        setUnderlineMetrics(post_Table, upem);
    }

    metrics[offset] = stPos * pointSize;
    metrics[offset+1] = stSize * pointSize;

    metrics[offset+2] = ulPos * pointSize;
    metrics[offset+3] = ulSize * pointSize;
}