Java Code Examples for java.nio.FloatBuffer#capacity()

The following examples show how to use java.nio.FloatBuffer#capacity() . 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: LibMatrixNative.java    From systemds with Apache License 2.0 6 votes vote down vote up
private static FloatBuffer toFloatBuffer(double[] input, ThreadLocal<FloatBuffer> buff, boolean copy) {
	//maintain thread-local buffer (resized on demand)
	FloatBuffer ret = buff.get();
	if( ret == null || ret.capacity() < input.length ) {
		ret = ByteBuffer.allocateDirect(4*input.length)
			.order(ByteOrder.nativeOrder()).asFloatBuffer();
		buff.set(ret);
	}
	//copy to direct byte buffer
	final FloatBuffer ret2 = ret;
	if( copy ) {
		IntStream.range(0, input.length).parallel()
			.forEach(i -> ret2.put(i, (float)input[i]));
	}
	return ret2;
}
 
Example 2
Source File: Mesh.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
public void scaleTextureCoordinates(Vector2f scaleFactor) {
	VertexBuffer tc = getBuffer(Type.TexCoord);
	if (tc == null) {
		throw new IllegalStateException("The mesh has no texture coordinates");
	}

	if (tc.getFormat() != VertexBuffer.Format.Float) {
		throw new UnsupportedOperationException("Only float texture coord format is supported");
	}

	if (tc.getNumComponents() != 2) {
		throw new UnsupportedOperationException("Only 2D texture coords are supported");
	}

	FloatBuffer fb = (FloatBuffer) tc.getData();
	fb.clear();
	for (int i = 0; i < fb.capacity() / 2; i++) {
		float x = fb.get();
		float y = fb.get();
		fb.position(fb.position() - 2);
		x *= scaleFactor.getX();
		y *= scaleFactor.getY();
		fb.put(x).put(y);
	}
	fb.clear();
}
 
Example 3
Source File: GeometrySimplifier.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean matchExactlyTheSame(GeometryData geometryDate, GeometryData d) {
	ByteBuffer bb1 = ByteBuffer.wrap(geometryDate.getVertices().getData());
	bb1.order(ByteOrder.LITTLE_ENDIAN);
	FloatBuffer buffer1 = bb1.asFloatBuffer();
	ByteBuffer bb2 = ByteBuffer.wrap(d.getVertices().getData());
	bb2.order(ByteOrder.LITTLE_ENDIAN);
	FloatBuffer buffer2 = bb2.asFloatBuffer();
	if (buffer1.capacity() != buffer2.capacity()) {
		return false;
	}
	for (int i=0; i<buffer1.capacity(); i++) {
		float a = buffer1.get();
		float b = buffer1.get();
		if (b != a) {
			return false;
		}
	}
	return true;
}
 
Example 4
Source File: FloatToFixed.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static void convertToUByte(FloatBuffer input, ByteBuffer output){
    if (output.capacity() < input.capacity())
        throw new RuntimeException("Output must be at least as large as input!");

    input.clear();
    output.clear();
    for (int i = 0; i < input.capacity(); i++){
        output.put( (byte) (input.get() * 255f) );
    }
    output.flip();
}
 
Example 5
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 6
Source File: GeometryRunner.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private ByteBuffer quantizeNormals(FloatBuffer normals) {
	ByteBuffer quantizedNormals = ByteBuffer.wrap(new byte[normals.capacity()]);
	quantizedNormals.order(ByteOrder.LITTLE_ENDIAN);
	for (int i=0; i<normals.capacity(); i++) {
		float normal = normals.get(i);
		quantizedNormals.put((byte)(normal * 127));
	}
	return quantizedNormals;
}
 
Example 7
Source File: JCudnnMnistUtils.java    From jcuda-samples with MIT License 5 votes vote down vote up
private static float[] readBinaryFileAsFloats(String fileName) 
    throws IOException
{
    FileInputStream fis = new FileInputStream(new File(fileName));
    byte data[] = readFully(fis);
    ByteBuffer bb = ByteBuffer.wrap(data);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    float result[] = new float[fb.capacity()];
    fb.get(result);
    return result;
}
 
Example 8
Source File: PointCloud.java    From ParaViewTangoRecorder with Apache License 2.0 5 votes vote down vote up
public synchronized void UpdatePoints(byte[] byteArray, int pointCount) {
    FloatBuffer mPointCloudFloatBuffer;
    mPointCloudFloatBuffer = ByteBuffer.wrap(byteArray)
            .order(ByteOrder.nativeOrder()).asFloatBuffer();
    mPointCount = pointCount;
    mVertexBuffer.clear();
    mVertexBuffer.position(0);
    mVertexBuffer.put(mPointCloudFloatBuffer);
    float totalZ = 0;
    for (int i = 0; i < mPointCloudFloatBuffer.capacity() - 3; i = i + 3) {
        totalZ = totalZ + mPointCloudFloatBuffer.get(i + 2);
    }
    mAverageZ = totalZ / mPointCount;
}
 
Example 9
Source File: Util.java    From fast-elasticsearch-vector-scoring with Apache License 2.0 5 votes vote down vote up
public static float[] convertBase64ToArray(String base64Str) {
    final byte[] decode = Base64.getDecoder().decode(base64Str.getBytes());
    final FloatBuffer floatBuffer = ByteBuffer.wrap(decode).asFloatBuffer();
    final float[] dims = new float[floatBuffer.capacity()];
    floatBuffer.get(dims);

    return dims;
}
 
Example 10
Source File: MDAbsHotspot.java    From MD360Player4Android with Apache License 2.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 11
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int[] jointIndices, float[] weights) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    FloatBuffer weightsBuffer = null;
    IntBuffer jointIndicesBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Weights
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        weightsBuffer = MemoryUtil.memAllocFloat(weights.length);
        weightsBuffer.put(weights).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, weightsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(3);
        glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);

        // Joint indices
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        jointIndicesBuffer = MemoryUtil.memAllocInt(jointIndices.length);
        jointIndicesBuffer.put(jointIndices).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, jointIndicesBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(4);
        glVertexAttribPointer(4, 4, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (weightsBuffer != null) {
            MemoryUtil.memFree(weightsBuffer);
        }
        if (jointIndicesBuffer != null) {
            MemoryUtil.memFree(jointIndicesBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 12
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static VertexData[] processTriangleFan(Mesh mesh,
        int[] index, Vector3f[] v, Vector2f[] t)
{
    IndexBuffer indexBuffer =  mesh.getIndexBuffer();
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();

    VertexData[] vertices = initVertexData(vertexBuffer.capacity() / 3);

    index[0] = indexBuffer.get(0);
    index[1] = indexBuffer.get(1);

    populateFromBuffer(v[0], vertexBuffer, index[0]);
    populateFromBuffer(v[1], vertexBuffer, index[1]);

    populateFromBuffer(t[0], textureBuffer, index[0]);
    populateFromBuffer(t[1], textureBuffer, index[1]);

    for (int i = 2; i < vertexBuffer.capacity() / 3; i++) {
        index[2] = indexBuffer.get(i);
        populateFromBuffer(v[2], vertexBuffer, index[2]);
        populateFromBuffer(t[2], textureBuffer, index[2]);

        TriangleData triData = processTriangle(index, v, t);
        if (triData != null) {
            vertices[index[0]].triangles.add(triData);
            vertices[index[1]].triangles.add(triData);
            vertices[index[2]].triangles.add(triData);
        }

        Vector3f vTemp = v[1];
        v[1] = v[2];
        v[2] = vTemp;

        Vector2f tTemp = t[1];
        t[1] = t[2];
        t[2] = tTemp;

        index[1] = index[2];
    }

    return vertices;
}
 
Example 13
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 14
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 15
Source File: Object3DData.java    From react-native-3d-model-view with MIT License 4 votes vote down vote up
public Object3DData centerAndScale(float maxSize) {
	float leftPt = Float.MAX_VALUE, rightPt = Float.MIN_VALUE; // on x-axis
	float topPt = Float.MIN_VALUE, bottomPt = Float.MAX_VALUE; // on y-axis
	float farPt = Float.MAX_VALUE, nearPt = Float.MIN_VALUE; // on z-axis

	 FloatBuffer vertexBuffer = getVertexArrayBuffer() != null ? getVertexArrayBuffer() : getVertexBuffer();
	if (vertexBuffer == null) {
		Log.v("Object3DData", "Scaling for '" + getId() + "' I found that there is no vertex data");
		return this;
	}

	Log.i("Object3DData", "Calculating dimensions for '" + getId() + "...");
	for (int i = 0; i < vertexBuffer.capacity(); i += 3) {
		if (vertexBuffer.get(i) > rightPt)
			rightPt = vertexBuffer.get(i);
		else if (vertexBuffer.get(i) < leftPt)
			leftPt = vertexBuffer.get(i);
		if (vertexBuffer.get(i + 1) > topPt)
			topPt = vertexBuffer.get(i + 1);
		else if (vertexBuffer.get(i + 1) < bottomPt)
			bottomPt = vertexBuffer.get(i + 1);
		if (vertexBuffer.get(i + 2) > nearPt)
			nearPt = vertexBuffer.get(i + 2);
		else if (vertexBuffer.get(i + 2) < farPt)
			farPt = vertexBuffer.get(i + 2);
	} // end
	Log.i("Object3DData", "Dimensions for '" + getId() + " (X left, X right): ("+leftPt+","+rightPt+")");
	Log.i("Object3DData", "Dimensions for '" + getId() + " (Y top, Y bottom): ("+topPt+","+bottomPt+")");
	Log.i("Object3DData", "Dimensions for '" + getId() + " (Z near, Z far): ("+nearPt+","+farPt+")");

	// calculate center of 3D object
	float xc = (rightPt + leftPt) / 2.0f;
	float yc = (topPt + bottomPt) / 2.0f;
	float zc = (nearPt + farPt) / 2.0f;

	// this.setOriginalPosition(new float[]{-xc,-yc,-zc});

	// calculate largest dimension
	float height = topPt - bottomPt;
	float depth = nearPt - farPt;
	float largest = rightPt - leftPt;
	if (height > largest)
		largest = height;
	if (depth > largest)
		largest = depth;
	Log.i("Object3DData", "Largest dimension ["+largest+"]");

	// scale object

	// calculate a scale factor
	float scaleFactor = 1.0f;
	// System.out.println("Largest dimension: " + largest);
	if (largest != 0.0f)
		scaleFactor = (maxSize / largest);
	Log.i("Object3DData",
			"Centering & scaling '" + getId() + "' to (" + xc + "," + yc + "," + zc + ") scale: '" + scaleFactor + "'");

	// this.setOriginalScale(new float[]{scaleFactor,scaleFactor,scaleFactor});

	// modify the model's vertices
	for (int i = 0; i < vertexBuffer.capacity(); i += 3) {
		float x = vertexBuffer.get(i);
		float y = vertexBuffer.get(i + 1);
		float z = vertexBuffer.get(i + 2);
		x = (x - xc) * scaleFactor;
		y = (y - yc) * scaleFactor;
		z = (z - zc) * scaleFactor;
		vertexBuffer.put(i, x);
		vertexBuffer.put(i + 1, y);
		vertexBuffer.put(i + 2, z);
	}

	return this;
}
 
Example 16
Source File: RangeDumpFloatColumnBinaryMaker.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public RangeFloatDicManager( final FloatBuffer dicBuffer ){
  this.dicBuffer = dicBuffer;
  dicLength = dicBuffer.capacity(); 
}
 
Example 17
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int[] jointIndices, float[] weights) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    FloatBuffer weightsBuffer = null;
    IntBuffer jointIndicesBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Weights
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        weightsBuffer = MemoryUtil.memAllocFloat(weights.length);
        weightsBuffer.put(weights).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, weightsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(3);
        glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);

        // Joint indices
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        jointIndicesBuffer = MemoryUtil.memAllocInt(jointIndices.length);
        jointIndicesBuffer.put(jointIndices).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, jointIndicesBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(4);
        glVertexAttribPointer(4, 4, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (weightsBuffer != null) {
            MemoryUtil.memFree(weightsBuffer);
        }
        if (jointIndicesBuffer != null) {
            MemoryUtil.memFree(jointIndicesBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 18
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int[] jointIndices, float[] weights) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    FloatBuffer weightsBuffer = null;
    IntBuffer jointIndicesBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Weights
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        weightsBuffer = MemoryUtil.memAllocFloat(weights.length);
        weightsBuffer.put(weights).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, weightsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(3);
        glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);

        // Joint indices
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        jointIndicesBuffer = MemoryUtil.memAllocInt(jointIndices.length);
        jointIndicesBuffer.put(jointIndices).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, jointIndicesBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(4);
        glVertexAttribPointer(4, 4, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (weightsBuffer != null) {
            MemoryUtil.memFree(weightsBuffer);
        }
        if (jointIndicesBuffer != null) {
            MemoryUtil.memFree(jointIndicesBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 19
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices, int[] jointIndices, float[] weights) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    FloatBuffer weightsBuffer = null;
    IntBuffer jointIndicesBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Weights
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        weightsBuffer = MemoryUtil.memAllocFloat(weights.length);
        weightsBuffer.put(weights).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, weightsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(3);
        glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);

        // Joint indices
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        jointIndicesBuffer = MemoryUtil.memAllocInt(jointIndices.length);
        jointIndicesBuffer.put(jointIndices).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, jointIndicesBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(4);
        glVertexAttribPointer(4, 4, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (weightsBuffer != null) {
            MemoryUtil.memFree(weightsBuffer);
        }
        if (jointIndicesBuffer != null) {
            MemoryUtil.memFree(jointIndicesBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}
 
Example 20
Source File: Mesh.java    From lwjglbook with Apache License 2.0 4 votes vote down vote up
public Mesh(float[] positions, float[] textCoords, float[] normals, int[] indices) {
    FloatBuffer posBuffer = null;
    FloatBuffer textCoordsBuffer = null;
    FloatBuffer vecNormalsBuffer = null;
    IntBuffer indicesBuffer = null;
    try {
        vertexCount = indices.length;
        vboIdList = new ArrayList<>();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        // Position VBO
        int vboId = glGenBuffers();
        vboIdList.add(vboId);
        posBuffer = MemoryUtil.memAllocFloat(positions.length);
        posBuffer.put(positions).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, posBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        // Texture coordinates VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        textCoordsBuffer = MemoryUtil.memAllocFloat(textCoords.length);
        textCoordsBuffer.put(textCoords).flip();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, textCoordsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(1);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        // Vertex normals VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        vecNormalsBuffer = MemoryUtil.memAllocFloat(normals.length);
        if (vecNormalsBuffer.capacity() > 0) {
            vecNormalsBuffer.put(normals).flip();
        } else {
            // Create empty structure
            vecNormalsBuffer = MemoryUtil.memAllocFloat(positions.length);
        }
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, vecNormalsBuffer, GL_STATIC_DRAW);
        glEnableVertexAttribArray(2);
        glVertexAttribPointer(2, 3, GL_FLOAT, false, 0, 0);

        // Index VBO
        vboId = glGenBuffers();
        vboIdList.add(vboId);
        indicesBuffer = MemoryUtil.memAllocInt(indices.length);
        indicesBuffer.put(indices).flip();
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL_STATIC_DRAW);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);
    } finally {
        if (posBuffer != null) {
            MemoryUtil.memFree(posBuffer);
        }
        if (textCoordsBuffer != null) {
            MemoryUtil.memFree(textCoordsBuffer);
        }
        if (vecNormalsBuffer != null) {
            MemoryUtil.memFree(vecNormalsBuffer);
        }
        if (indicesBuffer != null) {
            MemoryUtil.memFree(indicesBuffer);
        }
    }
}