java.nio.FloatBuffer Java Examples

The following examples show how to use java.nio.FloatBuffer. 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: BufferUtils.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new FloatBuffer with the same contents as the given FloatBuffer. The new FloatBuffer is seperate from the old one and changes are not reflected across. If you want to reflect changes,
 * consider using Buffer.duplicate().
 *
 * @param buf
 *            the FloatBuffer to copy
 * @return the copy
 */
public static FloatBuffer clone(FloatBuffer buf) {
	if (buf == null) {
		return null;
	}
	buf.rewind();

	FloatBuffer copy;
	if (buf.isDirect()) {
		copy = createFloatBuffer(buf.limit());
	}
	else {
		copy = FloatBuffer.allocate(buf.limit());
	}
	copy.put(buf);

	return copy;
}
 
Example #2
Source File: LwjglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Vector2f[] getFrameBufferSamplePositions(FrameBuffer fb) {
    if (fb.getSamples() <= 1) {
        throw new IllegalArgumentException("Framebuffer must be multisampled");
    }

    setFrameBuffer(fb);

    Vector2f[] samplePositions = new Vector2f[fb.getSamples()];
    FloatBuffer samplePos = BufferUtils.createFloatBuffer(2);
    for (int i = 0; i < samplePositions.length; i++) {
        glGetMultisample(GL_SAMPLE_POSITION, i, samplePos);
        samplePos.clear();
        samplePositions[i] = new Vector2f(samplePos.get(0) - 0.5f,
                samplePos.get(1) - 0.5f);
    }
    return samplePositions;
}
 
Example #3
Source File: Gl_420_texture_compressed.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initSampler(GL4 gl4) {

        FloatBuffer borderColor = GLBuffers.newDirectFloatBuffer(new float[]{0.0f, 0.0f, 0.0f, 0.0f});

        gl4.glGenSamplers(1, samplerName);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
        gl4.glSamplerParameterfv(samplerName.get(0), GL_TEXTURE_BORDER_COLOR, borderColor);
        gl4.glSamplerParameterf(samplerName.get(0), GL_TEXTURE_MIN_LOD, -1000.f);
        gl4.glSamplerParameterf(samplerName.get(0), GL_TEXTURE_MAX_LOD, 1000.f);
        gl4.glSamplerParameterf(samplerName.get(0), GL_TEXTURE_LOD_BIAS, 0.0f);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_COMPARE_MODE, GL_NONE);
        gl4.glSamplerParameteri(samplerName.get(0), GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

        BufferUtils.destroyDirectBuffer(borderColor);

        return true;
    }
 
Example #4
Source File: SmoothFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public FloatBuffer filter(float sx, float sy, float base, FloatBuffer buffer, int size) {
	float[] data = buffer.array();
	float[] retval = new float[data.length];

	for (int y = this.radius; y < size - this.radius; y++) {
		for (int x = this.radius; x < size - this.radius; x++) {
			int idx = y * size + x;
			float n = 0;
			for (int i = -this.radius; i < this.radius + 1; i++) {
				for (int j = -this.radius; j < this.radius + 1; j++) {
					n += data[(y + i) * size + x + j];
				}
			}
			retval[idx] = this.effect * n / (4 * this.radius * (this.radius + 1) + 1) + (1 - this.effect) * data[idx];
		}
	}

	return FloatBuffer.wrap(retval);
}
 
Example #5
Source File: Example3_3.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void init() {
	glClearColor(0, 0, 0, 0);
	
	program = new ShaderProgram(readFromFile("example3.3.vert"), readFromFile("example3.3.frag"));
	timeLocation = program.getUniformLocation("time");
	
	int loopDurationLocation = program.getUniformLocation("loopDuration");
	program.begin();
	glUniform1f(loopDurationLocation, 5);
	program.end();
	
	vbo = glGenBuffers();
	
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f, 0.25f, 0.0f, 1.0f,
			0.25f, -0.25f, 0.0f, 1.0f,
			-0.25f, -0.25f, 0.0f, 1.0f }).flip(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	
	// In core OpenGL, Vertex Array Objects (VAOs) are required for all draw calls. VAOs will be explained in Chapter 5.
	glBindVertexArray(glGenVertexArrays());
}
 
Example #6
Source File: Gl_440_sampler_wrap.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL4 gl4) {

        // Generate a buffer object
        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexData);
        gl4.glBufferStorage(GL_ARRAY_BUFFER, vertexSize, vertexBuffer, 0);
        BufferUtils.destroyDirectBuffer(vertexBuffer);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

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

        gl4.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.TRANSFORM));
        gl4.glBufferStorage(GL_UNIFORM_BUFFER, uniformBlockSize, null, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT
                | GL_MAP_COHERENT_BIT);
        gl4.glBindBuffer(GL_UNIFORM_BUFFER, 0);

        return checkError(gl4, "initBuffer");
    }
 
Example #7
Source File: Gl_320_query_occlusion.java    From jogl-samples with MIT License 6 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);
        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
        gl3.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, 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(positionBuffer);
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return checkError(gl3, "initBuffer");
    }
 
Example #8
Source File: Gl_320_fbo_blend_points.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffer(GL3 gl3) {

        FloatBuffer vertexBuffer = GLBuffers.newDirectFloatBuffer(vertexSize);
        for (Vertex_v4fc4f vertex : vertexData) {
            vertexBuffer.put(vertex.toFa_());
        }
        vertexBuffer.rewind();
        IntBuffer uniformBufferOffset = GLBuffers.newDirectIntBuffer(1);

        gl3.glGenBuffers(Buffer.MAX, bufferName);

        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(vertexBuffer);
        BufferUtils.destroyDirectBuffer(uniformBufferOffset);

        return true;
    }
 
Example #9
Source File: ShaderProgram.java    From lwjglbook with Apache License 2.0 5 votes vote down vote up
public void setUniform(String uniformName, Matrix4f[] matrices) {
    try (MemoryStack stack = MemoryStack.stackPush()) {
        int length = matrices != null ? matrices.length : 0;
        FloatBuffer fb = stack.mallocFloat(16 * length);
        for (int i = 0; i < length; i++) {
            matrices[i].get(16 * i, fb);
        }
        glUniformMatrix4fv(uniforms.get(uniformName), false, fb);
    }
}
 
Example #10
Source File: Geometry.java    From Tanks with MIT License 5 votes vote down vote up
public void updateData(FloatBuffer data, int trianglesCount, Vector3 position, Vector3 angles)
{
  if (mode != MeshMode.Dynamic)
    throw new IllegalStateException("not right mode");

  this.data = data;
  this.pointsCount = trianglesCount;
  this.position = position == null ? null : new Vector3(position);
  this.angles = angles == null ? null : new Vector3(angles);
}
 
Example #11
Source File: Mat3Test.java    From jglm with Apache License 2.0 5 votes vote down vote up
@Test
public void testIdentity() {
	Assert.assertTrue(Mat3.MAT3_IDENTITY.isIdentity());
	Assert.assertFalse(Mat3.MAT3_IDENTITY.isZero());
	
	Assert.assertEquals(Mat3.MAT3_IDENTITY, new Mat3(1f));
	Assert.assertTrue(new Mat3(1f).isIdentity());
	
	FloatBuffer buffer = Mat3.MAT3_IDENTITY.getBuffer();
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
	
	// Should be able to get a "fresh" buffer.
	buffer = Mat3.MAT3_IDENTITY.getBuffer();
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(0f, buffer.get());
	JglmTesting.assertFloatsEqualDefaultTol(1f, buffer.get());
}
 
Example #12
Source File: Device.java    From KinectPV2 with MIT License 5 votes vote down vote up
/**
 * Get Point Cloud Color Positions as a FloatBuffer, transform to a float array with .array(), or get values with get(index)
 * @return FloatBuffer
 */
public FloatBuffer getPointCloudColorPos() {
	float[] pcRawData = jniGetPointCloudColorMap();
	pointCloudColorPos.put(pcRawData, 0, WIDTHColor * HEIGHTColor * 3);
	pointCloudColorPos.rewind();

	return pointCloudColorPos;
}
 
Example #13
Source File: Example17_3.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public FloatBuffer toBuffer() {
	buffer.clear();
	buffer.put(ambientIntensity.toBuffer());
	buffer.put(lightAttenuation);
	buffer.put(maxIntensity);
	buffer.put(padding);
	
	for(PerLight light : lights)
		if(light != null)
			buffer.put(light.toBuffer());
	
	buffer.flip();
	
	return buffer;
}
 
Example #14
Source File: GPUImageFilter.java    From sealrtc-android with MIT License 5 votes vote down vote up
protected void setFloatVec4(final int location, final float[] arrayValue) {
    runOnDraw(
            new Runnable() {
                @Override
                public void run() {
                    GLES20.glUniform4fv(location, 1, FloatBuffer.wrap(arrayValue));
                }
            });
}
 
Example #15
Source File: Gl_400_draw_indirect.java    From jogl-samples with MIT License 5 votes vote down vote up
private boolean initBuffers(GL4 gl4) {

        command = new DrawElementsIndirectCommand(elementCount, 1, 0, 0, 0);
        IntBuffer commandBuffer = GLBuffers.newDirectIntBuffer(command.toIa_());
        FloatBuffer positionBuffer = GLBuffers.newDirectFloatBuffer(positionData);
        IntBuffer elementBuffer = GLBuffers.newDirectIntBuffer(elementData);

        gl4.glGenBuffers(Buffer.MAX, bufferName);

        gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, bufferName.get(Buffer.INDIRECT));
        gl4.glBufferData(GL_DRAW_INDIRECT_BUFFER, command.SIZE, commandBuffer, GL_STATIC_READ);
        gl4.glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);

        gl4.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.ARRAY));
        gl4.glBufferData(GL_ARRAY_BUFFER, positionSize, positionBuffer, GL_STATIC_DRAW);
        gl4.glBindBuffer(GL_ARRAY_BUFFER, 0);

        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);

        BufferUtils.destroyDirectBuffer(positionBuffer);
        BufferUtils.destroyDirectBuffer(elementBuffer);
        BufferUtils.destroyDirectBuffer(commandBuffer);

        return checkError(gl4, "initBuffers");
    }
 
Example #16
Source File: NDArrayTests.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T convert(NDArray from, Class<T> to) {
    Preconditions.checkState(canConvert(from, to));
    SerializedNDArray s = (SerializedNDArray)from.get();
    FloatBuffer fb = s.getBuffer().asFloatBuffer();
    int len = fb.capacity();
    float[] out = new float[len];
    fb.get(out);
    return (T) new TestNDArrayObject(out);
}
 
Example #17
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Ensures there is at least the <code>required</code> number of entries left after the current position of the
 * buffer. If the buffer is too small a larger one is created and the old one copied to the new buffer.
 * @param buffer buffer that should be checked/copied (may be null)
 * @param required minimum number of elements that should be remaining in the returned buffer
 * @return a buffer large enough to receive at least the <code>required</code> number of entries, same position as
 * the input buffer, not null
 */
public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, int required) {
    if (buffer == null || (buffer.remaining() < required)) {
        int position = (buffer != null ? buffer.position() : 0);
        FloatBuffer newVerts = createFloatBuffer(position + required);
        if (buffer != null) {
            buffer.rewind();
            newVerts.put(buffer);
            newVerts.position(position);
        }
        buffer = newVerts;
    }
    return buffer;
}
 
Example #18
Source File: Example13_2.java    From LWJGL-OpenGL-Tutorials with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public FloatBuffer toBuffer() {
	buffer.clear();
	buffer.put(cameraSpaceLightPos.toBuffer());
	buffer.put(lightIntensity.toBuffer());
	buffer.flip();
	return buffer;
}
 
Example #19
Source File: GpuFloatBuffer.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
void ensureCapacity(int size)
{
	while (buffer.remaining() < size)
	{
		FloatBuffer newB = allocateDirect(buffer.capacity() * 2);
		buffer.flip();
		newB.put(buffer);
		buffer = newB;
	}
}
 
Example #20
Source File: TypedArrayFunctions.java    From es6draft with MIT License 5 votes vote down vote up
private static final FloatBuffer asFloatBuffer(ArrayBuffer buffer, int byteOffset, int length) {
    ByteBuffer data = byteBuffer(buffer);
    int byteLength = Float.BYTES * length;

    data.limit(byteOffset + byteLength).position(byteOffset);
    FloatBuffer view = data.asFloatBuffer();
    data.clear();
    return view;
}
 
Example #21
Source File: WaveformVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onRenderAudioData(
        GL10 gl, int width, int height,
        Object workObj, CapturedDataHolder data) {
    final RenderThreadWork work = (RenderThreadWork) workObj;

    // NOTE:
    // Increase the SKIP value if the visualization is too heavy
    // on your device

    final int SKIP = 1;
    final byte[] waveform = data.mByteData;
    final int N = waveform.length / SKIP;

    // 2: (x, 2)
    final int workBufferSize = N * 2;
    boolean needToUpdateX = false;

    // prepare working buffer
    if (work.mWorkFloatBuffer == null || work.mWorkFloatBuffer.length < workBufferSize) {
        work.mWorkFloatBuffer = new float[workBufferSize];
        work.mNativeFloatBuffer = allocateNativeFloatBuffer(workBufferSize);
        needToUpdateX |= true;
    }

    final float[] points = work.mWorkFloatBuffer;
    final FloatBuffer pointsBuffer = work.mNativeFloatBuffer;

    needToUpdateX |= (width != work.prevCanvasWidth);
    work.prevCanvasWidth = width;

    if (needToUpdateX) {
        makeXPointPositionData(N, points);
    }

    makeYPointPositionData(waveform, N, SKIP, 0, points);
    converToFloatBuffer(pointsBuffer, points, (2 * N));
    drawWaveForm(gl, width, height, pointsBuffer, N, (0.0f - 1.0f), (255.0f + 1.0f),
            work.mColor);
}
 
Example #22
Source File: BufferUtil.java    From Lwjgl3-Game-Engine-Programming-Series with MIT License 5 votes vote down vote up
public static FloatBuffer createFlippedBufferSOA(Vertex[] vertices)
{
	FloatBuffer buffer = createFloatBuffer(vertices.length * Vertex.FLOATS);
	
	for(int i = 0; i < vertices.length; i++)
	{
		buffer.put(vertices[i].getPos().getX());
		buffer.put(vertices[i].getPos().getY());
		buffer.put(vertices[i].getPos().getZ());
	}
	
	for(int i = 0; i < vertices.length; i++)
	{
		buffer.put(vertices[i].getNormal().getX());
		buffer.put(vertices[i].getNormal().getY());
		buffer.put(vertices[i].getNormal().getZ());
	}
		
	for(int i = 0; i < vertices.length; i++)
	{
		buffer.put(vertices[i].getTextureCoord().getX());
		buffer.put(vertices[i].getTextureCoord().getY());
	}	
	
	buffer.flip();
	
	return buffer;
}
 
Example #23
Source File: MatrixTrackingGL.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
public void glLoadMatrixf(FloatBuffer m) {
    int position = m.position();
    mCurrent.glLoadMatrixf(m);
    m.position(position);
    mgl.glLoadMatrixf(m);
    if ( _check) check();
}
 
Example #24
Source File: Uniform.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setVector4InArray(float x, float y, float z, float w, int index){
    if (location == -1)
        return;

    if (varType != null && varType != VarType.Vector4Array)
        throw new IllegalArgumentException("Expected a "+varType.name()+" value!");

    FloatBuffer fb = (FloatBuffer) value;
    fb.position(index * 4);
    fb.put(x).put(y).put(z).put(w);
    fb.rewind();
    updateNeeded = true;
    setByCurrentMaterial = true;
}
 
Example #25
Source File: Vec4.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
public FloatBuffer toDfb(FloatBuffer fb, int index) {
    return fb
            .put(index + 0, x)
            .put(index + 1, y)
            .put(index + 2, z)
            .put(index + 3, w);
}
 
Example #26
Source File: MDAbsHotspot.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
@Override
public MDHitPoint hit(MDRay ray) {
    if (object3D == null || object3D.getVerticesBuffer(0) == null){
        return MDHitPoint.notHit();
    }

    MDPosition position = getModelPosition();
    float[] model = position.getMatrix();

    List<MDVector3D> points = new LinkedList<>();

    FloatBuffer buffer = object3D.getVerticesBuffer(0);
    int numPoints = buffer.capacity() / 3;

    for (int i = 0; i < numPoints; i++){
        MDVector3D v = new MDVector3D();
        v.setX(buffer.get(i * 3)).setY(buffer.get(i * 3 + 1)).setZ(buffer.get(i * 3 + 2));
        v.multiplyMV(model);
        points.add(v);
    }
    MDHitPoint hit1 = hitPoint1;
    MDHitPoint hit2 = hitPoint2;
    if (points.size() == 4){
        VRUtil.intersectTriangle(ray, points.get(0), points.get(1), points.get(2), hitPoint1);
        VRUtil.intersectTriangle(ray, points.get(3), points.get(2), points.get(1), hitPoint2);
    }

    return MDHitPoint.min(hit1, hit2);
}
 
Example #27
Source File: Device.java    From KinectPV2 with MIT License 5 votes vote down vote up
/**
 * Get Point Cloud Color Positions as a FloatBuffer, transform to a float array with .array(), or get values with get(index)
 * @return FloatBuffer
 */
public FloatBuffer getPointCloudColorPos() {
	float[] pcRawData = jniGetPointCloudColorMap();
	pointCloudColorPos.put(pcRawData, 0, WIDTHColor * HEIGHTColor * 3);
	pointCloudColorPos.rewind();

	return pointCloudColorPos;
}
 
Example #28
Source File: GPUImageFilter.java    From TikTok with Apache License 2.0 5 votes vote down vote up
public int onDrawFrame(final int textureId, final FloatBuffer cubeBuffer,
                   final FloatBuffer textureBuffer) {
    GLES20.glUseProgram(mGLProgId);
    runPendingOnDrawTasks();
    if (!mIsInitialized) {
        return OpenGlUtils.NOT_INIT;
    }

    cubeBuffer.position(0);
    GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribPosition);
    textureBuffer.position(0);
    GLES20.glVertexAttribPointer(mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0,
            textureBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate);
    if (textureId != OpenGlUtils.NO_TEXTURE) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
        GLES20.glUniform1i(mGLUniformTexture, 0);
    }
    onDrawArraysPre();
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(mGLAttribPosition);
    GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate);
    onDrawArraysAfter();
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    return OpenGlUtils.ON_DRAWN;
}
 
Example #29
Source File: Gl_320_fbo_srgb.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);

        return true;
    }
 
Example #30
Source File: Arrow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Sets the arrow's extent.
     * This will modify the buffers on the mesh.
     * 
     * @param extent the arrow's extent.
     */
    public void setArrowExtent(Vector3f extent) {
        float len = extent.length();
//        Vector3f dir = extent.normalize();

        tempQuat.lookAt(extent, Vector3f.UNIT_Y);
        tempQuat.normalizeLocal();

        VertexBuffer pvb = getBuffer(Type.Position);
        FloatBuffer buffer = (FloatBuffer)pvb.getData(); 
        buffer.rewind();
        for (int i = 0; i < positions.length; i += 3) {
            Vector3f vec = tempVec.set(positions[i],
                    positions[i + 1],
                    positions[i + 2]);
            vec.multLocal(len);
            tempQuat.mult(vec, vec);

            buffer.put(vec.x);
            buffer.put(vec.y);
            buffer.put(vec.z);
        }
        
        pvb.updateData(buffer);

        updateBound();
        updateCounts();
    }